diff --git a/plugin/handlers/eventHandlers.ts b/plugin/handlers/eventHandlers.ts index b5fb7f50..6612eb1b 100644 --- a/plugin/handlers/eventHandlers.ts +++ b/plugin/handlers/eventHandlers.ts @@ -4,7 +4,9 @@ import { Inbox } from "../inbox"; export function registerEventHandlers(plugin: FileOrganizer) { plugin.registerEvent( - plugin.app.vault.on("create", file => { + plugin.app.vault.on("create", async file => { + // wait 1s + await new Promise(resolve => setTimeout(resolve, 1000)); if (!file.path.includes(plugin.settings.pathToWatch)) return; if (file instanceof TFile) { if (plugin.settings.useInbox) { @@ -17,7 +19,10 @@ export function registerEventHandlers(plugin: FileOrganizer) { ); plugin.registerEvent( - plugin.app.vault.on("rename", (file, oldPath) => { + plugin.app.vault.on("rename", async (file, oldPath) => { + // wait 1s + await new Promise(resolve => setTimeout(resolve, 1000)); + if (!file.path.includes(plugin.settings.pathToWatch)) return; if (file instanceof TFile) { if (plugin.settings.useInbox) { diff --git a/plugin/inbox/index.ts b/plugin/inbox/index.ts index 93918bc4..f1a00f8f 100644 --- a/plugin/inbox/index.ts +++ b/plugin/inbox/index.ts @@ -164,6 +164,7 @@ export class Inbox { idService: this.idService, queue: this.queue, }; + // wait 1s try { await startProcessing(context) @@ -180,12 +181,6 @@ export class Inbox { } } - private shouldCreateMarkdownContainer(file: TFile): boolean { - return ( - VALID_MEDIA_EXTENSIONS.includes(file.extension) || - file.extension === "pdf" - ); - } } // Pipeline processing steps @@ -221,6 +216,7 @@ async function extractTextStep( ): Promise { try { const text = await context.plugin.getTextFromFile(context.file); + logger.info("Extracted text", text); context.content = text; return context; } catch (error) { @@ -299,6 +295,9 @@ async function recommendOrganizationStructure( async function formatContentStep( context: ProcessingContext ): Promise { + logger.info("Formatting content step", context.classification); + // log content + logger.info("Content", context.content); if (!context.classification || context.classification.confidence < 50) return context; try { const instructions = await context.plugin.getTemplateInstructions( diff --git a/plugin/index.ts b/plugin/index.ts index e14bd7aa..f184a8bc 100644 --- a/plugin/index.ts +++ b/plugin/index.ts @@ -515,23 +515,23 @@ export default class FileOrganizer extends Plugin { formattingInstruction: string ): Promise { try { - const response = await makeApiRequest(() => - requestUrl({ - url: `${this.getServerUrl()}/api/format`, - method: "POST", - contentType: "application/json", - body: JSON.stringify({ - content, - formattingInstruction, - }), - throw: false, - headers: { - Authorization: `Bearer ${this.settings.API_KEY}`, - }, - }) - ); + const response = await fetch(`${this.getServerUrl()}/api/format`, { + method: "POST", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${this.settings.API_KEY}`, + }, + body: JSON.stringify({ + content, + formattingInstruction, + }), + }); + + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } - const { content: formattedContent } = await response.json; + const { content: formattedContent } = await response.json(); return formattedContent; } catch (error) { logger.error("Error formatting content:", error); @@ -1437,7 +1437,7 @@ export default class FileOrganizer extends Plugin { await this.app.vault.append(file, `\n${formattedTag}`); } - + async onload() { this.inbox = Inbox.initialize(this); await this.initializePlugin();