61 lines
1.4 KiB
TypeScript
61 lines
1.4 KiB
TypeScript
import { Attachment, BizIdUpdate, TempFile } from "../types";
|
|
import { axios } from "./BaseAPI";
|
|
import CommonAPI from "./CommonAPI";
|
|
|
|
const BASE_URI = "/attach";
|
|
|
|
export const AttachmentAPI = {
|
|
/**
|
|
* 上传临时附件
|
|
*
|
|
* @param file 文件或文件列表
|
|
* @param ttl 有效期
|
|
* @returns 临时附件列表
|
|
*/
|
|
async upload(file: File | File[], ttl?: string): Promise<TempFile[]> {
|
|
const formData = new FormData();
|
|
const fileList = Array.isArray(file) ? file : [file];
|
|
for (const item of fileList) {
|
|
formData.append("file", item);
|
|
}
|
|
if (ttl) {
|
|
formData.append("ttl", ttl);
|
|
}
|
|
return await axios.post(`${BASE_URI}/temp/upload`, formData);
|
|
},
|
|
/**
|
|
* 按业务差分更新附件
|
|
*
|
|
* @param req 更新请求
|
|
*/
|
|
async updateByBizId(req: BizIdUpdate): Promise<void> {
|
|
return await axios.post(`${BASE_URI}/update/biz/id`, req);
|
|
},
|
|
/**
|
|
* 按业务查询附件列表
|
|
*
|
|
* @param bizType 业务类型
|
|
* @param bizId 业务 ID
|
|
* @param attachTypeList 附件类型列表
|
|
*/
|
|
async listByBizId(bizType: string, bizId: string, attachTypeList?: string[]): Promise<Attachment[]> {
|
|
return await axios.get(`${BASE_URI}/list/biz/id`, {
|
|
params: {
|
|
bizType,
|
|
bizId,
|
|
attachTypeList
|
|
}
|
|
});
|
|
},
|
|
|
|
getReadURL(id: string): string {
|
|
return CommonAPI.getAttachmentReadAPI(id);
|
|
},
|
|
|
|
getTempReadURL(id: string): string {
|
|
return CommonAPI.getAttachmentTempReadAPI(id);
|
|
}
|
|
};
|
|
|
|
export default AttachmentAPI;
|