From ead9d90029766ef51a1909392fae80073728a7c9 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Sat, 19 Oct 2024 01:25:39 +0200 Subject: [PATCH] [backend/drive] Fix drive file expiry leaving orphaned file versions in the storage backend --- Iceshrimp.Backend/Core/Services/DriveService.cs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Iceshrimp.Backend/Core/Services/DriveService.cs b/Iceshrimp.Backend/Core/Services/DriveService.cs index b64fc20e..85a6e6d4 100644 --- a/Iceshrimp.Backend/Core/Services/DriveService.cs +++ b/Iceshrimp.Backend/Core/Services/DriveService.cs @@ -437,6 +437,8 @@ public class DriveService( { if (file is not { UserHost: not null, Uri: not null, IsLink: false }) return; + string?[] paths = [file.AccessKey, file.ThumbnailAccessKey, file.PublicAccessKey]; + file.IsLink = true; file.Url = file.Uri; file.ThumbnailUrl = null; @@ -453,15 +455,16 @@ public class DriveService( .ExecuteUpdateAsync(p => p.SetProperty(u => u.BannerUrl, file.Uri), token); await db.SaveChangesAsync(token); - if (file.AccessKey == null) return; - var deduplicated = - await db.DriveFiles.AnyAsync(p => p.Id != file.Id && p.AccessKey == file.AccessKey && !p.IsLink, - token); + if (file.AccessKey != null) + { + var deduplicated = await db.DriveFiles + .AnyAsync(p => p.Id != file.Id && p.AccessKey == file.AccessKey && !p.IsLink, + token); - if (deduplicated) - return; + if (deduplicated) + return; + } - string?[] paths = [file.AccessKey, file.ThumbnailAccessKey, file.PublicAccessKey]; if (file.StoredInternal) { var pathBase = storageConfig.Value.Local?.Path ??