add bilder cache
This commit is contained in:
parent
48d2de05ed
commit
4c1c2c3e6a
1 changed files with 15 additions and 0 deletions
|
|
@ -11,6 +11,7 @@ namespace wp2ghost
|
|||
{
|
||||
private static readonly HttpClient httpClient = 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 string LocalImageDir = "";
|
||||
private static string CachePath = "";
|
||||
|
|
@ -96,6 +97,19 @@ namespace wp2ghost
|
|||
if (string.IsNullOrEmpty(imageUrl) || !Uri.IsWellFormedUriString(imageUrl, UriKind.Absolute))
|
||||
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 (File.Exists(cachedFile.LocalPath))
|
||||
|
|
@ -144,6 +158,7 @@ namespace wp2ghost
|
|||
|
||||
var fileResult = (relativePath, localPath);
|
||||
Cache[imageUrl] = fileResult;
|
||||
WordpressToGhostImageName[wpImageName] = relativePath;
|
||||
FilesToZip.Add(fileResult);
|
||||
return fileResult;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue