]> git.lizzy.rs Git - frontend-next.git/blob - src/lib/api.ts
refactor(api): get url from api wrapper
[frontend-next.git] / src / lib / api.ts
1 // This file is part of frontend-next <https://github.com/senpy-club/frontend-next>.
2 // Copyright (C) 2022-2022 Fuwn <contact@fuwn.me>
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, version 3.
7 //
8 // This program is distributed in the hope that it will be useful, but
9 // WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program. If not, see <http://www.gnu.org/licenses/>.
15 //
16 // Copyright (C) 2022-2022 Fuwn <contact@fuwn.me>
17 // SPDX-License-Identifier: GPL-3.0-only
18
19 export const baseURL = "https://api.senpy.club";
20 export const baseAPI = `${baseURL}/v2`;
21
22 interface RandomImage {
23   language: string;
24   image: string;
25 }
26
27 export async function fetchImages(language: string): Promise<string[]> {
28   language = language.replace("#", "%23");
29
30   const response = await fetch(`${baseAPI}/language/${language}`);
31
32   return await response.json();
33 }
34
35 export async function fetchLanguages(): Promise<string[]> {
36   const response = await fetch(`${baseAPI}/languages`);
37
38   return await response.json();
39 }
40
41 export async function fetchRandomImage(): Promise<RandomImage> {
42   const response = await fetch(`${baseAPI}/random`);
43
44   return await response.json();
45 }