make generateFilePath async
This commit is contained in:
+2
-1
@@ -1,6 +1,7 @@
|
||||
import { Table } from "./db-tables/WorkspaceDB";
|
||||
|
||||
export async function getDB(table: Table): Promise<string | undefined> {
|
||||
console.warn("getDB is deprecated", table);
|
||||
try {
|
||||
const response = await fetch(`/workspace/get_db?table=${table}`);
|
||||
if (!response.ok) {
|
||||
@@ -150,7 +151,7 @@ export async function scanLocalNewFiles(path: string, existFlowIds: string[]) {
|
||||
},
|
||||
body: JSON.stringify({
|
||||
path,
|
||||
existFlowIds
|
||||
existFlowIds,
|
||||
}),
|
||||
});
|
||||
const result = await response.json();
|
||||
|
||||
@@ -92,6 +92,7 @@ export default function App() {
|
||||
document.title = name + " - ComfyUI";
|
||||
} else {
|
||||
localStorage.setItem("curFlowID", id);
|
||||
document.title = "ComfyUI - " + name;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -12,11 +12,11 @@ import {
|
||||
import { toFileNameFriendly } from "../utils";
|
||||
|
||||
export async function saveJsonFileMyWorkflows(workflow: Workflow) {
|
||||
const file_path = generateFilePath(workflow);
|
||||
const file_path = await generateFilePath(workflow);
|
||||
if (file_path == null) {
|
||||
return;
|
||||
}
|
||||
const fullPath = generateFilePathAbsolute(workflow);
|
||||
const fullPath = await generateFilePathAbsolute(workflow);
|
||||
updateFlow(workflow.id, {
|
||||
filePath: fullPath ?? undefined,
|
||||
});
|
||||
@@ -31,15 +31,17 @@ export async function saveJsonFileMyWorkflows(workflow: Workflow) {
|
||||
await updateFile(file_path, JSON.stringify(flow));
|
||||
}
|
||||
|
||||
export function deleteJsonFileMyWorkflows(workflow: Workflow) {
|
||||
export async function deleteJsonFileMyWorkflows(workflow: Workflow) {
|
||||
if (workflow.name == null) {
|
||||
return;
|
||||
}
|
||||
const file_path = generateFilePath(workflow);
|
||||
const file_path = await generateFilePath(workflow);
|
||||
file_path != null && deleteFile(file_path);
|
||||
}
|
||||
|
||||
export function generateFilePath(workflow: Workflow): string | null {
|
||||
export async function generateFilePath(
|
||||
workflow: Workflow
|
||||
): Promise<string | null> {
|
||||
let filePath = toFileNameFriendly(workflow.name) + ".json";
|
||||
let curFolderID = workflow.parentFolderID;
|
||||
while (curFolderID != null) {
|
||||
@@ -55,8 +57,10 @@ export function generateFilePath(workflow: Workflow): string | null {
|
||||
return filePath ?? null;
|
||||
}
|
||||
|
||||
export function generateFilePathAbsolute(workflow: Workflow): string | null {
|
||||
const subPath = generateFilePath(workflow);
|
||||
export async function generateFilePathAbsolute(
|
||||
workflow: Workflow
|
||||
): Promise<string | null> {
|
||||
const subPath = await generateFilePath(workflow);
|
||||
let myWorkflowsDir = userSettingsTable?.getSetting("myWorkflowsDir");
|
||||
if (myWorkflowsDir == null) {
|
||||
console.error("myWorkflowsDir is not set");
|
||||
|
||||
@@ -47,6 +47,8 @@ async function writeWorkspaceTable(data: string): Promise<void> {
|
||||
}
|
||||
|
||||
export async function updateWorkspaceIndexDB() {
|
||||
// console.log("mutating deprecated indexdb backup");
|
||||
return;
|
||||
try {
|
||||
const comfyspaceData = await curComfyspaceJson();
|
||||
await writeWorkspaceTable(comfyspaceData);
|
||||
|
||||
@@ -13,14 +13,20 @@ export class TableBase<T> {
|
||||
public async listAll(): Promise<T[]> {
|
||||
const objs = await indexdb[this.tableName].toArray();
|
||||
if (objs?.length) return objs as T[];
|
||||
console.warn("indexdb not found", this.tableName, "fallback to legacy db");
|
||||
const records = await this.getRecords();
|
||||
return Object.values(records);
|
||||
}
|
||||
|
||||
public async getRecords(): Promise<Record<string, T>> {
|
||||
console.error("[DEPRECATED]getRecords() call", this.tableName);
|
||||
|
||||
return await loadTable(this.tableName);
|
||||
}
|
||||
public async get(id: string): Promise<T | undefined> {
|
||||
const obj = await indexdb[this.tableName].get(id);
|
||||
if (obj) return obj as T;
|
||||
console.warn("indexdb not found", this.tableName, "fallback to legacy db");
|
||||
const records = await this.getRecords();
|
||||
return records[id];
|
||||
}
|
||||
|
||||
@@ -58,6 +58,7 @@ export let changelogsTable: ChangelogsTable | null = null;
|
||||
export let mediaTable: MediaTable | null = null;
|
||||
|
||||
export const loadTable = async (name: Table) => {
|
||||
const records = await indexdb[name].toCollection();
|
||||
let jsonStr = await getDB(name);
|
||||
let json: any;
|
||||
try {
|
||||
|
||||
+2
-2
@@ -156,7 +156,7 @@ export async function validateOrSaveAllJsonFileMyWorkflows(
|
||||
deleteEmptyFolder = false
|
||||
) {
|
||||
for (const workflow of listWorkflows()) {
|
||||
const fullPath = generateFilePathAbsolute(workflow);
|
||||
const fullPath = await generateFilePathAbsolute(workflow);
|
||||
if (workflow.filePath != fullPath) {
|
||||
// file path changed
|
||||
workflow.filePath != null &&
|
||||
@@ -400,7 +400,7 @@ export function generateUrlHashWithFlowId(id: string) {
|
||||
export async function rewriteAllLocalFiles() {
|
||||
for (const workflow of listWorkflows()) {
|
||||
try {
|
||||
const fullPath = generateFilePathAbsolute(workflow);
|
||||
const fullPath = await generateFilePathAbsolute(workflow);
|
||||
const flow = JSON.parse(workflow.json);
|
||||
flow.extra[COMFYSPACE_TRACKING_FIELD_NAME] = {
|
||||
id: workflow.id,
|
||||
|
||||
+2
-2
@@ -12,8 +12,8 @@ export default defineConfig({
|
||||
watch: {
|
||||
include: ["src/**"],
|
||||
},
|
||||
// minify: false, // ___DEBUG__MODE only
|
||||
// sourcemap: true, // ___DEBUG___MODE only
|
||||
minify: false, // ___DEBUG__MODE only
|
||||
sourcemap: true, // ___DEBUG___MODE only
|
||||
emptyOutDir: true,
|
||||
rollupOptions: {
|
||||
// externalize deps that shouldn't be bundled into your library
|
||||
|
||||
Reference in New Issue
Block a user