feat: 视频上传

This commit is contained in:
rd
2025-07-31 18:18:50 +08:00
parent 372f673119
commit 1cb33bd3ad
3 changed files with 157 additions and 33 deletions

View File

@ -109,4 +109,26 @@ export function downloadByUrl(url: string, filename?: string) {
export function genRandomId() {
return `id_${Date.now()}_${Math.floor(Math.random() * 10000)}`;
}
export function formatFileSize(bytes: number): string {
if (bytes === 0) return '0 Bytes';
const k = 1024;
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
}
export function getVideoDuration(file: any) {
return new Promise((resolve) => {
const video = document.createElement('video');
video.preload = 'metadata';
video.onloadedmetadata = function() {
window.URL.revokeObjectURL(video.src);
resolve(video.duration);
};
video.src = URL.createObjectURL(file);
});
}