Fixed some issues with attachment indexing and sync mode

pull/893/head
Zef Hemel 2024-06-13 12:01:40 +02:00
parent 470c1153ed
commit ad067e08e7
3 changed files with 13 additions and 4 deletions

View File

@ -25,6 +25,18 @@ export class EventedSpacePrimitives implements SpacePrimitives {
private wrapped: SpacePrimitives, private wrapped: SpacePrimitives,
private eventHook: EventHook, private eventHook: EventHook,
) { ) {
// Translate file change events for attachments into attachment:index events
this.eventHook.addLocalListener(
"file:changed",
async (
name: string,
) => {
if (!name.endsWith(".md") && !name.startsWith(plugPrefix)) {
// Not a page nor plug, so an attachment!
await this.dispatchEvent("attachment:index", name);
}
},
);
} }
dispatchEvent(name: string, ...args: any[]): Promise<any[]> { dispatchEvent(name: string, ...args: any[]): Promise<any[]> {
@ -150,8 +162,6 @@ export class EventedSpacePrimitives implements SpacePrimitives {
name: pageName, name: pageName,
text, text,
}); });
} else if (!name.endsWith(plugPrefix)) {
await this.dispatchEvent("attachment:index", name, newMeta);
} }
return newMeta; return newMeta;
} finally { } finally {

View File

@ -6,6 +6,7 @@ export async function indexAttachment(name: string) {
if (await system.getMode() === "ro") { if (await system.getMode() === "ro") {
return; return;
} }
console.log("Indexing attachment", name);
const fileMeta = await space.getAttachmentMeta(name); const fileMeta = await space.getAttachmentMeta(name);
await indexObjects<AttachmentMeta>(fileMeta.name, [fileMeta]); await indexObjects<AttachmentMeta>(fileMeta.name, [fileMeta]);
} }

View File

@ -163,8 +163,6 @@ export class ServerSystem extends CommonSystem {
name: pageName, name: pageName,
text: new TextDecoder().decode(data.data), text: new TextDecoder().decode(data.data),
}); });
} else if (!path.startsWith(plugPrefix)) {
await this.eventHook.dispatchEvent("attachment:index", path);
} }
} }