/** * Copyright (C) 2019-2021 Carl Kittelberger * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ import * as React from 'react'; import { Breadcrumb } from 'react-bootstrap'; import Head from 'next/head'; import Link from 'next/link'; import { useIntl } from 'react-intl'; import { FormattedMessage } from '../components/localization'; import RelativeTime from '../components/RelativeTime'; import VideoList from '../components/VideoList'; import { notFound } from '../util/status'; import { getIndex, getVideos } from '../util/api'; import { VideoEntry } from '../util/datatypes/VideoList'; import { GetServerSideProps, NextPage } from 'next'; interface VideoListPageProps { id?: string, lastUpdatedAt?: string, thumbnailServerURL?: string, title?: string, videos?: Array, }; export const getServerSideProps: GetServerSideProps = async ({ params: { id } }) => { // Fetch URL to thumbnails server const { ids, servers: { thumbnails: thumbnailServerURL }, } = await getIndex(); const vodMeta = ids.find(({ id: thisID, }: { id: string }) => id === thisID); if (!vodMeta) { return { props: {}, }; } const { title } = vodMeta; const requestedID = typeof id === 'string' ? id : id[0]; // Fetch list of videos for this VOD ID const vodInfo = await getVideos(requestedID); const { videos } = vodInfo; let lastUpdatedAt = null; lastUpdatedAt = vodInfo.lastUpdatedAt; const finalVideos: VideoEntry[] = videos .map((video: VideoEntry) => ({ ...video, duration: typeof video.duration === 'string' ? parseFloat(video.duration) : video.duration || null, sourceVideoStart: typeof video.sourceVideoStart === 'string' ? parseFloat(video.sourceVideoStart) : video.sourceVideoStart || null, sourceVideoEnd: typeof video.sourceVideoEnd === 'string' ? parseFloat(video.sourceVideoEnd) : video.sourceVideoEnd || null, })); // Pass data to the page via props return { props: { id: requestedID, thumbnailServerURL, title, videos: finalVideos, lastUpdatedAt, }, }; } const VideoListPage: NextPage = ({ id, lastUpdatedAt, thumbnailServerURL, title, videos, }) => { if (!id) { return notFound(); } let lastUpdatedDate = null; if (typeof (lastUpdatedAt) === 'string') { lastUpdatedDate = new Date(lastUpdatedAt); } const intl = useIntl(); return (
{title} {' '} – {' '} {intl.formatMessage({ id: 'App.title', description: 'The full title of the website', defaultMessage: 'Games Done Quick Instant Archive', })} {title} { lastUpdatedDate ? ( ) : '' }
); } export default VideoListPage;