feat(MediaManager, MediaBrowser): add file existence check before upload to prevent overwriting
This commit is contained in:
parent
c0d45e33f0
commit
e0ac2549c6
|
|
@ -14,6 +14,7 @@ import {
|
||||||
import {
|
import {
|
||||||
createFolder,
|
createFolder,
|
||||||
deletePath,
|
deletePath,
|
||||||
|
fileExists,
|
||||||
humanFileSize,
|
humanFileSize,
|
||||||
joinPath,
|
joinPath,
|
||||||
listDirectory,
|
listDirectory,
|
||||||
|
|
@ -99,7 +100,11 @@ export default function MediaBrowser({ currentPath, onSelect, onClose }: MediaBr
|
||||||
|
|
||||||
const handleUpload = async (file: File) => {
|
const handleUpload = async (file: File) => {
|
||||||
if (!path) return;
|
if (!path) return;
|
||||||
try { await putFileContents(joinPath(path, file.name), await file.arrayBuffer()); toast.success(`Uploaded ${file.name}`); void load(path); }
|
const target = joinPath(path, file.name);
|
||||||
|
if (await fileExists(target)) {
|
||||||
|
if (!window.confirm(`"${file.name}" already exists. Overwrite?`)) return;
|
||||||
|
}
|
||||||
|
try { await putFileContents(target, await file.arrayBuffer()); toast.success(`Uploaded ${file.name}`); void load(path); }
|
||||||
catch (e: any) { toast.error(`Failed to upload ${file.name}: ${e?.message ?? e}`); }
|
catch (e: any) { toast.error(`Failed to upload ${file.name}: ${e?.message ?? e}`); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -876,8 +876,12 @@ export default function MediaManager({ initialPath = '/', rootPath, title, confi
|
||||||
// ── Upload ───────────────────────────────────────────────────────────────
|
// ── Upload ───────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
const handleUpload = async (file: File) => {
|
const handleUpload = async (file: File) => {
|
||||||
|
const target = joinPath(path, file.name);
|
||||||
|
if (await fileExists(target)) {
|
||||||
|
if (!window.confirm(`"${file.name}" already exists. Overwrite?`)) return;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
await putFileContents(joinPath(path, file.name), await file.arrayBuffer());
|
await putFileContents(target, await file.arrayBuffer());
|
||||||
toast.success(`Uploaded ${file.name}`);
|
toast.success(`Uploaded ${file.name}`);
|
||||||
void load(path);
|
void load(path);
|
||||||
} catch (e: any) { toast.error(`Upload failed for ${file.name}: ${e?.message ?? e}`); }
|
} catch (e: any) { toast.error(`Upload failed for ${file.name}: ${e?.message ?? e}`); }
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user