add bilder cache

This commit is contained in:
Roland 2026-09-20 19:35:16 +02:00
parent 48d2de05ed
commit 4c1c2c3e6a

View file

@ -11,6 +11,7 @@ namespace wp2ghost
{ {
private static readonly HttpClient httpClient = new(); private static readonly HttpClient httpClient = new();
private static Dictionary<string, (string RelativePath, string LocalPath)> Cache = new(); private static Dictionary<string, (string RelativePath, string LocalPath)> Cache = new();
private static Dictionary<string, string> WordpressToGhostImageName = new();
private static List<(string RelativePath, string LocalPath)> FilesToZip = new(); private static List<(string RelativePath, string LocalPath)> FilesToZip = new();
private static string LocalImageDir = ""; private static string LocalImageDir = "";
private static string CachePath = ""; private static string CachePath = "";
@ -96,6 +97,19 @@ namespace wp2ghost
if (string.IsNullOrEmpty(imageUrl) || !Uri.IsWellFormedUriString(imageUrl, UriKind.Absolute)) if (string.IsNullOrEmpty(imageUrl) || !Uri.IsWellFormedUriString(imageUrl, UriKind.Absolute))
return null; return null;
string wpImageName = Path.GetFileNameWithoutExtension(new Uri(imageUrl).AbsolutePath);
if (WordpressToGhostImageName.TryGetValue(wpImageName, out string? ghostRelativePath) && !string.IsNullOrEmpty(ghostRelativePath))
{
string localPath = Path.Combine(LocalImageDir, ghostRelativePath);
if (File.Exists(localPath))
{
Console.WriteLine($" [Bild] Bereits heruntergeladen (Wörterbuch): {wpImageName} → {ghostRelativePath}");
return (ghostRelativePath, localPath);
}
WordpressToGhostImageName.Remove(wpImageName);
}
if (Cache.TryGetValue(imageUrl, out var cachedFile)) if (Cache.TryGetValue(imageUrl, out var cachedFile))
{ {
if (File.Exists(cachedFile.LocalPath)) if (File.Exists(cachedFile.LocalPath))
@ -144,6 +158,7 @@ namespace wp2ghost
var fileResult = (relativePath, localPath); var fileResult = (relativePath, localPath);
Cache[imageUrl] = fileResult; Cache[imageUrl] = fileResult;
WordpressToGhostImageName[wpImageName] = relativePath;
FilesToZip.Add(fileResult); FilesToZip.Add(fileResult);
return fileResult; return fileResult;
} }