proper src structure, dockerfile, entrypoint

This commit is contained in:
jarek committed 2025-12-29 08:40:11 +01:00
1 parent e5828c7d31
commit 73c9f580a1
556 files changed
+1390

No files matched your search

@@ -0,0 +1,112 @@
import { json } from '@sveltejs/kit';
import type { RequestHandler } from './$types';
import {
getGitRepository,
updateGitRepository,
deleteGitRepository,
getGitCredentials
} from '$lib/server/db';
import { deleteRepositoryFiles } from '$lib/server/git';
import { authorize } from '$lib/server/authorize';
export const GET: RequestHandler = async ({ params, cookies }) => {
const auth = await authorize(cookies);
if (auth.authEnabled && !await auth.can('git', 'view')) {
return json({ error: 'Permission denied' }, { status: 403 });
}
try {
const id = parseInt(params.id);
if (isNaN(id)) {
return json({ error: 'Invalid repository ID' }, { status: 400 });
}
const repository = await getGitRepository(id);
if (!repository) {
return json({ error: 'Repository not found' }, { status: 404 });
}
return json(repository);
} catch (error) {
console.error('Failed to get git repository:', error);
return json({ error: 'Failed to get git repository' }, { status: 500 });
}
};
export const PUT: RequestHandler = async ({ params, request, cookies }) => {
const auth = await authorize(cookies);
if (auth.authEnabled && !await auth.can('git', 'edit')) {
return json({ error: 'Permission denied' }, { status: 403 });
}
try {
const id = parseInt(params.id);
if (isNaN(id)) {
return json({ error: 'Invalid repository ID' }, { status: 400 });
}
const existing = await getGitRepository(id);
if (!existing) {
return json({ error: 'Repository not found' }, { status: 404 });
}
const data = await request.json();
// Validate credential if provided
if (data.credentialId) {
const credentials = await getGitCredentials();
const credential = credentials.find(c => c.id === data.credentialId);
if (!credential) {
return json({ error: 'Invalid credential ID' }, { status: 400 });
}
}
// Update only the basic repository fields
// Deployment-specific config (composePath, autoUpdate, webhook) now belongs to git_stacks
const repository = await updateGitRepository(id, {
name: data.name,
url: data.url,
branch: data.branch,
credentialId: data.credentialId
});
if (!repository) {
return json({ error: 'Failed to update repository' }, { status: 500 });
}
return json(repository);
} catch (error: any) {
console.error('Failed to update git repository:', error);
if (error.message?.includes('UNIQUE constraint failed')) {
return json({ error: 'A repository with this name already exists' }, { status: 400 });
}
return json({ error: 'Failed to update git repository' }, { status: 500 });
}
};
export const DELETE: RequestHandler = async ({ params, cookies }) => {
const auth = await authorize(cookies);
if (auth.authEnabled && !await auth.can('git', 'delete')) {
return json({ error: 'Permission denied' }, { status: 403 });
}
try {
const id = parseInt(params.id);
if (isNaN(id)) {
return json({ error: 'Invalid repository ID' }, { status: 400 });
}
// Delete repository files first
deleteRepositoryFiles(id);
const deleted = await deleteGitRepository(id);
if (!deleted) {
return json({ error: 'Repository not found' }, { status: 404 });
}
return json({ success: true });
} catch (error) {
console.error('Failed to delete git repository:', error);
return json({ error: 'Failed to delete git repository' }, { status: 500 });
}
};