complete backend
This commit is contained in:
@@ -7,15 +7,18 @@ export const mediaService = {
|
||||
});
|
||||
},
|
||||
|
||||
createMedia(mediaInfo) {
|
||||
return httpClient.post('/admin/medias', mediaInfo);
|
||||
},
|
||||
|
||||
getUploadToken() {
|
||||
return httpClient.get('/admin/uploads/token');
|
||||
},
|
||||
preUploadedCheck(md5) {
|
||||
return httpClient.get(`/admin/uploads/pre-uploaded-check/${md5}`);
|
||||
},
|
||||
|
||||
uploadedSuccess(data) {
|
||||
return httpClient.post('/admin/uploads/post-uploaded-action', data);
|
||||
},
|
||||
|
||||
createMedia(mediaInfo) {
|
||||
return httpClient.post('/admin/medias', mediaInfo);
|
||||
}
|
||||
};
|
||||
@@ -203,11 +203,10 @@ const formatDate = (date) => {
|
||||
</template>
|
||||
</Column>
|
||||
|
||||
<Column field="upload_time" header="时间信息">
|
||||
<Column field="upload_time" header="上传时间">
|
||||
<template #body="{ data }">
|
||||
<div class="flex flex-col">
|
||||
<span class="text-gray-500">更新: {{ formatDate(data.updated_at) }}</span>
|
||||
<span class="text-gray-400">上传: {{ formatDate(data.created_at) }}</span>
|
||||
<span class="text-gray-400"> {{ formatDate(data.upload_time) }}</span>
|
||||
</div>
|
||||
</template>
|
||||
</Column>
|
||||
|
||||
@@ -106,11 +106,28 @@ const processNextUpload = async () => {
|
||||
currentUploadIndex.value = 0;
|
||||
|
||||
try {
|
||||
await uploadFile(nextFile.file);
|
||||
uploadQueue.value.shift();
|
||||
addToHistory(nextFile.file, 'completed');
|
||||
const md5Hash = await calculateMD5(nextFile.file);
|
||||
// Check if file exists before upload
|
||||
const checkResult = await mediaService.preUploadedCheck(md5Hash);
|
||||
console.log(checkResult)
|
||||
if (checkResult.data === 'exists') {
|
||||
// Skip upload and mark as completed
|
||||
uploadQueue.value.shift();
|
||||
addToHistory(nextFile.file, 'completed');
|
||||
toast.add({
|
||||
severity: 'info',
|
||||
summary: '提示',
|
||||
detail: '文件已存在,已跳过上传',
|
||||
life: 3000
|
||||
});
|
||||
} else {
|
||||
// Proceed with upload
|
||||
await uploadFile(nextFile.file, md5Hash);
|
||||
uploadQueue.value.shift();
|
||||
addToHistory(nextFile.file, 'completed');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to upload file:', nextFile.file.name, error);
|
||||
console.error('Failed to process file:', nextFile.file.name, error);
|
||||
uploadQueue.value.shift();
|
||||
addToHistory(nextFile.file, 'error');
|
||||
}
|
||||
@@ -159,7 +176,7 @@ const calculateMD5 = (file) => {
|
||||
};
|
||||
|
||||
// Modify uploadFile function
|
||||
const uploadFile = async (file) => {
|
||||
const uploadFile = async (file, md5Hash) => {
|
||||
try {
|
||||
currentFile.value = file;
|
||||
isUploading.value = true;
|
||||
@@ -169,8 +186,6 @@ const uploadFile = async (file) => {
|
||||
await getOssToken();
|
||||
}
|
||||
|
||||
// Calculate MD5 before upload
|
||||
const md5Hash = await calculateMD5(file);
|
||||
const fileExt = file.name.split('.').pop();
|
||||
const newFileName = `${md5Hash}.${fileExt}`;
|
||||
|
||||
@@ -292,9 +307,9 @@ onMounted(() => {
|
||||
|
||||
<div ref="dropZone" @drop="onDrop" @dragover="onDragOver" @dragleave="onDragLeave" @click="onClick"
|
||||
class="border-2 border-dashed border-gray-300 rounded-lg transition-all duration-200 hover:border-blue-500 hover:bg-blue-50 cursor-pointer">
|
||||
<div class="flex flex-col items-center justify-center p-8">
|
||||
<div class="flex flex-col items-center justify-center p-8 py-36">
|
||||
<i class="pi pi-cloud-upload text-6xl! text-gray-500 mb-4"></i>
|
||||
<p class="text-gray-600 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>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user