5 Commits

4 changed files with 46 additions and 8 deletions

View File

@@ -139,7 +139,7 @@ public class GeneralUseHelpers(ApplicationDbContext db, IConfiguration appsettin
{ {
string _model = model ?? _appsettings.GetSection("LlmIntegration")["DefaultModel"] ?? "deepclaude"; string _model = model ?? _appsettings.GetSection("LlmIntegration")["DefaultModel"] ?? "deepclaude";
float _temp = temp ?? 0.6f; // sane default float _temp = temp ?? 0.8f; // sane default
string _included_sample = string.Empty; string _included_sample = string.Empty;
string _prompt = prompt ?? _appsettings.GetSection("LlmIntegration")["DefaultPrompt"] ?? string _prompt = prompt ?? _appsettings.GetSection("LlmIntegration")["DefaultPrompt"] ??
"Cześć, czy jesteś w stanie wymyślić i stworzyć jeden oryginalny cytat? " + "Cześć, czy jesteś w stanie wymyślić i stworzyć jeden oryginalny cytat? " +
@@ -233,7 +233,12 @@ public class GeneralUseHelpers(ApplicationDbContext db, IConfiguration appsettin
else else
{ {
// Handle the error // Handle the error
JObject error = JObject.Parse(await response.Content.ReadAsStringAsync());
Console.WriteLine($"[QuotifyBE] Error: response status code from API was {response.StatusCode}."); Console.WriteLine($"[QuotifyBE] Error: response status code from API was {response.StatusCode}.");
if (error != null && error["error"] != null && error["error"]!["message"] != null)
{
Console.WriteLine($" Error message: {error["error"]!["message"]}");
}
return null; return null;
} }
} }

View File

@@ -20,11 +20,13 @@ public class QuotesController : ControllerBase
private readonly ApplicationDbContext _db; private readonly ApplicationDbContext _db;
private readonly GeneralUseHelpers guhf; private readonly GeneralUseHelpers guhf;
private readonly IConfiguration _appsettings;
public QuotesController(ApplicationDbContext db, GeneralUseHelpers GUHF) public QuotesController(ApplicationDbContext db, GeneralUseHelpers GUHF, IConfiguration appsettings)
{ {
_db = db; _db = db;
guhf = GUHF; guhf = GUHF;
_appsettings = appsettings;
} }
// GET /api/v1/quotes // GET /api/v1/quotes
@@ -385,6 +387,7 @@ public class QuotesController : ControllerBase
// Try to find the quote in question // Try to find the quote in question
Quote? quote = await _db.Quotes Quote? quote = await _db.Quotes
.Include(q => q.QuoteCategories) .Include(q => q.QuoteCategories)
.Include(q => q.Image)
.FirstOrDefaultAsync(q => q.Id == id); .FirstOrDefaultAsync(q => q.Id == id);
// Failed? // Failed?
@@ -535,6 +538,8 @@ public class QuotesController : ControllerBase
request.CustomPrompt, request.Model, request.Temperature, request.CategoryId, request.UseSampleQuote request.CustomPrompt, request.Model, request.Temperature, request.CategoryId, request.UseSampleQuote
); );
string llmUsed = request.Model ?? _appsettings.GetSection("LlmIntegration")["DefaultModel"] ?? "deepclaude";
// Check if any errors occurred // Check if any errors occurred
if (generatedResponse == null) if (generatedResponse == null)
{ {
@@ -549,7 +554,7 @@ public class QuotesController : ControllerBase
return StatusCode(500, new ErrorDTO { Status = "error", Error_msg = "Unexpected API response" }); return StatusCode(500, new ErrorDTO { Status = "error", Error_msg = "Unexpected API response" });
// Otherwise, return the response // Otherwise, return the response
return Ok(new { Status = "ok", BotResponse = llmResponse }); return Ok(new { Status = "ok", BotResponse = llmResponse, Model = llmUsed });
} }
} }

View File

@@ -20,6 +20,7 @@ public class UserContentController : ControllerBase
private readonly IConfiguration _appsettings; private readonly IConfiguration _appsettings;
private readonly ApplicationDbContext _db; private readonly ApplicationDbContext _db;
private readonly GeneralUseHelpers guhf; 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) public UserContentController(IConfiguration appsettings, ApplicationDbContext db, GeneralUseHelpers GUHF)
{ {
@@ -86,15 +87,14 @@ public class UserContentController : ControllerBase
} }
// Dozwolone rozszerzenia // Dozwolone rozszerzenia
List<string> allowedExtensions = new List<string>() { ".jpg", ".jpeg", ".jfif", ".png", ".gif", ".avif", ".webp" };
string fileExtension = Path.GetExtension(file.FileName).ToLower(); string fileExtension = Path.GetExtension(file.FileName).ToLower();
if (!allowedExtensions.Contains(fileExtension)) if (!_allowedExtensions.Contains(fileExtension))
{ {
return StatusCode(415, new ErrorDTO return StatusCode(415, new ErrorDTO
{ {
Status = "error", 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} // DELETE /api/v1/uc/images/{id}
/// <summary> /// <summary>
/// [AUTHED] Delete an image /// [AUTHED] Delete an image

View File

@@ -2,8 +2,8 @@ namespace QuotifyBE.DTOs;
public record class AskLLMInDTO public record class AskLLMInDTO
{ {
public string? CustomPrompt { get; set; } public string? CustomPrompt { get; set; } = null;
public string? Model { get; set; } = "deepclaude"; public string? Model { get; set; } = null;
public float? Temperature { get; set; } = 0.8f; public float? Temperature { get; set; } = 0.8f;
public int? CategoryId { get; set; } = null; public int? CategoryId { get; set; } = null;
public bool? UseSampleQuote { get; set; } = false; public bool? UseSampleQuote { get; set; } = false;