787de74b3d
ci/woodpecker/tag/docker Pipeline was successful
## Why
Local repos store uploaded files in the \`local_files\` table, whereas remote/proxy repos cache into the \`artifacts\` table. The shared **Cached Objects** page always queried the artifacts table via \`/api/v2/remotes/{name}/objects\`, so files uploaded to a local repo (e.g. an internal RPM) were fully stored and servable but showed as **0 objects** in the UI.
## Changes
- Add \`ListLocalArtifacts\`, joining \`local_files\` with \`blobs\` and returning \`models.Artifact\`-shaped rows (size from the blob; access/fetch counters zero and timestamps derived from \`created_at\`, since local files track no access).
- Add \`LocalRoutes\` to the objects handler: \`listLocal\` reads \`local_files\`, \`evictLocal\` deletes via \`DeleteLocalFile\`. Extract shared page/per_page parsing into \`pageBounds\`.
- Mount \`/api/v2/locals/{name}/objects\` (GET + DELETE) in the server.
- Add \`listLocalObjects\`/\`evictLocalObject\` to the UI client and route the Objects page to them when viewing a local repo.
- Cover the listing and eviction paths with a dockerised test.
## Notes
Generated \`repodata/*\` files are not listed — they are produced on the fly from \`rpm_metadata\` and never stored in \`local_files\`, which matches how the repo serves them.
Reviewed-on: #99
Co-authored-by: Ben Vincent <ben@unkin.net>
Co-committed-by: Ben Vincent <ben@unkin.net>
52 lines
2.1 KiB
TypeScript
52 lines
2.1 KiB
TypeScript
import type { Remote, Virtual, Artifact, OverviewStats, RemoteStatRow, FileStatRow, BandwidthStatRow, HealthStatus, ProbeResult } from './types';
|
|
|
|
const BASE = '';
|
|
|
|
async function fetchJSON<T>(path: string, init?: RequestInit): Promise<T> {
|
|
const resp = await fetch(`${BASE}${path}`, {
|
|
...init,
|
|
headers: { 'Content-Type': 'application/json', ...init?.headers },
|
|
});
|
|
if (!resp.ok) {
|
|
const text = await resp.text();
|
|
throw new Error(`${resp.status}: ${text}`);
|
|
}
|
|
if (resp.status === 204) return undefined as T;
|
|
return resp.json();
|
|
}
|
|
|
|
export const api = {
|
|
health: () => fetchJSON<HealthStatus>('/api/v2/health'),
|
|
stats: () => fetchJSON<OverviewStats>('/api/v2/stats'),
|
|
topRemotes: () => fetchJSON<RemoteStatRow[]>('/api/v2/stats/top-remotes'),
|
|
topFilesByHits: () => fetchJSON<FileStatRow[]>('/api/v2/stats/top-files-by-hits'),
|
|
topFilesByBandwidth: () => fetchJSON<BandwidthStatRow[]>('/api/v2/stats/top-files-by-bandwidth'),
|
|
|
|
listRemotes: () => fetchJSON<Remote[]>('/api/v2/remotes'),
|
|
getRemote: (name: string) => fetchJSON<Remote>(`/api/v2/remotes/${name}`),
|
|
|
|
listVirtuals: () => fetchJSON<Virtual[]>('/api/v2/virtuals'),
|
|
getVirtual: (name: string) => fetchJSON<Virtual>(`/api/v2/virtuals/${name}`),
|
|
|
|
listObjects: (remote: string, page = 1, perPage = 50) =>
|
|
fetchJSON<Artifact[]>(`/api/v2/remotes/${remote}/objects?page=${page}&per_page=${perPage}`),
|
|
|
|
evictObject: (remote: string, path: string) =>
|
|
fetchJSON<void>(`/api/v2/remotes/${remote}/objects/${path}`, { method: 'DELETE' }),
|
|
|
|
listLocalObjects: (name: string, page = 1, perPage = 50) =>
|
|
fetchJSON<Artifact[]>(`/api/v2/locals/${name}/objects?page=${page}&per_page=${perPage}`),
|
|
|
|
evictLocalObject: (name: string, path: string) =>
|
|
fetchJSON<void>(`/api/v2/locals/${name}/objects/${path}`, { method: 'DELETE' }),
|
|
|
|
flushRemoteCache: (remote: string) =>
|
|
fetchJSON<void>(`/api/v2/remotes/${remote}/cache`, { method: 'DELETE' }),
|
|
|
|
probe: (remote: string, path: string) =>
|
|
fetchJSON<ProbeResult>('/api/v2/probe', {
|
|
method: 'POST',
|
|
body: JSON.stringify({ remote, path }),
|
|
}),
|
|
};
|