|
1 | | -import { siteConfig } from "@/config/site"; |
2 | | -import { getSitemapMediaMovies } from "@/features/server/sitemap"; |
3 | | -import { routing } from "@/lib/i18n/routing"; |
4 | | -import { buildSitemap } from "@/lib/sitemap"; |
5 | | -import { kebabCase } from "lodash"; |
| 1 | +import { supabaseAdmin } from "@/lib/supabase/supabase-admin"; |
6 | 2 | import { NextResponse } from "next/server"; |
7 | | -import { gzipSync } from 'zlib'; |
8 | 3 |
|
9 | 4 | export async function GET( |
10 | 5 | _: Request, |
11 | 6 | { params }: { params: Promise<{ id: string }> } |
12 | 7 | ) { |
13 | | - try { |
14 | | - const { id } = await params; |
15 | | - const films = await getSitemapMediaMovies(Number(id)); |
16 | | - const sitemapXML = buildSitemap(films.map((film) => { |
17 | | - const translations = Object.fromEntries( |
18 | | - film.tmdb_movie_translations.map((t) => [ |
19 | | - `${t.iso_639_1}-${t.iso_3166_1}`, |
20 | | - t.title, |
21 | | - ]) |
22 | | - ); |
23 | | - |
24 | | - return { |
25 | | - url: `${siteConfig.url}/film/${film.id}${film.original_title ? `-${kebabCase(film.original_title)}` : ''}`, |
26 | | - priority: 0.8, |
27 | | - alternates: { |
28 | | - languages: Object.fromEntries( |
29 | | - routing.locales.map((locale) => { |
30 | | - const title = translations[locale] || film.original_title; |
31 | | - const slug = `${film.id}${title ? `-${kebabCase(title)}` : ''}`; |
32 | | - return [ |
33 | | - locale, |
34 | | - `${siteConfig.url}/${locale}/film/${slug}`, |
35 | | - ]; |
36 | | - }) |
37 | | - ), |
38 | | - }, |
39 | | - }; |
40 | | - })); |
41 | | - |
42 | | - const gzippedXML = gzipSync(sitemapXML); |
43 | | - |
44 | | - return new NextResponse(Uint8Array.from(gzippedXML), { |
45 | | - headers: { |
46 | | - "Content-Type": "application/xml", |
47 | | - "Content-Encoding": "gzip", |
48 | | - "Content-Length": gzippedXML.length.toString(), |
49 | | - "Cache-Control": "public, max-age=86400", |
50 | | - }, |
51 | | - }); |
52 | | - } catch (error) { |
53 | | - console.error("Error generating sitemap:", error); |
54 | | - return NextResponse.error(); |
| 8 | + const { id } = await params; |
| 9 | + const { data, error } = await supabaseAdmin.storage |
| 10 | + .from("sitemaps") |
| 11 | + .download(`movies/${id}.xml.gz`); |
| 12 | + if (error || !data) { |
| 13 | + return new NextResponse("[sitemap] films page not found", { status: 404 }); |
55 | 14 | } |
| 15 | + return new NextResponse(data, { |
| 16 | + headers: { |
| 17 | + "Content-Type": "application/xml", |
| 18 | + "Content-Encoding": "gzip", |
| 19 | + "Cache-Control": "public, max-age=86400", |
| 20 | + }, |
| 21 | + }); |
56 | 22 | } |
0 commit comments