]> git.lizzy.rs Git - frontend-next.git/blob - src/lib/api.ts
fix(lib): replace api url with new
[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 const baseUrl = "https://api.senpy.club/v2";
20
21 interface RandomImage {
22   language: string;
23   image: string;
24 }
25
26 export async function fetchImages(language: string): Promise<string[]> {
27   language = language.replace("#", "%23");
28
29   const response = await fetch(`${baseUrl}/language/${language}`);
30
31   return await response.json();
32 }
33
34 export async function fetchLanguages(): Promise<string[]> {
35   const response = await fetch(`${baseUrl}/languages`);
36
37   return await response.json();
38 }
39
40 export async function fetchRandomImage(): Promise<RandomImage> {
41   const response = await fetch(`${baseUrl}/random`);
42
43   return await response.json();
44 }