增加作品完整性检查

This commit is contained in:
2025-08-26 08:43:55 +08:00
parent 5ce5543461
commit 7206d803eb
5 changed files with 331 additions and 18 deletions
+23 -7
View File
@@ -59,21 +59,37 @@ class DownloadExecutor {
const fileName = `image_${index + 1}.${this.getFileExtension(imageUrl)}`;
const filePath = path.join(artworkDir, fileName);
// 检查文件是否已存在
// 检查文件是否已存在且完整
if (await this.fileManager.fileExists(filePath)) {
task.completed_files++;
task.progress = Math.round((task.completed_files / task.total_files) * 100);
await this.taskManager.saveTasks();
this.progressManager.notifyProgressUpdate(task.id, task);
continue;
// 验证文件完整性
const integrity = await this.fileManager.checkFileIntegrity(filePath);
if (integrity.valid) {
task.completed_files++;
task.progress = Math.round((task.completed_files / task.total_files) * 100);
await this.taskManager.saveTasks();
this.progressManager.notifyProgressUpdate(task.id, task);
results.push({ success: true, file: fileName, skipped: true });
continue;
} else {
// 文件不完整,删除重新下载
console.log(`文件不完整,重新下载: ${filePath}`);
await this.fileManager.safeDeleteFile(filePath);
}
}
try {
// 确保目录存在
await this.fileManager.ensureDirectory(path.dirname(filePath));
// 下载文件并等待完成
await this.fileManager.downloadFile(imageUrl, filePath);
// 验证下载的文件完整性
const integrity = await this.fileManager.checkFileIntegrity(filePath);
if (!integrity.valid) {
throw new Error(`文件下载不完整: ${integrity.reason}`);
}
task.completed_files++;
task.progress = Math.round((task.completed_files / task.total_files) * 100);
await this.taskManager.saveTasks();
@@ -92,7 +108,7 @@ class DownloadExecutor {
const infoPath = path.join(artworkDir, 'artwork_info.json');
await fs.writeJson(infoPath, artwork, { spaces: 2 });
// 更新任务状态
// 更新任务状态 - 确保所有文件都处理完成后再更新
task.status = task.failed_files === 0 ? 'completed' : 'partial';
task.end_time = new Date();
task.progress = 100;