Initial project structure cleanup

This commit is contained in:
litoral05
2026-05-08 16:57:55 +01:00
commit 8075104243
59 changed files with 22335 additions and 0 deletions
+59
View File
@@ -0,0 +1,59 @@
import type { AppSettings } from '@/types/api';
const defaults: AppSettings = {
backendUrl: 'http://localhost:8080',
apiKey: 'dev-api-key',
};
const SETTINGS_KEY =
'lr-openwrt-tool.settings';
export function getSettings(): AppSettings {
try {
const storedSettings =
localStorage.getItem(SETTINGS_KEY);
return {
...defaults,
...JSON.parse(storedSettings || '{}'),
};
} catch {
return defaults;
}
}
export function saveSettings(
settings: AppSettings,
) {
localStorage.setItem(
SETTINGS_KEY,
JSON.stringify(settings),
);
}
export async function apiRequest<T>(
path: string,
init: RequestInit = {},
): Promise<T> {
const settings = getSettings();
const response = await fetch(
`${settings.backendUrl}${path}`,
{
...init,
headers: {
'Content-Type': 'application/json',
'X-API-Key': settings.apiKey,
...(init.headers || {}),
},
},
);
if (!response.ok) {
throw new Error(
`${response.status} ${response.statusText}`,
);
}
return response.json() as Promise<T>;
}