update api url

This commit is contained in:
2025-05-17 01:46:37 -04:00
parent 72e36a0f1c
commit 3e05722d91
+37 -27
View File
@@ -1,19 +1,19 @@
import { useState, useEffect } from 'react'; import { useState, useEffect } from "react";
type TVObject = { type TVObject = {
id: number, id: number;
type: string, type: string;
title: string, title: string;
author: string | null, author: string | null;
description: string, description: string;
image: string, image: string;
episode: string, episode: string;
tmdbId: string, tmdbId: string;
finished: boolean, finished: boolean;
yearReleased: string, yearReleased: string;
genre: string, genre: string;
startedOn: string startedOn: string;
} };
export default function TVComponent() { export default function TVComponent() {
const [show, setShow] = useState<TVObject | null>(null); const [show, setShow] = useState<TVObject | null>(null);
@@ -21,40 +21,50 @@ export default function TVComponent() {
useEffect(() => { useEffect(() => {
async function fetchMusic() { async function fetchMusic() {
const response = await fetch("https://api.alexav.gg/v4/tracker/latest/tv") const response = await fetch(
"https://api.alexav.gg/v4/tracker/items?type=tv&sort=desc"
);
if (response.ok) { if (response.ok) {
const data = await response.json() const data = await response.json();
setShow(data.data as TVObject) if (data.data && data.data.length <= 0) {
} else setFailedFetch(true) setFailedFetch(true);
} else setShow(data.data[0] as TVObject);
} else setFailedFetch(true);
} }
setTimeout(() => { setTimeout(() => {
fetchMusic() fetchMusic();
}, 60000) }, 60000);
fetchMusic() fetchMusic();
}, []) }, []);
if (show) { if (show) {
return ( return (
<div className="flex align-middle"> <div className="flex align-middle">
<a className="hover:underline" href={`https://tracker.alexav.gg/?id=${show.id}&type=${show.type}`} target="_blank"> <a
<h1 className="lowercase">{show.title} - {show.finished ? "finished" : show.episode}</h1> className="hover:underline"
href={`https://tracker.alexav.gg/?id=${show.id}&type=${show.type}`}
target="_blank"
>
<h1 className="lowercase">
{show.title} - {show.finished ? "finished" : show.episode}
</h1>
</a> </a>
</div> </div>
) );
} else { } else {
if (failedFetch) { if (failedFetch) {
return ( return (
<div> <div>
<p>failed to get show :(</p> <p>failed to get show :(</p>
</div> </div>
) );
} else { } else {
return ( return (
<div> <div>
<p>loading show..</p> <p>loading show..</p>
</div> </div>
) );
} }
} }
} }