diff --git a/Controllers/UserContentController.cs b/Controllers/UserContentController.cs index 7de1b70..ed3c940 100644 --- a/Controllers/UserContentController.cs +++ b/Controllers/UserContentController.cs @@ -20,6 +20,7 @@ public class UserContentController : ControllerBase private readonly IConfiguration _appsettings; private readonly ApplicationDbContext _db; private readonly GeneralUseHelpers guhf; + List _allowedExtensions = new List() { ".jpg", ".jpeg", ".jfif", ".png", ".gif", ".avif", ".webp" }; public UserContentController(IConfiguration appsettings, ApplicationDbContext db, GeneralUseHelpers GUHF) { @@ -86,15 +87,14 @@ public class UserContentController : ControllerBase } // Dozwolone rozszerzenia - List allowedExtensions = new List() { ".jpg", ".jpeg", ".jfif", ".png", ".gif", ".avif", ".webp" }; string fileExtension = Path.GetExtension(file.FileName).ToLower(); - if (!allowedExtensions.Contains(fileExtension)) + if (!_allowedExtensions.Contains(fileExtension)) { return StatusCode(415, new ErrorDTO { Status = "error", - Error_msg = $"Unknown file extension. Allowed: {string.Join(", ", allowedExtensions)}" + Error_msg = $"Unknown file extension. Allowed: {string.Join(", ", _allowedExtensions)}" }); } @@ -149,6 +149,34 @@ public class UserContentController : ControllerBase }); } + // GET /api/v1/uc/restrictions + /// + /// [AUTHED] Get server restrictions for file upload + /// + /// + /// Returns a list of allowed file extensions and mimetypes for upload. + /// + /// Returned on valid request + [HttpGet("restrictions")] + [Authorize] + [EnableCors] + [ProducesResponseType(200)] + public IActionResult GetFileUploadRestrictions() + { + return Ok(new + { + Status = "ok", + AllowedMimeTypes = new List + { + "image/" // this could be done dynamically ~eee4 + }, + AllowedExtensions = _allowedExtensions, + MaxFileSize = int.TryParse(_appsettings.GetSection("UserContent")["MaxFileSize"], out int r) + ? r + : 5 * 1024 * 1024 + }); + } + // DELETE /api/v1/uc/images/{id} /// /// [AUTHED] Delete an image