feat(file): 优化文件上传处理和ID管理规范

- 新增 buildFileProxyUrl 函数构建永久代理路径,避免富文本图片链接过期
- 重构 uploadFile 函数,统一将后端返回的数值型 ID 转换为字符串
- 在业务富文本编辑器中使用永久代理路径替换临时签名 URL
- 完善 API 适配层 ID 规范,确保所有 ID 字段统一转换为字符串类型
- 移除废弃的编辑器相关路由和组件
- 更新构建代理配置以支持富文本图片直连访问
- 删除冗余的类型定义和依赖包
This commit is contained in:
2026-05-15 10:06:51 +08:00
parent 3a064eb09f
commit 7a4d831c10
15 changed files with 61 additions and 137 deletions

View File

@@ -1,28 +1,61 @@
import { SYSTEM_SERVICE_PREFIX } from '@/constants/service';
import { request } from '../request';
import { type ServiceRequestResult, mapServiceResult } from './shared';
const FILE_PREFIX = `${SYSTEM_SERVICE_PREFIX}/file`;
/**
* 拼接文件永久代理路径,用于富文本 <img src>。
*
* 后端 GET 接口匿名访问、Content-Disposition: inline私有桶下也不会过期。
* 调用方拿到上传响应里的 configId + path 后直接调用本函数得到可写入 HTML 的 url。
*/
export function buildFileProxyUrl(configId: string, path: string) {
return `${FILE_PREFIX}/${configId}/get/${encodeURI(path)}`;
}
export interface UploadFileResult {
/** infra_file.id 的字符串形式(避免 Long 精度丢失) */
id: string;
/** 文件访问 URL私有桶带签名、公开桶裸 URL */
/** 对象存储配置编号(字符串形式),与 path 一起拼接永久代理路径 */
configId: string;
/** 文件相对路径(含日期目录、文件名),与 configId 一起拼接永久代理路径 */
path: string;
/**
* 文件访问 URL私有桶带签名24h 过期)、公开桶裸 URL。
* ⚠️ 仅供后端调试 / 历史兼容,禁止写进富文本 <img src> —— 会随签名过期导致回显失效。
* 富文本图片请用 buildFileProxyUrl(configId, path) 的返回值。
*/
url: string;
}
type UploadFileResponse = {
id: string | number;
configId: string | number;
path: string;
url: string;
};
/** 上传文件(模式一:后端中转) */
export function uploadFile(file: File, directory?: string) {
export async function uploadFile(file: File, directory?: string) {
const formData = new FormData();
formData.append('file', file);
if (directory) {
formData.append('directory', directory);
}
return request<UploadFileResult>({
const result = await request<UploadFileResponse>({
url: `${FILE_PREFIX}/upload`,
method: 'post',
data: formData
});
return mapServiceResult(result as ServiceRequestResult<UploadFileResponse>, data => ({
id: String(data.id),
configId: String(data.configId),
path: data.path,
url: data.url
}));
}
/**