Cleaned up the repo and fixed some bugs.
This commit is contained in:
@@ -71,7 +71,7 @@ app.MapGet("/edities/{bestand}", (string bestand) =>
|
||||
}
|
||||
var dirs = new[]
|
||||
{
|
||||
Path.Combine(app.Environment.ContentRootPath, app.Configuration["Paths:LatexOutput"] ?? "storage/latex"),
|
||||
Path.Combine(app.Environment.ContentRootPath, app.Configuration["Paths:LatexOutput"] ?? "archive"),
|
||||
Path.Combine(app.Environment.ContentRootPath, app.Configuration["Paths:StaticArchive"] ?? "archive"),
|
||||
};
|
||||
var path = dirs.Select(d => Path.Combine(d, safe)).FirstOrDefault(File.Exists);
|
||||
|
||||
@@ -36,7 +36,7 @@ public class LatexService
|
||||
private const double SafetyPt = 8;
|
||||
|
||||
private string OutputDir => Path.Combine(_env.ContentRootPath,
|
||||
_config["Paths:LatexOutput"] ?? "storage/latex");
|
||||
_config["Paths:LatexOutput"] ?? "archive");
|
||||
|
||||
private string ArchiveDir => Path.Combine(_env.ContentRootPath,
|
||||
_config["Paths:StaticArchive"] ?? "archive");
|
||||
@@ -59,7 +59,9 @@ public class LatexService
|
||||
public List<Edition> ListEditions()
|
||||
{
|
||||
var result = new List<Edition>();
|
||||
foreach (var dir in new[] { OutputDir, ArchiveDir })
|
||||
var gezien = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||
foreach (var dir in new[] { OutputDir, ArchiveDir }.DistinctBy(d => d,
|
||||
StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
if (!Directory.Exists(dir))
|
||||
{
|
||||
@@ -68,6 +70,10 @@ public class LatexService
|
||||
foreach (var file in Directory.GetFiles(dir, "*.pdf"))
|
||||
{
|
||||
var name = Path.GetFileName(file);
|
||||
if (!gezien.Add(name))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var info = new FileInfo(file);
|
||||
DateTime? date = null;
|
||||
var match = Regex.Match(name, @"(\d{4}-\d{2}-\d{2})");
|
||||
@@ -551,7 +557,9 @@ public class LatexService
|
||||
}
|
||||
|
||||
var pagina = 0;
|
||||
while (resterend.Count > 0)
|
||||
// Loop ook wanneer resterend leeg is maar er wel een kopartikel is:
|
||||
// anders verdwijnt het enige artikel van de editie uit de krant.
|
||||
while (resterend.Count > 0 || (pagina == 0 && leadId != 0))
|
||||
{
|
||||
var caps = new[]
|
||||
{
|
||||
|
||||
@@ -3,10 +3,15 @@ namespace ProostenKrant.Services;
|
||||
public class UploadService
|
||||
{
|
||||
private readonly IWebHostEnvironment _env;
|
||||
private readonly IConfiguration _config;
|
||||
private static readonly string[] AllowedExtensions = { ".jpg", ".jpeg", ".png", ".gif", ".webp" };
|
||||
private const long MaxBytes = 25 * 1024 * 1024;
|
||||
|
||||
public UploadService(IWebHostEnvironment env) => _env = env;
|
||||
public UploadService(IWebHostEnvironment env, IConfiguration config)
|
||||
{
|
||||
_env = env;
|
||||
_config = config;
|
||||
}
|
||||
|
||||
public async Task<(string? WebPath, string? Error)> SaveArticleImageAsync(IFormFile? file)
|
||||
{
|
||||
@@ -30,11 +35,15 @@ public class UploadService
|
||||
var safeBase = new string(baseName.Where(char.IsLetterOrDigit).Take(40).ToArray());
|
||||
var fileName = $"{Guid.NewGuid().ToString("N")[..8]}_{safeBase}{ext}";
|
||||
|
||||
var dir = Path.Combine(_env.WebRootPath, "uploads", "articles");
|
||||
// Artikelafbeeldingen landen in de resources-map
|
||||
// (resources/images/articles), zodat ze op de host bewaard blijven.
|
||||
var resources = _config["Paths:ResourceImages"] ?? "resources/images";
|
||||
var dir = Path.Combine(_env.WebRootPath ?? ".",
|
||||
resources.Replace('/', Path.DirectorySeparatorChar), "articles");
|
||||
Directory.CreateDirectory(dir);
|
||||
await using var stream = File.Create(Path.Combine(dir, fileName));
|
||||
await file.CopyToAsync(stream);
|
||||
|
||||
return ($"uploads/articles/{fileName}", null);
|
||||
return ($"{resources}/articles/{fileName}", null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,46 +49,40 @@ public class UserService
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Zoekt de profielfoto van een familielid. Volgorde: eigen uploadmap,
|
||||
/// resources-map (bijv. nieuwe familieleden), dan Unknown.jpg.
|
||||
/// Zoekt de profielfoto van een familielid in de resources-map
|
||||
/// (resources/images/profiles). Een foto hoort bij iemand als de
|
||||
/// bestandsnaam (zonder extensie) overeenkomt met de weergavenaam;
|
||||
/// een later toegevoegde foto wordt dus automatisch gekoppeld en een
|
||||
/// verwijderde foto valt terug op Unknown.jpg.
|
||||
/// </summary>
|
||||
public string GetProfileWebPath(User user)
|
||||
{
|
||||
var kandidaten = new List<(string Web, string Abs)>();
|
||||
|
||||
// Expliciet ingesteld pad (uit de database) gaat voor.
|
||||
if (!string.IsNullOrEmpty(user.ProfileImage))
|
||||
{
|
||||
var rel = user.ProfileImage.TrimStart('/');
|
||||
kandidaten.Add(("/" + rel, AbsPath(rel)));
|
||||
}
|
||||
|
||||
kandidaten.Add(("/uploads/profiles/" + user.DisplayName + ".jpg",
|
||||
AbsPath("uploads/profiles/" + user.DisplayName + ".jpg")));
|
||||
|
||||
var resources = _config["Paths:ResourceImages"] ?? "resources-images";
|
||||
var resDir = Path.Combine(_env.WebRootPath ?? ".", resources);
|
||||
if (Directory.Exists(resDir))
|
||||
{
|
||||
foreach (var bestand in Directory.GetFiles(resDir))
|
||||
if (File.Exists(AbsPath(rel)))
|
||||
{
|
||||
var naam = Path.GetFileNameWithoutExtension(bestand);
|
||||
var ext = Path.GetExtension(bestand).ToLowerInvariant();
|
||||
if (naam.Equals(user.DisplayName, StringComparison.OrdinalIgnoreCase) &&
|
||||
AfbeeldingExtensies.Contains(ext))
|
||||
{
|
||||
kandidaten.Insert(1, ("/" + resources + "/" + Path.GetFileName(bestand), bestand));
|
||||
}
|
||||
return "/" + rel;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var (web, abs) in kandidaten)
|
||||
var resources = _config["Paths:ResourceImages"] ?? "resources/images";
|
||||
var dir = Path.Combine(_env.WebRootPath ?? ".",
|
||||
resources.Replace('/', Path.DirectorySeparatorChar), "profiles");
|
||||
if (Directory.Exists(dir))
|
||||
{
|
||||
if (File.Exists(abs))
|
||||
var match = Directory.GetFiles(dir).FirstOrDefault(bestand =>
|
||||
AfbeeldingExtensies.Contains(Path.GetExtension(bestand).ToLowerInvariant()) &&
|
||||
Path.GetFileNameWithoutExtension(bestand)
|
||||
.Equals(user.DisplayName, StringComparison.OrdinalIgnoreCase));
|
||||
if (match is not null)
|
||||
{
|
||||
return web;
|
||||
return $"/{resources}/profiles/{Path.GetFileName(match)}";
|
||||
}
|
||||
}
|
||||
return "/uploads/profiles/Unknown.jpg";
|
||||
|
||||
return $"/{resources}/profiles/Unknown.jpg";
|
||||
}
|
||||
|
||||
private string AbsPath(string webPath) =>
|
||||
|
||||
@@ -14,9 +14,9 @@
|
||||
},
|
||||
"UniversalPassword": "ProostenKrant2024!",
|
||||
"Paths": {
|
||||
"LatexOutput": "storage/latex",
|
||||
"LatexOutput": "archive",
|
||||
"StaticArchive": "archive",
|
||||
"ResourceImages": "resources-images"
|
||||
"ResourceImages": "resources/images"
|
||||
},
|
||||
"Krant": {
|
||||
"PaperName": "Proo{s:}tenKrant",
|
||||
|
||||
Reference in New Issue
Block a user