Add upload overwrite confirmation

This commit is contained in:
Mikei386
2026-06-23 22:18:39 +02:00
parent 76fc7e7251
commit aa58014cd7
6 changed files with 60 additions and 12 deletions
+24 -4
View File
@@ -904,13 +904,27 @@ async function uploadFileList(win, files, targetPath) {
const uploadItems = normalizeUploadItems(files);
for (const [index, item] of uploadItems.entries()) {
recordDebug('upload.file.request', { path: item.path, size: item.file.size, index: index + 1, total: uploadItems.length });
await uploadFileChunked(targetPath, item.file, item.path);
recordDebug('upload.file.done', { path: item.path, index: index + 1, total: uploadItems.length });
try {
await uploadFileChunked(targetPath, item.file, item.path, false);
recordDebug('upload.file.done', { path: item.path, index: index + 1, total: uploadItems.length, overwrite: false });
} catch (error) {
if (error.status !== 409) {
throw error;
}
const overwrite = window.confirm(`"${item.path}" existiert bereits.\n\nVorhandene Datei überschreiben?`);
recordDebug('upload.overwrite.prompt', { path: item.path, overwrite });
if (!overwrite) {
recordDebug('upload.file.skipped', { path: item.path, index: index + 1, total: uploadItems.length });
continue;
}
await uploadFileChunked(targetPath, item.file, item.path, true);
recordDebug('upload.file.done', { path: item.path, index: index + 1, total: uploadItems.length, overwrite: true });
}
}
await loadExplorer(win, targetPath);
}
async function uploadFileChunked(targetPath, file, relativePath) {
async function uploadFileChunked(targetPath, file, relativePath, overwrite = false) {
const chunkSize = 256 * 1024;
const totalChunks = Math.max(1, Math.ceil(file.size / chunkSize));
let finalPayload = null;
@@ -924,6 +938,9 @@ async function uploadFileChunked(targetPath, file, relativePath) {
body.set('chunkIndex', String(chunkIndex));
body.set('totalChunks', String(totalChunks));
body.set('data', data);
if (overwrite) {
body.set('overwrite', '1');
}
appendCsrf(body);
const response = await fetch(apiUrl(`upload.php?path=${encodeURIComponent(targetPath)}`), {
method: 'POST',
@@ -941,7 +958,10 @@ async function uploadFileChunked(targetPath, file, relativePath) {
body: text.slice(0, 1000)
});
if (!response.ok) {
throw new Error(text || `${response.status} ${response.statusText}`);
const error = new Error(text || `${response.status} ${response.statusText}`);
error.status = response.status;
error.path = relativePath;
throw error;
}
try {
finalPayload = JSON.parse(text);