feat: upload cover not over yet
This commit is contained in:
75
src/services/uploadFiles.ts
Normal file
75
src/services/uploadFiles.ts
Normal file
@@ -0,0 +1,75 @@
|
||||
import httpService from './httpService'
|
||||
import type { ApiResponse } from './httpService'
|
||||
import Taro from '@tarojs/taro'
|
||||
import envConfig from '@/config/env'
|
||||
|
||||
// 用户接口
|
||||
export interface UploadFilesData {
|
||||
id: string,
|
||||
filePath: string,
|
||||
description?: string,
|
||||
tags?: string,
|
||||
is_public?: 0 | 1,
|
||||
}
|
||||
|
||||
// {"code":0,"message":"请求成功!","data":{"tags":["test"],"create_time":"2025-08-24 22:51:03","last_modify_time":"2025-08-24 22:51:03","duration":"0","thumbnail_url":"","view_count":"0","download_count":"0","id":16,"user_id":1,"resource_type":"image","file_name":"front/ball/images/63f56978-ffe9-4397-b897-8aca6f4fdcd8.png","original_name":"QyoUvEsLG6ci57c7e25cca0845dafed3ee1fde07876d.png","file_path":"http://bimwe.oss-cn-shanghai.aliyuncs.com/front/ball/images/63f56978-ffe9-4397-b897-8aca6f4fdcd8.png","file_url":"http://bimwe.oss-cn-shanghai.aliyuncs.com/front/ball/images/63f56978-ffe9-4397-b897-8aca6f4fdcd8.png","file_size":17756,"mime_type":"image/png","description":"test","is_public":"1","status":"active","width":0,"height":0,"uploadInfo":{"success":true,"name":"front/ball/images/63f56978-ffe9-4397-b897-8aca6f4fdcd8.png","path":"http://bimwe.oss-cn-shanghai.aliyuncs.com/front/ball/images/63f56978-ffe9-4397-b897-8aca6f4fdcd8.png","ossPath":"http://bimwe.oss-cn-shanghai.aliyuncs.com/front/ball/images/63f56978-ffe9-4397-b897-8aca6f4fdcd8.png","fileType":"image/png","fileSize":17756,"originalName":"QyoUvEsLG6ci57c7e25cca0845dafed3ee1fde07876d.png","suffix":"png","storagePath":"front/ball/images/63f56978-ffe9-4397-b897-8aca6f4fdcd8.png"}}}
|
||||
|
||||
export interface uploadFileResponse {
|
||||
code: number,
|
||||
message: string,
|
||||
data: uploadFileResponseData,
|
||||
}
|
||||
|
||||
export interface uploadFileResponseData {
|
||||
id: number,
|
||||
user_id: number,
|
||||
file_name: string,
|
||||
original_name: string,
|
||||
file_path: string,
|
||||
file_url: string,
|
||||
file_size: number,
|
||||
resource_type: string,
|
||||
mime_type: string,
|
||||
description: string,
|
||||
tags: string[],
|
||||
is_public: string,
|
||||
view_count: number,
|
||||
download_count: number,
|
||||
created_at: string,
|
||||
updated_at: string,
|
||||
}
|
||||
|
||||
function delay(ms: number) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms))
|
||||
}
|
||||
// 发布球局类
|
||||
class UploadApi {
|
||||
async upload(req: UploadFilesData): Promise<{ id: string, data: uploadFileResponseData }> {
|
||||
// return httpService.post('/files/upload', req, {
|
||||
// showLoading: true,
|
||||
// })
|
||||
const { id, ...rest } = req
|
||||
return Taro.uploadFile({
|
||||
url: `${envConfig.apiBaseURL}/api/gallery/upload`,
|
||||
filePath: rest.filePath,
|
||||
name: 'file',
|
||||
formData: {
|
||||
description: rest.description,
|
||||
tags: rest.tags,
|
||||
is_public: rest.is_public,
|
||||
}
|
||||
}).then(res => {
|
||||
return {
|
||||
id,
|
||||
data: JSON.parse(res.data).data,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async batchUpload(req: UploadFilesData[]): Promise<{ id: string, data: uploadFileResponseData }[]> {
|
||||
return Promise.all(req.map(item => this.upload(item)))
|
||||
}
|
||||
}
|
||||
|
||||
// 导出认证服务实例
|
||||
export default new UploadApi()
|
||||
Reference in New Issue
Block a user