From 259aacca67ccf6b2139893bd7d0ec78da8ff8480 Mon Sep 17 00:00:00 2001 From: Jens Pelzetter Date: Tue, 11 Aug 2020 17:27:34 +0200 Subject: [PATCH] Client for themes API finished Former-commit-id: 344f8aa3700e07a0a3c571eb8148376ea7d41dab --- .../src/main/typescript/clients/themes.ts | 68 ++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/ccm-core-apiclient/src/main/typescript/clients/themes.ts b/ccm-core-apiclient/src/main/typescript/clients/themes.ts index 2dbe4ea3d..1d904fe6a 100644 --- a/ccm-core-apiclient/src/main/typescript/clients/themes.ts +++ b/ccm-core-apiclient/src/main/typescript/clients/themes.ts @@ -241,15 +241,81 @@ export class ThemesApiClient { async createOrUpdateThemeFile( themeName: string, path: string, - data: unknown + data: string | Record | ArrayBuffer ): Promise { try { const response: ApiResponse = await this.#apiClient.put( `${this.#THEMES_API_PREFIX}/${themeName}/files/${path}`, data ); + + if (response.ok) { + return; + } } catch (err) { throw `Failed to create or update file ${path} in theme ${themeName}: ${err}`; } } + + async deleteThemeFile( + themeName: string, + path: string, + recursive: boolean + ): Promise { + try { + const response: ApiResponse = await this.#apiClient.delete( + `${this.#THEMES_API_PREFIX}/${themeName}/files/${path}`, + { + recursive: recursive.toString(), + } + ); + + if (response.ok) { + return; + } else { + throw `Failed to delete file ${path} in theme ${themeName}: + ${response.status} ${response.statusText}`; + } + } catch (err) { + throw `Failed to delete file ${path} in theme ${themeName}: ${err}`; + } + } + + async downloadTheme(themeName: string): Promise { + try { + const response: ApiResponse = await this.#apiClient.get( + `${this.#THEMES_API_PREFIX}/${themeName}/@download` + ); + + if (response.ok) { + return response.arrayBuffer(); + } else { + throw `Failed to download theme ${themeName}: + ${response.status} ${response.statusText}`; + } + } catch (err) { + throw `Failed to download theme ${themeName}: ${err}`; + } + } + + async updateTheme( + themeName: string, + updateTheme: ArrayBuffer + ): Promise { + try { + const response: ApiResponse = await this.#apiClient.post( + `${this.#THEMES_API_PREFIX}/${themeName}/@update`, + updateTheme + ); + + if (response.ok) { + return; + } else { + throw `Failed to update theme ${themeName}: + ${response.status} ${response.statusText}`; + } + } catch (err) { + throw `Failed to update theme ${themeName}: ${err}`; + } + } }