silverbullet/plugs/index/attachment.ts

14 lines
552 B
TypeScript
Raw Normal View History

2024-05-31 01:55:35 +08:00
import { space, system } from "$sb/syscalls.ts";
2024-07-30 23:33:33 +08:00
import type { AttachmentMeta } from "$sb/types.ts";
2024-05-28 02:33:41 +08:00
import { indexObjects } from "./api.ts";
// Note: clearFileIndex is not called but since this is the only attachmet:index listener, this should be fine (famous last words)
2024-05-31 01:55:35 +08:00
export async function indexAttachment(name: string) {
if (await system.getMode() === "ro") {
return;
2024-05-28 02:33:41 +08:00
}
console.log("Indexing attachment", name);
2024-05-31 01:55:35 +08:00
const fileMeta = await space.getAttachmentMeta(name);
await indexObjects<AttachmentMeta>(fileMeta.name, [fileMeta]);
2024-05-28 02:33:41 +08:00
}