🐛 Trying to fix the file migration service

This commit is contained in:
2026-01-13 00:39:52 +08:00
parent 2e945ee477
commit dadf3c67bf

View File

@@ -1,6 +1,5 @@
using DysonNetwork.Shared.Models; using DysonNetwork.Shared.Models;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System.IO;
namespace DysonNetwork.Drive.Storage; namespace DysonNetwork.Drive.Storage;
@@ -13,8 +12,7 @@ public class FileMigrationService(AppDatabase db, ILogger<FileMigrationService>
var cloudFiles = await db.Files var cloudFiles = await db.Files
.Where(f => .Where(f =>
f.ObjectId == null && f.ObjectId == null &&
f.PoolId != null && f.PoolId != null
!db.FileObjects.Any(fo => fo.Id == f.Id)
) )
.ToListAsync(); .ToListAsync();
@@ -22,6 +20,12 @@ public class FileMigrationService(AppDatabase db, ILogger<FileMigrationService>
foreach (var cf in cloudFiles) foreach (var cf in cloudFiles)
{ {
if (await db.FileObjects.AnyAsync(fo => fo.Id == cf.Id))
{
logger.LogWarning("FileObject for {Id} already exists, skipping.", cf.Id);
continue;
}
var ext = Path.GetExtension(cf.Name); var ext = Path.GetExtension(cf.Name);
var mimeType = ext != "" && MimeTypes.TryGetMimeType(ext, out var mime) ? mime : "application/octet-stream"; var mimeType = ext != "" && MimeTypes.TryGetMimeType(ext, out var mime) ? mime : "application/octet-stream";