feat: improve audio clip URL handling after upload
All checks were successful
Deploy to Production / deploy (push) Successful in 1m47s
All checks were successful
Deploy to Production / deploy (push) Successful in 1m47s
- Added URL switching from blob to server URL after successful clip upload - Implemented memory cleanup by revoking blob URLs when no longer needed - Updated clip state to include server-generated URL using bucket and key data - Improved error handling to preserve existing URL if server doesn't return storage data
This commit is contained in:
parent
8a81712cce
commit
321fd63f5a
@ -82,7 +82,27 @@ export default function Recorder({ postId, initialClips, onInsertAtCursor, onTra
|
|||||||
throw new Error(`Upload failed: ${res.status} ${txt}`);
|
throw new Error(`Upload failed: ${res.status} ${txt}`);
|
||||||
}
|
}
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
setClips((prev) => prev.map(x => x.id === id ? { ...x, id: (data.clipId || x.id), uploadedKey: data.key || 'uploaded', uploadedBucket: data.bucket || null, isUploading: false } : x));
|
// Update clip with server data and switch to server URL
|
||||||
|
const serverUrl = data.bucket && data.key
|
||||||
|
? `/api/media/obj?bucket=${encodeURIComponent(data.bucket)}&key=${encodeURIComponent(data.key)}`
|
||||||
|
: undefined;
|
||||||
|
setClips((prev) => prev.map(x => {
|
||||||
|
if (x.id === id) {
|
||||||
|
// Revoke old blob URL to free memory
|
||||||
|
if (x.url && x.url.startsWith('blob:')) {
|
||||||
|
URL.revokeObjectURL(x.url);
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
...x,
|
||||||
|
id: (data.clipId || x.id),
|
||||||
|
uploadedKey: data.key || 'uploaded',
|
||||||
|
uploadedBucket: data.bucket || null,
|
||||||
|
url: serverUrl || x.url, // Use server URL after upload
|
||||||
|
isUploading: false
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return x;
|
||||||
|
}));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
setClips((prev) => prev.map(x => x.id === id ? { ...x, error: e?.message || 'Upload failed', isUploading: false } : x));
|
setClips((prev) => prev.map(x => x.id === id ? { ...x, error: e?.message || 'Upload failed', isUploading: false } : x));
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user