You've already forked DataMate
fix(upload): 修复流式上传中的文件名处理逻辑
- 修正预上传接口调用时传递正确的文件总数而非固定值-1 - 移除导入配置中文件分割时的文件扩展名保留逻辑 - 删除流式上传选项中的fileExtension参数定义 - 移除流式上传实现中的文件扩展名处理相关代码 - 简化新文件名生成逻辑,不再附加扩展名后缀
This commit is contained in:
@@ -205,7 +205,7 @@ export function useFileSliceUpload(
|
||||
// 预上传,获取 reqId
|
||||
const totalSize = files.reduce((acc, file) => acc + file.size, 0);
|
||||
const { data: reqId } = await preUpload(task.key, {
|
||||
totalFileNum: -1, // 流式上传,文件数量不确定
|
||||
totalFileNum: files.length,
|
||||
totalSize,
|
||||
datasetId: task.key,
|
||||
hasArchive: task.hasArchive,
|
||||
|
||||
@@ -90,14 +90,16 @@ async function splitFileByLines(file: UploadFile): Promise<UploadFile[]> {
|
||||
const lines = text.split(/\r?\n/).filter((line: string) => line.trim() !== "");
|
||||
if (lines.length === 0) return [];
|
||||
|
||||
// 生成文件名:原文件名_序号.扩展名
|
||||
// 生成文件名:原文件名_序号(不保留后缀)
|
||||
const nameParts = file.name.split(".");
|
||||
const ext = nameParts.length > 1 ? "." + nameParts.pop() : "";
|
||||
if (nameParts.length > 1) {
|
||||
nameParts.pop();
|
||||
}
|
||||
const baseName = nameParts.join(".");
|
||||
const padLength = String(lines.length).length;
|
||||
|
||||
return lines.map((line: string, index: number) => {
|
||||
const newFileName = `${baseName}_${String(index + 1).padStart(padLength, "0")}${ext}`;
|
||||
const newFileName = `${baseName}_${String(index + 1).padStart(padLength, "0")}`;
|
||||
const blob = new Blob([line], { type: "text/plain" });
|
||||
const newFile = new File([blob], newFileName, { type: "text/plain" });
|
||||
return {
|
||||
|
||||
@@ -403,7 +403,6 @@ export function readFileAsText(
|
||||
export interface StreamUploadOptions {
|
||||
reqId: number;
|
||||
fileNamePrefix?: string;
|
||||
fileExtension?: string;
|
||||
hasArchive?: boolean;
|
||||
prefix?: string;
|
||||
signal?: AbortSignal;
|
||||
@@ -423,7 +422,7 @@ export async function streamSplitAndUpload(
|
||||
chunkSize: number = 1024 * 1024, // 1MB
|
||||
options: StreamUploadOptions
|
||||
): Promise<StreamUploadResult> {
|
||||
const { reqId, fileNamePrefix, fileExtension = ".txt", prefix, signal, maxConcurrency = 3 } = options;
|
||||
const { reqId, fileNamePrefix, prefix, signal, maxConcurrency = 3 } = options;
|
||||
|
||||
const fileSize = file.size;
|
||||
let offset = 0;
|
||||
@@ -434,7 +433,6 @@ export async function streamSplitAndUpload(
|
||||
|
||||
// 获取文件名基础部分
|
||||
const baseName = fileNamePrefix || file.name.replace(/\.[^/.]+$/, "");
|
||||
const ext = fileExtension.startsWith(".") ? fileExtension : `.${fileExtension}`;
|
||||
|
||||
// 用于并发控制的队列
|
||||
const uploadQueue: Promise<void>[] = [];
|
||||
@@ -449,7 +447,7 @@ export async function streamSplitAndUpload(
|
||||
return;
|
||||
}
|
||||
|
||||
const newFileName = `${baseName}_${String(index + 1).padStart(6, "0")}${ext}`;
|
||||
const newFileName = `${baseName}_${String(index + 1).padStart(6, "0")}`;
|
||||
const blob = new Blob([line], { type: "text/plain" });
|
||||
const lineFile = new File([blob], newFileName, { type: "text/plain" });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user