fix(storage): let the app boot with the reclaim routes and keep the ratchets where they were

The two admin routes go on the managed allow list, without which buildApp
refused to start. The reclaim calls move to their own api module so
client.ts stays at its size, the phone card sizes its text through the
type tiers, and the tests drop a hand-built service, a non-null assertion
and a promise read as a boolean.
This commit is contained in:
Maurice
2026-11-01 14:44:53 +01:00
parent a1d9cdc8f2
commit 382797febc
9 changed files with 58 additions and 29 deletions
-8
View File
@@ -56,8 +56,6 @@ import {
type BookingImportMode,
type ReceiptScanResult,
type StorageAdminState,
type StorageReclaimReport,
type StorageReclaimState,
type StorageBackend,
type StorageConfigPut,
type StorageTestResponse,
@@ -736,12 +734,6 @@ export const adminApi = {
// A full scan of a large install can exceed the 8s instance timeout.
refreshStorageStats: (): Promise<StorageUsage> =>
apiClient.post('/admin/storage/stats/refresh', undefined, { timeout: 120_000 }).then(r => r.data),
setStorageReclaimDelete: (deleteEnabled: boolean): Promise<StorageReclaimState> =>
apiClient.put('/admin/storage/reclaim', { deleteEnabled }).then(r => r.data),
// A check lists every reclaimable category and asks each domain about it; a
// large bucket outlasts the 8s instance timeout. It only reports, whatever the switch says.
runStorageReclaimCheck: (): Promise<StorageReclaimReport> =>
apiClient.post('/admin/storage/reclaim/run', { reportOnly: true }, { timeout: 300_000 }).then(r => r.data),
}
export const addonsApi = {
+12
View File
@@ -0,0 +1,12 @@
import type { StorageReclaimReport, StorageReclaimState } from '@trek/shared';
import { apiClient } from './client';
/** Admin > Storage, unreferenced files: the nightly deletion switch and a check on demand. */
export const storageReclaimApi = {
setDelete: (deleteEnabled: boolean): Promise<StorageReclaimState> =>
apiClient.put('/admin/storage/reclaim', { deleteEnabled }).then((r) => r.data),
// A check lists every reclaimable category and asks each domain about it; a
// large bucket outlasts the 8s instance timeout. It only reports, whatever the switch says.
check: (): Promise<StorageReclaimReport> =>
apiClient.post('/admin/storage/reclaim/run', { reportOnly: true }, { timeout: 300_000 }).then((r) => r.data),
};
@@ -1,6 +1,7 @@
import { useCallback, useEffect, useRef, useState } from 'react'
import type { StorageAdminState, StorageBackend, StorageConfig, StorageConfigPut, StorageTestResponse } from '@trek/shared'
import { adminApi } from '../../../api/client'
import { storageReclaimApi } from '../../../api/storageReclaim'
import { getApiErrorMessage, type ApiError } from '../../../types'
import { settingsDocumentOf } from './storageModel'
@@ -371,7 +372,7 @@ export function useStorageAdmin(genericError: string, conflictError: string): St
const setReclaimDelete = useCallback(async (enabled: boolean): Promise<string | null> => {
try {
setReclaim(await adminApi.setStorageReclaimDelete(enabled))
setReclaim(await storageReclaimApi.setDelete(enabled))
return null
} catch (err: unknown) {
return getApiErrorMessage(err, genericError)
@@ -380,7 +381,7 @@ export function useStorageAdmin(genericError: string, conflictError: string): St
const checkReclaim = useCallback(async (): Promise<string | null> => {
try {
const lastRun = await adminApi.runStorageReclaimCheck()
const lastRun = await storageReclaimApi.check()
setReclaim({ deleteEnabled: stateRef.current?.reclaim?.deleteEnabled ?? false, lastRun })
return null
} catch (err: unknown) {
@@ -1,5 +1,6 @@
import React from 'react';
import type { ReclaimCount, ReclaimView } from '../../../components/Admin/storage/reclaimModel';
import { fs } from '../../../components/shared/DialogShell';
import { useTranslation } from '../../../i18n';
import { formatBytes } from '../../../utils/formatBytes';
import { relativeTime } from '../../../utils/relativeTime';
@@ -39,13 +40,13 @@ export default function MStorageReclaimCard({ reclaim, checking, onCheck, onDele
}
/>
<div className="border-t border-[color:var(--m-rowbr)] pt-[11px]" data-testid="m-storage-reclaim-summary">
<p className="font-geist text-[0.625rem] text-m-muted">
<p className="font-geist text-m-muted" style={fs(10)}>
{reclaim.checkedAt !== null
? t('storage.reclaim.checked', { age: relativeTime(reclaim.checkedAt, locale) })
: t('storage.reclaim.never')}
</p>
{reclaim.stopped && (
<p role="note" className="mt-1 font-geist text-[0.625rem] text-m-muted">
<p role="note" className="mt-1 font-geist text-m-muted" style={fs(10)}>
{t('storage.reclaim.stopped')}
</p>
)}
@@ -57,24 +58,30 @@ export default function MStorageReclaimCard({ reclaim, checking, onCheck, onDele
</div>
)}
{checked && reclaim.lines.length === 0 && (
<p className="mt-2 font-geist text-[0.625rem] text-m-muted">{t('storage.reclaim.nothing')}</p>
<p className="mt-2 font-geist text-m-muted" style={fs(10)}>
{t('storage.reclaim.nothing')}
</p>
)}
{reclaim.lines.length > 0 && (
<div className="mt-2 space-y-1.5">
{reclaim.lines.map((line) => (
<div key={line.category} data-testid={`m-storage-reclaim-${line.category}`}>
<p className="text-[0.75rem] font-bold text-m-ink">{t(`storage.category.${line.category}`)}</p>
<p className="font-bold text-m-ink" style={fs(12, 'body')}>
{t(`storage.category.${line.category}`)}
</p>
{line.skipped ? (
<p className="font-geist text-[0.625rem] text-m-muted">{t(`storage.reclaim.skip.${line.skipped}`)}</p>
<p className="font-geist text-m-muted" style={fs(10)}>
{t(`storage.reclaim.skip.${line.skipped}`)}
</p>
) : (
<>
{line.freeable.objects > 0 && (
<p className="font-geist text-[0.625rem] text-m-muted">
<p className="font-geist text-m-muted" style={fs(10)}>
{t('storage.reclaim.freeable')}: {count(line.freeable)}
</p>
)}
{line.waiting.objects > 0 && (
<p className="font-geist text-[0.625rem] text-m-muted">
<p className="font-geist text-m-muted" style={fs(10)}>
{t('storage.reclaim.waiting')}: {count(line.waiting)}
</p>
)}
@@ -92,8 +99,12 @@ export default function MStorageReclaimCard({ reclaim, checking, onCheck, onDele
function Figure({ label, value }: { label: string; value: string }): React.ReactElement {
return (
<div className="flex items-baseline justify-between gap-3">
<span className="font-geist text-[0.6875rem] text-m-muted">{label}</span>
<span className="font-geist text-[0.6875rem] font-bold tabular-nums text-m-ink">{value}</span>
<span className="font-geist text-m-muted" style={fs(11)}>
{label}
</span>
<span className="font-geist font-bold tabular-nums text-m-ink" style={fs(11)}>
{value}
</span>
</div>
);
}