🐛 Trying to fix the file migration service
This commit is contained in:
@@ -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";
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user