- Wire local embedding provider as the default on startup when no profile is configured - Refactor embedding settings into dedicated service, DTOs, mappers and models - Rebuild settings page with profile management UI and live test feedback - Expose index summary (indexed versions + embedding count) on repo endpoints - Harden indexing pipeline and context search with additional test coverage Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
70 lines
2.0 KiB
TypeScript
70 lines
2.0 KiB
TypeScript
/**
|
|
* GET /api/v1/libs/:id — get a single repository
|
|
* PATCH /api/v1/libs/:id — update repository metadata
|
|
* DELETE /api/v1/libs/:id — delete a repository
|
|
*/
|
|
import { json } from '@sveltejs/kit';
|
|
import type { RequestHandler } from './$types';
|
|
import { getClient } from '$lib/server/db/client';
|
|
import { RepositoryMapper } from '$lib/server/mappers/repository.mapper.js';
|
|
import { RepositoryService } from '$lib/server/services/repository.service';
|
|
import { handleServiceError } from '$lib/server/utils/validation';
|
|
|
|
function getService() {
|
|
return new RepositoryService(getClient());
|
|
}
|
|
|
|
export const GET: RequestHandler = ({ params }) => {
|
|
try {
|
|
const service = getService();
|
|
const id = decodeURIComponent(params.id);
|
|
const repo = service.get(id);
|
|
if (!repo) {
|
|
return json({ error: 'Repository not found', code: 'NOT_FOUND' }, { status: 404 });
|
|
}
|
|
const versions = service.getVersions(id);
|
|
return json({ ...RepositoryMapper.toDto(repo), versions, ...service.getIndexSummary(id) });
|
|
} catch (err) {
|
|
return handleServiceError(err);
|
|
}
|
|
};
|
|
|
|
export const PATCH: RequestHandler = async ({ params, request }) => {
|
|
try {
|
|
const service = getService();
|
|
const id = decodeURIComponent(params.id);
|
|
const body = await request.json();
|
|
const updated = service.update(id, {
|
|
title: body.title,
|
|
description: body.description,
|
|
branch: body.branch,
|
|
githubToken: body.githubToken
|
|
});
|
|
return json(RepositoryMapper.toDto(updated));
|
|
} catch (err) {
|
|
return handleServiceError(err);
|
|
}
|
|
};
|
|
|
|
export const DELETE: RequestHandler = ({ params }) => {
|
|
try {
|
|
const service = getService();
|
|
const id = decodeURIComponent(params.id);
|
|
service.remove(id);
|
|
return new Response(null, { status: 204 });
|
|
} catch (err) {
|
|
return handleServiceError(err);
|
|
}
|
|
};
|
|
|
|
export const OPTIONS: RequestHandler = () => {
|
|
return new Response(null, {
|
|
status: 204,
|
|
headers: {
|
|
'Access-Control-Allow-Origin': '*',
|
|
'Access-Control-Allow-Methods': 'GET, PATCH, DELETE, OPTIONS',
|
|
'Access-Control-Allow-Headers': 'Content-Type, Authorization'
|
|
}
|
|
});
|
|
};
|