feat(upload): add image format conversion and quality settings for uploads #6

This commit is contained in:
shiyu
2025-05-23 20:10:09 +08:00
parent c6cc7cc777
commit b26b076736
10 changed files with 438 additions and 132 deletions

View File

@@ -119,6 +119,8 @@ export async function uploadPicture(
data: {
permission?: number;
albumId?: number;
convertToFormat?: string;
quality?: number;
onProgress?: (percent: number) => void
} = {}
): Promise<BaseResult<PictureResponse>> {
@@ -133,6 +135,14 @@ export async function uploadPicture(
formData.append('albumId', data.albumId.toString());
}
if (data.convertToFormat !== undefined) {
formData.append('convertToFormat', data.convertToFormat.toString());
}
if (data.quality !== undefined) {
formData.append('quality', data.quality.toString());
}
try {
const token = localStorage.getItem('token');
const headers: Record<string, string> = {};

View File

@@ -103,10 +103,24 @@ export interface UploadFile {
response?: PictureResponse; // 上传成功后的响应
}
// 上传图片请求参数
// 图片格式类型
export type ImageFormat = 0 | 1 | 2 | 3;
// 添加常量对象提供运行时值
export const ImageFormat = {
Original: 0 as ImageFormat,
Jpeg: 1 as ImageFormat,
Png: 2 as ImageFormat,
WebP: 3 as ImageFormat
};
// 上传图片参数
export interface UploadPictureParams {
permission?: number; // 权限设置默认为0公开
albumId?: number; // 相册ID可选
permission?: number;
albumId?: number;
convertToFormat?: ImageFormat;
quality?: number;
onProgress?: (percent: number) => void;
}
// 相册响应数据