feat: update max file size for media upload

This commit is contained in:
yanghao05
2025-04-18 21:05:50 +08:00
parent 850d0c6486
commit a6a010d31f

View File

@@ -19,6 +19,10 @@ const currentFile = ref(null);
const uploadHistory = ref([]); const uploadHistory = ref([]);
const STORAGE_KEY = 'media_upload_history'; const STORAGE_KEY = 'media_upload_history';
// Add max file size constant (100MB)
const MAX_FILE_SIZE = 300 * 1024 * 1024;
const MAX_FILE_SIZE_DISPLAY = '300MB';
// Add computed for completed uploads // Add computed for completed uploads
const completedUploads = computed(() => { const completedUploads = computed(() => {
return uploadHistory.value.filter(item => item.status === 'completed'); return uploadHistory.value.filter(item => item.status === 'completed');
@@ -78,11 +82,29 @@ const addToUploadQueue = (files) => {
uploadQueue.value.push(...newFiles); uploadQueue.value.push(...newFiles);
}; };
// Add file size check
const checkFileSize = (file) => {
if (file.size > MAX_FILE_SIZE) {
toast.add({
severity: 'error',
summary: '错误',
detail: `文件大小超过限制 (最大 ${MAX_FILE_SIZE_DISPLAY})`,
life: 3000
});
return false;
}
return true;
};
const handleFiles = async (files) => { const handleFiles = async (files) => {
addToUploadQueue(files); // Filter out files that are too large
const validFiles = Array.from(files).filter(checkFileSize);
if (validFiles.length > 0) {
addToUploadQueue(validFiles);
if (!isUploading.value) { if (!isUploading.value) {
processNextUpload(); processNextUpload();
} }
}
}; };
const processNextUpload = async () => { const processNextUpload = async () => {
@@ -294,6 +316,7 @@ onMounted(() => {
<i class="pi pi-cloud-upload text-6xl! text-gray-500 mb-4"></i> <i class="pi pi-cloud-upload text-6xl! text-gray-500 mb-4"></i>
<p class="text-gray-600 text-2xl! font-bold text-center mb-2">拖拽文件到此处或点击上传</p> <p class="text-gray-600 text-2xl! font-bold text-center mb-2">拖拽文件到此处或点击上传</p>
<p class="text-gray-400 text-sm text-center">支持: MP4, JPG, PNG, GIF, MP4, PDF, DOC</p> <p class="text-gray-400 text-sm text-center">支持: MP4, JPG, PNG, GIF, MP4, PDF, DOC</p>
<p class="text-gray-400 text-sm text-center mt-1">单个文件最大 {{ MAX_FILE_SIZE_DISPLAY }}</p>
</div> </div>
</div> </div>