mirror of
https://github.com/khoaliber/dockhand.git
synced 2026-03-05 13:20:57 +00:00
46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
import { json } from '@sveltejs/kit';
|
|
import type { RequestHandler } from './$types';
|
|
import { getGitRepository } from '$lib/server/db';
|
|
import { syncRepository, checkForUpdates } from '$lib/server/git';
|
|
|
|
export const POST: RequestHandler = async ({ params }) => {
|
|
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 });
|
|
}
|
|
|
|
const result = await syncRepository(id);
|
|
return json(result);
|
|
} catch (error: any) {
|
|
console.error('Failed to sync git repository:', error);
|
|
return json({ success: false, error: error.message }, { status: 500 });
|
|
}
|
|
};
|
|
|
|
export const GET: RequestHandler = async ({ params }) => {
|
|
// Check for updates without syncing
|
|
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 });
|
|
}
|
|
|
|
const result = await checkForUpdates(id);
|
|
return json(result);
|
|
} catch (error: any) {
|
|
console.error('Failed to check for updates:', error);
|
|
return json({ hasUpdates: false, error: error.message }, { status: 500 });
|
|
}
|
|
};
|