mirror of
https://github.com/khoaliber/dockhand.git
synced 2026-03-02 21:19:05 +00:00
40 lines
1.3 KiB
TypeScript
40 lines
1.3 KiB
TypeScript
import { json } from '@sveltejs/kit';
|
|
import { listImages, EnvironmentNotFoundError } from '$lib/server/docker';
|
|
import { authorize } from '$lib/server/authorize';
|
|
import { hasEnvironments } from '$lib/server/db';
|
|
import type { RequestHandler } from './$types';
|
|
|
|
export const GET: RequestHandler = async ({ url, cookies }) => {
|
|
const auth = await authorize(cookies);
|
|
|
|
const envId = url.searchParams.get('env');
|
|
const envIdNum = envId ? parseInt(envId) : undefined;
|
|
|
|
// Permission check with environment context
|
|
if (auth.authEnabled && !await auth.can('images', 'view', envIdNum)) {
|
|
return json({ error: 'Permission denied' }, { status: 403 });
|
|
}
|
|
|
|
// Environment access check (enterprise only)
|
|
if (envIdNum && auth.isEnterprise && !await auth.canAccessEnvironment(envIdNum)) {
|
|
return json({ error: 'Access denied to this environment' }, { status: 403 });
|
|
}
|
|
|
|
// Early return if no environment specified
|
|
if (!envIdNum) {
|
|
return json([]);
|
|
}
|
|
|
|
try {
|
|
const images = await listImages(envIdNum);
|
|
return json(images);
|
|
} catch (error) {
|
|
if (error instanceof EnvironmentNotFoundError) {
|
|
return json({ error: 'Environment not found' }, { status: 404 });
|
|
}
|
|
console.error('Error listing images:', error);
|
|
// Return empty array instead of error to allow UI to load
|
|
return json([]);
|
|
}
|
|
};
|