Files
Stirling-PDF/frontend/src/core/services/openFilesFromDisk.ts
T
2026-02-24 23:05:23 +00:00

30 lines
892 B
TypeScript

import { openFileDialog } from '@app/services/fileDialogService';
import { pendingFilePathMappings } from '@app/services/pendingFilePathMappings';
import { getDocumentFileDialogFilter } from '@app/utils/fileDialogUtils';
interface OpenFilesFromDiskOptions {
multiple?: boolean;
filters?: Array<{
name: string;
extensions: string[];
}>;
onFallbackOpen?: () => void;
}
export async function openFilesFromDisk(options: OpenFilesFromDiskOptions = {}): Promise<File[]> {
const filesWithPaths = await openFileDialog({
multiple: options.multiple ?? true,
filters: options.filters ?? getDocumentFileDialogFilter()
});
if (filesWithPaths.length > 0) {
for (const { quickKey, path } of filesWithPaths) {
pendingFilePathMappings.set(quickKey, path);
}
return filesWithPaths.map((entry) => entry.file);
}
options.onFallbackOpen?.();
return [];
}