mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-01-27 03:19:56 +00:00
* Merge temp userfile Basic migration Remove deprecated isFavourite Rename nit nit Rework open/load Refactor save Refactor delete Remove workflow dep on manager WIP Change map to record Fix directory nit isActive Move nit Add unload Add close workflow Remove workflowManager.closeWorkflow nit Remove workflowManager.storePrompt move from commandStore move more from commandStore nit Use workflowservice nit nit implement setWorkflow nit Remove workflows.ts Fix strict errors nit nit Resolves circular dep nit nit Fix workflow switching Add openworkflowPaths Fix store Fix key Serialize by default Fix proxy nit Update path Proper sync Fix tabs WIP nit Resolve merge conflict Fix userfile store tests Update jest test Update tabs patch tests Fix changeTracker init Move insert to service nit Fix insert nit Handle bookmark rename Refactor tests Add delete workflow Add test on deleting workflow Add closeWorkflow tests nit * Fix path * Move load next/previous * Move logic from store to service * nit * nit * nit * nit * nit * Add ChangeTracker.initialState * ChangeTracker load/unload * Remove app.changeWorkflow * Hook to app.ts * Changetracker restore * nit * nit * nit * Add debug logs * Remove unnecessary checkState on graphLoad * nit * Fix strict * Fix temp workflow name * Track ismodified * Fix reactivity * nit * Fix graph equal * nit * update test * nit * nit * Fix modified state * nit * Fix modified state * Sidebar force close * tabs force close * Fix save * Add load remote workflow test * Force save * Add save test * nit * Correctly handle delete last opened workflow * nit * Fix workflow rename * Fix save * Fix tests * Fix strict * Update playwright tests * Fix filename conflict handling * nit * Merge temporary and persisted ref * Update playwright expectations * nit * nit * Fix saveAs * Add playwright test * nit
46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
import { api } from '@/scripts/api'
|
|
|
|
/**
|
|
* Sync entities from the API to the entityByPath map.
|
|
* @param dir The directory to sync from
|
|
* @param entityByPath The map to sync to
|
|
* @param createEntity A function to create an entity from a file
|
|
* @param updateEntity A function to update an entity from a file
|
|
* @param exclude A function to exclude an entity
|
|
*/
|
|
export async function syncEntities<T>(
|
|
dir: string,
|
|
entityByPath: Record<string, T>,
|
|
createEntity: (file: any) => T,
|
|
updateEntity: (entity: T, file: any) => void,
|
|
exclude: (file: T) => boolean = () => false
|
|
) {
|
|
const files = (await api.listUserDataFullInfo(dir)).map((file) => ({
|
|
...file,
|
|
path: dir ? `${dir}/${file.path}` : file.path
|
|
}))
|
|
|
|
for (const file of files) {
|
|
const existingEntity = entityByPath[file.path]
|
|
|
|
if (!existingEntity) {
|
|
// New entity, add it to the map
|
|
entityByPath[file.path] = createEntity(file)
|
|
} else if (exclude(existingEntity)) {
|
|
// Entity has been excluded, skip it
|
|
continue
|
|
} else {
|
|
// Entity has been modified, update its properties
|
|
updateEntity(existingEntity, file)
|
|
}
|
|
}
|
|
|
|
// Remove entities that no longer exist
|
|
for (const [path, entity] of Object.entries(entityByPath)) {
|
|
if (exclude(entity)) continue
|
|
if (!files.some((file) => file.path === path)) {
|
|
delete entityByPath[path]
|
|
}
|
|
}
|
|
}
|