Lot 3 (5/5) : interface (entrée S3, réglages admin) et tests S3

Entrée « S3 » dans la barre latérale et à la racine (icône nuage), pas
d'historique ni de favoris sur S3 ; section « Racine S3 » dans
Administration (champs verrouillés par l'environnement, clé secrète jamais
affichée, test de connexion). Tests : Store S3 sur stockage objet en
mémoire, intégration aux espaces.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LNfwm4pfYR9C914C2EeiuB
This commit is contained in:
claude BotandClaude Opus 5.5 committed 2026-11-20 18:06:58 +01:00
1 parent e79a813272
commit 6838c147b7
7 files changed
+618 -16

No files matched your search

+5 -2
View File
@@ -1,5 +1,5 @@
import { useCallback, useEffect, useRef, useState } from "react";
import { api, FAVORIS, PERSO, POUBELLE, type Entry, type Me } from "./api";
import { api, FAVORIS, PERSO, POUBELLE, S3, type Entry, type Me } from "./api";
import { ActionMenu } from "./ActionMenu";
import { Explorer } from "./Explorer";
import { FolderTree } from "./FolderTree";
@@ -9,6 +9,7 @@ import { Splitter } from "./Splitter";
import { UploadPanel } from "./UploadPanel";
import { fmtSize, initials } from "./format";
import {
CloudIcon,
CloudUpIcon,
FolderIcon,
KeyIcon,
@@ -187,7 +188,8 @@ function Shell({ me, reloadMe }: { me: Me; reloadMe: () => Promise<unknown> }) {
const trash = places.find((p) => p.special === "poubelle");
const user = me.user!;
const root = dir.split("/")[0];
const current = root === PERSO || root === FAVORIS || root === POUBELLE ? root : "";
const hasS3 = places.some((p) => p.special === "s3");
const current = root === PERSO || root === FAVORIS || root === POUBELLE || root === S3 ? root : "";
const navItem = (id: string, text: string, icon: React.ReactNode, active: boolean, badge?: number) => (
<button className={`nav-item ${active ? "on" : ""}`} onClick={() => go(id)} aria-current={active ? "page" : undefined}>
@@ -241,6 +243,7 @@ function Shell({ me, reloadMe }: { me: Me; reloadMe: () => Promise<unknown> }) {
{navItem("", "Fichiers", <FolderIcon />, dir === "")}
<FolderTree current={current === "" ? dir : ""} reloadKey={refreshKey + treeKey} onOpen={go} />
{navItem(PERSO, "Personnel", <UserIcon />, current === PERSO)}
{hasS3 && navItem(S3, "S3", <CloudIcon />, current === S3)}
{navItem(FAVORIS, "Favoris", <StarFilledIcon />, current === FAVORIS)}
{navItem(POUBELLE, "Poubelle", trash?.count ? <TrashFullIcon /> : <TrashIcon />, current === POUBELLE, trash?.count)}
</nav>
+9 -7
View File
@@ -1,5 +1,5 @@
import { useEffect, useState } from "react";
import { api, dirname, displayPath, type Entry } from "./api";
import { api, dirname, displayPath, inS3, type Entry } from "./api";
import { CloseIcon, DownloadIcon, EyeIcon, FolderIcon, HistoryIcon, ShareIcon, StarFilledIcon, StarIcon } from "./icons";
import { FolderGlyph } from "./folderIcons";
import { FileGlyph, Thumb, thumbSource } from "./FileGlyph";
@@ -113,16 +113,18 @@ export function DetailsPanel({ entry: e, onClose, onOpen, onShare, onHistory, on
<ShareIcon />
<span>Partager</span>
</button>
{!e.isDir && (
{!e.isDir && !inS3(e.path) && (
<button onClick={() => onHistory(e)}>
<HistoryIcon />
<span>Historique</span>
</button>
)}
<button onClick={() => onFavorite(e)} aria-pressed={!!e.favorite}>
{e.favorite ? <StarFilledIcon /> : <StarIcon />}
<span>{e.favorite ? "Favori" : "Ajouter aux favoris"}</span>
</button>
{!inS3(e.path) && (
<button onClick={() => onFavorite(e)} aria-pressed={!!e.favorite}>
{e.favorite ? <StarFilledIcon /> : <StarIcon />}
<span>{e.favorite ? "Favori" : "Ajouter aux favoris"}</span>
</button>
)}
</div>
<dl>
@@ -175,7 +177,7 @@ export function DetailsPanel({ entry: e, onClose, onOpen, onShare, onHistory, on
</dl>
{!e.isDir && (
<div className="details-foot muted">
<FileGlyph name={e.name} size={14} /> {e.path.startsWith(".perso") ? "Espace personnel" : "Arborescence commune"}
<FileGlyph name={e.name} size={14} /> {e.path.startsWith(".perso") ? "Espace personnel" : inS3(e.path) ? "Racine S3" : "Arborescence commune"}
</div>
)}
</aside>
+5 -3
View File
@@ -9,6 +9,7 @@ import {
displayPath,
inFavoris,
inPoubelle,
inS3,
join,
label,
POUBELLE,
@@ -18,6 +19,7 @@ import {
type TagCount,
} from "./api";
import {
CloudIcon,
CloseIcon,
ClockIcon,
CopyIcon,
@@ -565,7 +567,7 @@ export function Explorer({ me, refreshKey, goto, onDirChange, onMutated, toolbar
const icon = (e: Entry) =>
e.special ? (
<span className={`icon special ${e.special} ${e.count ? "full" : ""}`} aria-hidden>
{e.special === "favoris" ? <StarFilledIcon size={big} /> : e.special === "poubelle" ? e.count ? <TrashFullIcon size={big} /> : <TrashIcon size={big} /> : <UserIcon size={big} />}
{e.special === "favoris" ? <StarFilledIcon size={big} /> : e.special === "poubelle" ? e.count ? <TrashFullIcon size={big} /> : <TrashIcon size={big} /> : e.special === "s3" ? <CloudIcon size={big} /> : <UserIcon size={big} />}
</span>
) : e.broken ? (
<span className="icon folder" aria-hidden>
@@ -679,13 +681,13 @@ export function Explorer({ me, refreshKey, goto, onDirChange, onMutated, toolbar
</button>
</>
)}
{!e.isDir && !e.broken && (
{!e.isDir && !e.broken && !inS3(e.path) && (
<button role="menuitem" onClick={() => setHistory(e)}>
<HistoryIcon />
Historique…
</button>
)}
{!e.broken && !favView && (
{!e.broken && !favView && !inS3(e.path) && (
<button role="menuitem" onClick={() => toggleFavorite([e])}>
{e.favorite ? <StarFilledIcon /> : <StarIcon />}
{e.favorite ? "Retirer des favoris" : "Favori"}
+118 -2
View File
@@ -1,6 +1,6 @@
import { useCallback, useEffect, useState } from "react";
import type { ReactNode } from "react";
import { api, displayPath, type Account, type ApiToken, type Me, type Role, type Settings, type Share, type Status } from "./api";
import { api, displayPath, type Account, type ApiToken, type Me, type Role, type S3Patch, type S3Status, type Settings, type Share, type Status } from "./api";
import { csvPageSizes, usePreviewPrefs } from "./prefs";
import { CheckIcon, CloseIcon, CopyLinkIcon, EyeIcon, KeyIcon, LockIcon, ShareIcon, ShieldIcon, TrashIcon, UserIcon, UsersIcon } from "./icons";
import { ConfirmDialog } from "./Dialogs";
@@ -658,7 +658,7 @@ function GeneralTab({ onError, onChanged }: { onError: (m: string | null) => voi
</form>
<label className="check-row">
<input type="checkbox" checked={st.commonReadonly} onChange={(e) => apply({ commonReadonly: e.target.checked })} />
<span>Arborescence commune en lecture seule pour les utilisateurs (seuls les administrateurs y écrivent)</span>
<span>Arborescence commune (et racine S3) en lecture seule pour les utilisateurs (seuls les administrateurs y écrivent)</span>
</label>
<form
className="inline-form"
@@ -675,10 +675,126 @@ function GeneralTab({ onError, onChanged }: { onError: (m: string | null) => voi
Enregistrer
</button>
</form>
<S3Section onError={onError} onChanged={onChanged} />
</div>
);
}
// --- Racine S3 (administrateur) -----------------------------------------------------------
const s3Fields: { id: keyof S3Patch; label: string; placeholder?: string }[] = [
{ id: "endpoint", label: "Endpoint", placeholder: "https://garage:3900" },
{ id: "region", label: "Région", placeholder: "garage" },
{ id: "bucket", label: "Bucket" },
{ id: "accessKey", label: "Clé d'accès" },
{ id: "secretKey", label: "Clé secrète" },
];
/** Connexion au bucket : un champ fixé par une variable S3_* est verrouillé ;
* la clé secrète n'est jamais affichée (vide : inchangée). */
function S3Section({ onError, onChanged }: { onError: (m: string | null) => void; onChanged: () => void }) {
const [st, setSt] = useState<S3Status | null>(null);
const [form, setForm] = useState<Record<string, string>>({});
const [insecure, setInsecure] = useState(false);
const [busy, setBusy] = useState(false);
const [note, setNote] = useState<string | null>(null);
const reset = (s: S3Status) => {
setSt(s);
setForm({ endpoint: s.endpoint, region: s.region, bucket: s.bucket, accessKey: s.accessKey, secretKey: "" });
setInsecure(s.insecure);
};
useEffect(() => {
api.s3Status().then(reset).catch((e) => onError(msg(e)));
}, [onError]);
if (!st) return null;
const locked = (k: string) => st.locked.includes(k);
const patch = (): S3Patch => {
const p: S3Patch = {};
for (const f of s3Fields) {
if (locked(f.id) || f.id === "secretKey") continue;
const v = form[f.id] ?? "";
if (v !== (st[f.id as keyof S3Status] ?? "")) (p as Record<string, string>)[f.id] = v;
}
if (!locked("secretKey") && form.secretKey) p.secretKey = form.secretKey;
if (!locked("insecure") && insecure !== st.insecure) p.insecure = insecure;
return p;
};
const run = async (save: boolean) => {
onError(null);
setNote(null);
setBusy(true);
try {
if (save) {
reset(await api.saveS3(patch()));
setNote("Configuration S3 enregistrée.");
onChanged();
} else {
await api.testS3(patch());
setNote("Connexion au bucket réussie.");
}
} catch (e) {
onError(msg(e));
} finally {
setBusy(false);
}
};
return (
<>
<h4>Racine S3</h4>
{!st.available ? (
<p className="muted small-text">Disponible avec le catalogue PostgreSQL (DATABASE_URL).</p>
) : (
<form
onSubmit={(e) => {
e.preventDefault();
run(true);
}}
>
<p className="muted small-text">
{st.active ? "Branchée." : "Non branchée."} Bucket vide attendu au départ ; l'endpoint et le bucket ne changent plus une
fois la racine utilisée. Les champs grisés sont fixés par les variables S3_*.
</p>
{st.error && <p className="error-text">{st.error}</p>}
{s3Fields.map((f) => (
<label className="field" key={f.id}>
<span>{f.label}</span>
<input
type={f.id === "secretKey" ? "password" : "text"}
autoComplete="off"
value={form[f.id] ?? ""}
disabled={locked(f.id) || (!st.empty && (f.id === "endpoint" || f.id === "bucket"))}
placeholder={f.id === "secretKey" ? (st.secretSet ? "inchangée" : "") : f.placeholder}
onChange={(e) => setForm({ ...form, [f.id]: e.target.value })}
/>
</label>
))}
<label className="check-row">
<input type="checkbox" checked={insecure} disabled={locked("insecure")} onChange={(e) => setInsecure(e.target.checked)} />
<span>HTTP sans TLS (endpoint sans schéma)</span>
</label>
{note && (
<div className="notice">
<CheckIcon size={14} /> {note}
</div>
)}
<div className="inline-form">
<button type="button" disabled={busy} onClick={() => run(false)}>
Tester la connexion
</button>
<button type="submit" className="primary" disabled={busy}>
Enregistrer
</button>
</div>
</form>
)}
</>
);
}
// --- Utilisateurs (administrateur) ---------------------------------------------------------
const statusLabel: Record<Status, string> = { active: "Actif", pending: "En attente", disabled: "Désactivé" };
+30 -2
View File
@@ -11,7 +11,7 @@ export interface Entry {
/** Dossier : icône choisie (voir folderIcons.tsx). */
icon?: string;
/** Entrée virtuelle de la racine : "favoris", "perso" (espace personnel) ou "poubelle". */
special?: "favoris" | "perso" | "poubelle";
special?: "favoris" | "perso" | "poubelle" | "s3";
/** Entrée « poubelle » de la racine : nombre d'éléments qu'elle contient. */
count?: number;
/** Élément de la poubelle : chemin d'origine (modTime = date de suppression). */
@@ -91,6 +91,25 @@ export interface PreviewSettings {
shares: boolean;
}
/** Racine S3 (administrateur) : la clé secrète n'est jamais renvoyée ;
* locked liste les champs fixés par les variables d'environnement. */
export interface S3Status {
available: boolean;
active: boolean;
error?: string;
endpoint: string;
region: string;
bucket: string;
accessKey: string;
secretSet: boolean;
insecure: boolean;
locked: string[];
empty: boolean;
}
/** Modification de la racine S3 ; secretKey vide : clé conservée. */
export type S3Patch = Partial<Pick<S3Status, "endpoint" | "region" | "bucket" | "accessKey" | "insecure">> & { secretKey?: string };
/** Version enregistrée d'un fichier (time : date de ce contenu). */
export interface Version {
id: string;
@@ -426,6 +445,12 @@ export const api = {
removeLogo: async (): Promise<Settings> => (await request("/api/logo", { method: "DELETE" })).json(),
logoUrl: (v: string) => `/api/logo?v=${q(v)}`,
s3Status: async (): Promise<S3Status> => (await request("/api/admin/s3")).json(),
saveS3: async (p: S3Patch): Promise<S3Status> => (await request("/api/admin/s3", json(p, "PUT"))).json(),
testS3: async (p: S3Patch): Promise<void> => {
await request("/api/admin/s3/test", json(p, "POST"));
},
};
export type Conflict = "fail" | "overwrite" | "rename";
@@ -471,7 +496,9 @@ export const join = (dir: string, name: string) => (dir ? `${dir}/${name}` : nam
export const PERSO = ".perso";
export const FAVORIS = ".favoris";
export const POUBELLE = ".poubelle";
const SPECIAL_LABELS: Record<string, string> = { [PERSO]: "Personnel", [FAVORIS]: "Favoris", [POUBELLE]: "Poubelle" };
/** Racine commune sur stockage objet (si configurée) : ni favoris ni historique. */
export const S3 = ".s3";
const SPECIAL_LABELS: Record<string, string> = { [PERSO]: "Personnel", [FAVORIS]: "Favoris", [POUBELLE]: "Poubelle", [S3]: "S3" };
/** Libellé d'un composant de chemin (".perso" → "Personnel"). */
export const label = (part: string) => SPECIAL_LABELS[part] ?? part;
/** Chemin affiché : "Personnel/projets" pour ".perso/projets". */
@@ -479,6 +506,7 @@ export const displayPath = (p: string) => p.split("/").map(label).join("/");
export const inFavoris = (p: string) => p === FAVORIS || p.startsWith(FAVORIS + "/");
export const inPoubelle = (p: string) => p === POUBELLE || p.startsWith(POUBELLE + "/");
export const inPerso = (p: string) => p === PERSO || p.startsWith(PERSO + "/");
export const inS3 = (p: string) => p === S3 || p.startsWith(S3 + "/");
/** Extension (sans le point, minuscules) ; vide si aucune. */
export const extOf = (name: string) => {