refactor(web): clean up review findings from Preact port

- Remove duplicate style attribute on happy image preload in templ
- Remove unused getAvailableLanguages function from main.tsx
- Add type annotation to currentLang variable
- Add null check for missing challenge data with localized error

Assisted-by: Claude Opus 4.6 via Claude Code
Signed-off-by: Xe Iaso <me@xeiaso.net>
This commit is contained in:
Xe Iaso
2026-03-19 19:37:53 +00:00
parent 4969e36a6e
commit 7013c29443
3 changed files with 14 additions and 30 deletions
+1 -1
View File
@@ -7,7 +7,7 @@ import (
templ page(localizer *localization.SimpleLocalizer) { templ page(localizer *localization.SimpleLocalizer) {
<div class="centered-div"> <div class="centered-div">
<img style="display:none;" style="width:100%;max-width:256px;" src={ anubis.BasePrefix + "/.within.website/x/cmd/anubis/static/img/happy.webp?cacheBuster=" + anubis.Version }/> <img style="display:none;" src={ anubis.BasePrefix + "/.within.website/x/cmd/anubis/static/img/happy.webp?cacheBuster=" + anubis.Version }/>
<div id="app"> <div id="app">
<img style="width:100%;max-width:256px;" src={ anubis.BasePrefix + "/.within.website/x/cmd/anubis/static/img/pensive.webp?cacheBuster=" + anubis.Version }/> <img style="width:100%;max-width:256px;" src={ anubis.BasePrefix + "/.within.website/x/cmd/anubis/static/img/pensive.webp?cacheBuster=" + anubis.Version }/>
<p id="status">{ localizer.T("loading") }</p> <p id="status">{ localizer.T("loading") }</p>
+2 -2
View File
@@ -34,14 +34,14 @@ func page(localizer *localization.SimpleLocalizer) templ.Component {
templ_7745c5c3_Var1 = templ.NopComponent templ_7745c5c3_Var1 = templ.NopComponent
} }
ctx = templ.ClearChildren(ctx) ctx = templ.ClearChildren(ctx)
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<div class=\"centered-div\"><img style=\"display:none;\" style=\"width:100%;max-width:256px;\" src=\"") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<div class=\"centered-div\"><img style=\"display:none;\" src=\"")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
var templ_7745c5c3_Var2 string var templ_7745c5c3_Var2 string
templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(anubis.BasePrefix + "/.within.website/x/cmd/anubis/static/img/happy.webp?cacheBuster=" + anubis.Version) templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(anubis.BasePrefix + "/.within.website/x/cmd/anubis/static/img/happy.webp?cacheBuster=" + anubis.Version)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `proofofwork.templ`, Line: 10, Col: 174} return templ.Error{Err: templ_7745c5c3_Err, FileName: `proofofwork.templ`, Line: 10, Col: 138}
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2)) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
+11 -27
View File
@@ -27,31 +27,6 @@ const imageURL = (
cacheBuster, cacheBuster,
}); });
// Detect available languages by loading the manifest
const getAvailableLanguages = async () => {
const basePrefix = j("anubis_base_prefix");
if (basePrefix === null) {
return;
}
try {
const response = await fetch(
`${basePrefix}/.within.website/x/cmd/anubis/static/locales/manifest.json`,
);
if (response.ok) {
const manifest = await response.json();
return manifest.supportedLanguages || ["en"];
}
} catch (error) {
console.warn(
"Failed to load language manifest, falling back to default languages",
);
}
// Fallback to default languages if manifest loading fails
return ["en"];
};
// Use the browser language from the HTML lang attribute which is set by the server settings or request headers // Use the browser language from the HTML lang attribute which is set by the server settings or request headers
const getBrowserLanguage = async () => document.documentElement.lang; const getBrowserLanguage = async () => document.documentElement.lang;
@@ -91,7 +66,7 @@ const getRedirectUrl = () => {
}; };
let translations: Record<string, string> = {}; let translations: Record<string, string> = {};
let currentLang; let currentLang: string;
// Initialize translations // Initialize translations
const initTranslations = async () => { const initTranslations = async () => {
@@ -179,7 +154,16 @@ function App({ anubisVersion, basePrefix }: AppProps) {
} }
} }
const { challenge, rules } = j("anubis_challenge"); const challengeData = j("anubis_challenge");
if (!challengeData) {
showError(
t("challenge_error"),
t("challenge_data_missing"),
imageURL("reject", anubisVersion, basePrefix),
);
return;
}
const { challenge, rules } = challengeData;
const process = algorithms[rules.algorithm]; const process = algorithms[rules.algorithm];
if (!process) { if (!process) {