[backend] Reformat DriveService.cs

This commit is contained in:
Laura Hausmann 2024-12-16 21:30:35 +01:00
parent 48e688e514
commit 49e9c6d825
No known key found for this signature in database
GPG key ID: D044E84C5BE01605

View file

@ -101,8 +101,8 @@ public class DriveService(
var res = await httpClient.GetAsync(uri, HttpCompletionOption.ResponseHeadersRead); var res = await httpClient.GetAsync(uri, HttpCompletionOption.ResponseHeadersRead);
res.EnsureSuccessStatusCode(); res.EnsureSuccessStatusCode();
var filename = res.Content.Headers.ContentDisposition?.FileName ?? var filename = res.Content.Headers.ContentDisposition?.FileName
new Uri(uri).AbsolutePath.Split('/').LastOrDefault() ?? ""; ?? new Uri(uri).AbsolutePath.Split('/').LastOrDefault() ?? "";
var request = new DriveFileCreationRequest var request = new DriveFileCreationRequest
{ {
@ -228,8 +228,8 @@ public class DriveService(
var storedInternal = storageConfig.Value.Provider == Enums.FileStorage.Local; var storedInternal = storageConfig.Value.Provider == Enums.FileStorage.Local;
var shouldCache = var shouldCache =
storageConfig.Value is { MediaRetentionTimeSpan: not null, MediaProcessing.LocalOnly: false } && storageConfig.Value is { MediaRetentionTimeSpan: not null, MediaProcessing.LocalOnly: false }
buf.Length <= storageConfig.Value.MaxCacheSizeBytes; && buf.Length <= storageConfig.Value.MaxCacheSizeBytes;
var shouldStore = user.IsLocalUser || shouldCache; var shouldStore = user.IsLocalUser || shouldCache;
@ -291,8 +291,8 @@ public class DriveService(
.AwaitAllNoConcurrencyAsync() .AwaitAllNoConcurrencyAsync()
.ContinueWithResult(p => p.ToImmutableArray()); .ContinueWithResult(p => p.ToImmutableArray());
original = processed.FirstOrDefault(p => p?.format.Key == KeyEnum.Original) ?? original = processed.FirstOrDefault(p => p?.format.Key == KeyEnum.Original)
throw new Exception("Image processing didn't result in an original version"); ?? throw new Exception("Image processing didn't result in an original version");
thumbnail = processed.FirstOrDefault(p => p?.format.Key == KeyEnum.Thumbnail); thumbnail = processed.FirstOrDefault(p => p?.format.Key == KeyEnum.Thumbnail);
@public = processed.FirstOrDefault(p => p?.format.Key == KeyEnum.Public); @public = processed.FirstOrDefault(p => p?.format.Key == KeyEnum.Public);
@ -415,8 +415,7 @@ public class DriveService(
private async Task<string> StoreFileVersionLocalStorageAsync(Stream stream, string filename) private async Task<string> StoreFileVersionLocalStorageAsync(Stream stream, string filename)
{ {
var pathBase = storageConfig.Value.Local?.Path ?? var pathBase = storageConfig.Value.Local?.Path ?? throw new Exception("Local storage path cannot be null");
throw new Exception("Local storage path cannot be null");
var path = Path.Combine(pathBase, filename); var path = Path.Combine(pathBase, filename);
await using var writer = File.OpenWrite(path); await using var writer = File.OpenWrite(path);
@ -480,8 +479,8 @@ public class DriveService(
if (storedInternal) if (storedInternal)
{ {
var pathBase = storageConfig.Value.Local?.Path ?? var pathBase = storageConfig.Value.Local?.Path
throw new Exception("Cannot delete locally stored file: pathBase is null"); ?? throw new Exception("Cannot delete locally stored file: pathBase is null");
paths.Where(p => p != null) paths.Where(p => p != null)
.Select(p => Path.Combine(pathBase, p!)) .Select(p => Path.Combine(pathBase, p!))