silverbullet/plugs/index/attachment.ts

14 lines
596 B
TypeScript
Raw Normal View History

import { space, system } from "@silverbulletmd/silverbullet/syscalls";
import type { AttachmentMeta } from "@silverbulletmd/silverbullet/types";
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
}