mirror of
https://github.com/fabrice404/olympics-calendar.git
synced 2026-02-25 19:47:08 +00:00
add docker
This commit is contained in:
24
ui/app/api/data/[[...slug]]/route.ts
Normal file
24
ui/app/api/data/[[...slug]]/route.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { promises as fs } from "fs";
|
||||
import { NextResponse } from "next/server";
|
||||
import path from "path";
|
||||
|
||||
const DATA_FOLDER = path.resolve("data");
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ slug?: string[] | undefined }> }
|
||||
): Promise<NextResponse> {
|
||||
try {
|
||||
const { slug } = await params || [];
|
||||
const filePath = slug ? path.join(DATA_FOLDER, ...slug) : null;
|
||||
if (!filePath) throw new Error()
|
||||
|
||||
const content = await fs.readFile(filePath);
|
||||
if (!content) throw new Error()
|
||||
|
||||
return new NextResponse(content, { status: 200 });
|
||||
} catch (ex) {
|
||||
console.log(ex);
|
||||
return new NextResponse("File not found", { status: 404 });
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
export default function Flag({ iso3, name }: { iso3: string; name: string }) {
|
||||
|
||||
const iso3to2 = {
|
||||
const iso3to2: { [key: string]: string } = {
|
||||
AFG: "AF",
|
||||
ALA: "AX",
|
||||
ALB: "AL",
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
import { loadSchedule } from "../lib/data";
|
||||
import { useEffect, useState } from "react";
|
||||
import Flag from "./flag";
|
||||
import { useSearchParams } from "next/navigation";
|
||||
import { COPY, COPY_SUCCESS, FILTER_BY_COUNTRY, FILTER_BY_SPORT } from "../lib/text";
|
||||
import useLocalStorage from "@/lib/local-storage";
|
||||
|
||||
@@ -52,7 +51,7 @@ interface Calendar {
|
||||
const COLORS = ['azzurro', 'giallo', 'rosa', 'rosso', 'verde', 'viola'];
|
||||
|
||||
export default function Home() {
|
||||
const qs = useSearchParams();
|
||||
const qs = typeof window !== 'undefined' ? window.location.search ? new URLSearchParams(window.location.search) : new URLSearchParams() : new URLSearchParams();
|
||||
|
||||
const [data, setData] = useState<Calendar | null>(null);
|
||||
const [language, setLanguage] = useLocalStorage('lang', (navigator.language || 'en').split('-')[0]);
|
||||
@@ -95,7 +94,7 @@ export default function Home() {
|
||||
const noc = qs.get('noc') || 'calendar';
|
||||
const sport = qs.get('sport') || 'all-sports';
|
||||
|
||||
return `http://${host}/data/${language}/${sport}/${noc}.ics`;
|
||||
return `http://${host}/api/data/${language}/${sport}/${noc}.ics`;
|
||||
};
|
||||
|
||||
const getColor = (i: number) => COLORS[i % COLORS.length];
|
||||
|
||||
Reference in New Issue
Block a user