优化 cloudtentacles 多账号管理与任务展示
This commit is contained in:
@@ -65,6 +65,23 @@ export function saveCloudtentaclesSessionStateByKey(sourceKey: unknown, rawValue
|
||||
return states.sessions[key]
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a session by sourceKey.
|
||||
*/
|
||||
export function deleteCloudtentaclesSessionStateByKey(sourceKey: unknown) {
|
||||
const key = String(sourceKey || '').trim()
|
||||
if (!key) {
|
||||
throw new Error('deleteCloudtentaclesSessionStateByKey: sourceKey is required')
|
||||
}
|
||||
|
||||
const states = loadCloudtentaclesSessionStatesFromFile()
|
||||
delete states.sessions[key]
|
||||
|
||||
fs.mkdirSync(path.dirname(CLOUDTENTACLES_SESSION_FILE_PATH), { recursive: true })
|
||||
fs.writeFileSync(CLOUDTENTACLES_SESSION_FILE_PATH, `${JSON.stringify(states, null, 2)}\n`, 'utf8')
|
||||
return states
|
||||
}
|
||||
|
||||
/**
|
||||
* Backward-compatible clear: clears the 'default' session only.
|
||||
*/
|
||||
@@ -86,6 +103,26 @@ export function clearCloudtentaclesSessionStateByKey(sourceKey: unknown) {
|
||||
return cleared
|
||||
}
|
||||
|
||||
/**
|
||||
* Keep only sessions whose sourceKey still exists in source config.
|
||||
*/
|
||||
export function pruneCloudtentaclesSessionStates(sourceKeys: unknown[] = []) {
|
||||
const allowedKeys = new Set(
|
||||
Array.isArray(sourceKeys)
|
||||
? sourceKeys.map((value) => String(value || '').trim()).filter(Boolean)
|
||||
: []
|
||||
)
|
||||
|
||||
const states = loadCloudtentaclesSessionStatesFromFile()
|
||||
states.sessions = Object.fromEntries(
|
||||
Object.entries(states.sessions || {}).filter(([key]) => allowedKeys.has(String(key || '').trim()))
|
||||
)
|
||||
|
||||
fs.mkdirSync(path.dirname(CLOUDTENTACLES_SESSION_FILE_PATH), { recursive: true })
|
||||
fs.writeFileSync(CLOUDTENTACLES_SESSION_FILE_PATH, `${JSON.stringify(states, null, 2)}\n`, 'utf8')
|
||||
return states
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Internal helpers
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
@@ -133,6 +133,7 @@ function normalizeCloudtentaclesSourceItem(rawValue: unknown) {
|
||||
return {
|
||||
key: String(source.key || 'default').trim() || 'default',
|
||||
label: String(source.label || '').trim(),
|
||||
enabled: source.enabled !== false,
|
||||
baseUrl: String(source.baseUrl || 'https://123.207.217.176').trim() || 'https://123.207.217.176',
|
||||
username: String(source.username || '').trim(),
|
||||
password: String(source.password || '').trim(),
|
||||
|
||||
Reference in New Issue
Block a user