From 28a13f7baf12ab44bf22cd081764b513540437f3 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Tue, 13 Jan 2026 22:51:13 +0800 Subject: [PATCH] :necktie: No longer create permission for owner --- DysonNetwork.Drive/Storage/FileController.cs | 2 +- .../Storage/FileObjectCleanupJob.cs | 2 +- DysonNetwork.Drive/Storage/FileService.cs | 77 +------------------ DysonNetwork.Drive/Storage/Model/Events.cs | 4 +- 4 files changed, 6 insertions(+), 79 deletions(-) diff --git a/DysonNetwork.Drive/Storage/FileController.cs b/DysonNetwork.Drive/Storage/FileController.cs index 972b9512..4c83040c 100644 --- a/DysonNetwork.Drive/Storage/FileController.cs +++ b/DysonNetwork.Drive/Storage/FileController.cs @@ -321,7 +321,7 @@ public class FileController( string? overrideMimeType ) { - var client = fs.CreateMinioClient(dest); + var client = FileService.CreateMinioClient(dest); if (client is null) return BadRequest("Failed to configure client for remote destination, file got an invalid storage remote."); diff --git a/DysonNetwork.Drive/Storage/FileObjectCleanupJob.cs b/DysonNetwork.Drive/Storage/FileObjectCleanupJob.cs index 40d253e5..8c6b6972 100644 --- a/DysonNetwork.Drive/Storage/FileObjectCleanupJob.cs +++ b/DysonNetwork.Drive/Storage/FileObjectCleanupJob.cs @@ -49,7 +49,7 @@ public class FileObjectCleanupJob(AppDatabase db, FileService fileService, ILogg { var dest = await fileService.GetRemoteStorageConfig(replica.PoolId!.Value); if (dest == null) continue; - var client = fileService.CreateMinioClient(dest); + var client = FileService.CreateMinioClient(dest); if (client == null) continue; try { diff --git a/DysonNetwork.Drive/Storage/FileService.cs b/DysonNetwork.Drive/Storage/FileService.cs index fdecc43b..0380518e 100644 --- a/DysonNetwork.Drive/Storage/FileService.cs +++ b/DysonNetwork.Drive/Storage/FileService.cs @@ -257,19 +257,10 @@ public class FileService( IsPrimary = true }; - var permission = new SnFilePermission - { - Id = Guid.NewGuid(), - FileId = file.Id, - SubjectType = SnFilePermissionType.Someone, - SubjectId = file.AccountId.ToString(), - Permission = SnFilePermissionLevel.Write - }; db.Files.Add(file); db.FileObjects.Add(fileObject); db.FileReplicas.Add(replica); - db.FilePermissions.Add(permission); await db.SaveChangesAsync(); file.ObjectId = file.Id; @@ -700,7 +691,7 @@ public class FileService( return await GetRemoteStorageConfig(id); } - public IMinioClient? CreateMinioClient(RemoteStorageConfig dest) + public static IMinioClient? CreateMinioClient(RemoteStorageConfig dest) { var client = new MinioClient() .WithEndpoint(dest.Endpoint) @@ -717,76 +708,12 @@ public class FileService( await cache.RemoveAsync(cacheKey); } - internal async Task _PurgeCacheRangeAsync(IEnumerable fileIds) + private async Task _PurgeCacheRangeAsync(IEnumerable fileIds) { var tasks = fileIds.Select(_PurgeCacheAsync); await Task.WhenAll(tasks); } - public async Task> LoadFromReference(List references) - { - var cachedFiles = new Dictionary(); - var uncachedIds = new List(); - - foreach (var reference in references) - { - var cacheKey = string.Concat(CacheKeyPrefix, reference.Id); - var cachedFile = await cache.GetAsync(cacheKey); - - if (cachedFile != null) - { - cachedFiles[reference.Id] = cachedFile; - } - else - { - uncachedIds.Add(reference.Id); - } - } - - if (uncachedIds.Count > 0) - { - var dbFiles = await db.Files - .Where(f => uncachedIds.Contains(f.Id)) - .Include(f => f.Object) - .ThenInclude(o => o.FileReplicas) - .ToListAsync(); - - foreach (var file in dbFiles) - { - var cacheKey = string.Concat(CacheKeyPrefix, file.Id); - await cache.SetAsync(cacheKey, file, CacheDuration); - cachedFiles[file.Id] = file; - } - } - - return - [ - .. references - .Select(r => cachedFiles.GetValueOrDefault(r.Id)) - .Where(f => f != null) - ]; - } - - public async Task GetReferenceCountAsync(string fileId) - { - var file = await db.Files.FirstOrDefaultAsync(f => f.Id == fileId); - if (file == null || file.ObjectId == null) return 0; - - return await db.Files - .Where(f => f.ObjectId == file.ObjectId && f.Id != fileId) - .CountAsync(); - } - - public async Task IsReferencedAsync(string fileId) - { - var file = await db.Files.FirstOrDefaultAsync(f => f.Id == fileId); - if (file == null || file.ObjectId == null) return false; - - return await db.Files - .Where(f => f.ObjectId == file.ObjectId && f.Id != fileId) - .AnyAsync(); - } - private static bool IsIgnoredField(string fieldName) { var gpsFields = new[] diff --git a/DysonNetwork.Drive/Storage/Model/Events.cs b/DysonNetwork.Drive/Storage/Model/Events.cs index ab6320a8..b7aed0fb 100644 --- a/DysonNetwork.Drive/Storage/Model/Events.cs +++ b/DysonNetwork.Drive/Storage/Model/Events.cs @@ -8,8 +8,8 @@ public static class FileUploadedEvent public record FileUploadedEventPayload( string FileId, Guid RemoteId, - string StorageId, - string ContentType, + string? StorageId, + string? ContentType, string ProcessingFilePath, bool IsTempFile );