This commit is contained in:
jarek committed 2026-01-17 15:06:14 +01:00
1 parent 62636426bf
commit c185d00dc3
60 files changed
+2830 -918

No files matched your search

+32 -12
View File
@@ -1,10 +1,14 @@
import { json } from '@sveltejs/kit';
import type { RequestHandler } from './$types';
import { getRegistry } from '$lib/server/db';
import { getRegistryAuth } from '$lib/server/docker';
const PAGE_SIZE = 100;
export const GET: RequestHandler = async ({ url }) => {
try {
const registryId = url.searchParams.get('registry');
const lastParam = url.searchParams.get('last'); // For pagination
if (!registryId) {
return json({ error: 'Registry ID is required' }, { status: 400 });
@@ -20,22 +24,20 @@ export const GET: RequestHandler = async ({ url }) => {
return json({ error: 'Docker Hub does not support catalog listing. Please use search instead.' }, { status: 400 });
}
// Build the catalog URL
let catalogUrl = registry.url;
if (!catalogUrl.endsWith('/')) {
catalogUrl += '/';
const { baseUrl, authHeader } = await getRegistryAuth(registry, 'registry:catalog:*');
// Build catalog URL with pagination
let catalogUrl = `${baseUrl}/v2/_catalog?n=${PAGE_SIZE}`;
if (lastParam) {
catalogUrl += `&last=${encodeURIComponent(lastParam)}`;
}
catalogUrl += 'v2/_catalog';
// Prepare headers
const headers: HeadersInit = {
'Accept': 'application/json'
};
// Add auth if credentials are present
if (registry.username && registry.password) {
const credentials = Buffer.from(`${registry.username}:${registry.password}`).toString('base64');
headers['Authorization'] = `Basic ${credentials}`;
if (authHeader) {
headers['Authorization'] = authHeader;
}
const response = await fetch(catalogUrl, {
@@ -56,7 +58,18 @@ export const GET: RequestHandler = async ({ url }) => {
const data = await response.json();
// The V2 API returns { repositories: [...] }
const repositories = data.repositories || [];
const repositories: string[] = data.repositories || [];
// Parse Link header for pagination
// Format: </v2/_catalog?last=xxx&n=100>; rel="next"
let nextLast: string | null = null;
const linkHeader = response.headers.get('Link');
if (linkHeader) {
const nextMatch = linkHeader.match(/<[^>]*[?&]last=([^&>]+)[^>]*>;\s*rel="next"/);
if (nextMatch) {
nextLast = decodeURIComponent(nextMatch[1]);
}
}
// For each repository, we could fetch tags, but that's expensive
// Just return the repository names for now
@@ -68,7 +81,14 @@ export const GET: RequestHandler = async ({ url }) => {
is_automated: false
}));
return json(results);
return json({
repositories: results,
pagination: {
pageSize: PAGE_SIZE,
hasMore: !!nextLast,
nextLast: nextLast
}
});
} catch (error: any) {
console.error('Error fetching registry catalog:', error);