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:
1 parent
e79a813272
commit
6838c147b7
7 files changed
+614
-12
No files matched your search
@@ -1,5 +1,5 @@
|
|||||||
import { useCallback, useEffect, useRef, useState } from "react";
|
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 { ActionMenu } from "./ActionMenu";
|
||||||
import { Explorer } from "./Explorer";
|
import { Explorer } from "./Explorer";
|
||||||
import { FolderTree } from "./FolderTree";
|
import { FolderTree } from "./FolderTree";
|
||||||
@@ -9,6 +9,7 @@ import { Splitter } from "./Splitter";
|
|||||||
import { UploadPanel } from "./UploadPanel";
|
import { UploadPanel } from "./UploadPanel";
|
||||||
import { fmtSize, initials } from "./format";
|
import { fmtSize, initials } from "./format";
|
||||||
import {
|
import {
|
||||||
|
CloudIcon,
|
||||||
CloudUpIcon,
|
CloudUpIcon,
|
||||||
FolderIcon,
|
FolderIcon,
|
||||||
KeyIcon,
|
KeyIcon,
|
||||||
@@ -187,7 +188,8 @@ function Shell({ me, reloadMe }: { me: Me; reloadMe: () => Promise<unknown> }) {
|
|||||||
const trash = places.find((p) => p.special === "poubelle");
|
const trash = places.find((p) => p.special === "poubelle");
|
||||||
const user = me.user!;
|
const user = me.user!;
|
||||||
const root = dir.split("/")[0];
|
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) => (
|
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}>
|
<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 === "")}
|
{navItem("", "Fichiers", <FolderIcon />, dir === "")}
|
||||||
<FolderTree current={current === "" ? dir : ""} reloadKey={refreshKey + treeKey} onOpen={go} />
|
<FolderTree current={current === "" ? dir : ""} reloadKey={refreshKey + treeKey} onOpen={go} />
|
||||||
{navItem(PERSO, "Personnel", <UserIcon />, current === PERSO)}
|
{navItem(PERSO, "Personnel", <UserIcon />, current === PERSO)}
|
||||||
|
{hasS3 && navItem(S3, "S3", <CloudIcon />, current === S3)}
|
||||||
{navItem(FAVORIS, "Favoris", <StarFilledIcon />, current === FAVORIS)}
|
{navItem(FAVORIS, "Favoris", <StarFilledIcon />, current === FAVORIS)}
|
||||||
{navItem(POUBELLE, "Poubelle", trash?.count ? <TrashFullIcon /> : <TrashIcon />, current === POUBELLE, trash?.count)}
|
{navItem(POUBELLE, "Poubelle", trash?.count ? <TrashFullIcon /> : <TrashIcon />, current === POUBELLE, trash?.count)}
|
||||||
</nav>
|
</nav>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { useEffect, useState } from "react";
|
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 { CloseIcon, DownloadIcon, EyeIcon, FolderIcon, HistoryIcon, ShareIcon, StarFilledIcon, StarIcon } from "./icons";
|
||||||
import { FolderGlyph } from "./folderIcons";
|
import { FolderGlyph } from "./folderIcons";
|
||||||
import { FileGlyph, Thumb, thumbSource } from "./FileGlyph";
|
import { FileGlyph, Thumb, thumbSource } from "./FileGlyph";
|
||||||
@@ -113,16 +113,18 @@ export function DetailsPanel({ entry: e, onClose, onOpen, onShare, onHistory, on
|
|||||||
<ShareIcon />
|
<ShareIcon />
|
||||||
<span>Partager</span>
|
<span>Partager</span>
|
||||||
</button>
|
</button>
|
||||||
{!e.isDir && (
|
{!e.isDir && !inS3(e.path) && (
|
||||||
<button onClick={() => onHistory(e)}>
|
<button onClick={() => onHistory(e)}>
|
||||||
<HistoryIcon />
|
<HistoryIcon />
|
||||||
<span>Historique</span>
|
<span>Historique</span>
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
|
{!inS3(e.path) && (
|
||||||
<button onClick={() => onFavorite(e)} aria-pressed={!!e.favorite}>
|
<button onClick={() => onFavorite(e)} aria-pressed={!!e.favorite}>
|
||||||
{e.favorite ? <StarFilledIcon /> : <StarIcon />}
|
{e.favorite ? <StarFilledIcon /> : <StarIcon />}
|
||||||
<span>{e.favorite ? "Favori" : "Ajouter aux favoris"}</span>
|
<span>{e.favorite ? "Favori" : "Ajouter aux favoris"}</span>
|
||||||
</button>
|
</button>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<dl>
|
<dl>
|
||||||
@@ -175,7 +177,7 @@ export function DetailsPanel({ entry: e, onClose, onOpen, onShare, onHistory, on
|
|||||||
</dl>
|
</dl>
|
||||||
{!e.isDir && (
|
{!e.isDir && (
|
||||||
<div className="details-foot muted">
|
<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>
|
</div>
|
||||||
)}
|
)}
|
||||||
</aside>
|
</aside>
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import {
|
|||||||
displayPath,
|
displayPath,
|
||||||
inFavoris,
|
inFavoris,
|
||||||
inPoubelle,
|
inPoubelle,
|
||||||
|
inS3,
|
||||||
join,
|
join,
|
||||||
label,
|
label,
|
||||||
POUBELLE,
|
POUBELLE,
|
||||||
@@ -18,6 +19,7 @@ import {
|
|||||||
type TagCount,
|
type TagCount,
|
||||||
} from "./api";
|
} from "./api";
|
||||||
import {
|
import {
|
||||||
|
CloudIcon,
|
||||||
CloseIcon,
|
CloseIcon,
|
||||||
ClockIcon,
|
ClockIcon,
|
||||||
CopyIcon,
|
CopyIcon,
|
||||||
@@ -565,7 +567,7 @@ export function Explorer({ me, refreshKey, goto, onDirChange, onMutated, toolbar
|
|||||||
const icon = (e: Entry) =>
|
const icon = (e: Entry) =>
|
||||||
e.special ? (
|
e.special ? (
|
||||||
<span className={`icon special ${e.special} ${e.count ? "full" : ""}`} aria-hidden>
|
<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>
|
</span>
|
||||||
) : e.broken ? (
|
) : e.broken ? (
|
||||||
<span className="icon folder" aria-hidden>
|
<span className="icon folder" aria-hidden>
|
||||||
@@ -679,13 +681,13 @@ export function Explorer({ me, refreshKey, goto, onDirChange, onMutated, toolbar
|
|||||||
</button>
|
</button>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
{!e.isDir && !e.broken && (
|
{!e.isDir && !e.broken && !inS3(e.path) && (
|
||||||
<button role="menuitem" onClick={() => setHistory(e)}>
|
<button role="menuitem" onClick={() => setHistory(e)}>
|
||||||
<HistoryIcon />
|
<HistoryIcon />
|
||||||
Historique…
|
Historique…
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
{!e.broken && !favView && (
|
{!e.broken && !favView && !inS3(e.path) && (
|
||||||
<button role="menuitem" onClick={() => toggleFavorite([e])}>
|
<button role="menuitem" onClick={() => toggleFavorite([e])}>
|
||||||
{e.favorite ? <StarFilledIcon /> : <StarIcon />}
|
{e.favorite ? <StarFilledIcon /> : <StarIcon />}
|
||||||
{e.favorite ? "Retirer des favoris" : "Favori"}
|
{e.favorite ? "Retirer des favoris" : "Favori"}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { useCallback, useEffect, useState } from "react";
|
import { useCallback, useEffect, useState } from "react";
|
||||||
import type { ReactNode } 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 { csvPageSizes, usePreviewPrefs } from "./prefs";
|
||||||
import { CheckIcon, CloseIcon, CopyLinkIcon, EyeIcon, KeyIcon, LockIcon, ShareIcon, ShieldIcon, TrashIcon, UserIcon, UsersIcon } from "./icons";
|
import { CheckIcon, CloseIcon, CopyLinkIcon, EyeIcon, KeyIcon, LockIcon, ShareIcon, ShieldIcon, TrashIcon, UserIcon, UsersIcon } from "./icons";
|
||||||
import { ConfirmDialog } from "./Dialogs";
|
import { ConfirmDialog } from "./Dialogs";
|
||||||
@@ -658,7 +658,7 @@ function GeneralTab({ onError, onChanged }: { onError: (m: string | null) => voi
|
|||||||
</form>
|
</form>
|
||||||
<label className="check-row">
|
<label className="check-row">
|
||||||
<input type="checkbox" checked={st.commonReadonly} onChange={(e) => apply({ commonReadonly: e.target.checked })} />
|
<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>
|
</label>
|
||||||
<form
|
<form
|
||||||
className="inline-form"
|
className="inline-form"
|
||||||
@@ -675,10 +675,126 @@ function GeneralTab({ onError, onChanged }: { onError: (m: string | null) => voi
|
|||||||
Enregistrer
|
Enregistrer
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<S3Section onError={onError} onChanged={onChanged} />
|
||||||
</div>
|
</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) ---------------------------------------------------------
|
// --- Utilisateurs (administrateur) ---------------------------------------------------------
|
||||||
|
|
||||||
const statusLabel: Record<Status, string> = { active: "Actif", pending: "En attente", disabled: "Désactivé" };
|
const statusLabel: Record<Status, string> = { active: "Actif", pending: "En attente", disabled: "Désactivé" };
|
||||||
|
|||||||
+30
-2
@@ -11,7 +11,7 @@ export interface Entry {
|
|||||||
/** Dossier : icône choisie (voir folderIcons.tsx). */
|
/** Dossier : icône choisie (voir folderIcons.tsx). */
|
||||||
icon?: string;
|
icon?: string;
|
||||||
/** Entrée virtuelle de la racine : "favoris", "perso" (espace personnel) ou "poubelle". */
|
/** 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. */
|
/** Entrée « poubelle » de la racine : nombre d'éléments qu'elle contient. */
|
||||||
count?: number;
|
count?: number;
|
||||||
/** Élément de la poubelle : chemin d'origine (modTime = date de suppression). */
|
/** Élément de la poubelle : chemin d'origine (modTime = date de suppression). */
|
||||||
@@ -91,6 +91,25 @@ export interface PreviewSettings {
|
|||||||
shares: boolean;
|
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). */
|
/** Version enregistrée d'un fichier (time : date de ce contenu). */
|
||||||
export interface Version {
|
export interface Version {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -426,6 +445,12 @@ export const api = {
|
|||||||
removeLogo: async (): Promise<Settings> => (await request("/api/logo", { method: "DELETE" })).json(),
|
removeLogo: async (): Promise<Settings> => (await request("/api/logo", { method: "DELETE" })).json(),
|
||||||
|
|
||||||
logoUrl: (v: string) => `/api/logo?v=${q(v)}`,
|
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";
|
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 PERSO = ".perso";
|
||||||
export const FAVORIS = ".favoris";
|
export const FAVORIS = ".favoris";
|
||||||
export const POUBELLE = ".poubelle";
|
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"). */
|
/** Libellé d'un composant de chemin (".perso" → "Personnel"). */
|
||||||
export const label = (part: string) => SPECIAL_LABELS[part] ?? part;
|
export const label = (part: string) => SPECIAL_LABELS[part] ?? part;
|
||||||
/** Chemin affiché : "Personnel/projets" pour ".perso/projets". */
|
/** 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 inFavoris = (p: string) => p === FAVORIS || p.startsWith(FAVORIS + "/");
|
||||||
export const inPoubelle = (p: string) => p === POUBELLE || p.startsWith(POUBELLE + "/");
|
export const inPoubelle = (p: string) => p === POUBELLE || p.startsWith(POUBELLE + "/");
|
||||||
export const inPerso = (p: string) => p === PERSO || p.startsWith(PERSO + "/");
|
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. */
|
/** Extension (sans le point, minuscules) ; vide si aucune. */
|
||||||
export const extOf = (name: string) => {
|
export const extOf = (name: string) => {
|
||||||
|
|||||||
@@ -0,0 +1,313 @@
|
|||||||
|
package storage
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"io"
|
||||||
|
"io/fs"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
// memObjects : stockage objet en mémoire pour les tests.
|
||||||
|
type memObjects struct {
|
||||||
|
mu sync.Mutex
|
||||||
|
objs map[string][]byte
|
||||||
|
meta map[string]map[string]string
|
||||||
|
}
|
||||||
|
|
||||||
|
func newMemObjects() *memObjects {
|
||||||
|
return &memObjects{objs: map[string][]byte{}, meta: map[string]map[string]string{}}
|
||||||
|
}
|
||||||
|
|
||||||
|
type memFile struct{ *bytes.Reader }
|
||||||
|
|
||||||
|
func (memFile) Close() error { return nil }
|
||||||
|
|
||||||
|
func (m *memObjects) Put(_ context.Context, key string, r io.Reader, meta map[string]string) (int64, error) {
|
||||||
|
b, err := io.ReadAll(r)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
m.mu.Lock()
|
||||||
|
defer m.mu.Unlock()
|
||||||
|
m.objs[key], m.meta[key] = b, meta
|
||||||
|
return int64(len(b)), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *memObjects) Get(_ context.Context, key string) (File, error) {
|
||||||
|
m.mu.Lock()
|
||||||
|
defer m.mu.Unlock()
|
||||||
|
b, ok := m.objs[key]
|
||||||
|
if !ok {
|
||||||
|
return nil, ErrNotFound
|
||||||
|
}
|
||||||
|
return memFile{bytes.NewReader(b)}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *memObjects) Copy(_ context.Context, src, dst string, meta map[string]string) error {
|
||||||
|
m.mu.Lock()
|
||||||
|
defer m.mu.Unlock()
|
||||||
|
b, ok := m.objs[src]
|
||||||
|
if !ok {
|
||||||
|
return ErrNotFound
|
||||||
|
}
|
||||||
|
m.objs[dst], m.meta[dst] = append([]byte(nil), b...), meta
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *memObjects) Remove(_ context.Context, key string) error {
|
||||||
|
m.mu.Lock()
|
||||||
|
defer m.mu.Unlock()
|
||||||
|
delete(m.objs, key)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *memObjects) Empty(context.Context) (bool, error) {
|
||||||
|
m.mu.Lock()
|
||||||
|
defer m.mu.Unlock()
|
||||||
|
return len(m.objs) == 0, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *memObjects) count() int {
|
||||||
|
m.mu.Lock()
|
||||||
|
defer m.mu.Unlock()
|
||||||
|
return len(m.objs)
|
||||||
|
}
|
||||||
|
|
||||||
|
func newS3Store(t *testing.T) (*Store, *memObjects) {
|
||||||
|
t.Helper()
|
||||||
|
db := needCatalog(t)
|
||||||
|
ctx := context.Background()
|
||||||
|
if _, err := db.Pool.Exec(ctx, "TRUNCATE s3_nodes, s3_trash, s3_config; DELETE FROM item_meta WHERE root = 's3'; DELETE FROM shares WHERE root = 's3'"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
objs := newMemObjects()
|
||||||
|
s, err := NewS3(t.TempDir(), db, objs)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
return s, objs
|
||||||
|
}
|
||||||
|
|
||||||
|
func readAll(t *testing.T, s *Store, rel string) string {
|
||||||
|
t.Helper()
|
||||||
|
f, _, err := s.Open(rel)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
b, _ := io.ReadAll(f)
|
||||||
|
return string(b)
|
||||||
|
}
|
||||||
|
|
||||||
|
func names(es []Entry) string {
|
||||||
|
var n []string
|
||||||
|
for _, e := range es {
|
||||||
|
n = append(n, e.Name)
|
||||||
|
}
|
||||||
|
return strings.Join(n, ",")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestS3RootBasics(t *testing.T) {
|
||||||
|
s, objs := newS3Store(t)
|
||||||
|
if _, err := s.Put("a/b/c.txt", strings.NewReader("bonjour"), PutOptions{By: "alice"}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if es, err := s.List(""); err != nil || names(es) != "a" {
|
||||||
|
t.Fatalf("racine : %v %v", names(es), err)
|
||||||
|
}
|
||||||
|
if es, _ := s.List("a/b"); names(es) != "c.txt" || es[0].Size != 7 || es[0].EditedBy != "alice" {
|
||||||
|
t.Fatalf("a/b : %+v", es)
|
||||||
|
}
|
||||||
|
if got := readAll(t, s, "a/b/c.txt"); got != "bonjour" {
|
||||||
|
t.Fatal(got)
|
||||||
|
}
|
||||||
|
// Conflits et remplacement.
|
||||||
|
if _, err := s.Put("a/b/c.txt", strings.NewReader("x"), PutOptions{}); !errors.Is(err, ErrExists) {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
e, err := s.Put("a/b/c.txt", strings.NewReader("x"), PutOptions{Conflict: "rename"})
|
||||||
|
if err != nil || e.Path != "a/b/c (2).txt" {
|
||||||
|
t.Fatalf("rename : %v %+v", err, e)
|
||||||
|
}
|
||||||
|
_, fi, _ := s.Open("a/b/c.txt")
|
||||||
|
if _, err := s.Put("a/b/c.txt", strings.NewReader("salut"), PutOptions{Conflict: "overwrite", IfMatch: "faux"}); !errors.Is(err, ErrConflict) {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if _, err := s.Put("a/b/c.txt", strings.NewReader("salut"), PutOptions{Conflict: "overwrite", IfMatch: ETag(fi)}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if got := readAll(t, s, "a/b/c.txt"); got != "salut" || objs.count() != 2 {
|
||||||
|
t.Fatalf("remplacement : %q, %d objets", got, objs.count())
|
||||||
|
}
|
||||||
|
if _, err := s.Put("a/b/c.txt/d", strings.NewReader("x"), PutOptions{}); !errors.Is(err, ErrExists) {
|
||||||
|
t.Fatalf("fichier en chemin : %v", err)
|
||||||
|
}
|
||||||
|
if _, err := s.Put("big", strings.NewReader("0123456789"), PutOptions{Limit: 5}); !errors.Is(err, ErrTooLarge) || objs.count() != 2 {
|
||||||
|
t.Fatalf("limite : %v, %d objets", err, objs.count())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tags, déplacement (catalogue seul), copie (objets dupliqués).
|
||||||
|
if err := s.EditTags([]string{"a/b"}, []string{"Projet"}, nil); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if _, err := s.Move("a/b", "x/y"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if _, err := s.Move("x", "x/z"); !errors.Is(err, ErrInvalidPath) {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if e, err := s.Stat("x/y"); err != nil || len(e.Tags) != 1 {
|
||||||
|
t.Fatalf("tags suivis : %v %+v", err, e)
|
||||||
|
}
|
||||||
|
if got := readAll(t, s, "x/y/c.txt"); got != "salut" || objs.count() != 2 {
|
||||||
|
t.Fatalf("déplacé : %q %d", got, objs.count())
|
||||||
|
}
|
||||||
|
if _, err := s.Copy("x", "copie"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if got := readAll(t, s, "copie/y/c (2).txt"); got != "x" || objs.count() != 4 {
|
||||||
|
t.Fatalf("copie : %q %d", got, objs.count())
|
||||||
|
}
|
||||||
|
var walked []string
|
||||||
|
_ = s.Walk("copie", func(rel string, e Entry) error {
|
||||||
|
walked = append(walked, rel)
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if strings.Join(walked, "|") != "copie|copie/y|copie/y/c (2).txt|copie/y/c.txt" {
|
||||||
|
t.Fatalf("walk : %q", walked)
|
||||||
|
}
|
||||||
|
if s.Usage() != 12 {
|
||||||
|
t.Errorf("usage : %d", s.Usage())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Corbeille : suppression, restauration, purge.
|
||||||
|
if err := s.Delete("x", false); !errors.Is(err, ErrNotEmpty) {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := s.Delete("x", true); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if _, err := s.Stat("x/y/c.txt"); !errors.Is(err, ErrNotFound) {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
items, _ := s.TrashItems()
|
||||||
|
if len(items) != 1 || items[0].Path != "x" || !items[0].IsDir || s.TrashCount() != 1 {
|
||||||
|
t.Fatalf("corbeille : %+v", items)
|
||||||
|
}
|
||||||
|
if es, _ := s.List(""); names(es) != "a,copie" {
|
||||||
|
t.Fatalf("racine après suppression : %s", names(es))
|
||||||
|
}
|
||||||
|
if _, err := s.RestoreTrash(items[0].ID); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if e, err := s.Stat("x/y"); err != nil || len(e.Tags) != 1 {
|
||||||
|
t.Fatalf("restauré : %v %+v", err, e)
|
||||||
|
}
|
||||||
|
if err := s.Delete("x", true); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := s.EmptyTrash(); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if objs.count() != 2 || s.TrashCount() != 0 {
|
||||||
|
t.Fatalf("purge : %d objets", objs.count())
|
||||||
|
}
|
||||||
|
if err := s.Remove("copie"); err != nil || objs.count() != 0 {
|
||||||
|
t.Fatalf("remove : %v %d", err, objs.count())
|
||||||
|
}
|
||||||
|
if vs, err := s.Versions("a"); err != nil || len(vs) != 0 {
|
||||||
|
t.Fatalf("versions : %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Transfert disque -> S3 et S3 -> disque par la fonction commune.
|
||||||
|
func TestS3Transfer(t *testing.T) {
|
||||||
|
s3s, _ := newS3Store(t)
|
||||||
|
disk := newStore(t)
|
||||||
|
if _, err := disk.Put("d/f.txt", strings.NewReader("disque"), PutOptions{}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if _, err := transfer(disk, "d", s3s, "d", "bob"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if got := readAll(t, s3s, "d/f.txt"); got != "disque" {
|
||||||
|
t.Fatal(got)
|
||||||
|
}
|
||||||
|
if _, err := transfer(s3s, "d", disk, "retour", "bob"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if got := readAll(t, disk, "retour/f.txt"); got != "disque" {
|
||||||
|
t.Fatal(got)
|
||||||
|
}
|
||||||
|
if err := s3s.Walk("absent", func(string, Entry) error { return nil }); !errors.Is(err, ErrNotFound) {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
// Walk : SkipDir saute le contenu d'un dossier.
|
||||||
|
var seen []string
|
||||||
|
_ = s3s.Walk("", func(rel string, e Entry) error {
|
||||||
|
seen = append(seen, rel)
|
||||||
|
if rel == "d" {
|
||||||
|
return fs.SkipDir
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if strings.Join(seen, "|") != "|d" {
|
||||||
|
t.Fatalf("SkipDir : %q", seen)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestS3MetaSharesSearch(t *testing.T) {
|
||||||
|
s, _ := newS3Store(t)
|
||||||
|
s.SetShareSecret("0123456789abcdef0123")
|
||||||
|
if _, err := s.Put("docs/rapport.txt", strings.NewReader("contenu"), PutOptions{}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := s.SetIcon([]string{"docs"}, ""); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := s.SetIcon([]string{"docs/rapport.txt"}, ""); !errors.Is(err, ErrInvalidPath) {
|
||||||
|
t.Fatalf("icône sur fichier : %v", err)
|
||||||
|
}
|
||||||
|
if err := s.EditTags([]string{"docs/rapport.txt"}, []string{"Urgent"}, nil); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
sh, err := s.CreateShare("docs", ShareOptions{})
|
||||||
|
if err != nil || !sh.IsDir {
|
||||||
|
t.Fatalf("partage : %v %+v", err, sh)
|
||||||
|
}
|
||||||
|
if _, err := s.ResolveShare(sh.Token); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if _, err := s.Move("docs", "archives"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if got, err := s.ResolveShare(sh.Token); err != nil || got.Path != "archives" {
|
||||||
|
t.Fatalf("partage suivi : %v %+v", err, got)
|
||||||
|
}
|
||||||
|
hits, err := s.Search("rapp", Filter{}, 10)
|
||||||
|
if err != nil || len(hits) != 1 || hits[0].Path != "archives/rapport.txt" {
|
||||||
|
t.Fatalf("recherche nom : %v %+v", err, hits)
|
||||||
|
}
|
||||||
|
if hits, _ := s.Search("contenu", Filter{}, 10); len(hits) != 0 {
|
||||||
|
t.Fatal("plein texte inattendu sur S3")
|
||||||
|
}
|
||||||
|
if hits, _ := s.Search("", Filter{Tag: "urgent"}, 10); len(hits) != 1 {
|
||||||
|
t.Fatalf("tag : %+v", hits)
|
||||||
|
}
|
||||||
|
if d, err := s.dirDetails("archives"); err != nil || d.Files != 1 || d.Total != 7 {
|
||||||
|
t.Fatalf("détails : %v %+v", err, d)
|
||||||
|
}
|
||||||
|
if _, _, _, err := s.Thumb("archives/rapport.txt"); !errors.Is(err, ErrNotFound) {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if _, err := s.Put("img.png", bytes.NewReader(makePNG(300, 200)), PutOptions{}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if b, _, _, err := s.Thumb("img.png"); err != nil || len(b) == 0 {
|
||||||
|
t.Fatalf("miniature : %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,138 @@
|
|||||||
|
package storage
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"io"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func uread(t *testing.T, u *Space, p string) string {
|
||||||
|
t.Helper()
|
||||||
|
f, _, err := u.Open(p)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Open(%s) : %v", p, err)
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
b, _ := io.ReadAll(f)
|
||||||
|
return string(b)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSpaceS3Root(t *testing.T) {
|
||||||
|
s3, _ := newS3Store(t)
|
||||||
|
sp := newSpaces(t)
|
||||||
|
sp.SetS3(s3)
|
||||||
|
alice := space(t, sp, "alice", false)
|
||||||
|
admin := space(t, sp, "admin", true)
|
||||||
|
|
||||||
|
es, err := alice.List("")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
found := false
|
||||||
|
for _, e := range es {
|
||||||
|
found = found || (e.Special == "s3" && e.Path == S3Prefix)
|
||||||
|
}
|
||||||
|
if !found {
|
||||||
|
t.Fatalf("entrée S3 absente de la racine : %v", es)
|
||||||
|
}
|
||||||
|
|
||||||
|
e := uput(t, alice, ".s3/docs/a.txt", "AAA")
|
||||||
|
if e.Path != ".s3/docs/a.txt" {
|
||||||
|
t.Errorf("chemin virtuel %q", e.Path)
|
||||||
|
}
|
||||||
|
if got := uread(t, alice, ".s3/docs/a.txt"); got != "AAA" {
|
||||||
|
t.Errorf("contenu %q", got)
|
||||||
|
}
|
||||||
|
if l, _ := alice.List(".s3/docs"); len(l) != 1 || l[0].Path != ".s3/docs/a.txt" {
|
||||||
|
t.Errorf("liste .s3/docs : %v", l)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copie et déplacement entre disque et S3, dans les deux sens.
|
||||||
|
uput(t, alice, "commun/b.txt", "BB")
|
||||||
|
if err := alice.EditTags([]string{"commun/b.txt"}, []string{"rouge"}, nil); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if _, err := alice.Copy("commun", ".s3/copie"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if got := uread(t, alice, ".s3/copie/b.txt"); got != "BB" {
|
||||||
|
t.Errorf("copie vers S3 : %q", got)
|
||||||
|
}
|
||||||
|
if _, err := alice.Move("commun/b.txt", ".s3/b.txt"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if _, err := alice.Stat("commun/b.txt"); !errors.Is(err, ErrNotFound) {
|
||||||
|
t.Errorf("original toujours présent : %v", err)
|
||||||
|
}
|
||||||
|
st, err := alice.Stat(".s3/b.txt")
|
||||||
|
if err != nil || len(st.Tags) != 1 || st.Tags[0] != "rouge" {
|
||||||
|
t.Errorf("tags non repris : %+v %v", st, err)
|
||||||
|
}
|
||||||
|
if _, err := alice.Move(".s3/docs", ".perso/docs"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if got := uread(t, alice, ".perso/docs/a.txt"); got != "AAA" {
|
||||||
|
t.Errorf("S3 → perso : %q", got)
|
||||||
|
}
|
||||||
|
if _, err := alice.Stat(".s3/docs"); !errors.Is(err, ErrNotFound) {
|
||||||
|
t.Errorf("dossier S3 toujours présent : %v", err)
|
||||||
|
}
|
||||||
|
if res, err := alice.MoveMany([]string{".perso/docs/a.txt"}, ".s3/copie"); err != nil || res[0].Error != "" {
|
||||||
|
t.Errorf("MoveMany vers S3 : %v %+v", err, res)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pas de favoris sur S3.
|
||||||
|
if err := alice.SetFavorite([]string{".s3/b.txt"}, true); !errors.Is(err, ErrInvalidPath) {
|
||||||
|
t.Errorf("favori S3 accepté : %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Poubelle : s-<id>, restauration.
|
||||||
|
if err := alice.Delete(".s3/b.txt", false); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
tr, _ := alice.Trash()
|
||||||
|
var item string
|
||||||
|
for _, e := range tr {
|
||||||
|
if strings.HasPrefix(e.Path, TrashPrefix+"/s-") {
|
||||||
|
item = e.Path
|
||||||
|
if e.Origin != ".s3/b.txt" {
|
||||||
|
t.Errorf("origine %q", e.Origin)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if item == "" {
|
||||||
|
t.Fatalf("élément S3 absent de la poubelle : %v", tr)
|
||||||
|
}
|
||||||
|
if r := alice.RestoreTrash([]string{item}); r[0].Error != "" || r[0].To != ".s3/b.txt" {
|
||||||
|
t.Errorf("restauration : %+v", r)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Partage d'un fichier S3, résolu par Spaces.
|
||||||
|
sh, err := alice.CreateShare(".s3/b.txt", ShareOptions{})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if sh.Path != ".s3/b.txt" {
|
||||||
|
t.Errorf("chemin du partage %q", sh.Path)
|
||||||
|
}
|
||||||
|
if _, store, err := sp.ResolveShare(sh.Token); err != nil || store != s3 {
|
||||||
|
t.Errorf("ResolveShare : %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Lecture seule : mêmes règles que l'arborescence commune.
|
||||||
|
if _, err := sp.Main.WriteCommonReadonly(true); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if _, err := alice.Put(".s3/x.txt", strings.NewReader("x"), 1, PutOptions{}); !errors.Is(err, ErrForbidden) {
|
||||||
|
t.Errorf("écriture S3 en lecture seule : %v", err)
|
||||||
|
}
|
||||||
|
uput(t, admin, ".s3/x.txt", "x")
|
||||||
|
|
||||||
|
// Racine S3 absente : .s3 introuvable.
|
||||||
|
sp.SetS3(nil)
|
||||||
|
alice = space(t, sp, "alice", false)
|
||||||
|
if _, err := alice.List(".s3"); !errors.Is(err, ErrNotFound) {
|
||||||
|
t.Errorf("sans S3 : %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user