diff --git a/db.sqlite b/db.sqlite index 39b99c0..c0229c8 100644 Binary files a/db.sqlite and b/db.sqlite differ diff --git a/server/api/homebrew/[id].get.ts b/server/api/homebrew/[id].get.ts index ab8367d..6d8df32 100644 --- a/server/api/homebrew/[id].get.ts +++ b/server/api/homebrew/[id].get.ts @@ -14,8 +14,6 @@ export default defineEventHandler(async (e) => { setResponseStatus(e, 401); return; } - - console.log(id); setResponseStatus(e, 200); return {}; diff --git a/server/api/homebrew/[id].post.ts b/server/api/homebrew/[id].post.ts index 1b58876..aa48c13 100644 --- a/server/api/homebrew/[id].post.ts +++ b/server/api/homebrew/[id].post.ts @@ -14,9 +14,6 @@ export default defineEventHandler(async (e) => { setResponseStatus(e, 401); return; } - - console.log(id); - console.log(await readBody(e)); setResponseStatus(e, 200); return; diff --git a/server/tasks/pull.ts b/server/tasks/pull.ts index 5fcd95b..4b9434d 100644 --- a/server/tasks/pull.ts +++ b/server/tasks/pull.ts @@ -91,7 +91,7 @@ export default defineTask({ function reshapeLinks(content: string | null, all: ProjectContent[]) { return content?.replace(/\[\[(.*?)?(#.*?)?(\|.*?)?\]\]/g, (str, link, header, title) => { - return `[[${link ? parsePath(all.find(e => e.path.endsWith(parsePath(link)))?.path ?? parsePath(link)) : ''}${header ?? ''}${title ?? ''}]]`; + return `[[${link ? parsePath(all.findLast(e => e.path.endsWith(parsePath(link)))?.path ?? parsePath(link)) : ''}${header ?? ''}${title ?? ''}]]`; }); } diff --git a/shared/canvas.util.ts b/shared/canvas.util.ts index 8344631..7eade22 100644 --- a/shared/canvas.util.ts +++ b/shared/canvas.util.ts @@ -482,8 +482,6 @@ export class Canvas ]), ]), this.transform, ]); - - console.log(this.nodes.length, this.edges.length); } protected computeLimits() diff --git a/shared/content.util.ts b/shared/content.util.ts index 7319b24..facc0a7 100644 --- a/shared/content.util.ts +++ b/shared/content.util.ts @@ -139,11 +139,12 @@ export class Content try { Content._overview = parse>>(overview); + await Content.pull(); } catch(e) { Content._overview = {}; - await Content.pull(); + await Content.pull(true); } Content._reverseMapping = Object.values(Content._overview).reduce((p, v) => { p[v.path] = v.id; @@ -230,7 +231,7 @@ export class Content return Content.queue.promise; } - static async pull() + static async pull(force: boolean = false) { const overview = (await useRequestFetch()('/api/file/overview', { cache: 'no-cache' })) as ProjectContent[] | undefined; @@ -241,19 +242,16 @@ export class Content return; } + const deletable = Object.keys(Content._overview); for(const file of overview) { const _overview = Content._overview[file.id]; - if(_overview && _overview.localEdit) - { - //TODO: Ask what to do about this file. - } - else + if(force || !_overview || new Date(_overview.timestamp) < new Date(file.timestamp)) { Content._overview[file.id] = file; Content.queue.queue(() => { - return useRequestFetch()(`/api/file/content/${file.id}`, { cache: 'no-cache' }).then(async (content: string | undefined) => { + return useRequestFetch()(`/api/file/content/${file.id}`, { cache: 'no-cache' }).then(async (content: string | undefined | null) => { if(content) { if(file.type !== 'folder') @@ -269,8 +267,13 @@ export class Content }); }); } + + deletable.splice(deletable.findIndex(e => e === file.id), 1); } + for(const id of deletable) + Content.queue.queue(() => Content.remove(id).then(e => delete Content._overview[id])); + return Content.queue.queue(() => { return Content.write('overview', JSON.stringify(Content._overview), { create: true }); }); @@ -296,18 +299,15 @@ export class Content { try { - console.time(`Reading '${path}'`); const handle = await Content.root.getFileHandle(path, options); const file = await handle.getFile(); const text = await file.text(); - console.timeEnd(`Reading '${path}'`); return text; } catch(e) { console.error(path, e); - console.timeEnd(`Reading '${path}'`); } } private static async goto(path: string, options?: FileSystemGetDirectoryOptions): Promise @@ -331,7 +331,6 @@ export class Content private static async write(path: string, content: string, options?: FileSystemGetFileOptions): Promise { const size = new TextEncoder().encode(content).byteLength; - console.time(`Writing ${size} bytes to '${path}'`); try { const parent = path.split('/').slice(0, -1).join('/'), basename = path.split('/').slice(-1).join('/'); @@ -345,7 +344,18 @@ export class Content { console.error(path, e); } - console.timeEnd(`Writing ${size} bytes to '${path}'`); + } + private static async remove(path: string): Promise + { + try + { + const parent = path.split('/').slice(0, -1).join('/'), basename = path.split('/').slice(-1).join('/'); + return (await Content.goto(parent, { create: true }) ?? Content.root).removeEntry(basename); + } + catch(e) + { + console.error(path, e); + } } static get estimate(): Promise @@ -456,7 +466,9 @@ const handlers: { [K in FileType]: ContentTypeHandler } = { 'cyan': '5', 'purple': '6', }; + //@ts-ignore content.edges?.forEach(e => e.color = e.color ? e.color.hex ?? (e.color.class ? mapping[e.color.class]! : undefined) : undefined); + //@ts-ignore content.nodes?.forEach(e => e.color = e.color ? e.color.hex ?? (e.color.class ? mapping[e.color.class]! : undefined) : undefined); return JSON.stringify(content); diff --git a/shared/general.util.ts b/shared/general.util.ts index 123ec23..9f528dd 100644 --- a/shared/general.util.ts +++ b/shared/general.util.ts @@ -56,7 +56,7 @@ export function format(date: Date, template: string): string for(const key of keys) { - template = template.replaceAll(key, () => transforms[key](date)); + template = template.replaceAll(key, () => transforms[key]!(date)); } return template; diff --git a/shared/grammar/wikilink.extension.ts b/shared/grammar/wikilink.extension.ts index 607983c..b396480 100644 --- a/shared/grammar/wikilink.extension.ts +++ b/shared/grammar/wikilink.extension.ts @@ -50,7 +50,6 @@ export const wikilink: MarkdownConfig = { } else if(match[1] && match[2] && match[3]) //Link, hash and title { - //console.log(cx.slice(pos, end), '/', cx.slice(start + 2, start + 2 + match[1].length + match[2].length), '/', cx.slice(start + 2 + match[1].length + match[2].length, start + 2 + match[1].length + match[2].length + 1), cx.slice(start + 2 + match[1].length + match[2].length + 1, start + 2 + match[1].length + match[2].length + match[3].length)) children.push(cx.elt('WikilinkHref', start + 2, start + 2 + match[1].length + match[2].length)); children.push(cx.elt('WikilinkMeta', start + 2 + match[1].length + match[2].length, start + 2 + match[1].length + match[2].length + 1)); children.push(cx.elt('WikilinkTitle', start + 2 + match[1].length + match[2].length + 1, start + 2 + match[1].length + match[2].length + match[3].length));