diff --git a/apps/app-frontend/src/providers/setup/file-picker.ts b/apps/app-frontend/src/providers/setup/file-picker.ts index b07bdca63..6fcdb9649 100644 --- a/apps/app-frontend/src/providers/setup/file-picker.ts +++ b/apps/app-frontend/src/providers/setup/file-picker.ts @@ -1,6 +1,17 @@ import { provideFilePicker } from '@modrinth/ui' import { convertFileSrc } from '@tauri-apps/api/core' import { open } from '@tauri-apps/plugin-dialog' +import { readFile } from '@tauri-apps/plugin-fs' + +function getFileName(path: string, fallback: string) { + return path.split(/[\\/]/).pop() || fallback +} + +async function createFileFromPath(path: string, fallbackName: string, type?: string) { + const bytes = await readFile(path) + const name = getFileName(path, fallbackName) + return new File([bytes], name, type ? { type } : undefined) +} export function setupFilePickerProvider() { provideFilePicker({ @@ -12,8 +23,7 @@ export function setupFilePickerProvider() { if (!result) return null const path = result.path ?? result if (!path) return null - const name = path.split(/[\\/]/).pop() || 'icon' - const file = new File([], name) + const file = await createFileFromPath(path, 'icon') return { file, path, previewUrl: convertFileSrc(path) } }, async pickModpackFile() { @@ -24,8 +34,11 @@ export function setupFilePickerProvider() { if (!result) return null const path = result.path ?? result if (!path) return null - const name = path.split(/[\\/]/).pop() || 'modpack.mrpack' - const file = new File([], name) + const file = await createFileFromPath( + path, + 'modpack.mrpack', + 'application/x-modrinth-modpack+zip', + ) return { file, path, previewUrl: '' } }, })