mirror of
https://github.com/travisvn/obsidian-vision-recall.git
synced 2026-07-22 05:38:13 +00:00
- Migrated CSS files to SCSS with more modular and scoped styling - Added new DeleteConfirmationModal for consistent deletion UX - Updated file and folder handling to use Obsidian's native methods - Improved local storage interactions through Obsidian app methods - Bumped version to 1.0.4 and updated minimum app version - Added new path alias and TypeScript configuration updates And all other points outlined in the PR review
46 lines
1.8 KiB
TypeScript
46 lines
1.8 KiB
TypeScript
import VisionRecallPlugin from '@/main';
|
|
import { normalizePath } from 'obsidian';
|
|
|
|
export async function initializeFolders(plugin: VisionRecallPlugin) {
|
|
try {
|
|
const screenshotStorageFolder = await plugin.getFolderWithPrefixIfEnabled(plugin.settings.screenshotStorageFolderPath);
|
|
const screenshotIntakeFolder = await plugin.getFolderWithPrefixIfEnabled(plugin.settings.screenshotIntakeFolderPath);
|
|
const tempFolder = await plugin.getFolderWithPrefixIfEnabled(plugin.settings.tempFolderPath);
|
|
const outputNotesFolder = await plugin.getFolderWithPrefixIfEnabled(plugin.settings.outputNotesFolderPath);
|
|
|
|
if (!plugin.app.vault.getFolderByPath(screenshotStorageFolder)) {
|
|
await plugin.app.vault.createFolder(screenshotStorageFolder);
|
|
}
|
|
|
|
if (!plugin.app.vault.getFolderByPath(screenshotIntakeFolder)) {
|
|
await plugin.app.vault.createFolder(screenshotIntakeFolder);
|
|
}
|
|
|
|
if (!plugin.app.vault.getFolderByPath(tempFolder)) {
|
|
await plugin.app.vault.createFolder(tempFolder);
|
|
}
|
|
|
|
if (!plugin.app.vault.getFolderByPath(outputNotesFolder)) {
|
|
await plugin.app.vault.createFolder(outputNotesFolder);
|
|
}
|
|
|
|
return true;
|
|
} catch (error) {
|
|
this.logger.error('Error initializing folders:', error);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Sanitizes a filename by replacing problematic characters with an empty string
|
|
* This is used in addition to normalizePath() (which is used 20+ times in this project)
|
|
* @param input - The filename to sanitize
|
|
* @returns The sanitized filename
|
|
*/
|
|
export function sanitizeFilename(input: string): string {
|
|
// Define a regex pattern to match problematic filename characters
|
|
const forbiddenChars = /[<>:"\/\\|?*\x00-\x1F]/g
|
|
|
|
// Replace them with an empty string
|
|
return normalizePath(input.replace(forbiddenChars, ''))
|
|
}
|