a fork of iceshrimp.net but a tweaked frontend to my personal liking. waow
fediverse social-media social iceshrimp fedi
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

[backend] Make zip file handling asynchronous

+8 -8
+1 -1
Iceshrimp.Backend/Controllers/Web/EmojiController.cs
··· 196 196 [ProducesResults(HttpStatusCode.Accepted)] 197 197 public async Task<AcceptedResult> ImportEmoji(IFormFile file) 198 198 { 199 - var zip = await emojiImportSvc.ParseAsync(file.OpenReadStream()); 199 + var zip = await EmojiImportService.ParseAsync(file.OpenReadStream()); 200 200 await emojiImportSvc.ImportAsync(zip); // TODO: run in background. this will take a while 201 201 return Accepted(); 202 202 }
+7 -7
Iceshrimp.Backend/Core/Services/EmojiImportService.cs
··· 33 33 ILogger<EmojiImportService> logger 34 34 ) : IScopedService 35 35 { 36 - public static readonly JsonSerializerOptions SerializerOptions = new(JsonSerializerDefaults.Web); 36 + private static readonly JsonSerializerOptions SerializerOptions = new(JsonSerializerDefaults.Web); 37 37 38 - public async Task<EmojiZip> ParseAsync(Stream zipStream) 38 + public static async Task<EmojiZip> ParseAsync(Stream zipStream) 39 39 { 40 40 var archive = new ZipArchive(zipStream, ZipArchiveMode.Read); 41 41 ··· 48 48 var metaJson = await JsonSerializer.DeserializeAsync<EmojiZipMeta>(meta.Open(), SerializerOptions) ?? 49 49 throw GracefulException.BadRequest("Invalid emoji zip metadata"); 50 50 51 - if (metaJson.MetaVersion < 1 || metaJson.MetaVersion > 2) 51 + if (metaJson.MetaVersion is < 1 or > 2) 52 52 throw GracefulException.BadRequest("Unrecognized metaVersion {version}, expected 1 or 2", 53 53 metaJson.MetaVersion.ToString()); 54 54 ··· 57 57 catch 58 58 { 59 59 // We don't want to dispose of archive on success, as Import will do it when it's done. 60 - archive.Dispose(); 60 + await archive.DisposeAsync(); 61 61 throw; 62 62 } 63 63 } 64 64 65 65 public async Task ImportAsync(EmojiZip zip) 66 66 { 67 - using var archive = zip.Archive; 68 - var contentTypeProvider = new FileExtensionContentTypeProvider(); 67 + await using var archive = zip.Archive; 68 + var contentTypeProvider = new FileExtensionContentTypeProvider(); 69 69 70 70 foreach (var emoji in zip.Metadata.Emojis) 71 71 { ··· 84 84 85 85 // DriveService requires a seekable and .Length-able stream, which the DeflateStream from file.Open does not support. 86 86 using var buffer = new MemoryStream((int)file.Length); 87 - await file.Open().CopyToAsync(buffer); 87 + await (await file.OpenAsync()).CopyToAsync(buffer); 88 88 buffer.Seek(0, SeekOrigin.Begin); 89 89 90 90 var name = emoji.Emoji.Name ?? emoji.FileName;