summaryrefslogtreecommitdiffstats
path: root/api/WhatApi/Endpoints/DownloadContentEndpoint.cs
diff options
context:
space:
mode:
authorivar <i@oiee.no>2025-10-20 00:26:34 +0200
committerivar <i@oiee.no>2025-10-20 00:26:34 +0200
commita1f0518d0cd123a791adde64f4f11bd8e44276c7 (patch)
tree675a7dff8262eea877ec800ff1efe9b92f5d7e7d /api/WhatApi/Endpoints/DownloadContentEndpoint.cs
downloadwhat-a1f0518d0cd123a791adde64f4f11bd8e44276c7.tar.xz
what-a1f0518d0cd123a791adde64f4f11bd8e44276c7.zip
Initial commit
Diffstat (limited to 'api/WhatApi/Endpoints/DownloadContentEndpoint.cs')
-rw-r--r--api/WhatApi/Endpoints/DownloadContentEndpoint.cs19
1 files changed, 19 insertions, 0 deletions
diff --git a/api/WhatApi/Endpoints/DownloadContentEndpoint.cs b/api/WhatApi/Endpoints/DownloadContentEndpoint.cs
new file mode 100644
index 0000000..dbe6bff
--- /dev/null
+++ b/api/WhatApi/Endpoints/DownloadContentEndpoint.cs
@@ -0,0 +1,19 @@
+using Microsoft.AspNetCore.Mvc;
+
+namespace WhatApi.Endpoints;
+
+public class DownloadContentEndpoint : BaseEndpoint
+{
+ [HttpGet("~/{id:guid}")]
+ public async Task<ActionResult> HandleAsync(Guid id, CancellationToken ct = default) {
+ try {
+ var path = Path.Combine(Directory.GetCurrentDirectory(), "files", id.ToString());
+ await using var file = new FileStream(path, FileMode.Open);
+ if (!file.CanRead) return NotFound();
+ return File(file, "application/octet-stream", id.ToString());
+ } catch (Exception e) {
+ if (e is not FileNotFoundException) Console.WriteLine(e);
+ return NotFound();
+ }
+ }
+} \ No newline at end of file