fix: 404 rewrite status, 503 charset
This commit is contained in:
@@ -8,21 +8,21 @@ import { sanitizeHtml } from '../../../../lib/sanitize';
|
||||
const course = bySlug(Astro.params.slug ?? '');
|
||||
const mMatch = /^module-(\d+)$/.exec(Astro.params.module ?? '');
|
||||
const cMatch = /^chapitre-(\d+)$/.exec(Astro.params.chapitre ?? '');
|
||||
if (!course || !course.published || !mMatch || !cMatch) return Astro.redirect('/404');
|
||||
if (!course || !course.published || !mMatch || !cMatch) return Astro.rewrite('/404');
|
||||
|
||||
let modules;
|
||||
try { modules = await getCourseBooks(course.id); }
|
||||
catch { return new Response('Formation momentanément indisponible.', { status: 503 }); }
|
||||
catch { return new Response('Formation momentanément indisponible.', { status: 503, headers: { 'Content-Type': 'text/plain; charset=utf-8' } }); }
|
||||
|
||||
const mi = Number(mMatch[1]) - 1;
|
||||
const ci = Number(cMatch[1]) - 1;
|
||||
const mod = modules[mi];
|
||||
const chapter = mod?.chapters[ci];
|
||||
if (!mod || !chapter) return Astro.redirect('/404');
|
||||
if (!mod || !chapter) return Astro.rewrite('/404');
|
||||
|
||||
let html;
|
||||
try { html = sanitizeHtml(await getChapterHtml(chapter.fileUrl)); }
|
||||
catch { return new Response('Chapitre momentanément indisponible.', { status: 503 }); }
|
||||
catch { return new Response('Chapitre momentanément indisponible.', { status: 503, headers: { 'Content-Type': 'text/plain; charset=utf-8' } }); }
|
||||
|
||||
const prev = ci > 0 ? `/cours/${course.slug}/module-${mi + 1}/chapitre-${ci}`
|
||||
: mi > 0 ? `/cours/${course.slug}/module-${mi}/chapitre-${modules[mi - 1].chapters.length}` : null;
|
||||
|
||||
@@ -6,13 +6,13 @@ import { bySlug } from '../../../config/courses';
|
||||
import { getCourseBooks } from '../../../lib/moodle';
|
||||
|
||||
const course = bySlug(Astro.params.slug ?? '');
|
||||
if (!course || !course.published) return Astro.redirect('/404');
|
||||
if (!course || !course.published) return Astro.rewrite('/404');
|
||||
|
||||
let modules;
|
||||
try {
|
||||
modules = await getCourseBooks(course.id);
|
||||
} catch {
|
||||
return new Response('Formation momentanément indisponible — réessayez dans quelques minutes.', { status: 503 });
|
||||
return new Response('Formation momentanément indisponible — réessayez dans quelques minutes.', { status: 503, headers: { 'Content-Type': 'text/plain; charset=utf-8' } });
|
||||
}
|
||||
const hubData = {
|
||||
slug: course.slug,
|
||||
|
||||
Reference in New Issue
Block a user