From bd72a08287411e2c316d10d507f4404ffa3e2668 Mon Sep 17 00:00:00 2001 From: Guilherme Werner Date: Sun, 7 Jan 2024 19:13:08 -0300 Subject: [PATCH] Add files endpoint --- src/api.ts | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/api.ts b/src/api.ts index 7367f9c..3455964 100644 --- a/src/api.ts +++ b/src/api.ts @@ -240,7 +240,7 @@ export class TribufuApi { } /** - * Get a game from the Tribufu API. + * Get servers from the Tribufu API. * @param page * @returns Server[] */ @@ -391,4 +391,36 @@ export class TribufuApi { return responseBody; } + + /** + * Get files from the Tribufu API. + * @param page + * @returns File[] + */ + public async getFiles(page: number = 1): Promise { + const headers = this.getHeaders(); + const responseBody = await this.http.get(`/v1/files?page=${page}`, headers); + + if (!responseBody) { + return []; + } + + return responseBody; + } + + /** + * Get a file by id from the Tribufu API. + * @param id + * @returns File | null + */ + public async getFileById(id: string): Promise { + const headers = this.getHeaders() + const responseBody = await this.http.get(`/v1/files/${id}`, headers); + + if (!responseBody) { + return null; + } + + return responseBody; + } }