summary refs log tree commit diff
path: root/extra/admin-api/Spacebar.Cdn/Controllers/StaticAssetController.cs
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2026-04-11 21:38:36 +0200
committerRory& <root@rory.gay>2026-04-11 21:39:47 +0200
commit1d7627454675c9ebfa7c1a9c5add79f8fcf36691 (patch)
treee866e38e88119c9ef70abd4452d6049a57459b5c /extra/admin-api/Spacebar.Cdn/Controllers/StaticAssetController.cs
parentFunctioning CDN-CS workers (diff)
downloadserver-ts-1d7627454675c9ebfa7c1a9c5add79f8fcf36691.tar.xz
Cdn cs worker cleanup
Diffstat (limited to 'extra/admin-api/Spacebar.Cdn/Controllers/StaticAssetController.cs')
-rw-r--r--extra/admin-api/Spacebar.Cdn/Controllers/StaticAssetController.cs132
1 files changed, 66 insertions, 66 deletions
diff --git a/extra/admin-api/Spacebar.Cdn/Controllers/StaticAssetController.cs b/extra/admin-api/Spacebar.Cdn/Controllers/StaticAssetController.cs

index 5d9d0d78..48ae2253 100644 --- a/extra/admin-api/Spacebar.Cdn/Controllers/StaticAssetController.cs +++ b/extra/admin-api/Spacebar.Cdn/Controllers/StaticAssetController.cs
@@ -1,66 +1,66 @@ -using ArcaneLibs.Extensions.Streams; -using Microsoft.AspNetCore.Mvc; -using Microsoft.OpenApi; -using Spacebar.AdminApi.TestClient.Services.Services; -using Spacebar.Cdn.Extensions; -using Spacebar.Interop.Cdn.Abstractions; - -namespace Spacebar.Cdn.Controllers; - -[ApiController] -public class StaticAssetController(LruFileCache lfc, IFileSource fs, DiscordImageResizeService dirs) : ImageController { - private static readonly Dictionary<string, string> defaultAvatarHashMap = new() { - { "0", "4a8562cf00887030c416d3ec2d46385a" }, - { "1", "9b0bb198936784c45c72833cc426cc55" }, - { "2", "22341bdb500c7b63a93bbce957d1601e" }, - { "3", "d9977836b82058bf2f74eebd50edc095" }, - { "4", "9d6ddb4e4d899a533a8cc617011351c9" }, - { "5", "7213ab6677377974697dfdfbaf5f6a6f" }, - }; - - private static readonly Dictionary<string, string> defaultGroupDMAvatarHashMap = new() { - { "0", "3b70bb66089c60f8be5e214bf8574c9d" }, - { "1", "9581acd31832465bdeaa5385b0e919a3" }, - { "2", "a8a4727cf2dc2939bd3c657fad4463fa" }, - { "3", "2e46fe14586f8e95471c0917f56726b5" }, - { "4", "fac7e78de9753d4a37083bba74c1d9ef" }, - { "5", "4ab900144b0865430dc9be825c838faa" }, - { "6", "1276374a404452756f3c9cc2601508a5" }, - { "7", "904bf9f1b61f53ef4a3b7a893afeabe3" }, - }; - - // png only - [HttpGet("/embed/avatars/{userIndex}.{ext}")] - public async Task<IActionResult> GetDefaultUserAvatar(string userIndex, string ext) { - - var cacheKey = Request.Path + Request.QueryString; - - DiscordImageResizeParams resizeParams = GetResizeParams(); - - var entry = await lfc.GetOrAdd(cacheKey, async () => { - var original = await fs.GetFile(Request.Path); - - if (Request.Query.Any()) { - using var img = await original.ToMagickImageCollectionAsync(); - dirs.Apply(img, resizeParams); - - var outStream = new MemoryStream(); - await img.WriteAsync(outStream, img.First().Format); - outStream.Position = 0; - - return new LruFileCache.Entry() { - Data = outStream.ReadToEnd().ToArray(), - MimeType = original.MimeType - }; - } - - return new LruFileCache.Entry() { - Data = original.Stream.ReadToEnd().ToArray(), - MimeType = original.MimeType - }; - }); - - // byte array with mime type result - return new FileContentResult(entry.Data, entry.MimeType); - } -} \ No newline at end of file +// using ArcaneLibs.Extensions.Streams; +// using Microsoft.AspNetCore.Mvc; +// using Microsoft.OpenApi; +// using Spacebar.AdminApi.TestClient.Services.Services; +// using Spacebar.Cdn.Extensions; +// using Spacebar.Interop.Cdn.Abstractions; +// +// namespace Spacebar.Cdn.Controllers; +// +// [ApiController] +// public class StaticAssetController(LruFileCache lfc, IFileSource fs, DiscordImageResizeService dirs) : ImageController { +// private static readonly Dictionary<string, string> defaultAvatarHashMap = new() { +// { "0", "4a8562cf00887030c416d3ec2d46385a" }, +// { "1", "9b0bb198936784c45c72833cc426cc55" }, +// { "2", "22341bdb500c7b63a93bbce957d1601e" }, +// { "3", "d9977836b82058bf2f74eebd50edc095" }, +// { "4", "9d6ddb4e4d899a533a8cc617011351c9" }, +// { "5", "7213ab6677377974697dfdfbaf5f6a6f" }, +// }; +// +// private static readonly Dictionary<string, string> defaultGroupDMAvatarHashMap = new() { +// { "0", "3b70bb66089c60f8be5e214bf8574c9d" }, +// { "1", "9581acd31832465bdeaa5385b0e919a3" }, +// { "2", "a8a4727cf2dc2939bd3c657fad4463fa" }, +// { "3", "2e46fe14586f8e95471c0917f56726b5" }, +// { "4", "fac7e78de9753d4a37083bba74c1d9ef" }, +// { "5", "4ab900144b0865430dc9be825c838faa" }, +// { "6", "1276374a404452756f3c9cc2601508a5" }, +// { "7", "904bf9f1b61f53ef4a3b7a893afeabe3" }, +// }; +// +// // png only +// [HttpGet("/embed/avatars/{userIndex}.{ext}")] +// public async Task<IActionResult> GetDefaultUserAvatar(string userIndex, string ext) { +// +// var cacheKey = Request.Path + Request.QueryString; +// +// DiscordImageResizeParams resizeParams = GetResizeParams(); +// +// var entry = await lfc.GetOrAdd(cacheKey, async () => { +// var original = await fs.GetFile(Request.Path); +// +// if (Request.Query.Any()) { +// using var img = await original.ToMagickImageCollectionAsync(); +// dirs.Apply(img, resizeParams); +// +// var outStream = new MemoryStream(); +// await img.WriteAsync(outStream, img.First().Format); +// outStream.Position = 0; +// +// return new LruFileCache.Entry() { +// Data = outStream.ReadToEnd().ToArray(), +// MimeType = original.MimeType +// }; +// } +// +// return new LruFileCache.Entry() { +// Data = original.Stream.ReadToEnd().ToArray(), +// MimeType = original.MimeType +// }; +// }); +// +// // byte array with mime type result +// return new FileContentResult(entry.Data, entry.MimeType); +// } +// } \ No newline at end of file