fix(webui): resolve svelte-check type errors
- commit
- 9b5fe54e2daed8e477c141f53f39d93f0f19930a
- author
- bnema · · 2025-12-21 21:53 UTC
- parent
- ad3456a
- signature
- unsigned
3 files · +42 -13
M webui/src/pages/ErrorPage.svelte +21 -4
| @@ -3,10 +3,26 @@ | |||
| 3 | 3 | import { Button } from '$lib/components/ui/button'; | |
| 4 | 4 | import * as Card from '$lib/components/ui/card'; | |
| 5 | 5 | ||
| 6 | + | type ErrorConfig = { | |
| 7 | + | code: number; | |
| 8 | + | title: string; | |
| 9 | + | message: string; | |
| 10 | + | icon: string; | |
| 11 | + | actions: string[]; | |
| 12 | + | }; | |
| 13 | + | ||
| 14 | + | const defaultConfig: ErrorConfig = { | |
| 15 | + | code: 404, | |
| 16 | + | title: 'Page Not Found', | |
| 17 | + | message: 'The page you are looking for does not exist.', | |
| 18 | + | icon: 'warning', | |
| 19 | + | actions: ['back'], | |
| 20 | + | }; | |
| 21 | + | ||
| 6 | 22 | // Error configurations | |
| 7 | - | const errorConfigs: Record<string, { code: number; title: string; message: string; icon: string; actions: string[] }> = { | |
| 23 | + | const errorConfigs: Record<string, ErrorConfig> = { | |
| 8 | 24 | blocked: { code: 0, title: 'Page Blocked', message: 'Content blocked by filter', icon: 'shield', actions: ['whitelist', 'bypass', 'back'] }, | |
| 9 | - | '404': { code: 404, title: 'Page Not Found', message: 'The page you are looking for does not exist.', icon: 'warning', actions: ['back'] }, | |
| 25 | + | '404': defaultConfig, | |
| 10 | 26 | '500': { code: 500, title: 'Server Error', message: 'Something went wrong on the server.', icon: 'error', actions: ['retry', 'back'] }, | |
| 11 | 27 | '502': { code: 502, title: 'Bad Gateway', message: 'The server received an invalid response.', icon: 'error', actions: ['retry', 'back'] }, | |
| 12 | 28 | '503': { code: 503, title: 'Service Unavailable', message: 'The server is temporarily unavailable.', icon: 'error', actions: ['retry', 'back'] }, | |
| @@ -15,7 +31,7 @@ | |||
| 15 | 31 | timeout: { code: 0, title: 'Connection Timed Out', message: 'The server took too long to respond.', icon: 'warning', actions: ['retry', 'back'] }, | |
| 16 | 32 | }; | |
| 17 | 33 | ||
| 18 | - | let config = $state(errorConfigs['404']); | |
| 34 | + | let config = $state<ErrorConfig>(defaultConfig); | |
| 19 | 35 | let targetUrl = $state(''); | |
| 20 | 36 | let targetDomain = $state(''); | |
| 21 | 37 | let customMessage = $state(''); | |
| @@ -26,7 +42,8 @@ | |||
| 26 | 42 | const params = new URLSearchParams(window.location.search); | |
| 27 | 43 | const typeParam = params.get('type') || params.get('code') || '404'; | |
| 28 | 44 | ||
| 29 | - | config = errorConfigs[typeParam] || { | |
| 45 | + | const selectedConfig = errorConfigs[typeParam]; | |
| 46 | + | config = selectedConfig ?? { | |
| 30 | 47 | code: parseInt(typeParam) || 0, | |
| 31 | 48 | title: `Error ${typeParam}`, | |
| 32 | 49 | message: 'An unexpected error occurred.', | |
| @@ -3,10 +3,26 @@ | |||||
| 3 | import { Button } from '$lib/components/ui/button'; | 3 | import { Button } from '$lib/components/ui/button'; | ||
| 4 | import * as Card from '$lib/components/ui/card'; | 4 | import * as Card from '$lib/components/ui/card'; | ||
| 5 | 5 | ||||
| 6 | + | type ErrorConfig = { | |||
| 7 | + | code: number; | |||
| 8 | + | title: string; | |||
| 9 | + | message: string; | |||
| 10 | + | icon: string; | |||
| 11 | + | actions: string[]; | |||
| 12 | + | }; | |||
| 13 | + | ||||
| 14 | + | const defaultConfig: ErrorConfig = { | |||
| 15 | + | code: 404, | |||
| 16 | + | title: 'Page Not Found', | |||
| 17 | + | message: 'The page you are looking for does not exist.', | |||
| 18 | + | icon: 'warning', | |||
| 19 | + | actions: ['back'], | |||
| 20 | + | }; | |||
| 21 | + | ||||
| 6 | // Error configurations | 22 | // Error configurations | ||
| 7 | - | const errorConfigs: Record<string, { code: number; title: string; message: string; icon: string; actions: string[] }> = { | 23 | + | const errorConfigs: Record<string, ErrorConfig> = { |
| 8 | blocked: { code: 0, title: 'Page Blocked', message: 'Content blocked by filter', icon: 'shield', actions: ['whitelist', 'bypass', 'back'] }, | 24 | blocked: { code: 0, title: 'Page Blocked', message: 'Content blocked by filter', icon: 'shield', actions: ['whitelist', 'bypass', 'back'] }, | ||
| 9 | - | '404': { code: 404, title: 'Page Not Found', message: 'The page you are looking for does not exist.', icon: 'warning', actions: ['back'] }, | 25 | + | '404': defaultConfig, |
| 10 | '500': { code: 500, title: 'Server Error', message: 'Something went wrong on the server.', icon: 'error', actions: ['retry', 'back'] }, | 26 | '500': { code: 500, title: 'Server Error', message: 'Something went wrong on the server.', icon: 'error', actions: ['retry', 'back'] }, | ||
| 11 | '502': { code: 502, title: 'Bad Gateway', message: 'The server received an invalid response.', icon: 'error', actions: ['retry', 'back'] }, | 27 | '502': { code: 502, title: 'Bad Gateway', message: 'The server received an invalid response.', icon: 'error', actions: ['retry', 'back'] }, | ||
| 12 | '503': { code: 503, title: 'Service Unavailable', message: 'The server is temporarily unavailable.', icon: 'error', actions: ['retry', 'back'] }, | 28 | '503': { code: 503, title: 'Service Unavailable', message: 'The server is temporarily unavailable.', icon: 'error', actions: ['retry', 'back'] }, | ||
| @@ -15,7 +31,7 @@ | |||||
| 15 | timeout: { code: 0, title: 'Connection Timed Out', message: 'The server took too long to respond.', icon: 'warning', actions: ['retry', 'back'] }, | 31 | timeout: { code: 0, title: 'Connection Timed Out', message: 'The server took too long to respond.', icon: 'warning', actions: ['retry', 'back'] }, | ||
| 16 | }; | 32 | }; | ||
| 17 | 33 | ||||
| 18 | - | let config = $state(errorConfigs['404']); | 34 | + | let config = $state<ErrorConfig>(defaultConfig); |
| 19 | let targetUrl = $state(''); | 35 | let targetUrl = $state(''); | ||
| 20 | let targetDomain = $state(''); | 36 | let targetDomain = $state(''); | ||
| 21 | let customMessage = $state(''); | 37 | let customMessage = $state(''); | ||
| @@ -26,7 +42,8 @@ | |||||
| 26 | const params = new URLSearchParams(window.location.search); | 42 | const params = new URLSearchParams(window.location.search); | ||
| 27 | const typeParam = params.get('type') || params.get('code') || '404'; | 43 | const typeParam = params.get('type') || params.get('code') || '404'; | ||
| 28 | 44 | ||||
| 29 | - | config = errorConfigs[typeParam] || { | 45 | + | const selectedConfig = errorConfigs[typeParam]; |
| 46 | + | config = selectedConfig ?? { | |||
| 30 | code: parseInt(typeParam) || 0, | 47 | code: parseInt(typeParam) || 0, | ||
| 31 | title: `Error ${typeParam}`, | 48 | title: `Error ${typeParam}`, | ||
| 32 | message: 'An unexpected error occurred.', | 49 | message: 'An unexpected error occurred.', | ||
M webui/src/pages/homepage/messaging.ts +0 -9
| @@ -142,15 +142,6 @@ function initializeCallbacks(): void { | |||
| 142 | 142 | callbacksInitialized = true; | |
| 143 | 143 | } | |
| 144 | 144 | ||
| 145 | - | function handleLegacyCallback(requestId: string | undefined, data: unknown): void { | |
| 146 | - | const request = pendingRequests.get(requestId || 'default'); | |
| 147 | - | if (request) { | |
| 148 | - | clearTimeout(request.timeout); | |
| 149 | - | pendingRequests.delete(requestId || 'default'); | |
| 150 | - | request.resolve(data); | |
| 151 | - | } | |
| 152 | - | } | |
| 153 | - | ||
| 154 | 145 | // Handle both legacy raw data and new Response object format | |
| 155 | 146 | function handleLegacyOrResponseCallback(dataOrResponse: unknown): void { | |
| 156 | 147 | // Check if it's a Response object (has requestId and success fields) | |
| @@ -142,15 +142,6 @@ function initializeCallbacks(): void { | |||||
| 142 | callbacksInitialized = true; | 142 | callbacksInitialized = true; | ||
| 143 | } | 143 | } | ||
| 144 | 144 | ||||
| 145 | - | function handleLegacyCallback(requestId: string | undefined, data: unknown): void { | |||
| 146 | - | const request = pendingRequests.get(requestId || 'default'); | |||
| 147 | - | if (request) { | |||
| 148 | - | clearTimeout(request.timeout); | |||
| 149 | - | pendingRequests.delete(requestId || 'default'); | |||
| 150 | - | request.resolve(data); | |||
| 151 | - | } | |||
| 152 | - | } | |||
| 153 | - | ||||
| 154 | // Handle both legacy raw data and new Response object format | 145 | // Handle both legacy raw data and new Response object format | ||
| 155 | function handleLegacyOrResponseCallback(dataOrResponse: unknown): void { | 146 | function handleLegacyOrResponseCallback(dataOrResponse: unknown): void { | ||
| 156 | // Check if it's a Response object (has requestId and success fields) | 147 | // Check if it's a Response object (has requestId and success fields) | ||
A webui/src/types/generated.ts +21 -0
| @@ -0,0 +1,21 @@ | |||
| 1 | + | export interface HistoryEntry { | |
| 2 | + | id: number; | |
| 3 | + | url: string; | |
| 4 | + | title: string | null; | |
| 5 | + | favicon_url: string | null; | |
| 6 | + | visit_count: number; | |
| 7 | + | last_visited: string; | |
| 8 | + | created_at: string; | |
| 9 | + | } | |
| 10 | + | ||
| 11 | + | export type History = HistoryEntry; | |
| 12 | + | ||
| 13 | + | export interface SearchShortcut { | |
| 14 | + | url: string; | |
| 15 | + | description: string; | |
| 16 | + | } | |
| 17 | + | ||
| 18 | + | export interface Shortcut { | |
| 19 | + | url_template: string; | |
| 20 | + | description?: string; | |
| 21 | + | } | |
| @@ -0,0 +1,21 @@ | |||||
| 1 | + | export interface HistoryEntry { | |||
| 2 | + | id: number; | |||
| 3 | + | url: string; | |||
| 4 | + | title: string | null; | |||
| 5 | + | favicon_url: string | null; | |||
| 6 | + | visit_count: number; | |||
| 7 | + | last_visited: string; | |||
| 8 | + | created_at: string; | |||
| 9 | + | } | |||
| 10 | + | ||||
| 11 | + | export type History = HistoryEntry; | |||
| 12 | + | ||||
| 13 | + | export interface SearchShortcut { | |||
| 14 | + | url: string; | |||
| 15 | + | description: string; | |||
| 16 | + | } | |||
| 17 | + | ||||
| 18 | + | export interface Shortcut { | |||
| 19 | + | url_template: string; | |||
| 20 | + | description?: string; | |||
| 21 | + | } | |||