:feature: Mise en place de l'interface et de la configuration
This commit is contained in:
1 parent
6278d19618
commit
311ec74668
21 files changed
+1920
-231
No files matched your search
@@ -0,0 +1,356 @@
|
||||
import {useCallback, useEffect, useMemo, useState} from "react";
|
||||
import type React from "react";
|
||||
|
||||
import {api, jsonHeaders} from "../lib/api";
|
||||
import type {SettingsRead} from "../types";
|
||||
|
||||
export default function Settings() {
|
||||
const [radarrUrl, setRadarrUrl] = useState("");
|
||||
const [radarrApiKey, setRadarrApiKey] = useState("");
|
||||
const [radarrKeyConfigured, setRadarrKeyConfigured] = useState(false);
|
||||
|
||||
const [sonarrUrl, setSonarrUrl] = useState("");
|
||||
const [sonarrApiKey, setSonarrApiKey] = useState("");
|
||||
const [sonarrKeyConfigured, setSonarrKeyConfigured] = useState(false);
|
||||
|
||||
const [prowlarrUrl, setProwlarrUrl] = useState("");
|
||||
const [prowlarrApiKey, setProwlarrApiKey] = useState("");
|
||||
const [prowlarrKeyConfigured, setProwlarrKeyConfigured] = useState(false);
|
||||
|
||||
const [jellyfinUrl, setJellyfinUrl] = useState("");
|
||||
const [jellyfinApiKey, setJellyfinApiKey] = useState("");
|
||||
const [jellyfinKeyConfigured, setJellyfinKeyConfigured] = useState(false);
|
||||
|
||||
const [seerrUrl, setSeerrUrl] = useState("");
|
||||
const [seerrApiKey, setSeerrApiKey] = useState("");
|
||||
const [seerrKeyConfigured, setSeerrKeyConfigured] = useState(false);
|
||||
|
||||
const [qbitUrl, setQbitUrl] = useState("");
|
||||
const [qbitUsername, setQbitUsername] = useState("");
|
||||
const [qbitPassword, setQbitPassword] = useState("");
|
||||
const [qbitPasswordConfigured, setQbitPasswordConfigured] = useState(false);
|
||||
|
||||
const [message, setMessage] = useState("");
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
const serviceHelp = useMemo(() => "L’URL doit être accessible depuis le conteneur MKVTool.", []);
|
||||
|
||||
const hydrateSettings = useCallback((settings: SettingsRead) => {
|
||||
setRadarrUrl(settings.radarr.url ?? "");
|
||||
setRadarrKeyConfigured(settings.radarr.api_key_configured);
|
||||
|
||||
setSonarrUrl(settings.sonarr.url ?? "");
|
||||
setSonarrKeyConfigured(settings.sonarr.api_key_configured);
|
||||
|
||||
setProwlarrUrl(settings.prowlarr.url ?? "");
|
||||
setProwlarrKeyConfigured(settings.prowlarr.api_key_configured);
|
||||
|
||||
setJellyfinUrl(settings.jellyfin.url ?? "");
|
||||
setJellyfinKeyConfigured(settings.jellyfin.api_key_configured);
|
||||
|
||||
setSeerrUrl(settings.seerr.url ?? "");
|
||||
setSeerrKeyConfigured(settings.seerr.api_key_configured);
|
||||
|
||||
setQbitUrl(settings.qbittorrent.url ?? "");
|
||||
setQbitUsername(settings.qbittorrent.username ?? "");
|
||||
setQbitPasswordConfigured(settings.qbittorrent.password_configured);
|
||||
}, []);
|
||||
|
||||
const refreshSettings = useCallback(async () => {
|
||||
hydrateSettings(await api<SettingsRead>("/api/settings"));
|
||||
}, [hydrateSettings]);
|
||||
|
||||
useEffect(() => {
|
||||
refreshSettings().catch((error: Error) => setMessage(error.message));
|
||||
}, [refreshSettings]);
|
||||
|
||||
async function saveRadarr(event: React.FormEvent<HTMLFormElement>) {
|
||||
event.preventDefault();
|
||||
setBusy(true);
|
||||
setMessage("");
|
||||
try {
|
||||
await api<SettingsRead>("/api/settings", {
|
||||
method: "PUT",
|
||||
headers: jsonHeaders,
|
||||
body: JSON.stringify({
|
||||
radarr: {
|
||||
url: radarrUrl || null,
|
||||
api_key: radarrApiKey || null,
|
||||
},
|
||||
}),
|
||||
});
|
||||
setRadarrApiKey("");
|
||||
await refreshSettings();
|
||||
const result = await api<{ message: string }>("/api/settings/radarr/test", {method: "POST"});
|
||||
setMessage(result.message);
|
||||
} catch (error) {
|
||||
setMessage((error as Error).message);
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function saveApiService(
|
||||
name: "sonarr" | "prowlarr" | "jellyfin" | "seerr",
|
||||
event: React.FormEvent<HTMLFormElement>,
|
||||
) {
|
||||
event.preventDefault();
|
||||
setBusy(true);
|
||||
setMessage("");
|
||||
|
||||
const model = {
|
||||
sonarr: {url: sonarrUrl || null, api_key: sonarrApiKey || null},
|
||||
prowlarr: {url: prowlarrUrl || null, api_key: prowlarrApiKey || null},
|
||||
jellyfin: {url: jellyfinUrl || null, api_key: jellyfinApiKey || null},
|
||||
seerr: {url: seerrUrl || null, api_key: seerrApiKey || null},
|
||||
}[name];
|
||||
|
||||
try {
|
||||
await api<SettingsRead>("/api/settings", {
|
||||
method: "PUT",
|
||||
headers: jsonHeaders,
|
||||
body: JSON.stringify({[name]: model}),
|
||||
});
|
||||
|
||||
if (name === "sonarr") setSonarrApiKey("");
|
||||
if (name === "prowlarr") setProwlarrApiKey("");
|
||||
if (name === "jellyfin") setJellyfinApiKey("");
|
||||
if (name === "seerr") setSeerrApiKey("");
|
||||
|
||||
await refreshSettings();
|
||||
setMessage("Configuration enregistrée");
|
||||
} catch (error) {
|
||||
setMessage((error as Error).message);
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function saveQbittorrent(event: React.FormEvent<HTMLFormElement>) {
|
||||
event.preventDefault();
|
||||
setBusy(true);
|
||||
setMessage("");
|
||||
try {
|
||||
await api<SettingsRead>("/api/settings", {
|
||||
method: "PUT",
|
||||
headers: jsonHeaders,
|
||||
body: JSON.stringify({
|
||||
qbittorrent: {
|
||||
url: qbitUrl || null,
|
||||
username: qbitUsername || null,
|
||||
password: qbitPassword || null,
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
setQbitPassword("");
|
||||
await refreshSettings();
|
||||
setMessage("Configuration enregistrée");
|
||||
} catch (error) {
|
||||
setMessage((error as Error).message);
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="page">
|
||||
<section className="hero">
|
||||
<div>
|
||||
<h2>Connexions</h2>
|
||||
<p className="muted">
|
||||
Configurez vos services. Les secrets ne sont pas affichés et seront conservés si vous laissez
|
||||
les champs
|
||||
vides.
|
||||
</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section className="card grid-2">
|
||||
<div>
|
||||
<h3>Radarr</h3>
|
||||
<p className="muted">Obligatoire pour le scan et la détection des films.</p>
|
||||
</div>
|
||||
<form onSubmit={saveRadarr} className="form-2">
|
||||
<label>
|
||||
URL Radarr
|
||||
<input
|
||||
type="url"
|
||||
required
|
||||
placeholder="http://radarr:7878"
|
||||
value={radarrUrl}
|
||||
onChange={(event) => setRadarrUrl(event.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
Clé API {radarrKeyConfigured && <span>· configurée</span>}
|
||||
<input
|
||||
type="password"
|
||||
required={!radarrKeyConfigured}
|
||||
placeholder={radarrKeyConfigured ? "Laisser vide pour conserver" : "Clé API Radarr"}
|
||||
value={radarrApiKey}
|
||||
onChange={(event) => setRadarrApiKey(event.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<button disabled={busy}>Enregistrer et tester</button>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<section className="card grid-2">
|
||||
<div>
|
||||
<h3>Sonarr</h3>
|
||||
<p className="muted">Optionnel (hors périmètre MVP), mais stocké dans conf.json.</p>
|
||||
</div>
|
||||
<form onSubmit={(e) => saveApiService("sonarr", e)} className="form-2">
|
||||
<label>
|
||||
URL Sonarr
|
||||
<input
|
||||
type="url"
|
||||
placeholder="http://sonarr:8989"
|
||||
value={sonarrUrl}
|
||||
onChange={(event) => setSonarrUrl(event.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
Clé API {sonarrKeyConfigured && <span>· configurée</span>}
|
||||
<input
|
||||
type="password"
|
||||
placeholder={sonarrKeyConfigured ? "Laisser vide pour conserver" : "Clé API Sonarr"}
|
||||
value={sonarrApiKey}
|
||||
onChange={(event) => setSonarrApiKey(event.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<button disabled={busy}>Enregistrer</button>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<section className="card grid-2">
|
||||
<div>
|
||||
<h3>Prowlarr</h3>
|
||||
<p className="muted">Optionnel (hors périmètre MVP), mais stocké dans conf.json.</p>
|
||||
</div>
|
||||
<form onSubmit={(e) => saveApiService("prowlarr", e)} className="form-2">
|
||||
<label>
|
||||
URL Prowlarr
|
||||
<input
|
||||
type="url"
|
||||
placeholder="http://prowlarr:9696"
|
||||
value={prowlarrUrl}
|
||||
onChange={(event) => setProwlarrUrl(event.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
Clé API {prowlarrKeyConfigured && <span>· configurée</span>}
|
||||
<input
|
||||
type="password"
|
||||
placeholder={prowlarrKeyConfigured ? "Laisser vide pour conserver" : "Clé API Prowlarr"}
|
||||
value={prowlarrApiKey}
|
||||
onChange={(event) => setProwlarrApiKey(event.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<button disabled={busy}>Enregistrer</button>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<section className="card grid-2">
|
||||
<div>
|
||||
<h3>Jellyfin</h3>
|
||||
<p className="muted">Optionnel (hors périmètre MVP), mais stocké dans conf.json.</p>
|
||||
</div>
|
||||
<form onSubmit={(e) => saveApiService("jellyfin", e)} className="form-2">
|
||||
<label>
|
||||
URL Jellyfin
|
||||
<input
|
||||
type="url"
|
||||
placeholder="http://jellyfin:8096"
|
||||
value={jellyfinUrl}
|
||||
onChange={(event) => setJellyfinUrl(event.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
Clé API {jellyfinKeyConfigured && <span>· configurée</span>}
|
||||
<input
|
||||
type="password"
|
||||
placeholder={jellyfinKeyConfigured ? "Laisser vide pour conserver" : "Clé API Jellyfin"}
|
||||
value={jellyfinApiKey}
|
||||
onChange={(event) => setJellyfinApiKey(event.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<button disabled={busy}>Enregistrer</button>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<section className="card grid-2">
|
||||
<div>
|
||||
<h3>Overseerr</h3>
|
||||
<p className="muted">Optionnel (hors périmètre MVP), mais stocké dans conf.json.</p>
|
||||
</div>
|
||||
<form onSubmit={(e) => saveApiService("seerr", e)} className="form-2">
|
||||
<label>
|
||||
URL Seerr
|
||||
<input
|
||||
type="url"
|
||||
placeholder="http://seerr:5055"
|
||||
value={seerrUrl}
|
||||
onChange={(event) => setSeerrUrl(event.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
Clé API {seerrKeyConfigured && <span>· configurée</span>}
|
||||
<input
|
||||
type="password"
|
||||
placeholder={seerrKeyConfigured ? "Laisser vide pour conserver" : "Clé API Seerr"}
|
||||
value={seerrApiKey}
|
||||
onChange={(event) => setSeerrApiKey(event.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<button disabled={busy}>Enregistrer</button>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<section className="card grid-2">
|
||||
<div>
|
||||
<h3>qBittorrent</h3>
|
||||
<p className="muted">Optionnel: nécessaire pour supprimer torrent + données après import validé.</p>
|
||||
</div>
|
||||
<form onSubmit={saveQbittorrent} className="form-3">
|
||||
<label>
|
||||
URL WebUI
|
||||
<input
|
||||
type="url"
|
||||
placeholder="http://qbittorrent:8080"
|
||||
value={qbitUrl}
|
||||
onChange={(event) => setQbitUrl(event.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
Utilisateur
|
||||
<input
|
||||
type="text"
|
||||
placeholder="admin"
|
||||
value={qbitUsername}
|
||||
onChange={(event) => setQbitUsername(event.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
Mot de passe {qbitPasswordConfigured && <span>· configuré</span>}
|
||||
<input
|
||||
type="password"
|
||||
placeholder={qbitPasswordConfigured ? "Laisser vide pour conserver" : "Mot de passe"}
|
||||
value={qbitPassword}
|
||||
onChange={(event) => setQbitPassword(event.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<button disabled={busy}>Enregistrer</button>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<section className="card">
|
||||
<h3>Aide</h3>
|
||||
<p className="muted">{serviceHelp}</p>
|
||||
</section>
|
||||
|
||||
{message && <div className="toast">{message}</div>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user