fixes the cmd prompt on start + api key defaults
This commit is contained in:
@@ -1 +1,5 @@
|
||||
fn main() { lr_openwrt_tool_lib::run() }
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
fn main() {
|
||||
lr_openwrt_tool_lib::run()
|
||||
}
|
||||
@@ -36,6 +36,11 @@ export function LoginScreen({
|
||||
setError('');
|
||||
|
||||
try {
|
||||
console.log('LOGIN TRY', {
|
||||
username: username.trim(),
|
||||
passwordLength: password.length,
|
||||
});
|
||||
|
||||
const response = await loginApi.login(
|
||||
username.trim(),
|
||||
password,
|
||||
@@ -47,13 +52,12 @@ export function LoginScreen({
|
||||
}
|
||||
|
||||
setError('Credenciais inválidas.');
|
||||
} catch {
|
||||
setError('Credenciais inválidas.');
|
||||
} catch (error) {
|
||||
setError(`Falha no login: ${String(error)}`);
|
||||
} finally {
|
||||
setSubmitting(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="relative flex min-h-screen items-center justify-center overflow-hidden bg-ink-950 px-6 text-white">
|
||||
<div className="pointer-events-none absolute -left-32 top-10 h-96 w-96 rounded-full bg-blue-500/20 blur-3xl" />
|
||||
|
||||
@@ -1,21 +1,41 @@
|
||||
import type { AppSettings } from '@/types/api';
|
||||
|
||||
const defaults: AppSettings = {
|
||||
backendUrl: 'http://localhost:8080',
|
||||
apiKey: 'dev-api-key',
|
||||
backendUrl: 'http://146.59.230.190:8080',
|
||||
apiKey:
|
||||
'b8184608fcab419da2ce9a220ee6017daaff637b627e43ebac31b6b7c3344349',
|
||||
};
|
||||
|
||||
const SETTINGS_KEY =
|
||||
'lr-openwrt-tool.settings';
|
||||
|
||||
function joinUrl(
|
||||
baseUrl: string,
|
||||
path: string,
|
||||
) {
|
||||
return `${baseUrl.replace(/\/+$/, '')}/${path.replace(
|
||||
/^\/+/,
|
||||
'',
|
||||
)}`;
|
||||
}
|
||||
|
||||
export function getSettings(): AppSettings {
|
||||
try {
|
||||
const storedSettings =
|
||||
localStorage.getItem(SETTINGS_KEY);
|
||||
|
||||
const parsed =
|
||||
JSON.parse(storedSettings || '{}');
|
||||
|
||||
return {
|
||||
...defaults,
|
||||
...JSON.parse(storedSettings || '{}'),
|
||||
...parsed,
|
||||
backendUrl:
|
||||
parsed.backendUrl?.trim() ||
|
||||
defaults.backendUrl,
|
||||
apiKey:
|
||||
parsed.apiKey?.trim() ||
|
||||
defaults.apiKey,
|
||||
};
|
||||
} catch {
|
||||
return defaults;
|
||||
@@ -27,18 +47,32 @@ export function saveSettings(
|
||||
) {
|
||||
localStorage.setItem(
|
||||
SETTINGS_KEY,
|
||||
JSON.stringify(settings),
|
||||
JSON.stringify({
|
||||
...settings,
|
||||
backendUrl:
|
||||
settings.backendUrl.trim(),
|
||||
apiKey: settings.apiKey.trim(),
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export function resetSettings() {
|
||||
localStorage.removeItem(SETTINGS_KEY);
|
||||
}
|
||||
|
||||
export async function apiRequest<T>(
|
||||
path: string,
|
||||
init: RequestInit = {},
|
||||
): Promise<T> {
|
||||
const settings = getSettings();
|
||||
|
||||
console.log(
|
||||
'[API]',
|
||||
joinUrl(settings.backendUrl, path),
|
||||
);
|
||||
|
||||
const response = await fetch(
|
||||
`${settings.backendUrl}${path}`,
|
||||
joinUrl(settings.backendUrl, path),
|
||||
{
|
||||
...init,
|
||||
headers: {
|
||||
|
||||
Reference in New Issue
Block a user