diff --git a/src/api/review/meeting.ts b/src/api/review/meeting.ts index b9e320b30..271941415 100644 --- a/src/api/review/meeting.ts +++ b/src/api/review/meeting.ts @@ -1,4 +1,6 @@ import request from '@/config/axios' +import axios from 'axios' +import * as FileApi from '@/api/infra/file' // ============================================================ // 类型定义 @@ -84,6 +86,8 @@ export interface ReviewMeetingAgendaAttachmentRespVO { size: number } +const REVIEW_MEETING_ATTACHMENT_DIR = 'review-meeting/attachment' + // 短信发送状态 VO export interface ReviewMeetingSmsLogRespVO { id: number @@ -173,12 +177,10 @@ export const importProjectsFromExcel = async (file: File): Promise => { - const formData = new FormData() - formData.append('file', file) - return request - .upload({ url: '/project/review-meeting/upload-agenda-attachment', data: formData }) - .then((res) => res?.data as ReviewMeetingAgendaAttachmentRespVO) +export const uploadAgendaAttachment = async ( + file: File +): Promise => { + return uploadMeetingAttachmentByPresignedUrl(file) } /** 上传会议纪要附件(Word/PDF/图片) */ @@ -186,14 +188,48 @@ export const uploadMinutesAttachment = ( id: number, file: File ): Promise => { - const formData = new FormData() - formData.append('id', String(id)) - formData.append('file', file) - return request - .upload({ url: '/project/review-meeting/upload-minutes-attachment', data: formData }) - .then((res) => res?.data as ReviewMeetingAgendaAttachmentRespVO) + return uploadMeetingAttachmentByPresignedUrl(file).then((attachment) => + request + .put({ + url: '/project/review-meeting/minutes-attachment', + params: { id }, + data: attachment + }) + .then((res) => res?.data as ReviewMeetingAgendaAttachmentRespVO) + ) } /** 下载导入模板 */ export const getImportTemplate = () => request.download({ url: '/project/review-meeting/get-import-template' }) + +const uploadMeetingAttachmentByPresignedUrl = async ( + file: File +): Promise => { + const presignedInfo = await FileApi.getFilePresignedUrl(file.name, REVIEW_MEETING_ATTACHMENT_DIR) + await axios.put(presignedInfo.uploadUrl, file, { + headers: { + 'Content-Type': file.type || 'application/octet-stream' + } + }) + + await FileApi.createFile({ + configId: presignedInfo.configId, + url: presignedInfo.url, + path: presignedInfo.path, + name: file.name, + type: file.type || 'application/octet-stream', + size: file.size + }) + + return { + name: file.name, + url: presignedInfo.url, + type: resolveAttachmentType(file.name), + size: file.size + } +} + +const resolveAttachmentType = (fileName: string): string => { + return fileName.includes('.') ? fileName.substring(fileName.lastIndexOf('.') + 1).toLowerCase() : '' +}