Skip to content

Commit

Permalink
feat(plugin/workflowInbox): experiment with batch processing
Browse files Browse the repository at this point in the history
feat: basic logging

checkpoint

feat: other weird checkpoint

new

back on track

broken checkpoint

kinda working

feat: cleanup

feat: update empty state
  • Loading branch information
benjaminshafii committed Nov 11, 2024
1 parent b58c719 commit 0a71592
Show file tree
Hide file tree
Showing 23 changed files with 2,151 additions and 560 deletions.
39 changes: 39 additions & 0 deletions plugin/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Notice } from "obsidian";

export const VALID_IMAGE_EXTENSIONS = ["png", "jpg", "jpeg", "gif", "svg", "webp"];

export const VALID_AUDIO_EXTENSIONS = [
"mp3",
"mp4",
"mpeg",
"mpga",
"m4a",
"wav",
"webm",
];

export const VALID_MEDIA_EXTENSIONS = [
...VALID_IMAGE_EXTENSIONS,
...VALID_AUDIO_EXTENSIONS,
];

export const VALID_TEXT_EXTENSIONS = ["md", "txt"];

export const VALID_EXTENSIONS = [
...VALID_MEDIA_EXTENSIONS,
...VALID_TEXT_EXTENSIONS,
"pdf",
];

/**
* Validates if a given file extension is supported by FileOrganizer
* @param extension - The file extension to validate (without the dot)
* @returns boolean indicating if the extension is supported
*/
export const isValidExtension = (extension: string): boolean => {
const isSupported = VALID_EXTENSIONS.includes(extension);
if (!isSupported) {
new Notice("Sorry, FileOrganizer does not support this file type.");
}
return isSupported;
};
1 change: 0 additions & 1 deletion plugin/fileUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { App, TFolder, TFile, normalizePath } from "obsidian";
import { FileOrganizerSettings } from "./FileOrganizerSettings";
import { Notice } from "obsidian";
export async function ensureFolderExists(app: App, folderPath: string) {
if (!(await app.vault.adapter.exists(folderPath))) {
Expand Down
6 changes: 4 additions & 2 deletions plugin/handlers/commandHandlers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { WorkspaceLeaf } from "obsidian";
import FileOrganizer from "../index";
import { ORGANIZER_VIEW_TYPE, AssistantViewWrapper } from "../views/organizer";
import { ORGANIZER_VIEW_TYPE, AssistantViewWrapper } from "../views/organizer/view";
import { AIChatView, CHAT_VIEW_TYPE } from "../views/ai-chat/view";
import { Inbox } from "../inbox";

export function initializeChat(plugin: FileOrganizer) {
plugin.registerView(
Expand Down Expand Up @@ -50,8 +51,9 @@ export function initializeFileOrganizationCommands(plugin: FileOrganizer) {
name: "Put in inbox",
callback: async () => {
const activeFile = plugin.app.workspace.getActiveFile();
// move to file to inbox
if (activeFile) {
await plugin.processFileV2(activeFile);
await plugin.app.vault.rename(activeFile, `${plugin.settings.pathToWatch}/${activeFile.name}`);
}
},
});
Expand Down
17 changes: 13 additions & 4 deletions plugin/handlers/eventHandlers.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { TFile } from "obsidian";
import FileOrganizer from "..";
import { Inbox } from "../inbox";

export function registerEventHandlers(plugin: FileOrganizer) {
plugin.registerEvent(
plugin.app.vault.on("create", (file) => {
plugin.app.vault.on("create", file => {
if (!file.path.includes(plugin.settings.pathToWatch)) return;
if (file instanceof TFile) {
plugin.processFileV2(file);
if (plugin.settings.useInbox) {
Inbox.getInstance().enqueueFiles([file]);
} else {
plugin.processFileV2(file);
}
}
})
);
Expand All @@ -15,8 +20,12 @@ export function registerEventHandlers(plugin: FileOrganizer) {
plugin.app.vault.on("rename", (file, oldPath) => {
if (!file.path.includes(plugin.settings.pathToWatch)) return;
if (file instanceof TFile) {
plugin.processFileV2(file, oldPath);
if (plugin.settings.useInbox) {
Inbox.getInstance().enqueueFiles([file]);
} else {
plugin.processFileV2(file, oldPath);
}
}
})
);
}
}
38 changes: 38 additions & 0 deletions plugin/inbox/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
export const VALID_MEDIA_EXTENSIONS = [
"png",
"jpg",
"jpeg",
"gif",
"bmp",
"svg",
"mp3",
"wav",
"mp4",
"mov",
"wmv",
];

export const CHUNK_SIZE = 1024 * 1024; // 1MB
export const MAX_CONCURRENT_TASKS = 100;
export const BATCH_DELAY = 100; // ms
export const MAX_BATCH_SIZE = 10;
export const CACHE_TTL = 1000 * 60 * 60 * 24; // 24 hours
export const MAX_LOG_SIZE = 100;
export const ERROR_FOLDER = "_FileOrganizer2000/Error";

export const NOTIFICATION_DURATIONS = {
CRITICAL: 10000, // 10 seconds
HIGH: 5000, // 5 seconds
MEDIUM: 3000, // 3 seconds
LOW: 2000, // 2 seconds
};

export const FILE_PRIORITIES = {
SMALL: 3, // Small files (<100KB)
MARKDOWN: 2, // Markdown files
DEFAULT: 1, // Default priority
};

export const SIZE_THRESHOLDS = {
SMALL: 1024 * 100, // 100KB
};
Loading

0 comments on commit 0a71592

Please sign in to comment.