fix window controls and ui zoom - stop externalizing tauri api modules
This commit is contained in:
+4
-35
@@ -1,11 +1,11 @@
|
||||
import { useDownloads } from '../stores/downloads-store'
|
||||
import { isTauri } from './tauri'
|
||||
|
||||
/**
|
||||
* Download a Jellyfin stream to local storage.
|
||||
* Download a Jellyfin stream to local storage as a Blob URL.
|
||||
*
|
||||
* Browser: caches the response as a Blob URL (session-only, lost on reload).
|
||||
* Tauri: writes the bytes to the app's AppLocalData directory and stores the path.
|
||||
* Note: persistent disk storage in the Tauri build would require the
|
||||
* tauri-plugin-fs plugin, which is not currently included. For now both
|
||||
* browser and Tauri builds cache downloads as in-memory Blob URLs.
|
||||
*/
|
||||
export async function startDownload(args: {
|
||||
itemId: string
|
||||
@@ -27,36 +27,6 @@ export async function startDownload(args: {
|
||||
try {
|
||||
store.update(dl.id, { status: 'downloading', progress: 0 })
|
||||
|
||||
if (isTauri) {
|
||||
// Tauri path: fetch via the Rust-backed HTTP client so we avoid
|
||||
// CORS + we can stream large files without the browser's memory
|
||||
// pressure.
|
||||
// @ts-ignore
|
||||
const { fetch } = await import('@tauri-apps/api/http') as any
|
||||
// @ts-ignore
|
||||
const { appLocalDataDir } = await import('@tauri-apps/api/path') as any
|
||||
// @ts-ignore
|
||||
const { writeBinaryFile, BaseDirectory } = await import('@tauri-apps/api/fs') as any
|
||||
|
||||
const res = await (fetch as any)(streamUrl, {
|
||||
method: 'GET',
|
||||
responseType: 3, // ResponseType.Binary
|
||||
})
|
||||
const bytes: Uint8Array = res.data
|
||||
const dir = await appLocalDataDir()
|
||||
const fileName = `download_${itemId}_${Date.now()}.mp4`
|
||||
await writeBinaryFile(fileName, bytes, { dir: BaseDirectory.AppLocalData })
|
||||
const localPath = `${dir}/${fileName}`
|
||||
store.update(dl.id, {
|
||||
status: 'done',
|
||||
progress: 100,
|
||||
sizeBytes: bytes.length,
|
||||
localPath,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// Browser path: fetch with progress tracking via a ReadableStream reader
|
||||
const response = await fetch(streamUrl)
|
||||
if (!response.ok || !response.body) {
|
||||
throw new Error(`Download failed: ${response.status}`)
|
||||
@@ -79,7 +49,6 @@ export async function startDownload(args: {
|
||||
}
|
||||
}
|
||||
|
||||
// Assemble the full blob
|
||||
const blob = new Blob(chunks as any)
|
||||
const objectUrl = URL.createObjectURL(blob)
|
||||
store.update(dl.id, {
|
||||
|
||||
Reference in New Issue
Block a user