diff --git a/DysonNetwork.Drive/Storage/FileService.cs b/DysonNetwork.Drive/Storage/FileService.cs index 514a5b17..fdecc43b 100644 --- a/DysonNetwork.Drive/Storage/FileService.cs +++ b/DysonNetwork.Drive/Storage/FileService.cs @@ -30,7 +30,7 @@ public class FileService( public async Task GetFileAsync(string fileId) { - var cacheKey = $"{CacheKeyPrefix}{fileId}"; + var cacheKey = string.Concat(CacheKeyPrefix, fileId); var cachedFile = await cache.GetAsync(cacheKey); if (cachedFile is not null) @@ -57,7 +57,7 @@ public class FileService( foreach (var fileId in fileIds) { - var cacheKey = $"{CacheKeyPrefix}{fileId}"; + var cacheKey = string.Concat(CacheKeyPrefix, fileId); var cachedFile = await cache.GetAsync(cacheKey); if (cachedFile != null) @@ -77,7 +77,7 @@ public class FileService( foreach (var file in dbFiles) { - var cacheKey = $"{CacheKeyPrefix}{file.Id}"; + var cacheKey = string.Concat(CacheKeyPrefix, file.Id); await cache.SetAsync(cacheKey, file, CacheDuration); cachedFiles[file.Id] = file; } @@ -295,6 +295,8 @@ public class FileService( private async Task ExtractMetadataAsync(SnCloudFile file, string filePath) { + if (file.Object == null) return; + switch (file.MimeType?.Split('/')[0]) { case "image": @@ -340,11 +342,11 @@ public class FileService( if (orientation is 6 or 8) (width, height) = (height, width); meta["exif"] = exif; meta["ratio"] = height != 0 ? (double)width / height : 0; - file.Object!.Meta = meta; + file.Object.Meta = meta; } catch (Exception ex) { - file.Object!.Meta = new Dictionary(); + file.Object.Meta = new Dictionary(); logger.LogError(ex, "Failed to analyze image file {FileId}", file.Id); } @@ -355,7 +357,7 @@ public class FileService( try { var mediaInfo = await FFProbe.AnalyseAsync(filePath); - file.Object!.Meta = new Dictionary + file.Object.Meta = new Dictionary { ["width"] = mediaInfo.PrimaryVideoStream?.Width, ["height"] = mediaInfo.PrimaryVideoStream?.Height, @@ -391,7 +393,7 @@ public class FileService( .ToList(), }; if (mediaInfo.PrimaryVideoStream is not null) - file.Object!.Meta["ratio"] = (double)mediaInfo.PrimaryVideoStream.Width / + file.Object.Meta["ratio"] = (double)mediaInfo.PrimaryVideoStream.Width / mediaInfo.PrimaryVideoStream.Height; } catch (Exception ex) @@ -711,7 +713,7 @@ public class FileService( internal async Task _PurgeCacheAsync(string fileId) { - var cacheKey = $"{CacheKeyPrefix}{fileId}"; + var cacheKey = string.Concat(CacheKeyPrefix, fileId); await cache.RemoveAsync(cacheKey); } @@ -728,7 +730,7 @@ public class FileService( foreach (var reference in references) { - var cacheKey = $"{CacheKeyPrefix}{reference.Id}"; + var cacheKey = string.Concat(CacheKeyPrefix, reference.Id); var cachedFile = await cache.GetAsync(cacheKey); if (cachedFile != null) @@ -751,7 +753,7 @@ public class FileService( foreach (var file in dbFiles) { - var cacheKey = $"{CacheKeyPrefix}{file.Id}"; + var cacheKey = string.Concat(CacheKeyPrefix, file.Id); await cache.SetAsync(cacheKey, file, CacheDuration); cachedFiles[file.Id] = file; } @@ -911,4 +913,4 @@ file class UpdatableCloudFile(SnCloudFile file) .SetProperty(f => f.UserMeta, userMeta) .SetProperty(f => f.IsMarkedRecycle, IsMarkedRecycle); } -} \ No newline at end of file +} diff --git a/DysonNetwork.Shared/Cache/JsonCacheSerializer.cs b/DysonNetwork.Shared/Cache/JsonCacheSerializer.cs index 31d13fde..24ebbc26 100644 --- a/DysonNetwork.Shared/Cache/JsonCacheSerializer.cs +++ b/DysonNetwork.Shared/Cache/JsonCacheSerializer.cs @@ -19,7 +19,7 @@ public class JsonCacheSerializer : ICacheSerializer { Modifiers = { JsonExtensions.UnignoreAllProperties() }, }, - ReferenceHandler = ReferenceHandler.Preserve, + ReferenceHandler = ReferenceHandler.IgnoreCycles, NumberHandling = JsonNumberHandling.AllowNamedFloatingPointLiterals, Converters = { new ByteStringConverter() } }; @@ -32,4 +32,4 @@ public class JsonCacheSerializer : ICacheSerializer public T? Deserialize(string data) => JsonSerializer.Deserialize(data, _options); -} \ No newline at end of file +}