Buckets : bouton Vider (objets et envois multipart inachevés)
L'API d'administration ne sait pas supprimer d'objets : le serveur passe par l'API S3 avec une clé temporaire (CreateKey + AllowBucketKey), supprime les objets par lots de 1000 (ListObjectsV2 + DeleteObjects, signature v4 en bibliothèque standard), nettoie les envois inachevés (CleanupIncompleteUploads, olderThanSecs 0) puis supprime la clé. Avancement diffusé en NDJSON (POST /api/buckets/empty?id=...). Confirmation par saisie du nom, interruption et reprise possibles. Nouvelle variable GARAGE_S3_API_URL (défaut : hôte admin, port 3900). Mock : API S3 minimale sur :3900. Tests : signature (exemple AWS) et vidage complet simulé. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LNfwm2bSk3o3YKYUP5P691
This commit is contained in:
1 parent
ea2058b6c1
commit
e21ef321f9
7 files changed
+278
-8
No files matched your search
@@ -173,6 +173,54 @@ export const appApi = {
|
||||
cli: (args: string[]) => req<{ exitCode: number; output: string; ms: number }>("/api/cli", { method: "POST", body: JSON.stringify({ args }) }),
|
||||
};
|
||||
|
||||
/** Avancement du vidage d'un bucket (une ligne NDJSON par lot de 1000 objets). */
|
||||
export interface EmptyProgress {
|
||||
phase: "start" | "objects" | "uploads" | "done" | "error";
|
||||
deleted: number;
|
||||
failed: number;
|
||||
uploadsDeleted?: number;
|
||||
errors?: string[];
|
||||
message?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Vide un bucket (objets puis envois multipart inachevés). Le serveur passe par l'API S3 avec une
|
||||
* clé temporaire, et diffuse l'avancement : onProgress est appelé à chaque lot.
|
||||
*/
|
||||
export async function emptyBucket(id: string, onProgress: (p: EmptyProgress) => void, signal?: AbortSignal): Promise<EmptyProgress> {
|
||||
const r = await fetch(`/api/buckets/empty${qs({ id })}`, { method: "POST", credentials: "same-origin", headers: { "X-Requested-With": "garage-ui" }, signal });
|
||||
if (!r.ok || !r.body) {
|
||||
let msg = r.statusText;
|
||||
try {
|
||||
msg = (await r.json()).message || msg;
|
||||
} catch {
|
||||
/* réponse non JSON */
|
||||
}
|
||||
throw new ApiError(r.status, msg);
|
||||
}
|
||||
const reader = r.body.getReader();
|
||||
const dec = new TextDecoder();
|
||||
let buf = "";
|
||||
let last: EmptyProgress | null = null;
|
||||
for (;;) {
|
||||
const { value, done } = await reader.read();
|
||||
if (value) buf += dec.decode(value, { stream: true });
|
||||
let nl;
|
||||
while ((nl = buf.indexOf("\n")) >= 0) {
|
||||
const line = buf.slice(0, nl).trim();
|
||||
buf = buf.slice(nl + 1);
|
||||
if (!line) continue;
|
||||
last = JSON.parse(line) as EmptyProgress;
|
||||
onProgress(last);
|
||||
}
|
||||
if (done) break;
|
||||
}
|
||||
if (!last) throw new ApiError(502, "Réponse vide du serveur");
|
||||
if (last.phase === "error") throw new ApiError(502, last.message || "Échec du vidage");
|
||||
if (last.phase !== "done") throw new ApiError(502, `Vidage interrompu après ${last.deleted} objets supprimés`);
|
||||
return last;
|
||||
}
|
||||
|
||||
export const bucketName = (b: { id: string; globalAliases?: string[]; localAliases?: { alias: string }[] }) =>
|
||||
b.globalAliases?.[0] ?? b.localAliases?.[0]?.alias ?? b.id.slice(0, 12);
|
||||
|
||||
|
||||
Reference in new issue
Block a user