FE-0: Projektgrundgerüst (SvelteKit, Tailwind, Docker, Caddy)
This commit is contained in:
60
src/lib/api.ts
Normal file
60
src/lib/api.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
const API_BASE_URL = import.meta.env.NSCT_API_BASE_URL || 'http://localhost:8080';
|
||||
|
||||
interface ApiConfig {
|
||||
apiKey?: string;
|
||||
}
|
||||
|
||||
function headers(config?: ApiConfig): Record<string, string> {
|
||||
const h: Record<string, string> = {
|
||||
'Content-Type': 'application/json'
|
||||
};
|
||||
if (config?.apiKey) {
|
||||
h['X-API-Key'] = config.apiKey;
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
export async function apiPost<T>(
|
||||
path: string,
|
||||
body?: unknown,
|
||||
config?: ApiConfig
|
||||
): Promise<T> {
|
||||
const res = await fetch(`${API_BASE_URL}${path}`, {
|
||||
method: 'POST',
|
||||
headers: headers(config),
|
||||
body: body ? JSON.stringify(body) : undefined
|
||||
});
|
||||
if (!res.ok) {
|
||||
throw new Error(`API Error ${res.status}: ${res.statusText}`);
|
||||
}
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export async function apiGet<T>(
|
||||
path: string,
|
||||
config?: ApiConfig
|
||||
): Promise<T> {
|
||||
const res = await fetch(`${API_BASE_URL}${path}`, {
|
||||
headers: headers(config)
|
||||
});
|
||||
if (!res.ok) {
|
||||
throw new Error(`API Error ${res.status}: ${res.statusText}`);
|
||||
}
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export async function apiDelete<T>(
|
||||
path: string,
|
||||
config?: ApiConfig
|
||||
): Promise<T> {
|
||||
const res = await fetch(`${API_BASE_URL}${path}`, {
|
||||
method: 'DELETE',
|
||||
headers: headers(config)
|
||||
});
|
||||
if (!res.ok) {
|
||||
throw new Error(`API Error ${res.status}: ${res.statusText}`);
|
||||
}
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export { API_BASE_URL };
|
||||
13
src/lib/stores.ts
Normal file
13
src/lib/stores.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { writable } from 'svelte/store';
|
||||
|
||||
// Theme: 'dark' | 'light'
|
||||
export const theme = writable<'dark' | 'light'>('dark');
|
||||
|
||||
// User: null oder { apiKey, username? }
|
||||
export const user = writable<{ apiKey: string; username?: string } | null>(null);
|
||||
|
||||
// Sidebar: ist offen oder geschlossen (mobile)
|
||||
export const sidebarOpen = writable(false);
|
||||
|
||||
// Session IDs der letzten Researches
|
||||
export const recentResearchIds = writable<string[]>([]);
|
||||
20
src/lib/theme.ts
Normal file
20
src/lib/theme.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { theme } from '$lib/stores';
|
||||
|
||||
export function initTheme() {
|
||||
const stored = localStorage.getItem('nsct-theme');
|
||||
if (stored === 'dark' || stored === 'light') {
|
||||
theme.set(stored);
|
||||
} else {
|
||||
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
|
||||
theme.set(prefersDark ? 'dark' : 'light');
|
||||
}
|
||||
}
|
||||
|
||||
export function toggleTheme() {
|
||||
theme.update(t => t === 'dark' ? 'light' : 'dark');
|
||||
}
|
||||
|
||||
export function applyTheme(t: 'dark' | 'light') {
|
||||
document.documentElement.classList.toggle('dark', t === 'dark');
|
||||
localStorage.setItem('nsct-theme', t);
|
||||
}
|
||||
41
src/lib/types.ts
Normal file
41
src/lib/types.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
export interface ResearchStatus {
|
||||
id: string;
|
||||
status: string;
|
||||
progress?: number;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
export interface ResearchSummary {
|
||||
id: string;
|
||||
query: string;
|
||||
status: string;
|
||||
created_at: string;
|
||||
completed_at?: string;
|
||||
}
|
||||
|
||||
export interface SourceInfo {
|
||||
id: string;
|
||||
url: string;
|
||||
title: string;
|
||||
domain?: string;
|
||||
source_type?: string;
|
||||
independence_score?: number;
|
||||
}
|
||||
|
||||
export interface ClaimInfo {
|
||||
id: string;
|
||||
claim: string;
|
||||
claim_type: string;
|
||||
confidence: number;
|
||||
source_id?: string;
|
||||
evidence_span?: string;
|
||||
}
|
||||
|
||||
export interface EvidenceScore {
|
||||
source_independence: number;
|
||||
primary_source_proximity: number;
|
||||
cross_source_support: number;
|
||||
contradiction_level: number;
|
||||
evidence_directness: number;
|
||||
date_relevance: number;
|
||||
}
|
||||
Reference in New Issue
Block a user