···196196 [ProducesResults(HttpStatusCode.Accepted)]
197197 public async Task<AcceptedResult> ImportEmoji(IFormFile file)
198198 {
199199- var zip = await emojiImportSvc.ParseAsync(file.OpenReadStream());
199199+ var zip = await EmojiImportService.ParseAsync(file.OpenReadStream());
200200 await emojiImportSvc.ImportAsync(zip); // TODO: run in background. this will take a while
201201 return Accepted();
202202 }
···3333 ILogger<EmojiImportService> logger
3434) : IScopedService
3535{
3636- public static readonly JsonSerializerOptions SerializerOptions = new(JsonSerializerDefaults.Web);
3636+ private static readonly JsonSerializerOptions SerializerOptions = new(JsonSerializerDefaults.Web);
37373838- public async Task<EmojiZip> ParseAsync(Stream zipStream)
3838+ public static async Task<EmojiZip> ParseAsync(Stream zipStream)
3939 {
4040 var archive = new ZipArchive(zipStream, ZipArchiveMode.Read);
4141···4848 var metaJson = await JsonSerializer.DeserializeAsync<EmojiZipMeta>(meta.Open(), SerializerOptions) ??
4949 throw GracefulException.BadRequest("Invalid emoji zip metadata");
50505151- if (metaJson.MetaVersion < 1 || metaJson.MetaVersion > 2)
5151+ if (metaJson.MetaVersion is < 1 or > 2)
5252 throw GracefulException.BadRequest("Unrecognized metaVersion {version}, expected 1 or 2",
5353 metaJson.MetaVersion.ToString());
5454···5757 catch
5858 {
5959 // We don't want to dispose of archive on success, as Import will do it when it's done.
6060- archive.Dispose();
6060+ await archive.DisposeAsync();
6161 throw;
6262 }
6363 }
64646565 public async Task ImportAsync(EmojiZip zip)
6666 {
6767- using var archive = zip.Archive;
6868- var contentTypeProvider = new FileExtensionContentTypeProvider();
6767+ await using var archive = zip.Archive;
6868+ var contentTypeProvider = new FileExtensionContentTypeProvider();
69697070 foreach (var emoji in zip.Metadata.Emojis)
7171 {
···84848585 // DriveService requires a seekable and .Length-able stream, which the DeflateStream from file.Open does not support.
8686 using var buffer = new MemoryStream((int)file.Length);
8787- await file.Open().CopyToAsync(buffer);
8787+ await (await file.OpenAsync()).CopyToAsync(buffer);
8888 buffer.Seek(0, SeekOrigin.Begin);
89899090 var name = emoji.Emoji.Name ?? emoji.FileName;