Fixed some issues with attachment indexing and sync mode
parent
470c1153ed
commit
ad067e08e7
|
@ -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 {
|
||||||
|
|
|
@ -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]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue