配置改为数据库存储
将运行时 JSON 配置迁入 app_config_entries,启动时从文件导入并删除源文件。
This commit is contained in:
@@ -178,28 +178,28 @@ export function getAdminCloudtentaclesOverrideRules() {
|
||||
};
|
||||
}
|
||||
|
||||
export function updateAdminCloudtentaclesOverrideRules(
|
||||
export async function updateAdminCloudtentaclesOverrideRules(
|
||||
payload: AdminCloudtentaclesOverrideRuleConfigInput = {}
|
||||
) {
|
||||
return {
|
||||
filePath: getCloudtentaclesOverrideRuleFilePath(),
|
||||
...saveCloudtentaclesOverrideRuleConfig(payload),
|
||||
...(await saveCloudtentaclesOverrideRuleConfig(payload)),
|
||||
};
|
||||
}
|
||||
|
||||
export function updateAdminCloudtentaclesSourceConfig(
|
||||
export async function updateAdminCloudtentaclesSourceConfig(
|
||||
payload: AdminCloudtentaclesSourceConfigInput = {}
|
||||
) {
|
||||
// Batch save: if payload.sources is an array, save the whole list
|
||||
// 批量保存:payload.sources 是数组时替换整份账号列表。
|
||||
if (Array.isArray(payload.sources)) {
|
||||
const normalizedList = payload.sources.map((item) =>
|
||||
normalizeAdminCloudtentaclesSourceConfigPayload(item)
|
||||
);
|
||||
const savedList = saveCloudtentaclesSourcesList({
|
||||
const savedList = await saveCloudtentaclesSourcesList({
|
||||
enabled: payload.enabled !== false,
|
||||
sources: normalizedList,
|
||||
});
|
||||
const sessions = pruneCloudtentaclesSessionStates(
|
||||
const sessions = await pruneCloudtentaclesSessionStates(
|
||||
normalizedList.map((item) => item.key)
|
||||
);
|
||||
|
||||
@@ -220,20 +220,20 @@ export function updateAdminCloudtentaclesSourceConfig(
|
||||
};
|
||||
}
|
||||
|
||||
// Single source save
|
||||
// 单账号保存。
|
||||
const sourceKey = String(payload.sourceKey || "").trim() || "default";
|
||||
const current = getCloudtentaclesSourceByKey(sourceKey);
|
||||
const normalized = normalizeAdminCloudtentaclesSourceConfigPayload({
|
||||
...payload,
|
||||
sourceKey,
|
||||
});
|
||||
const saved = saveCloudtentaclesSourceByKey(sourceKey, normalized);
|
||||
const saved = await saveCloudtentaclesSourceByKey(sourceKey, normalized);
|
||||
const shouldClearSession = hasCloudtentaclesCredentialContextChanged(
|
||||
current || undefined,
|
||||
saved
|
||||
);
|
||||
const session = shouldClearSession
|
||||
? (clearCloudtentaclesSessionStateByKey(sourceKey),
|
||||
? (await clearCloudtentaclesSessionStateByKey(sourceKey),
|
||||
getCloudtentaclesSessionStateByKey(sourceKey))
|
||||
: getCloudtentaclesSessionStateByKey(sourceKey);
|
||||
|
||||
@@ -245,7 +245,7 @@ export function updateAdminCloudtentaclesSourceConfig(
|
||||
};
|
||||
}
|
||||
|
||||
export function deleteAdminCloudtentaclesSource(sourceKey: string) {
|
||||
export async function deleteAdminCloudtentaclesSource(sourceKey: string) {
|
||||
const key = String(sourceKey || "").trim();
|
||||
if (!key) {
|
||||
throw createHttpError("cloudtentacles sourceKey 不能为空", {
|
||||
@@ -253,8 +253,8 @@ export function deleteAdminCloudtentaclesSource(sourceKey: string) {
|
||||
errorCode: "cloudtentacles_source_key_required",
|
||||
});
|
||||
}
|
||||
deleteCloudtentaclesSessionStateByKey(key);
|
||||
deleteCloudtentaclesSourceByKey(key);
|
||||
await deleteCloudtentaclesSessionStateByKey(key);
|
||||
await deleteCloudtentaclesSourceByKey(key);
|
||||
}
|
||||
|
||||
export async function sendAdminCloudtentaclesSmsCode(
|
||||
@@ -283,7 +283,7 @@ export async function testAdminCloudtentaclesLogin(
|
||||
...credentialContext,
|
||||
code: String(payload.code || "").trim(),
|
||||
});
|
||||
const savedSession = saveCloudtentaclesSessionStateByKey(
|
||||
const savedSession = await saveCloudtentaclesSessionStateByKey(
|
||||
sourceKey,
|
||||
buildAdminCloudtentaclesPersistedSessionPayload(session, {
|
||||
deviceId: credentialContext.deviceId,
|
||||
@@ -305,7 +305,7 @@ export async function validateAdminCloudtentaclesSession(
|
||||
persistedSession,
|
||||
});
|
||||
const session = await validateCloudtentaclesSession(sessionContext);
|
||||
const savedSession = saveCloudtentaclesSessionStateByKey(
|
||||
const savedSession = await saveCloudtentaclesSessionStateByKey(
|
||||
sourceKey,
|
||||
buildAdminCloudtentaclesPersistedSessionPayload(session, {
|
||||
username: pickFirstNonEmpty([
|
||||
|
||||
@@ -14,10 +14,10 @@ export function getAdminFulfillmentRoutingConfig() {
|
||||
}
|
||||
}
|
||||
|
||||
export function updateAdminFulfillmentRoutingConfig(payload: JsonRecord = {}) {
|
||||
export async function updateAdminFulfillmentRoutingConfig(payload: JsonRecord = {}) {
|
||||
return {
|
||||
filePath: getFulfillmentRoutingConfigFilePath(),
|
||||
...saveFulfillmentRoutingConfig(payload),
|
||||
...(await saveFulfillmentRoutingConfig(payload)),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,8 +29,8 @@ export function getAdminKuaishouFeifeiConfig() {
|
||||
}
|
||||
}
|
||||
|
||||
export function updateAdminKuaishouFeifeiConfig(payload: JsonObject = {}) {
|
||||
const saved = saveKuaishouFeifeiSourceConfig(payload)
|
||||
export async function updateAdminKuaishouFeifeiConfig(payload: JsonObject = {}) {
|
||||
const saved = await saveKuaishouFeifeiSourceConfig(payload)
|
||||
const effective = getKuaishouFeifeiConfig()
|
||||
|
||||
return {
|
||||
@@ -92,7 +92,7 @@ export async function syncAdminKuaishouFeifeiProductRules(payload: JsonObject =
|
||||
}
|
||||
})
|
||||
.filter((rule): rule is NonNullable<typeof rule> => Boolean(rule))
|
||||
const saved = saveKuaishouFeifeiSourceConfig({
|
||||
const saved = await saveKuaishouFeifeiSourceConfig({
|
||||
...source,
|
||||
productRules,
|
||||
})
|
||||
|
||||
@@ -35,9 +35,9 @@ export function getAdminKuaishouIndustrySourceConfig() {
|
||||
}
|
||||
}
|
||||
|
||||
export function updateAdminKuaishouIndustrySourceConfig(payload: JsonObject = {}) {
|
||||
export async function updateAdminKuaishouIndustrySourceConfig(payload: JsonObject = {}) {
|
||||
const current = getKuaishouIndustrySourceConfig()
|
||||
const saved = saveKuaishouIndustrySourceConfig({
|
||||
const saved = await saveKuaishouIndustrySourceConfig({
|
||||
...current,
|
||||
enabled: hasPayloadField(payload, 'enabled') ? payload.enabled !== false : current.enabled !== false,
|
||||
baseUrl: readConfigString(payload, 'baseUrl', current.baseUrl),
|
||||
|
||||
@@ -35,8 +35,8 @@ export function getAdminNotificationConfig() {
|
||||
}
|
||||
}
|
||||
|
||||
export function updateAdminNotificationConfig(payload: AdminNotificationConfigInput = {}) {
|
||||
const saved = saveNotificationConfig(payload)
|
||||
export async function updateAdminNotificationConfig(payload: AdminNotificationConfigInput = {}) {
|
||||
const saved = await saveNotificationConfig(payload)
|
||||
|
||||
return {
|
||||
filePath: getNotificationConfigFilePath(),
|
||||
@@ -64,8 +64,8 @@ export function getAdminScheduledJobsConfig() {
|
||||
}
|
||||
}
|
||||
|
||||
export function updateAdminScheduledJobsConfig(payload: AdminScheduledJobsConfigInput = {}) {
|
||||
const saved = saveScheduledJobsConfig(payload)
|
||||
export async function updateAdminScheduledJobsConfig(payload: AdminScheduledJobsConfigInput = {}) {
|
||||
const saved = await saveScheduledJobsConfig(payload)
|
||||
reloadScheduledJobs()
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user