task-24: java-modules.ts 改为纯 re-export 聚合器,upload helpers 移至 upload.ts
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import { http, type JavaApiResponse } from './http.ts'
|
||||
import { JAVA_API_PREFIX } from './url.ts'
|
||||
|
||||
export interface UploadedFileRef {
|
||||
fileKey: string;
|
||||
originalFilename?: string;
|
||||
relativePath?: string;
|
||||
}
|
||||
|
||||
export interface UploadFileVo {
|
||||
fileKey: string;
|
||||
originalFilename: string;
|
||||
localPath: string;
|
||||
size: number;
|
||||
relativePath?: string;
|
||||
objectKey?: string;
|
||||
url?: string;
|
||||
mediaType?: "image" | "video" | "audio" | "file" | string;
|
||||
}
|
||||
|
||||
export interface UploadTempFileOptions {
|
||||
relativePath?: string;
|
||||
uploadToOss?: boolean;
|
||||
moduleType?: string;
|
||||
}
|
||||
|
||||
export async function uploadTempFileToJava(
|
||||
file: File,
|
||||
relativePathOrOptions?: string | UploadTempFileOptions,
|
||||
) {
|
||||
const options =
|
||||
typeof relativePathOrOptions === 'string'
|
||||
? { relativePath: relativePathOrOptions }
|
||||
: relativePathOrOptions || {}
|
||||
const formData = new FormData()
|
||||
formData.append('file', file)
|
||||
if (options.relativePath) {
|
||||
formData.append('relativePath', options.relativePath)
|
||||
}
|
||||
if (options.uploadToOss) {
|
||||
formData.append('uploadToOss', 'true')
|
||||
}
|
||||
if (options.moduleType) {
|
||||
formData.append('moduleType', options.moduleType)
|
||||
}
|
||||
const response = await http.post<JavaApiResponse<UploadFileVo>>(
|
||||
`${JAVA_API_PREFIX}/files/upload`,
|
||||
formData,
|
||||
{
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data',
|
||||
},
|
||||
timeout: 120000,
|
||||
},
|
||||
)
|
||||
return response.data
|
||||
}
|
||||
Reference in New Issue
Block a user