feat(runtime): 即梦本机运行时 - 接入安全生成闭环与桌面本机渠道
Refs #225 Co-authored-by: zkhyww <127009345+zkhyww@users.noreply.github.com>
This commit is contained in:
@@ -122,19 +122,19 @@ export async function deleteStoredImages(keys: Iterable<string>) {
|
||||
);
|
||||
}
|
||||
|
||||
export async function cleanupUnusedImages(usedData: unknown) {
|
||||
export async function cleanupUnusedImages(usedData: unknown, scope = getActiveUserScope()) {
|
||||
const usedKeys = collectImageStorageKeys(usedData);
|
||||
const currentPrefix = `image:${getActiveUserScope()}:`;
|
||||
const currentPrefixes = [`image:${scope}:`, `generation-image:${scope}:`];
|
||||
const unused: string[] = [];
|
||||
await store.iterate((_value, key) => {
|
||||
if (key.startsWith(currentPrefix) && !usedKeys.has(key)) unused.push(key);
|
||||
if (currentPrefixes.some((prefix) => key.startsWith(prefix)) && !usedKeys.has(key)) unused.push(key);
|
||||
});
|
||||
await deleteStoredImages(unused);
|
||||
}
|
||||
|
||||
export function collectImageStorageKeys(value: unknown, keys = new Set<string>()) {
|
||||
if (!value || typeof value !== "object") return keys;
|
||||
if ("storageKey" in value && typeof value.storageKey === "string" && (value.storageKey.startsWith("image:") || resourceIdFromStorageKey(value.storageKey))) keys.add(value.storageKey);
|
||||
if ("storageKey" in value && typeof value.storageKey === "string" && (value.storageKey.startsWith("image:") || value.storageKey.startsWith("generation-image:") || resourceIdFromStorageKey(value.storageKey))) keys.add(value.storageKey);
|
||||
Object.values(value).forEach((item) => (Array.isArray(item) ? item.forEach((child) => collectImageStorageKeys(child, keys)) : collectImageStorageKeys(item, keys)));
|
||||
return keys;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user