Content auto pulling, git pull link fix and cleaning console.log/console.time.

This commit is contained in:
Clément Pons 2025-10-28 16:45:35 +01:00
parent ab36eec4de
commit 1c3211d28e
8 changed files with 27 additions and 23 deletions

BIN
db.sqlite

Binary file not shown.

View File

@ -14,8 +14,6 @@ export default defineEventHandler(async (e) => {
setResponseStatus(e, 401);
return;
}
console.log(id);
setResponseStatus(e, 200);
return {};

View File

@ -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;

View File

@ -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 ?? ''}]]`;
});
}

View File

@ -482,8 +482,6 @@ export class Canvas
]),
]), this.transform,
]);
console.log(this.nodes.length, this.edges.length);
}
protected computeLimits()

View File

@ -139,11 +139,12 @@ export class Content
try
{
Content._overview = parse<Record<string, Omit<LocalContent, 'content'>>>(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<FileType>[] | 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<FileSystemDirectoryHandle | undefined>
@ -331,7 +331,6 @@ export class Content
private static async write(path: string, content: string, options?: FileSystemGetFileOptions): Promise<void>
{
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<void>
{
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<StorageEstimate>
@ -456,7 +466,9 @@ const handlers: { [K in FileType]: ContentTypeHandler<K> } = {
'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);

View File

@ -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;

View File

@ -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));