Infotexte sind jetzt DAAAAAA GEIL

This commit is contained in:
2023-08-18 11:52:58 +02:00
parent 57c110aea3
commit fc4c96745e
3 changed files with 57 additions and 2 deletions

View File

@@ -355,6 +355,12 @@
string mapPath = $"./wwwroot/{imgUrl}";
await image.SaveAsJpegAsync(mapPath);
// Hier speichern wir die Daten in die 'info_texts.txt'-Datei
string infoTextsPath = Path.Combine(_environment.WebRootPath, "generated_images", "info_texts.txt");
string desc = _imageDescription.Replace("\r\n", "").Replace("\n", "").Replace("\r", "");
string newLine = $"{imgUrl}: {request}, {desc}\n";
await File.AppendAllTextAsync(infoTextsPath, newLine);
return imgUrl;
}
else
@@ -460,5 +466,8 @@
[Inject]
private NavigationManager NavigationManager { get; set; }
[Inject]
private IWebHostEnvironment _environment { get; set; }
}

View File

@@ -103,11 +103,41 @@
}
}
private void ShowImageInfo(string imagePath)
private async void ShowImageInfo(string imagePath)
{
selectedImage = imagePath;
infoText = "Info Text"; // Hier kannst du den gewünschten Infotext setzen
popupStyle = "display: block;";
infoText = await GetInfoTextForImageAsync(imagePath);
}
private async Task<string> GetInfoTextForImageAsync(string imagePath)
{
// Bestimme den Ordnerpfad, in dem sich die Bilder und die info_texts.txt Datei befinden
string folderPath = Path.Combine(_environment.WebRootPath, "generated_images");
// Bestimme den Pfad zur info_texts.txt Datei
string infoTextsFilePath = Path.Combine(folderPath, "info_texts.txt");
// Überprüfe, ob die Datei existiert
if (!File.Exists(infoTextsFilePath))
return $"Kein Infotext für {imagePath} gefunden.";
// Lies alle Zeilen der Datei
var lines = await File.ReadAllLinesAsync(infoTextsFilePath);
string adaptedImagePath = imagePath.Substring(1) + ":";
// Durchsuche jede Zeile nach dem gegebenen imagePath
foreach (var line in lines)
{
if (line.StartsWith(adaptedImagePath)) // Überprüft, ob die Zeile mit dem Dateinamen des Bildes beginnt
{
// Trenne den Dateinamen und den Infotext und gib den Infotext zurück
return line.Split(new[] { ':' }, 2).LastOrDefault()?.Trim();
}
}
return $"Kein Infotext für {imagePath} gefunden.";
}
private void CloseImageInfo()