schwarzesbrett/docker/schwarzesbrett/src/lib/api.ts
Dominic Grimm 62bdf3f1d9
All checks were successful
continuous-integration/drone/push Build is passing
Fix content URL gen
2022-08-03 09:40:35 +02:00

31 lines
679 B
TypeScript

export const API_ROOT_URL = new URL("http://techgames.gnetx.com/infoscreen");
export const CONTENT_ROOT_URL = new URL("/listings", API_ROOT_URL);
export enum ListingType {
IMAGE = "IMAGE",
VIDEO = "VIDEO",
}
export interface Listing {
name: string;
type: ListingType;
content: string;
time?: number;
}
export interface Data {
listings: Listing[];
}
export async function fetchData(): Promise<Data> {
const response = await fetch(`${API_ROOT_URL}/config.json`, {
cache: "no-store",
});
return await response.json();
}
export function generateContentURL(content: string): URL {
return new URL(`/${encodeURIComponent(content)}`, CONTENT_ROOT_URL);
}