Add upload overwrite confirmation
This commit is contained in:
+24
-4
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user