From 036247d23165ad0bb96172e2826c95c2df2108ae Mon Sep 17 00:00:00 2001 From: schneefux Date: Thu, 14 Nov 2024 11:22:34 +0100 Subject: [PATCH] web: Implement token for devfox API --- web/api/services/BrawlstarsService.ts | 22 +++++++++++-------- web/components/player/player-brawler-card.vue | 2 -- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/web/api/services/BrawlstarsService.ts b/web/api/services/BrawlstarsService.ts index 7c056e61..12e80db2 100644 --- a/web/api/services/BrawlstarsService.ts +++ b/web/api/services/BrawlstarsService.ts @@ -11,10 +11,14 @@ const BrawlerNames: Record = BrawlerNamesMap import { Cache } from '~/lib/cache' const brawlapiUrl = process.env.BRAWLAPI_URL || 'https://api.brawlapi.com/v1/'; +const brawlapiToken = process.env.BRAWLAPI_TOKEN || ''; + const brawlstarsUrl = process.env.BRAWLSTARS_URL || 'https://api.brawlstars.com/v1/'; +const brawlstarsToken = process.env.BRAWLSTARS_TOKEN || ''; + const devfoxUrl = process.env.HPDEVFOX_URL || 'https://api.hpdevfox.ru/'; -const tokenUnofficial = process.env.BRAWLAPI_TOKEN || ''; -const tokenOfficial = process.env.BRAWLSTARS_TOKEN || ''; +const devfoxToken = process.env.HPDEVFOX_TOKEN || ''; + const clickhouseUrl = process.env.CLICKHOUSE_URL const twoMonths = 2*4*7*24*60*60*1000 const balanceChangesDate = new Date(Date.parse(process.env.BALANCE_CHANGES_DATE || '') || (Date.now() - twoMonths)) @@ -53,7 +57,7 @@ export default class BrawlstarsService { private async apiRequest(path: string, metricName: string, timeout: number = 1000) { return request(path, brawlstarsUrl, metricName, - {}, { 'Authorization': 'Bearer ' + tokenOfficial }, timeout) + {}, { 'Authorization': 'Bearer ' + brawlstarsToken }, timeout) } // TODO official API does not show all future events as of 2022-01-07 @@ -63,7 +67,7 @@ export default class BrawlstarsService { brawlapiUrl, 'fetch_events', { }, - { 'Authorization': 'Bearer ' + tokenUnofficial }, + { 'Authorization': 'Bearer ' + brawlapiToken }, 1000, ); @@ -107,14 +111,14 @@ export default class BrawlstarsService { brawlstarsUrl, 'fetch_player', { }, - { 'Authorization': 'Bearer ' + tokenOfficial }, + { 'Authorization': 'Bearer ' + brawlstarsToken }, 1000, ); } private async getPlayerDevfox(tag: string): Promise { return request( - 'profile/' + tag, + 'profile/' + tag + (devfoxToken ? '?api_key=' + devfoxToken : ''), devfoxUrl, 'fetch_player_devfox', { }, @@ -132,7 +136,7 @@ export default class BrawlstarsService { brawlapiUrl, 'fetch_brawlers', { }, - { 'Authorization': 'Bearer ' + tokenUnofficial }, + { 'Authorization': 'Bearer ' + brawlapiToken }, 1000, ); return Object.fromEntries(response.list.map(b => [b.id, b.name])) @@ -145,7 +149,7 @@ export default class BrawlstarsService { brawlstarsUrl, 'fetch_player_battles', { }, - { 'Authorization': 'Bearer ' + tokenOfficial }, + { 'Authorization': 'Bearer ' + brawlstarsToken }, 1000, ) } @@ -370,7 +374,7 @@ export default class BrawlstarsService { brawlstarsUrl, 'fetch_club', { }, - { 'Authorization': 'Bearer ' + tokenOfficial }, + { 'Authorization': 'Bearer ' + brawlstarsToken }, 1000, ) // official API: with hash, unofficial API: no hash diff --git a/web/components/player/player-brawler-card.vue b/web/components/player/player-brawler-card.vue index 45d98c2a..915d501e 100644 --- a/web/components/player/player-brawler-card.vue +++ b/web/components/player/player-brawler-card.vue @@ -169,8 +169,6 @@ export default defineComponent({ const brawlerId = computed(() => getBrawlerId({ name: props.brawler.name })) const title = computed(() => capitalizeWords(props.brawler.name.toLowerCase())) - console.log('extra', props.brawler.name, props.brawlerExtra) - const i18n = useI18n() const kvTableRows = computed(() => { const rows = []