:chore: Initialisation du projet

This commit is contained in:
Orionis312050 committed 2026-10-08 23:48:33 +02:00
1 parent 75a8c6addd
commit 6278d19618
27 files changed
+4418 -81

No files matched your search

+159
View File
@@ -0,0 +1,159 @@
import { FormEvent, useCallback, useEffect, useState } from "react";
type Movie = {
id: number;
title: string;
year: number | null;
path: string;
size: number | null;
status: string;
};
type RadarrSettings = { url: string | null; api_key_configured: boolean };
const jsonHeaders = { "Content-Type": "application/json" };
async function api<T>(path: string, init?: RequestInit): Promise<T> {
const response = await fetch(path, init);
if (!response.ok) {
const body = await response.json().catch(() => null);
throw new Error(body?.detail ?? `Erreur HTTP ${response.status}`);
}
return response.json();
}
function readableSize(size: number | null): string {
if (size === null) return "—";
return `${(size / 1024 ** 3).toFixed(1)} Go`;
}
export default function App() {
const [movies, setMovies] = useState<Movie[]>([]);
const [url, setUrl] = useState("");
const [apiKey, setApiKey] = useState("");
const [keyConfigured, setKeyConfigured] = useState(false);
const [message, setMessage] = useState("");
const [busy, setBusy] = useState(false);
const loadMovies = useCallback(async () => {
setMovies(await api<Movie[]>("/api/movies"));
}, []);
useEffect(() => {
Promise.all([api<RadarrSettings>("/api/settings/radarr"), loadMovies()])
.then(([settings]) => {
setUrl(settings.url ?? "");
setKeyConfigured(settings.api_key_configured);
})
.catch((error: Error) => setMessage(error.message));
}, [loadMovies]);
async function saveSettings(event: FormEvent) {
event.preventDefault();
setBusy(true);
setMessage("");
try {
const settings = await api<RadarrSettings>("/api/settings/radarr", {
method: "PUT",
headers: jsonHeaders,
body: JSON.stringify({ url, api_key: apiKey || null }),
});
setKeyConfigured(settings.api_key_configured);
setApiKey("");
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 scan() {
setBusy(true);
setMessage("");
try {
const result = await api<{ iso_files: number; scanned_movies: number }>("/api/scans", {
method: "POST",
});
await loadMovies();
setMessage(`${result.iso_files} ISO trouvée(s) sur ${result.scanned_movies} film(s)`);
} catch (error) {
setMessage((error as Error).message);
} finally {
setBusy(false);
}
}
return (
<main>
<header>
<div>
<p className="eyebrow">RADARR · ISO → MKV</p>
<h1>MKVTool</h1>
</div>
<button onClick={scan} disabled={busy || !keyConfigured}>Scanner maintenant</button>
</header>
<section className="panel settings">
<div>
<h2>Connexion Radarr</h2>
<p>L’URL doit être accessible depuis le conteneur MKVTool.</p>
</div>
<form onSubmit={saveSettings}>
<label>
URL Radarr
<input
type="url"
required
placeholder="http://radarr:7878"
value={url}
onChange={(event) => setUrl(event.target.value)}
/>
</label>
<label>
Clé API {keyConfigured && <span>· configurée</span>}
<input
type="password"
required={!keyConfigured}
placeholder={keyConfigured ? "Laisser vide pour conserver" : "Clé API Radarr"}
value={apiKey}
onChange={(event) => setApiKey(event.target.value)}
/>
</label>
<button disabled={busy}>Enregistrer et tester</button>
</form>
</section>
{message && <p className="message">{message}</p>}
<section className="library">
<div className="section-title">
<div>
<p className="eyebrow">INVENTAIRE</p>
<h2>Films ISO</h2>
</div>
<span>{movies.length} détecté(s)</span>
</div>
{movies.length === 0 ? (
<div className="empty">Configurez Radarr puis lancez votre premier scan.</div>
) : (
<div className="movie-list">
{movies.map((movie) => (
<article key={movie.id}>
<div>
<h3>{movie.title}</h3>
<p>{movie.year ?? "Année inconnue"} · {readableSize(movie.size)}</p>
<code>{movie.path}</code>
</div>
<span className="status">{movie.status}</span>
</article>
))}
</div>
)}
</section>
</main>
);
}
+10
View File
@@ -0,0 +1,10 @@
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import App from "./App";
import "./style.css";
createRoot(document.getElementById("root")!).render(
<StrictMode>
<App />
</StrictMode>,
);
+42
View File
@@ -0,0 +1,42 @@
:root {
font-family: Inter, ui-sans-serif, system-ui, sans-serif;
color: #e8ebe9;
background: #0b0f0e;
font-synthesis: none;
}
* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100vh; }
button, input { font: inherit; }
button {
border: 0; border-radius: 10px; padding: 0.75rem 1rem; color: #07110d;
background: #62e6a7; font-weight: 750; cursor: pointer;
}
button:disabled { cursor: not-allowed; opacity: 0.45; }
main { width: min(1100px, calc(100% - 2rem)); margin: 0 auto; padding: 3rem 0; }
header, .section-title { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(2.5rem, 8vw, 5rem); letter-spacing: -0.07em; }
.eyebrow { color: #62e6a7; font-size: 0.75rem; font-weight: 800; letter-spacing: 0.14em; }
.panel { margin: 3rem 0 1rem; padding: 1.5rem; border: 1px solid #26332e; border-radius: 16px; background: #111816; }
.settings { display: grid; grid-template-columns: 1fr 2fr; gap: 2rem; }
.settings p, article p { color: #91a199; }
form { display: grid; grid-template-columns: 1fr 1fr auto; align-items: end; gap: 0.75rem; }
label { display: grid; gap: 0.4rem; color: #b7c1bc; font-size: 0.85rem; }
label span { color: #62e6a7; }
input { width: 100%; padding: 0.75rem; color: #eef5f1; border: 1px solid #35463f; border-radius: 9px; background: #090e0c; }
.message { padding: 0.8rem 1rem; border-left: 3px solid #62e6a7; background: #111816; }
.library { margin-top: 3rem; }
.section-title > span { color: #91a199; }
.empty { padding: 4rem 1rem; text-align: center; color: #91a199; border: 1px dashed #35463f; border-radius: 16px; }
.movie-list { display: grid; gap: 0.75rem; }
article { display: flex; justify-content: space-between; gap: 1rem; padding: 1.25rem; border: 1px solid #26332e; border-radius: 13px; background: #111816; }
article h3 { margin-bottom: 0.3rem; }
article p { margin-bottom: 0.6rem; }
code { color: #a9b6b0; overflow-wrap: anywhere; }
.status { align-self: start; padding: 0.35rem 0.6rem; color: #62e6a7; background: #183328; border-radius: 999px; font-size: 0.75rem; }
@media (max-width: 800px) {
.settings, form { grid-template-columns: 1fr; }
header { align-items: flex-end; }
}
+2
View File
@@ -0,0 +1,2 @@
/// <reference types="vite/client" />