mirror of
https://codeberg.org/demostf/frontend.git
synced 2026-06-03 18:24:12 +02:00
filterbar wip
This commit is contained in:
parent
10ea8ddcbc
commit
e5c9aeb7fe
15 changed files with 1905 additions and 420 deletions
38
script/api.ts
Normal file
38
script/api.ts
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
export type SteamId = string;
|
||||
export interface SteamUser {
|
||||
id: number;
|
||||
steamid: SteamId;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export class Api {
|
||||
private base: string;
|
||||
|
||||
constructor(base: string) {
|
||||
this.base = base;
|
||||
}
|
||||
|
||||
getApiUrl(url) {
|
||||
return this.base + url;
|
||||
}
|
||||
|
||||
request(url, params = {}, json = true): Promise<string | any> {
|
||||
let queryParams = new URLSearchParams(params);
|
||||
return fetch(this.getApiUrl(url) + '?' + queryParams)
|
||||
.then((response) => {
|
||||
if (json) {
|
||||
return response.json()
|
||||
} else {
|
||||
return response.text();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async searchPlayer(query: string): Promise<SteamUser[]> {
|
||||
if (query.length < 2) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return await this.request('users/search', {query}) as SteamUser[];
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue