refactor: Backend deduplizieren – 13 Dateien, -528 Zeilen netto
ChatContext: 3 identische Context-Klassen (PreparerContext, ReviewContext, FinalizerContext) zu einer SubAgentContext-Klasse zusammengefasst. ChatService: 3x40 Zeilen Sub-Agent-Setup durch BuildSubAgentContext() ersetzt. AnthropicService: 5 Hilfsmethoden extrahiert – ExtractWebSearchSources(), TruncateToolResult(), AddToolsToPayload(), ParseServerToolUse(), TrackUsage(). WorkspaceEndpoint: 5 Session/Agent-Endpoint-Paare durch generische Core-Handler mit basePath-Parameter ersetzt. Ungenutzte rmdir-Endpoints entfernt. AgentEndpoint: Doppeltes Agent-DTO-Mapping durch MapAgentList() ersetzt. SessionEndpoint: Doppelte Session/Agent-Auflösung durch ResolvePromptContext() ersetzt. DatabaseService: Toten Code entfernt (SetSessionTelegramChatId, ClearSessionTelegramChatId, GetSessions, GetUserSessions). ConvertDataUrlToWebP und ResizeDataUrlToWebP zu einer Methode zusammengefasst. TelegramEndpoint: Bot-DTO-Mapping durch MapBotResponse() dedupliziert. KreaEndpoint + SkillEndpoint: Thumbnail-Generierung in ImageService.GenerateThumbnail() extrahiert, SixLabors-Imports aus Endpoints entfernt. CronjobEndpoint: 7x ctx.Items[UserId] durch ctx.GetUserId() ersetzt.
This commit is contained in:
1 parent
0097ce69db
commit
dcedbaa074
13 files changed
+447
-975
No files matched your search
+18
-40
@@ -7,9 +7,6 @@ using Gott.Services;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.Processing;
|
||||
using SixLabors.ImageSharp.Formats.Webp;
|
||||
|
||||
namespace Gott.Endpoints
|
||||
{
|
||||
@@ -142,50 +139,31 @@ namespace Gott.Endpoints
|
||||
return;
|
||||
}
|
||||
|
||||
// Cache-Verzeichnis: data/cache/images/
|
||||
var imagesDir = Path.GetDirectoryName(originalPath);
|
||||
var dataDir = Path.GetDirectoryName(imagesDir);
|
||||
var cacheDir = Path.Combine(dataDir, "cache", "images");
|
||||
Directory.CreateDirectory(cacheDir);
|
||||
|
||||
var thumbFilename = Path.GetFileNameWithoutExtension(filename) + ".webp";
|
||||
var thumbPath = Path.Combine(cacheDir, thumbFilename);
|
||||
|
||||
if (!File.Exists(thumbPath) || File.GetLastWriteTimeUtc(originalPath) > File.GetLastWriteTimeUtc(thumbPath))
|
||||
var thumbPath = await ImageService.GenerateThumbnail(originalPath, cacheDir);
|
||||
if (thumbPath != null)
|
||||
{
|
||||
try
|
||||
res.ContentType = "image/webp";
|
||||
res.Headers["Cache-Control"] = "private, max-age=86400";
|
||||
await res.SendFileAsync(thumbPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Fallback: Original ausliefern
|
||||
res.ContentType = ext switch
|
||||
{
|
||||
using var image = await Image.LoadAsync(originalPath);
|
||||
var maxSize = 320;
|
||||
image.Mutate(x => x.Resize(new ResizeOptions
|
||||
{
|
||||
Size = new Size(maxSize, maxSize),
|
||||
Mode = ResizeMode.Max
|
||||
}));
|
||||
var encoder = new WebpEncoder { Quality = 75 };
|
||||
await image.SaveAsync(thumbPath, encoder);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Fallback: Original ausliefern
|
||||
var contentType = ext switch
|
||||
{
|
||||
".png" => "image/png",
|
||||
".jpg" => "image/jpeg",
|
||||
".jpeg" => "image/jpeg",
|
||||
".gif" => "image/gif",
|
||||
_ => "image/webp",
|
||||
};
|
||||
res.ContentType = contentType;
|
||||
res.Headers["Cache-Control"] = "private, max-age=3600";
|
||||
await res.SendFileAsync(originalPath);
|
||||
return;
|
||||
}
|
||||
".png" => "image/png",
|
||||
".jpg" => "image/jpeg",
|
||||
".jpeg" => "image/jpeg",
|
||||
".gif" => "image/gif",
|
||||
_ => "image/webp",
|
||||
};
|
||||
res.Headers["Cache-Control"] = "private, max-age=3600";
|
||||
await res.SendFileAsync(originalPath);
|
||||
}
|
||||
|
||||
res.ContentType = "image/webp";
|
||||
res.Headers["Cache-Control"] = "private, max-age=86400";
|
||||
await res.SendFileAsync(thumbPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user