schwarzesbrett/docker/schwarzesbrett/src/lib/api.ts

34 lines
754 B
TypeScript
Raw Normal View History

2022-08-03 07:56:22 +00:00
import urlJoin from "url-join";
export const API_ROOT_URL = "http://techgames.gnetx.com/infoscreen";
export const CONTENT_ROOT_URL = urlJoin(API_ROOT_URL, "/listings");
2022-08-02 07:56:40 +00:00
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();
}
2022-08-03 07:56:22 +00:00
export function generateContentURL(content: string): string {
// return new URL(`/${encodeURIComponent(content)}`, CONTENT_ROOT_URL);
2022-08-04 09:26:52 +00:00
return urlJoin(CONTENT_ROOT_URL, content);
2022-08-02 07:56:40 +00:00
}