schwarzesbrett/docker/schwarzesbrett/src/lib/api.ts
2022-08-02 09:56:40 +02:00

31 lines
657 B
TypeScript

export const API_ROOT_URL = "http://techgames.gnetx.com/infoscreen";
export const CONTENT_ROOT_URL = `${API_ROOT_URL}/listings`;
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): string {
return `${CONTENT_ROOT_URL}/${encodeURIComponent(content)}`;
}