feat/estimate #50

Merged
notazof merged 27 commits from feat/estimate into main 2026-09-04 22:07:17 +01:00
5 changed files with 88 additions and 29 deletions
Showing only changes of commit 0d784e919c - Show all commits

ensure the avatar path

Paul Schneider 2026-09-04 15:08:35 +01:00
Signed by: notazof
GPG key ID: 1DD5D838E5343B06

View file

@ -18,6 +18,7 @@ using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.AspNetCore.Localization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Razor;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Infrastructure;
@ -1282,10 +1283,52 @@ ADD COLUMN IF NOT EXISTS ""Moderated"" boolean NOT NULL DEFAULT FALSE;");
app.UseFileServer(Config.AvatarsOptions);
app.Use(async (context, next) =>
{
await next();
if (context.Response.StatusCode != StatusCodes.Status404NotFound
|| context.Response.HasStarted
|| !HttpMethods.IsGet(context.Request.Method)
|| !context.Request.Path.StartsWithSegments(Constants.AvatarsPath, out var avatarFile))
{
return;
}
var webHostEnvironment = app.ApplicationServices.GetRequiredService<IWebHostEnvironment>();
var fallbackAsset = ResolveAvatarFallbackAsset(avatarFile);
var fallbackFile = webHostEnvironment.WebRootFileProvider.GetFileInfo(fallbackAsset.TrimStart('/'));
if (!fallbackFile.Exists)
{
return;
}
context.Response.StatusCode = StatusCodes.Status200OK;
context.Response.ContentType = "image/png";
await context.Response.SendFileAsync(fallbackFile);
});
app.UseFileServer(Config.GitOptions);
app.UseStaticFiles();
return app;
}
private static string ResolveAvatarFallbackAsset(PathString avatarFile)
{
var fileName = avatarFile.Value ?? string.Empty;
if (fileName.EndsWith(".xs.png", StringComparison.OrdinalIgnoreCase))
{
return "/images/Users/icon_user.xs.png";
}
if (fileName.EndsWith(".s.png", StringComparison.OrdinalIgnoreCase))
{
return "/images/Users/icon_user.s.png";
}
return Constants.DefaultAvatar;
}
}

View file

@ -2,6 +2,9 @@
@using System.Security.Claims
@{
ViewBag.Title = "Manage your account";
var avatarSrc = string.IsNullOrWhiteSpace(Model.UserName)
? Yavsc.Constants.DefaultAvatar
: $"{Yavsc.Constants.AvatarsPath}/{Model.UserName}.s.png";
}
<h2>@ViewBag.Title</h2>
@ -86,7 +89,7 @@ Html.DisplayText("Modify");
<dt>Avatar:</dt>
<dd>
<img src="/Avatars/@(User.GetUserName()+".s").png" asp-append-version="true" class="smalltofhol" />
<img src="@avatarSrc" asp-append-version="true" class="smalltofhol" />
[<a asp-controller="Manage" asp-action="SetAvatar">Modify</a>]
</dd>

View file

@ -1,5 +1,10 @@
@model PerformerProfile
@{ ViewBag.Title = "Edit your avatar"; }
@{
var previewAvatarSrc = string.IsNullOrWhiteSpace(User?.Identity?.Name)
? Yavsc.Constants.DefaultAvatar
: $"{Yavsc.Constants.AvatarsPath}/{User.Identity.Name}.png";
}
@section header{
<script src="https://unpkg.com/dropzone@5/dist/min/dropzone.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/dropzone@5/dist/min/dropzone.min.css" type="text/css" />
@ -21,7 +26,7 @@ $(document).ready(function() {
});
</script>
}
<img src="~/avatars/@(User.Identity.Name).png">
<img src="@previewAvatarSrc">
<form id="postavatar" action="/api/setavatar" class="dropzone" method="post" enctype="multipart/form-data">
<div class="fallback">

View file

@ -1,5 +1,13 @@
@using Yavsc.Abstract.Identity
@model ApplicationUser
@if (Model!=null) {
<img src="/Avatars/@(Model.UserName+".xs").png" asp-append-version="true" class="smalltofhol" />
@if (Model != null)
{
var avatarSrc = UserDisplayHelpers.AvatarSrc(Model);
if (avatarSrc.EndsWith(".s.png", StringComparison.Ordinal))
{
avatarSrc = avatarSrc.Replace(".s.png", ".xs.png", StringComparison.Ordinal);
}
<img src="@avatarSrc" asp-append-version="true" class="smalltofhol" />
}

View file

@ -10,7 +10,7 @@ if (Model ==null || Model.UserName==null)
}
}
else {
string avuri = "/Avatars/" + Model.UserName + ".s.png";
string avuri = UserDisplayHelpers.AvatarSrc(Model);
<div class="userinfo">
<a title="Posts" asp-controller="Blogspot" asp-action="Index" asp-route-id="@Model.UserName" class="btn btn-primary">