mirror of
https://github.com/ostris/ai-toolkit.git
synced 2026-01-26 16:39:47 +00:00
Fix upload progress for datasets in the ui
This commit is contained in:
@@ -22,19 +22,21 @@ export async function POST(request: NextRequest) {
|
||||
const uploadDir = join(datasetsPath, datasetName);
|
||||
await mkdir(uploadDir, { recursive: true });
|
||||
|
||||
const savedFiles = await Promise.all(
|
||||
files.map(async (file: any) => {
|
||||
const bytes = await file.arrayBuffer();
|
||||
const buffer = Buffer.from(bytes);
|
||||
const savedFiles: string[] = [];
|
||||
|
||||
// Process files sequentially to avoid overwhelming the system
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
const file = files[i] as any;
|
||||
const bytes = await file.arrayBuffer();
|
||||
const buffer = Buffer.from(bytes);
|
||||
|
||||
// Clean filename and ensure it's unique
|
||||
const fileName = file.name.replace(/[^a-zA-Z0-9.-]/g, '_');
|
||||
const filePath = join(uploadDir, fileName);
|
||||
// Clean filename and ensure it's unique
|
||||
const fileName = file.name.replace(/[^a-zA-Z0-9.-]/g, '_');
|
||||
const filePath = join(uploadDir, fileName);
|
||||
|
||||
await writeFile(filePath, buffer);
|
||||
return fileName;
|
||||
}),
|
||||
);
|
||||
await writeFile(filePath, buffer);
|
||||
savedFiles.push(fileName);
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
message: 'Files uploaded successfully',
|
||||
|
||||
Reference in New Issue
Block a user