fix: 修复配额说明重复和undefined问题

- 在editStorageForm中初始化oss_storage_quota_value和oss_quota_unit
- 删除重复的旧配额说明块,保留新的当前配额设置显示

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-22 19:39:53 +08:00
commit 4350113979
7649 changed files with 897277 additions and 0 deletions

View File

@@ -0,0 +1 @@
export const CONFIG_PREFIX_SEPARATOR = ".";

View File

@@ -0,0 +1,16 @@
import { tokenIntercept } from "./getSSOTokenFromFile";
import { fileIntercept } from "./readFile";
export const externalDataInterceptor = {
getFileRecord() {
return fileIntercept;
},
interceptFile(path, contents) {
fileIntercept[path] = Promise.resolve(contents);
},
getTokenRecord() {
return tokenIntercept;
},
interceptToken(id, contents) {
tokenIntercept[id] = contents;
},
};

View File

@@ -0,0 +1,18 @@
import { IniSectionType } from "@smithy/types";
import { CONFIG_PREFIX_SEPARATOR } from "./constants";
export const getConfigData = (data) => Object.entries(data)
.filter(([key]) => {
const indexOfSeparator = key.indexOf(CONFIG_PREFIX_SEPARATOR);
if (indexOfSeparator === -1) {
return false;
}
return Object.values(IniSectionType).includes(key.substring(0, indexOfSeparator));
})
.reduce((acc, [key, value]) => {
const indexOfSeparator = key.indexOf(CONFIG_PREFIX_SEPARATOR);
const updatedKey = key.substring(0, indexOfSeparator) === IniSectionType.PROFILE ? key.substring(indexOfSeparator + 1) : key;
acc[updatedKey] = value;
return acc;
}, {
...(data.default && { default: data.default }),
});

View File

@@ -0,0 +1,4 @@
import { join } from "path";
import { getHomeDir } from "./getHomeDir";
export const ENV_CONFIG_PATH = "AWS_CONFIG_FILE";
export const getConfigFilepath = () => process.env[ENV_CONFIG_PATH] || join(getHomeDir(), ".aws", "config");

View File

@@ -0,0 +1,4 @@
import { join } from "path";
import { getHomeDir } from "./getHomeDir";
export const ENV_CREDENTIALS_PATH = "AWS_SHARED_CREDENTIALS_FILE";
export const getCredentialsFilepath = () => process.env[ENV_CREDENTIALS_PATH] || join(getHomeDir(), ".aws", "credentials");

View File

@@ -0,0 +1,22 @@
import { homedir } from "os";
import { sep } from "path";
const homeDirCache = {};
const getHomeDirCacheKey = () => {
if (process && process.geteuid) {
return `${process.geteuid()}`;
}
return "DEFAULT";
};
export const getHomeDir = () => {
const { HOME, USERPROFILE, HOMEPATH, HOMEDRIVE = `C:${sep}` } = process.env;
if (HOME)
return HOME;
if (USERPROFILE)
return USERPROFILE;
if (HOMEPATH)
return `${HOMEDRIVE}${HOMEPATH}`;
const homeDirCacheKey = getHomeDirCacheKey();
if (!homeDirCache[homeDirCacheKey])
homeDirCache[homeDirCacheKey] = homedir();
return homeDirCache[homeDirCacheKey];
};

View File

@@ -0,0 +1,3 @@
export const ENV_PROFILE = "AWS_PROFILE";
export const DEFAULT_PROFILE = "default";
export const getProfileName = (init) => init.profile || process.env[ENV_PROFILE] || DEFAULT_PROFILE;

View File

@@ -0,0 +1,8 @@
import { createHash } from "crypto";
import { join } from "path";
import { getHomeDir } from "./getHomeDir";
export const getSSOTokenFilepath = (id) => {
const hasher = createHash("sha1");
const cacheName = hasher.update(id).digest("hex");
return join(getHomeDir(), ".aws", "sso", "cache", `${cacheName}.json`);
};

View File

@@ -0,0 +1,11 @@
import { readFile } from "fs/promises";
import { getSSOTokenFilepath } from "./getSSOTokenFilepath";
export const tokenIntercept = {};
export const getSSOTokenFromFile = async (id) => {
if (tokenIntercept[id]) {
return tokenIntercept[id];
}
const ssoTokenFilepath = getSSOTokenFilepath(id);
const ssoTokenText = await readFile(ssoTokenFilepath, "utf8");
return JSON.parse(ssoTokenText);
};

View File

@@ -0,0 +1,5 @@
import { IniSectionType } from "@smithy/types";
import { CONFIG_PREFIX_SEPARATOR } from "./loadSharedConfigFiles";
export const getSsoSessionData = (data) => Object.entries(data)
.filter(([key]) => key.startsWith(IniSectionType.SSO_SESSION + CONFIG_PREFIX_SEPARATOR))
.reduce((acc, [key, value]) => ({ ...acc, [key.substring(key.indexOf(CONFIG_PREFIX_SEPARATOR) + 1)]: value }), {});

View File

@@ -0,0 +1,10 @@
export * from "./getHomeDir";
export * from "./getProfileName";
export * from "./getSSOTokenFilepath";
export { getSSOTokenFromFile } from "./getSSOTokenFromFile";
export * from "./loadSharedConfigFiles";
export * from "./loadSsoSessionData";
export * from "./parseKnownFiles";
export { externalDataInterceptor } from "./externalDataInterceptor";
export * from "./types";
export { readFile } from "./readFile";

