Lokale Dateien implementiert

This commit is contained in:
2026-03-14 20:13:55 +01:00
parent 1a4a22eafd
commit b5eb3b56c0
9 changed files with 249 additions and 178 deletions

View File

@@ -3,6 +3,9 @@ import { protocolInfo, fsInfo, transferStats, resetTransferStats, transferDetail
import { addToast } from '../toast';
import { SETTINGS } from '../settings';
import { crc32 } from './crc32';
import { get } from 'svelte/store';
import { saveLocalFile } from '../db';
import { refreshLocal } from '../sync';
let lastUiUpdate = 0;
let currentFileCrc32 = 0;
@@ -10,6 +13,7 @@ let currentFileCrc32 = 0;
export type FrameSender = (buffer: ArrayBuffer) => Promise<void>;
let lsBuffer: any[] = [];
let fileChunks: Uint8Array[] = [];
let lsTimeout: ReturnType<typeof setTimeout> | null = null;
let lsResolve: ((data: any[]) => void) | null = null;
let lsReject: ((error: Error) => void) | null = null;
@@ -98,6 +102,7 @@ case FRAME.FILE_START:
currentFileCrc32 = 0;
const totalBytes = view.getUint32(3, true);
const nowStart = performance.now();
fileChunks = [];
transferStats.update(s => ({
...s,
@@ -155,6 +160,7 @@ case FRAME.FILE_START:
const chunkData = new Uint8Array(view.buffer, 3, payloadLength);
currentFileCrc32 = crc32(chunkData, currentFileCrc32);
fileChunks.push(new Uint8Array(chunkData));
const previousReceived = fileTransfer.receivedBytes;
fileTransfer.receivedBytes += payloadLength;
@@ -202,6 +208,17 @@ case FRAME.FILE_START:
if (currentFileCrc32 === buzzerCrc32) {
console.log("%c[CRC] Match! Datei ist integer.", "color: green; font-weight: bold;");
const fileBlob = new Blob(fileChunks, { type: 'audio/wav' });
const fileName = get(transferStats).currentFileName;
saveLocalFile(fileName, fileBlob, fileTransfer.totalBytes)
.then(() => {
console.log(`Datei ${fileName} erfolgreich lokal gespeichert.`);
refreshLocal();
})
.catch(err => {
console.error("Datenbankfehler:", err);
addToast(`Speichern von ${fileName} fehlgeschlagen.`, 'error');
});
} else {
console.error("[CRC] Mismatch! Datei beschädigt.");
addToast("CRC Fehler: Datei wurde fehlerhaft übertragen.", "error");