diff --git a/common/spaces/evented_space_primitives.ts b/common/spaces/evented_space_primitives.ts index 70babd48..59cebbcd 100644 --- a/common/spaces/evented_space_primitives.ts +++ b/common/spaces/evented_space_primitives.ts @@ -25,6 +25,18 @@ export class EventedSpacePrimitives implements SpacePrimitives { private wrapped: SpacePrimitives, 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 { @@ -150,8 +162,6 @@ export class EventedSpacePrimitives implements SpacePrimitives { name: pageName, text, }); - } else if (!name.endsWith(plugPrefix)) { - await this.dispatchEvent("attachment:index", name, newMeta); } return newMeta; } finally { diff --git a/plugs/index/attachment.ts b/plugs/index/attachment.ts index aca86c98..e88583c6 100644 --- a/plugs/index/attachment.ts +++ b/plugs/index/attachment.ts @@ -6,6 +6,7 @@ export async function indexAttachment(name: string) { if (await system.getMode() === "ro") { return; } + console.log("Indexing attachment", name); const fileMeta = await space.getAttachmentMeta(name); await indexObjects(fileMeta.name, [fileMeta]); } diff --git a/server/server_system.ts b/server/server_system.ts index 40a4b8af..1d92a8b8 100644 --- a/server/server_system.ts +++ b/server/server_system.ts @@ -163,8 +163,6 @@ export class ServerSystem extends CommonSystem { name: pageName, text: new TextDecoder().decode(data.data), }); - } else if (!path.startsWith(plugPrefix)) { - await this.eventHook.dispatchEvent("attachment:index", path); } }