23 lines
792 B
TypeScript

import SQL from 'sql-template-strings';
import { getLocale, loadConfig } from '~/server/data.ts';
import { linkOtherVersions } from '~/server/sources.ts';
export default defineEventHandler(async (event) => {
const locale = getLocale(event);
checkIsConfigEnabledOr404(await loadConfig(locale), 'sources');
const { isGranted } = await useAuthentication(event);
const id = getRouterParam(event, 'id');
const db = useDatabase();
return await linkOtherVersions(db, isGranted, locale, await db.all(SQL`
SELECT s.*, u.username AS submitter FROM sources s
LEFT JOIN users u ON s.submitter_id = u.id
WHERE s.locale = ${locale}
AND s.deleted = 0
AND s.approved >= ${isGranted('sources') ? 0 : 1}
AND s.id = ${id}
`));
});