Files
animethemes-web/src/lib/client/randomTheme.js
T
Manuel S 31aee782b0 feat: Migrated to Next.js (#87)
* Rewrote data layer to work on-demand.
* Added several favicon formats.
* Added image for SEO page previews.
* Disabled GitHub pages as it no longer works.
* Several other adjustments.
2022-01-16 04:09:29 +01:00

25 lines
797 B
JavaScript

import { baseUrl } from "lib/client/api";
const backLog = [];
export async function fetchRandomTheme() {
if (!backLog.length) {
const res = await fetch(`${baseUrl}/api/animetheme?sort=random&include=anime,animethemeentries.videos&filter[has]=animethemeentries&filter[spoiler]=false`);
const json = await res.json();
backLog.push(...json.animethemes.map((theme) => {
// Remove all entries which have spoilers (the filter parameter guarantees at least one spoiler-free entry)
while (theme.animethemeentries[0].spoiler) {
theme.animethemeentries.shift();
}
return {
...theme,
entries: theme.animethemeentries
};
}));
}
return backLog.pop();
}