From fa42ea67ac1b77cbc6e804e3d3044ce0336557ff Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Tue, 15 Apr 2025 00:39:22 +0800 Subject: [PATCH] :necktie: File analyzer no longer remove GPS EXIF --- DysonNetwork.Sphere/Program.cs | 7 +-- DysonNetwork.Sphere/Storage/FileService.cs | 62 ++++------------------ 2 files changed, 10 insertions(+), 59 deletions(-) diff --git a/DysonNetwork.Sphere/Program.cs b/DysonNetwork.Sphere/Program.cs index d82b393..1a66c11 100644 --- a/DysonNetwork.Sphere/Program.cs +++ b/DysonNetwork.Sphere/Program.cs @@ -204,12 +204,7 @@ app.MapTus("/files/tus", (_) => Task.FromResult(new() var fileService = eventContext.HttpContext.RequestServices.GetRequiredService(); - var (info, processedStream) = await fileService.AnalyzeFileAsync(account, file.Id, fileStream, fileName, contentType); - // Write the processed stream to the disk - var tusPath = builder.Configuration.GetSection("Tus").GetValue("StorePath")!; - var tusFilePath = Path.Combine(tusPath, file.Id); - await using var fileStreamWriter = new FileStream(tusFilePath, FileMode.Create, FileAccess.Write); - await processedStream.CopyToAsync(fileStreamWriter); + var info = await fileService.AnalyzeFileAsync(account, file.Id, fileStream, fileName, contentType); var jsonOptions = httpContext.RequestServices.GetRequiredService>().Value .JsonSerializerOptions; diff --git a/DysonNetwork.Sphere/Storage/FileService.cs b/DysonNetwork.Sphere/Storage/FileService.cs index 0653496..66db4f6 100644 --- a/DysonNetwork.Sphere/Storage/FileService.cs +++ b/DysonNetwork.Sphere/Storage/FileService.cs @@ -14,46 +14,14 @@ namespace DysonNetwork.Sphere.Storage; public class FileService(AppDatabase db, IConfiguration configuration) { - private static readonly List BlacklistExifTags = - [ - ExifTag.GPSLatitudeRef, - ExifTag.GPSLatitude, - ExifTag.GPSLongitudeRef, - ExifTag.GPSLongitude, - ExifTag.GPSAltitudeRef, - ExifTag.GPSAltitude, - ExifTag.GPSSatellites, - ExifTag.GPSStatus, - ExifTag.GPSMeasureMode, - ExifTag.GPSDOP, - ExifTag.GPSSpeedRef, - ExifTag.GPSSpeed, - ExifTag.GPSTrackRef, - ExifTag.GPSTrack, - ExifTag.GPSImgDirectionRef, - ExifTag.GPSImgDirection, - ExifTag.GPSMapDatum, - ExifTag.GPSDestLatitudeRef, - ExifTag.GPSDestLatitude, - ExifTag.GPSDestLongitudeRef, - ExifTag.GPSDestLongitude, - ExifTag.GPSDestBearingRef, - ExifTag.GPSDestBearing, - ExifTag.GPSDestDistanceRef, - ExifTag.GPSDestDistance, - ExifTag.GPSProcessingMethod, - ExifTag.GPSAreaInformation, - ExifTag.GPSDateStamp, - ExifTag.GPSDifferential - ]; - - public async Task<(CloudFile, Stream)> AnalyzeFileAsync( + // The analysis file method no longer will remove the GPS EXIF data + // It should be handled on the client side, and for some specific cases it should be keep + public async Task AnalyzeFileAsync( Account.Account account, string fileId, Stream stream, string fileName, - string? contentType, - string? filePath = null + string? contentType ) { var fileSize = stream.Length; @@ -61,7 +29,7 @@ public class FileService(AppDatabase db, IConfiguration configuration) contentType ??= !fileName.Contains('.') ? "application/octet-stream" : MimeTypes.GetMimeType(fileName); var existingFile = await db.Files.Where(f => f.Hash == hash).FirstOrDefaultAsync(); - if (existingFile is not null) return (existingFile, stream); + if (existingFile is not null) return existingFile; var file = new CloudFile { @@ -88,16 +56,9 @@ public class FileService(AppDatabase db, IConfiguration configuration) ushort orientation = 1; List exif = []; - if (exifProfile is not null) - { - exif = exifProfile.Values - .Where(v => !BlacklistExifTags.Contains((ExifTag)v.Tag)) - .ToList(); - - if (exifProfile.Values.FirstOrDefault(e => e.Tag == ExifTag.Orientation) - ?.GetValue() is ushort o) - orientation = o; - } + if (exifProfile?.Values.FirstOrDefault(e => e.Tag == ExifTag.Orientation) + ?.GetValue() is ushort o) + orientation = o; if (orientation is 6 or 8) (width, height) = (height, width); @@ -114,11 +75,6 @@ public class FileService(AppDatabase db, IConfiguration configuration) ["ratio"] = aspectRatio, ["exif"] = exif }; - - var newStream = new MemoryStream(); - await imageSharp.SaveAsWebpAsync(newStream); - file.MimeType = "image/webp"; - stream = newStream; } break; @@ -140,7 +96,7 @@ public class FileService(AppDatabase db, IConfiguration configuration) db.Files.Add(file); await db.SaveChangesAsync(); - return (file, stream); + return file; } private static async Task HashFileAsync(Stream stream, int chunkSize = 1024 * 1024, long? fileSize = null)