From 8a7c318f6273c51ea1b96c87f98b0320ef339e16 Mon Sep 17 00:00:00 2001 From: ivarlovlie Date: Mon, 16 Jan 2023 19:42:07 +0100 Subject: feat: Check if file exists on disk --- src/Program.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/Program.cs') diff --git a/src/Program.cs b/src/Program.cs index 51ef4b0..29b0fe1 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -244,11 +244,12 @@ async Task GetFile(HttpContext context, Db db, string id, bool download db.SaveChanges(); } - var reader = await System.IO.File.ReadAllBytesAsync( - Path.Combine( - Tools.GetFilesDirectoryPath(), file.Id.ToString() - ) - ); + var path = Path.Combine(Tools.GetFilesDirectoryPath(), file.Id.ToString()); + if (!System.IO.File.Exists(path)) { + return Results.NotFound(); + } + + var reader = await System.IO.File.ReadAllBytesAsync(path); return download ? Results.File(reader, file.MimeType, file.Name) : Results.Bytes(reader, file.MimeType); } -- cgit v1.3