fix: asset operations

This commit is contained in:
rgrgogu
2026-08-01 12:18:15 +08:00
parent c647b06cd1
commit 4f738a691d
+16 -10
View File
@@ -315,20 +315,26 @@ export function AssetsProvider({ children }) {
); );
// ─── PATCH /api/admin/assets/:assetId ──────────────────────────────────── // ─── PATCH /api/admin/assets/:assetId ────────────────────────────────────
//
// A replacement file (video thumbnail, or an image/audio asset's main
// file) goes out the same presigned direct-to-storage path as
// uploadAsset() above — this backend never buffers it. The PATCH body
// itself is plain JSON either way (storage_key when a file was replaced).
const updateAsset = useCallback( const updateAsset = useCallback(
(assetId, fields, file = null) => (assetId, fields, file = null) =>
request(async () => { request(async () => {
const formData = new FormData(); let filePayload = {};
Object.entries(fields).forEach(([key, value]) => { if (file) {
if (value !== undefined && value !== null) formData.append(key, value); const presigned = await presignAssetUpload(file);
}); await uploadPresigned(file, presigned);
if (file) formData.append("file", file); filePayload = {
storage_key: presigned.key,
original_name: file.name,
mimetype: file.type || undefined,
};
}
// No explicit Content-Type here — axios/the browser must set it const res = await api.patch(`/admin/assets/${assetId}`, { ...fields, ...filePayload });
// itself so the multipart boundary is included. A hardcoded
// "multipart/form-data" header (no boundary) makes multer fail
// to parse the body, silently dropping the file and every field.
const res = await api.patch(`/admin/assets/${assetId}`, formData);
const asset = res.data?.data?.data ?? null; const asset = res.data?.data?.data ?? null;
if (asset) { if (asset) {