feat: endpoint for getting server restrictions

This commit is contained in:
2025-07-29 13:40:22 +02:00
parent 56bd82f6a2
commit d81a6b961c

View File

@@ -20,6 +20,7 @@ public class UserContentController : ControllerBase
private readonly IConfiguration _appsettings;
private readonly ApplicationDbContext _db;
private readonly GeneralUseHelpers guhf;
List<string> _allowedExtensions = new List<string>() { ".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<string> allowedExtensions = new List<string>() { ".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
/// <summary>
/// [AUTHED] Get server restrictions for file upload
/// </summary>
/// <remarks>
/// Returns a list of allowed file extensions and mimetypes for upload.
/// </remarks>
/// <response code="200">Returned on valid request</response>
[HttpGet("restrictions")]
[Authorize]
[EnableCors]
[ProducesResponseType(200)]
public IActionResult GetFileUploadRestrictions()
{
return Ok(new
{
Status = "ok",
AllowedMimeTypes = new List<string>
{
"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}
/// <summary>
/// [AUTHED] Delete an image