From 39119a3419a2c9a2023e4e6e610e635cfa47f82d Mon Sep 17 00:00:00 2001 From: Marshall Polaris Date: Sun, 18 Sep 2022 01:13:10 -0700 Subject: [PATCH] Twitch bot deployment work (#892) * Point at production Twitch bot endpoint * Move Twitch endpoints into env config --- common/envs/dev.ts | 2 ++ common/envs/prod.ts | 2 ++ web/lib/twitch/link-twitch-account.ts | 33 +++++++++++++++------------ 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/common/envs/dev.ts b/common/envs/dev.ts index 719de36e..96ec4dc2 100644 --- a/common/envs/dev.ts +++ b/common/envs/dev.ts @@ -16,4 +16,6 @@ export const DEV_CONFIG: EnvConfig = { cloudRunId: 'w3txbmd3ba', cloudRunRegion: 'uc', amplitudeApiKey: 'fd8cbfd964b9a205b8678a39faae71b3', + // this is Phil's deployment + twitchBotEndpoint: 'https://king-prawn-app-5btyw.ondigitalocean.app', } diff --git a/common/envs/prod.ts b/common/envs/prod.ts index 73bd6029..3014f4e3 100644 --- a/common/envs/prod.ts +++ b/common/envs/prod.ts @@ -2,6 +2,7 @@ export type EnvConfig = { domain: string firebaseConfig: FirebaseConfig amplitudeApiKey?: string + twitchBotEndpoint?: string // IDs for v2 cloud functions -- find these by deploying a cloud function and // examining the URL, https://[name]-[cloudRunId]-[cloudRunRegion].a.run.app @@ -66,6 +67,7 @@ export const PROD_CONFIG: EnvConfig = { appId: '1:128925704902:web:f61f86944d8ffa2a642dc7', measurementId: 'G-SSFK1Q138D', }, + twitchBotEndpoint: 'https://twitch-bot-nggbo3neva-uc.a.run.app', cloudRunId: 'nggbo3neva', cloudRunRegion: 'uc', adminEmails: [ diff --git a/web/lib/twitch/link-twitch-account.ts b/web/lib/twitch/link-twitch-account.ts index f36a03b3..c68a781b 100644 --- a/web/lib/twitch/link-twitch-account.ts +++ b/web/lib/twitch/link-twitch-account.ts @@ -1,7 +1,6 @@ import { PrivateUser, User } from 'common/user' import { generateNewApiKey } from '../api/api-key' - -const TWITCH_BOT_PUBLIC_URL = 'https://king-prawn-app-5btyw.ondigitalocean.app' // TODO: Add this to env config appropriately +import { ENV_CONFIG } from 'common/envs/constants' async function postToBot(url: string, body: unknown) { const result = await fetch(url, { @@ -21,13 +20,16 @@ export async function initLinkTwitchAccount( manifoldUserID: string, manifoldUserAPIKey: string ): Promise<[string, Promise<{ twitchName: string; controlToken: string }>]> { - const response = await postToBot(`${TWITCH_BOT_PUBLIC_URL}/api/linkInit`, { - manifoldID: manifoldUserID, - apiKey: manifoldUserAPIKey, - redirectURL: window.location.href, - }) + const response = await postToBot( + `${ENV_CONFIG.twitchBotEndpoint}/api/linkInit`, + { + manifoldID: manifoldUserID, + apiKey: manifoldUserAPIKey, + redirectURL: window.location.href, + } + ) const responseFetch = fetch( - `${TWITCH_BOT_PUBLIC_URL}/api/linkResult?userID=${manifoldUserID}` + `${ENV_CONFIG.twitchBotEndpoint}/api/linkResult?userID=${manifoldUserID}` ) return [response.twitchAuthURL, responseFetch.then((r) => r.json())] } @@ -50,15 +52,18 @@ export async function updateBotEnabledForUser( botEnabled: boolean ) { if (botEnabled) { - return postToBot(`${TWITCH_BOT_PUBLIC_URL}/registerchanneltwitch`, { + return postToBot(`${ENV_CONFIG.twitchBotEndpoint}/registerchanneltwitch`, { apiKey: privateUser.apiKey, }).then((r) => { if (!r.success) throw new Error(r.message) }) } else { - return postToBot(`${TWITCH_BOT_PUBLIC_URL}/unregisterchanneltwitch`, { - apiKey: privateUser.apiKey, - }).then((r) => { + return postToBot( + `${ENV_CONFIG.twitchBotEndpoint}/unregisterchanneltwitch`, + { + apiKey: privateUser.apiKey, + } + ).then((r) => { if (!r.success) throw new Error(r.message) }) } @@ -66,10 +71,10 @@ export async function updateBotEnabledForUser( export function getOverlayURLForUser(privateUser: PrivateUser) { const controlToken = privateUser?.twitchInfo?.controlToken - return `${TWITCH_BOT_PUBLIC_URL}/overlay?t=${controlToken}` + return `${ENV_CONFIG.twitchBotEndpoint}/overlay?t=${controlToken}` } export function getDockURLForUser(privateUser: PrivateUser) { const controlToken = privateUser?.twitchInfo?.controlToken - return `${TWITCH_BOT_PUBLIC_URL}/dock?t=${controlToken}` + return `${ENV_CONFIG.twitchBotEndpoint}/dock?t=${controlToken}` }