From d51747ad5a808eb45989f12f16612a9e5e3521ef Mon Sep 17 00:00:00 2001 From: Djuri Baars Date: Fri, 17 Nov 2023 21:02:31 +0100 Subject: [PATCH] Fix swagger page and update swagger JSON --- src/routes/+layout.svelte | 49 ++++- src/routes/api/+page.svelte | 41 ++-- {src/routes/api => static}/swagger.json | 22 ++- static/swagger.yaml | 239 ++++++++++++++++++++++++ 4 files changed, 328 insertions(+), 23 deletions(-) rename {src/routes/api => static}/swagger.json (94%) create mode 100644 static/swagger.yaml diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 972ae36..b7f1a34 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -17,10 +17,43 @@ import { browser } from '$app/environment'; import { page } from '$app/stores'; - export const setLocale = (lang: string) => () => { - locale.set(lang); - localStorage.setItem("locale", lang) - } + export const setLocale = (lang: string) => () => { + locale.set(lang); + localStorage.setItem('locale', lang); + }; + + export const getFlagEmoji = (languageCode: string): string | null => { + const flagMap: { [key: string]: string } = { + en: '🇬🇧', // English flag emoji + nl: '🇳🇱', // Dutch flag emoji + es: '🇪🇸' // Spanish flag emoji + }; + + // Convert the language code to lowercase for case-insensitive matching + const lowercaseCode = languageCode.toLowerCase(); + + // Check if the language code is in the flagMap + if (flagMap.hasOwnProperty(lowercaseCode)) { + return flagMap[lowercaseCode]; + } else { + // Return null for unsupported language codes + return null; + } + }; + + export const getLanguageName = (languageCode: string): string | null => { + const languageNames: { [key: string]: { [key: string]: string } } = { + en: { en: 'English', nl: 'English', es: 'English' }, + nl: { en: 'Nederlands', nl: 'Nederlands', es: 'Neerlandés' }, + es: { en: 'Español', nl: 'Spaans', es: 'Español' } + }; + + const lowercaseCode = languageCode.toLowerCase(); + + return languageNames.hasOwnProperty(lowercaseCode) + ? languageNames[lowercaseCode][lowercaseCode] + : null; + }; @@ -28,17 +61,17 @@ - {$locale} + {getFlagEmoji($locale)} {getLanguageName($locale)} {#each $locales as locale} - {locale} + {getFlagEmoji(locale)} {getLanguageName(locale)} {/each} diff --git a/src/routes/api/+page.svelte b/src/routes/api/+page.svelte index 52cf39e..cb11cd6 100644 --- a/src/routes/api/+page.svelte +++ b/src/routes/api/+page.svelte @@ -1,26 +1,36 @@ @@ -44,8 +54,11 @@ crossorigin="anonymous" referrerpolicy="no-referrer" /> + - + +
+ diff --git a/src/routes/api/swagger.json b/static/swagger.json similarity index 94% rename from src/routes/api/swagger.json rename to static/swagger.json index 5343ed5..24c8231 100644 --- a/src/routes/api/swagger.json +++ b/static/swagger.json @@ -68,6 +68,26 @@ "description": "successful operation" } } + }, + "patch": { + "tags": [ + "system" + ], + "summary": "Save current settings", + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Settings" + } + } + } + }, + "responses": { + "200": { + "description": "successful operation" + } + } } }, "/action/pause": { @@ -272,7 +292,7 @@ "default": true, "description": "Enable over-the-air updates" }, - "stealFocusOnBlock": { + "stealFocus": { "type": "boolean", "default": false, "description": "Steal focus on new block" diff --git a/static/swagger.yaml b/static/swagger.yaml new file mode 100644 index 0000000..a518f62 --- /dev/null +++ b/static/swagger.yaml @@ -0,0 +1,239 @@ +openapi: 3.0.3 +info: + title: BTClock API + version: '3.0' + description: BTClock V3 API +servers: + - url: /api/ +paths: + /status: + get: + tags: + - system + summary: Get current status + responses: + '200': + description: successful operation + /system_status: + get: + tags: + - system + summary: Get system status + responses: + '200': + description: successful operation + /settings: + get: + tags: + - system + summary: Get current settings + responses: + '200': + description: successful operation + post: + tags: + - system + summary: Save current settings + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Settings' + responses: + '200': + description: successful operation + patch: + tags: + - system + summary: Save current settings + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Settings' + responses: + '200': + description: successful operation + /action/pause: + get: + tags: + - timer + summary: Pause screen rotation + responses: + '200': + description: successful operation + /action/timer_restart: + get: + tags: + - timer + summary: Restart screen rotation + responses: + '200': + description: successful operation + /show/screen/{id}: + get: + tags: + - screens + summary: Set screen to show + parameters: + - in: path + name: id + schema: + type: integer + default: 1 + required: true + description: ID of screen to show + responses: + '200': + description: successful operation + /show/text/{text}: + get: + tags: + - screens + summary: Set text to show + parameters: + - in: path + name: text + schema: + type: string + default: text + required: true + description: Text to show + responses: + '200': + description: successful operation + /show/custom: + post: + tags: + - screens + summary: Set text to show (advanced) + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/CustomText' + responses: + '200': + description: successful operation + /full_refresh: + get: + tags: + - system + summary: Force full refresh of all displays + responses: + '200': + description: successful operation + /lights/{color}: + get: + tags: + - lights + summary: Turn on LEDs with specific color + parameters: + - in: path + name: color + schema: + type: string + default: FFCC00 + required: true + description: Color in RGB hex + responses: + '200': + description: successful operation + /lights/off: + get: + tags: + - lights + summary: Turn LEDs off + responses: + '200': + description: successful operation + /restart: + get: + tags: + - system + summary: Restart BTClock + responses: + '200': + description: successful operation +components: + schemas: + Settings: + type: object + properties: + fetchEurPrice: + type: boolean + description: Fetch EUR price instead of USD + fgColor: + type: string + default: 16777215 + description: ePaper foreground (text) color + bgColor: + type: string + default: 0 + description: ePaper background color + ledTestOnPower: + type: boolean + default: true + description: Do LED test on power-on + ledFlashOnUpd: + type: boolean + default: false + description: Flash LEDs on new block + mdnsEnabled: + type: boolean + default: true + description: Enable mDNS + otaEnabled: + type: boolean + default: true + description: Enable over-the-air updates + stealFocus: + type: boolean + default: false + description: Steal focus on new block + mcapBigChar: + type: boolean + default: false + description: Use big characters for market cap screen + mempoolInstance: + type: string + default: mempool.space + description: Mempool.space instance to connect to + ledBrightness: + type: integer + default: 128 + description: Brightness of LEDs + fullRefreshMin: + type: integer + default: 60 + description: Full refresh time of ePaper displays in minutes + screen[0]: + type: boolean + screen[1]: + type: boolean + screen[2]: + type: boolean + screen[3]: + type: boolean + screen[4]: + type: boolean + screen[5]: + type: boolean + tzOffset: + type: integer + default: 60 + description: Timezone offset in minutes + minSecPriceUpd: + type: integer + default: 30 + description: Minimum time between price updates in seconds + timePerScreen: + type: integer + default: 30 + description: Time between screens when rotating in minutes + CustomText: + type: array + items: + type: string + minItems: 7 + maxItems: 7