fix: bw/stats 404, gateway links, history crash

- swr.ts: remove useBandwidth(), drop bw from useDashboard()
- events/route.ts: skip bandwidth SSE (Kubo 0.28.0 unsupported)
- usage/page.tsx: remove getBWStats call + bw references
- helpers.ts: gatewayLink -> ipfs.maos.dedyn.io (subdomain only)
- upload/page.tsx: fix local gatewayLink (subdomain only)
- storage.ts: update default gatewayUrl, add defensive getHistory()
This commit is contained in:
maikrolf
2026-07-05 16:57:29 +02:00
parent c9432a16ba
commit 99c113b6f5
42 changed files with 10081 additions and 263 deletions
+33 -12
View File
@@ -1,8 +1,8 @@
'use client';
import { useState, useRef, type DragEvent, useCallback } from 'react';
import { useState, useRef, type DragEvent, useCallback, useMemo } from 'react';
import { uploadFile } from '@/lib/api';
import { addToHistory } from '@/lib/storage';
import { addToHistory, getSettings } from '@/lib/storage';
import PortalLayout from '@/app/layout-portal';
import { checkUploadAllowed } from '@/lib/limits';
import { useNotify } from '@/lib/notifications';
@@ -10,17 +10,13 @@ import { Zap, ArrowUp } from 'lucide-react';
import QuickUpload, { type FileEntry } from './components/QuickUpload';
import CryptoUpload from './components/CryptoUpload';
/* ── Constants ── */
const MAX_FILES = 20;
const MAX_FILE_SIZE = 100 * 1024 * 1024; // 100 MB
const ALLOWED_TYPES = ['image/png', 'image/jpeg', 'image/gif', 'image/webp'];
type TabMode = 'quick' | 'crypto';
/* ════════════════════════════ Page ════════════════════════════ */
export default function UploadPage() {
const { notify } = useNotify();
const settings = useMemo(() => getSettings(), []);
const inputRef = useRef<HTMLInputElement>(null);
const cryptoInputRef = useRef<HTMLInputElement>(null);
@@ -41,24 +37,49 @@ export default function UploadPage() {
/* ── File management ── */
const addFiles = useCallback((incoming: FileList | File[]) => {
const s = getSettings();
const arr = Array.from(incoming);
const remaining = MAX_FILES - files.length;
const remaining = s.maxFiles - files.length;
const toAdd = arr.slice(0, remaining);
const allowedExts = s.allowedFileTypes
? s.allowedFileTypes.split(',').map(e => e.trim().toLowerCase()).filter(Boolean)
: null;
const rejected: string[] = [];
const entries: FileEntry[] = toAdd
.filter(f => f.size <= MAX_FILE_SIZE)
.filter(f => s.maxFileSize === 0 || f.size <= s.maxFileSize)
.filter(f => !files.some(ex => ex.file.name === f.name && ex.file.size === f.size))
.filter(f => {
if (!allowedExts) return true;
const ext = f.name.split('.').pop()?.toLowerCase();
if (ext && allowedExts.includes(ext)) return true;
rejected.push(f.name);
return false;
})
.map(f => ({
id: Math.random().toString(36).slice(2, 9),
file: f,
preview: ALLOWED_TYPES.includes(f.type) ? URL.createObjectURL(f) : undefined,
preview: !allowedExts || allowedExts.some(ext => f.name.toLowerCase().endsWith('.' + ext))
? URL.createObjectURL(f)
: undefined,
status: 'pending' as const,
}));
if (rejected.length > 0) {
notify({
type: 'warning',
title: 'Bestandstype niet toegestaan',
message: `De volgende bestanden zijn overgeslagen: ${rejected.join(', ')}`,
duration: 5000,
});
}
if (entries.length === 0) return;
setFiles(prev => [...prev, ...entries]);
setUploadDone(false);
}, [files]);
}, [files, notify]);
function removeFile(id: string) {
setFiles(prev => {
@@ -176,7 +197,7 @@ export default function UploadPage() {
}
function gatewayLink(cid: string) {
return `https://maos.dedyn.io/ipfs/${cid}`;
return `https://ipfs.maos.dedyn.io/${cid}`;
}
/* ════════════ Render ════════════ */