Fix page bucket: GetBucketInfo de Garage 2.x n'a pas localAliases, reponse normalisee (getBucket)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
cedricandClaude Sonnet 5.5 committed 2026-11-21 12:49:28 +01:00
1 parent f01dad73ef
commit 8de5262c12
5 files changed
+38 -12

No files matched your search

+1 -1
View File
@@ -94,7 +94,7 @@ func (b *bucket) info() map[string]any {
wc = map[string]any{"indexDocument": b.Index, "errorDocument": b.ErrDoc}
}
return map[string]any{
"id": b.ID, "created": b.Created, "globalAliases": b.Aliases, "localAliases": []any{}, "websiteAccess": b.Site, "websiteConfig": wc,
"id": b.ID, "created": b.Created, "globalAliases": b.Aliases, "websiteAccess": b.Site, "websiteConfig": wc,
"keys": ks, "objects": b.Objects, "bytes": b.Bytes, "unfinishedUploads": 0, "unfinishedMultipartUploads": 2,
"unfinishedMultipartUploadParts": 5, "unfinishedMultipartUploadBytes": 30 << 20,
"quotas": map[string]any{"maxSize": b.MaxSize, "maxObjects": b.MaxObjs},
+4 -4
View File
@@ -1,5 +1,5 @@
import { useState } from "react";
import { garage, bucketName, type BucketInfo, type BucketListItem, type KeyListItem, type Perm } from "./api";
import { garage, getBucket, bucketName, type BucketInfo, type BucketListItem, type KeyListItem, type Perm } from "./api";
import { GIB, fmtDate, fmtNum, fmtSize } from "./format";
import { BucketIcon, GlobeIcon } from "./gicons";
import { CloseIcon, PlusIcon, RefreshIcon, TrashIcon } from "./icons";
@@ -13,7 +13,7 @@ export function Buckets() {
const [creating, setCreating] = useState(false);
const { data, error, loading, reload } = useLoad(async () => {
const list = await garage.get<BucketListItem[]>("ListBuckets");
const infos = await Promise.all(list.map((b) => garage.get<BucketInfo>("GetBucketInfo", { id: b.id }).catch(() => null)));
const infos = await Promise.all(list.map((b) => getBucket(b.id).catch(() => null)));
return list.map((b, i) => ({ b, info: infos[i] }));
});
const rows = (data ?? []).filter(({ b }) => bucketName(b).toLowerCase().includes(filter.toLowerCase()));
@@ -55,7 +55,7 @@ export function Buckets() {
<GlobeIcon size={12} /> web
</span>
)}
{b.globalAliases.length > 1 && <span className="pill">+{b.globalAliases.length - 1} alias</span>}
{b.globalAliases?.length > 1 && <span className="pill">+{b.globalAliases.length - 1} alias</span>}
</td>
<td className="num">{fmtNum(info?.objects)}</td>
<td className="num">{fmtSize(info?.bytes)}</td>
@@ -135,7 +135,7 @@ function CreateBucket({ onClose, onCreate }: { onClose: () => void; onCreate: (a
export function BucketPage({ id }: { id: string }) {
const act = useAct();
const { data: b, error, loading, reload } = useLoad(() => garage.get<BucketInfo>("GetBucketInfo", { id }), [id]);
const { data: b, error, loading, reload } = useLoad(() => getBucket(id), [id]);
const keys = useLoad(() => garage.get<KeyListItem[]>("ListKeys"), []);
const [confirmDelete, setConfirmDelete] = useState(false);
const [alias, setAlias] = useState("");
+3 -3
View File
@@ -298,10 +298,10 @@ export function KeyPage({ id, cfg }: { id: string; cfg: Config }) {
</tr>
</thead>
<tbody>
{k.buckets.map((b) => (
{(k.buckets ?? []).map((b) => (
<tr key={b.id}>
<td>
<a href={`#/buckets/${b.id}`}>{b.globalAliases[0] ?? b.localAliases[0] ?? b.id.slice(0, 12)}</a>
<a href={`#/buckets/${b.id}`}>{b.globalAliases?.[0] ?? b.localAliases?.[0] ?? b.id.slice(0, 12)}</a>
</td>
{(["read", "write", "owner"] as const).map((p) => (
<td className="c" key={p}>
@@ -317,7 +317,7 @@ export function KeyPage({ id, cfg }: { id: string; cfg: Config }) {
))}
</tr>
))}
{k.buckets.length === 0 && (
{(k.buckets ?? []).length === 0 && (
<tr>
<td colSpan={4} className="muted center">
Cette clé n'a accès à aucun bucket.
+2 -2
View File
@@ -1,4 +1,4 @@
import { garage, bucketName, type BucketInfo, type BucketListItem, type ClusterHealth, type ClusterStatus, type KeyListItem } from "./api";
import { garage, getBucket, bucketName, type BucketInfo, type BucketListItem, type ClusterHealth, type ClusterStatus, type KeyListItem } from "./api";
import { fmtNum, fmtSize } from "./format";
import { Loading, PageHead, Status, UsageBar, useLoad } from "./ui";
import { RefreshIcon } from "./icons";
@@ -18,7 +18,7 @@ export function Overview() {
garage.get<KeyListItem[]>("ListKeys"),
garage.get<{ freeform?: string }>("GetClusterStatistics").catch(() => ({ freeform: "" })),
]);
const infos = await Promise.all(buckets.map((b) => garage.get<BucketInfo>("GetBucketInfo", { id: b.id }).catch(() => null)));
const infos = await Promise.all(buckets.map((b) => getBucket(b.id).catch(() => null)));
return { health, status, buckets, keys, stats, infos: infos.filter((x): x is BucketInfo => !!x) };
});
+28 -2
View File
@@ -173,7 +173,33 @@ export const appApi = {
cli: (args: string[]) => req<{ exitCode: number; output: string; ms: number }>("/api/cli", { method: "POST", body: JSON.stringify({ args }) }),
};
export const bucketName = (b: { id: string; globalAliases: string[]; localAliases: { alias: string }[] }) =>
b.globalAliases[0] ?? b.localAliases[0]?.alias ?? b.id.slice(0, 12);
export const bucketName = (b: { id: string; globalAliases?: string[]; localAliases?: { alias: string }[] }) =>
b.globalAliases?.[0] ?? b.localAliases?.[0]?.alias ?? b.id.slice(0, 12);
/**
* GetBucketInfo, normalisé : Garage 2.x ne renvoie pas `localAliases` au niveau du bucket (ils sont
* dans `keys[].bucketLocalAliases`) et peut omettre d'autres champs ; l'interface n'a ainsi jamais
* à tester leur présence.
*/
export async function getBucket(id: string): Promise<BucketInfo> {
const b = await garage.get<Partial<BucketInfo>>("GetBucketInfo", { id });
const keys = b.keys ?? [];
return {
id: b.id ?? id,
created: b.created ?? "",
globalAliases: b.globalAliases ?? [],
localAliases: b.localAliases ?? keys.flatMap((k) => (k.bucketLocalAliases ?? []).map((alias) => ({ accessKeyId: k.accessKeyId, alias }))),
websiteAccess: !!b.websiteAccess,
websiteConfig: b.websiteConfig ?? null,
keys,
objects: b.objects ?? 0,
bytes: b.bytes ?? 0,
unfinishedUploads: b.unfinishedUploads ?? 0,
unfinishedMultipartUploads: b.unfinishedMultipartUploads ?? 0,
unfinishedMultipartUploadParts: b.unfinishedMultipartUploadParts ?? 0,
unfinishedMultipartUploadBytes: b.unfinishedMultipartUploadBytes ?? 0,
quotas: b.quotas ?? {},
};
}
export const errMsg = (e: unknown) => (e instanceof Error ? e.message : String(e));