View File

@@ -0,0 +1,39 @@
import { join } from "path";
import { getConfigData } from "./getConfigData";
import { getConfigFilepath } from "./getConfigFilepath";
import { getCredentialsFilepath } from "./getCredentialsFilepath";
import { getHomeDir } from "./getHomeDir";
import { parseIni } from "./parseIni";
import { readFile } from "./readFile";
const swallowError = () => ({});
export { CONFIG_PREFIX_SEPARATOR } from "./constants";
export const loadSharedConfigFiles = async (init = {}) => {
const { filepath = getCredentialsFilepath(), configFilepath = getConfigFilepath() } = init;
const homeDir = getHomeDir();
const relativeHomeDirPrefix = "~/";
let resolvedFilepath = filepath;
if (filepath.startsWith(relativeHomeDirPrefix)) {
resolvedFilepath = join(homeDir, filepath.slice(2));
}
let resolvedConfigFilepath = configFilepath;
if (configFilepath.startsWith(relativeHomeDirPrefix)) {
resolvedConfigFilepath = join(homeDir, configFilepath.slice(2));
}
const parsedFiles = await Promise.all([
readFile(resolvedConfigFilepath, {
ignoreCache: init.ignoreCache,
})
.then(parseIni)
.then(getConfigData)
.catch(swallowError),
readFile(resolvedFilepath, {
ignoreCache: init.ignoreCache,
})
.then(parseIni)
.catch(swallowError),
]);
return {
configFile: parsedFiles[0],
credentialsFile: parsedFiles[1],
};
};

View File

@@ -0,0 +1,9 @@
import { getConfigFilepath } from "./getConfigFilepath";
import { getSsoSessionData } from "./getSsoSessionData";
import { parseIni } from "./parseIni";
import { readFile } from "./readFile";
const swallowError = () => ({});
export const loadSsoSessionData = async (init = {}) => readFile(init.configFilepath ?? getConfigFilepath())
.then(parseIni)
.then(getSsoSessionData)
.catch(swallowError);

View File

@@ -0,0 +1,14 @@
export const mergeConfigFiles = (...files) => {
const merged = {};
for (const file of files) {
for (const [key, values] of Object.entries(file)) {
if (merged[key] !== undefined) {
Object.assign(merged[key], values);
}
else {
merged[key] = values;
}
}
}
return merged;
};

View File

@@ -0,0 +1,52 @@
import { IniSectionType } from "@smithy/types";
import { CONFIG_PREFIX_SEPARATOR } from "./constants";
const prefixKeyRegex = /^([\w-]+)\s(["'])?([\w-@\+\.%:/]+)\2$/;
const profileNameBlockList = ["__proto__", "profile __proto__"];
export const parseIni = (iniData) => {
const map = {};
let currentSection;
let currentSubSection;
for (const iniLine of iniData.split(/\r?\n/)) {
const trimmedLine = iniLine.split(/(^|\s)[;#]/)[0].trim();
const isSection = trimmedLine[0] === "[" && trimmedLine[trimmedLine.length - 1] === "]";
if (isSection) {
currentSection = undefined;
currentSubSection = undefined;
const sectionName = trimmedLine.substring(1, trimmedLine.length - 1);
const matches = prefixKeyRegex.exec(sectionName);
if (matches) {
const [, prefix, , name] = matches;
if (Object.values(IniSectionType).includes(prefix)) {
currentSection = [prefix, name].join(CONFIG_PREFIX_SEPARATOR);
}
}
else {
currentSection = sectionName;
}
if (profileNameBlockList.includes(sectionName)) {
throw new Error(`Found invalid profile name "${sectionName}"`);
}
}
else if (currentSection) {
const indexOfEqualsSign = trimmedLine.indexOf("=");
if (![0, -1].includes(indexOfEqualsSign)) {
const [name, value] = [
trimmedLine.substring(0, indexOfEqualsSign).trim(),
trimmedLine.substring(indexOfEqualsSign + 1).trim(),
];
if (value === "") {
currentSubSection = name;
}
else {
if (currentSubSection && iniLine.trimStart() === iniLine) {
currentSubSection = undefined;
}
map[currentSection] = map[currentSection] || {};
const key = currentSubSection ? [currentSubSection, name].join(CONFIG_PREFIX_SEPARATOR) : name;
map[currentSection][key] = value;
}
}
}
}
return map;
};

View File

@@ -0,0 +1,6 @@
import { loadSharedConfigFiles } from "./loadSharedConfigFiles";
import { mergeConfigFiles } from "./mergeConfigFiles";
export const parseKnownFiles = async (init) => {
const parsedFiles = await loadSharedConfigFiles(init);
return mergeConfigFiles(parsedFiles.configFile, parsedFiles.credentialsFile);
};

View File

@@ -0,0 +1,12 @@
import { readFile as fsReadFile } from "node:fs/promises";
export const filePromises = {};
export const fileIntercept = {};
export const readFile = (path, options) => {
if (fileIntercept[path] !== undefined) {
return fileIntercept[path];
}
if (!filePromises[path] || options?.ignoreCache) {
filePromises[path] = fsReadFile(path, "utf8");
}
return filePromises[path];
};

View File

@@ -0,0 +1 @@
export {};