task-24: java-modules.ts 改为纯 re-export 聚合器,upload helpers 移至 upload.ts

This commit is contained in:
2026-08-31 20:00:45 +08:00
parent 21c92afa7a
commit eaf457c6c0
3 changed files with 193 additions and 175 deletions
+57
View File
@@ -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
}