using Microsoft.AspNetCore.Http.HttpResults; using Microsoft.AspNetCore.Mvc; using Mizuki.Services; namespace Mizuki.Controllers; /// /// The controller serving the uploaded files. /// [ApiController] [Route("/f")] public class ServeController( DriveService driveService, UploadService uploadService) : ControllerBase { /// /// Tries to get the file by its filename. /// /// The filename. /// The file, or an error. [Route("/{filename}")] public async Task> GetFile( [FromRoute] string filename) { var file = await uploadService.GetByFilename(filename); if (file is null) return TypedResults.NotFound(); var stream = driveService.OpenFileByFilename(filename); if (stream is null) return TypedResults.NotFound(); return TypedResults.File( stream, fileDownloadName: file.OriginalFilename); } }