refactor: codebase opschoning — type safety, error handling, central config, page splits

- categorie A: alle catch(e: any) → catch(e: unknown) met instanceof check
- categorie B: stille .catch() logging toegevoegd (SWRegister, admin, upload, auth)
- categorie C: hardcoded 192.168.1.176 IPs vervangen door env var defaults
- categorie D: page files >250L gesplitst (history, settings, explorer, admin/payment,
  ipns, users, upload, dashboard) in helpers/components
- categorie E: eslint-disable vervangen in SearchInput.tsx
- src/lib/config.ts centrale config module (localhost defaults)
- CSP in next.config.ts dynamisch via env var
- deploy.sh: geen hardcoded IP meer (REQUIRED arg)
- lib/api/ lib/auth/ lib/wallet/ lib/search-index/ lib/storage/ gesplitst in modules
- ongebruikte bestanden verwijderd: api.ts, auth.tsx, wallet.ts, search-index.ts,
  PaymentPanel.tsx, SearchBar.tsx, proxy.ts, serve-static.js
This commit is contained in:
maikrolf
2026-07-19 15:35:18 +02:00
parent 88ce38a49e
commit f72b775379
144 changed files with 4644 additions and 10230 deletions
+44
View File
@@ -0,0 +1,44 @@
/* ── Settings Page Helpers ── */
import type { PortalSettings } from "@/lib/storage";
export function formatStorageMB(mb: number): string {
if (mb >= 1024) return (mb / 1024).toFixed(0) + " GB";
return mb + " MB";
}
export function inputCls(field: string, validation: Record<string, string | null>): string {
return `w-full rounded-lg bg-surface-900 border ${
validation[field] ? "border-accent-rose/50" : "border-surface-700"
} px-3 py-2 text-sm text-surface-200 placeholder:text-surface-500 focus:outline-none focus:border-brand-500 focus:ring-1 focus:ring-brand-500 transition-colors`;
}
export function validateSettings(
form: PortalSettings,
): { valid: boolean; errors: Record<string, string | null> } {
const errors: Record<string, string | null> = {};
let valid = true;
if (!form.gatewayUrl.startsWith("http://") && !form.gatewayUrl.startsWith("https://")) {
errors.gatewayUrl = "Must start with http:// or https://";
valid = false;
}
if (form.gatewayUrl.length > 500) {
errors.gatewayUrl = "Too long (max 500 chars)";
valid = false;
}
if (form.apiEndpoint && !form.apiEndpoint.startsWith("/") && !form.apiEndpoint.startsWith("http")) {
errors.apiEndpoint = "Must be empty, a path (/…), or a URL";
valid = false;
}
if (form.storageMax < 1 || form.storageMax > 102400) {
errors.storageMax = "Must be 1–102400 MB";
valid = false;
}
if (form.refreshInterval < 5 || form.refreshInterval > 300) {
errors.refreshInterval = "Must be 5–300 seconds";
valid = false;
}
return { valid, errors };
}