30 lines
1 KiB
TypeScript
30 lines
1 KiB
TypeScript
import { error, type ServerLoad } from '@sveltejs/kit';
|
|
import { getJobApiJobsJobIdGet, getArticleBffArticlesArticleIdGet } from '../../../../client/sdk.gen.ts';
|
|
import { PUBLIC_API_BASE_URL } from '$env/static/public';
|
|
|
|
export const load: ServerLoad = async ({ params, locals }) => {
|
|
const { data, response } = await getJobApiJobsJobIdGet({
|
|
headers: { Authorization: `Bearer ${locals.authToken ?? ''}` },
|
|
path: { job_id: params.job_id as string }
|
|
});
|
|
|
|
let translatedArticle = null;
|
|
|
|
if (!data || response.status !== 200) {
|
|
error(response.status === 404 ? 404 : 500, 'Job not found');
|
|
}
|
|
|
|
if (data.translated_article_id) {
|
|
const articleResponse = await getArticleBffArticlesArticleIdGet({
|
|
headers: { Authorization: `Bearer ${locals.authToken ?? ''}` },
|
|
path: { article_id: data.translated_article_id as string }
|
|
});
|
|
|
|
if (articleResponse.data) {
|
|
translatedArticle = articleResponse.data;
|
|
}
|
|
}
|
|
|
|
const fullAudioUrl = `${PUBLIC_API_BASE_URL}/media/${data.audio_url}`;
|
|
return { job: data, fullAudioUrl, translatedArticle };
|
|
};
|