Skip to content

Commit 457cb23

Browse files
committed
Updates check of imageSource to include the game setting.
1 parent fd4e504 commit 457cb23

File tree

15 files changed

+42
-21
lines changed

15 files changed

+42
-21
lines changed

functions/achievements.mts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { BikeTagClient, Game } from 'biketag'
22
import {
33
acceptCorsHeaders,
44
getBikeTagClientOpts,
5+
getImageSource,
56
getPayloadOpts,
67
HttpStatusCode,
78
log,
@@ -38,7 +39,7 @@ export default async (req: Request) => {
3839
})
3940
log('[get-achievements] Prepared biketag payload', biketagPayload)
4041

41-
const imageSource = game.awsRegion ? 'aws' : 'imgur'
42+
const imageSource = getImageSource(game)
4243
log('[get-achievements] Using image source', { imageSource })
4344

4445
const achievementsResponse = await biketag.getAchievements(biketagPayload, {

functions/ambassadors.mts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { BikeTagClient, Game } from 'biketag'
22
import {
33
acceptCorsHeaders,
44
getBikeTagClientOpts,
5+
getImageSource,
56
getPayloadOpts,
67
HttpStatusCode,
78
log,
@@ -42,7 +43,7 @@ export default async (req: Request) => {
4243
})
4344
log('[ambassadors] Prepared payload for getAmbassadors', biketagPayload)
4445

45-
const imageSource = game.awsRegion ? 'aws' : 'imgur'
46+
const imageSource = getImageSource(game)
4647
log('[ambassadors] Using image source', { imageSource })
4748

4849
const ambassadorsResponse = await biketag.getAmbassadors(biketagPayload, {

functions/approve.mts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
acceptCorsHeaders,
44
getActiveQueueForGame,
55
getBikeTagClientOpts,
6+
getImageSource,
67
getPayloadOpts,
78
getProfileAuthorization,
89
log,
@@ -58,7 +59,7 @@ export default async (req: Request) => {
5859
}, false, true)
5960
log('[approve-tag] Non-admin BikeTagClient options', nonAdminBiketagOptsUpdated)
6061

61-
const imageSource = game.awsRegion ? 'aws' : 'imgur'
62+
const imageSource = getImageSource(game)
6263
log('[approve-tag] Using image source', { imageSource }, 'info')
6364
const currentBikeTag = (await nonAdminBiketag.getTag(undefined, { source: imageSource })).data
6465
log('[approve-tag] Current bike tag', { tagnumber: currentBikeTag?.tagnumber })

functions/autopost-background.mts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import BikeTagClient, { Game } from 'biketag'
22
import {
33
getActiveQueueForGame,
44
getBikeTagClientOpts,
5+
getImageSource,
56
getWinningTagForCurrentRound,
67
log,
78
setNewBikeTagPost,
@@ -63,7 +64,7 @@ export const autoPostNewBikeTags = async (): Promise<BackgroundProcessResults> =
6364

6465
nonAdminBiketag.config(thisGameConfig, false, true)
6566
adminBiketag.config(thisGameConfig, false, true)
66-
const imageSource = game.awsRegion ? 'aws' : 'imgur'
67+
const imageSource = getImageSource(game)
6768
const activeQueue = await getActiveQueueForGame(game, nonAdminBiketag)
6869

6970
if (activeQueue.completedTags.length && activeQueue.timedOutTags.length === 0) {

functions/autopost-clear.mts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
archiveAndClearQueue,
44
getActiveQueueForGame,
55
getBikeTagClientOpts,
6+
getImageSource,
67
isRequestAllowed,
78
log,
89
} from './common'
@@ -38,7 +39,7 @@ export const autoClearQueue = async (req: Request): Promise<BackgroundProcessRes
3839
}, false, true)
3940
const adminBiketagOpts = getBikeTagClientOpts(req, true, true, game)
4041
const adminBiketag = new BikeTagClient(adminBiketagOpts)
41-
const imageSource = game.awsRegion ? 'aws' : 'imgur'
42+
const imageSource = getImageSource(game)
4243
const { data: mostRecentTag } = await adminBiketag.getTag(undefined, { source: imageSource })
4344
const twentyFourHoursAgo = new Date().getTime() - 60 * 60 * 24 * 1000
4445

functions/autopost-notify.mts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import BikeTagClient, { Game } from 'biketag'
2-
import { BackgroundProcessResults, getBikeTagClientOpts, getPayloadOpts, isRequestAllowed, log, sendNewBikeTagNotifications } from './common'
2+
import { BackgroundProcessResults, getBikeTagClientOpts, getImageSource, getPayloadOpts, isRequestAllowed, log, sendNewBikeTagNotifications } from './common'
33
import { HttpStatusCode } from './common/constants'
44

55
export const autoNotifyNewBikeTagPosted = async (req: Request): Promise<BackgroundProcessResults> => {
@@ -24,7 +24,7 @@ export const autoNotifyNewBikeTagPosted = async (req: Request): Promise<Backgrou
2424
{ source: 'sanity' },
2525
)) as Game
2626

27-
const imageSource = game.awsRegion ? 'aws' : 'imgur'
27+
const imageSource = getImageSource(game)
2828
nonAdminBiketag.config({
2929
aws: {
3030
region: game.awsRegion,

functions/common/methods.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,7 @@ export const getActiveQueueForGame = async (
962962
: 0
963963

964964
const approvingAmbassadorIsApproved = !!approvingAmbassador?.length
965-
const imageSource = game.awsRegion ? 'aws' : 'imgur'
965+
const imageSource = getImageSource(game)
966966

967967
log('Evaluating active queue for game', { game: game.name, autoPostSetting, imageSource }, 'info')
968968

@@ -1323,7 +1323,7 @@ export const sendBikeTagPostNotificationToBlueSky = async (
13231323
const timestamp = getTagDateISOFromTimezone(currentTag.foundTime, game.region.tz)
13241324
const link = `${host}/${winningTagnumber}`
13251325
const gameLinkFacet = getStartAndEndBytesOfStringWithinString(heading, game.name)
1326-
const imageSource = game.awsRegion ? 'aws' : 'imgur'
1326+
const imageSource = getImageSource(game)
13271327
const imageUrl = getImageSized(imageSource, winningTag.mysteryImageUrl, 'm')
13281328

13291329
try {
@@ -1404,7 +1404,7 @@ export const sendBikeTagPostNotificationToWebhook = (
14041404
const mysteryAltText = `BikeTag #${winningTagnumber} by ${winningTag.mysteryPlayer}`
14051405
const foundAltText = `BikeTag #${currentNumber} found by ${currentTag.foundPlayer}`
14061406
const timestamp = getTagDateISOFromTimezone(currentTag.foundTime, game.region.tz)
1407-
const imageSource = game.awsRegion ? 'aws' : 'imgur'
1407+
const imageSource = getImageSource(game)
14081408
const mysteryImageUrl = getImageSized(imageSource, winningTag.mysteryImageUrl, 'l')
14091409
const foundImageUrl = getImageSized(imageSource, currentTag.foundImageUrl, 'l')
14101410

@@ -1635,7 +1635,7 @@ export const setNewBikeTagPost = async (
16351635
): Promise<BackgroundProcessResults> => {
16361636
adminBiketag =
16371637
adminBiketag ?? new BikeTagClient(getBikeTagClientOpts(undefined, true, true, game))
1638-
const imageSource = game.awsRegion ? 'aws' : 'imgur'
1638+
const imageSource = getImageSource(game)
16391639
previousBikeTag =
16401640
previousBikeTag ?? ((await adminBiketag.getTag(undefined, { source: imageSource })).data as Tag)
16411641
let errors = false
@@ -1932,3 +1932,12 @@ export const getEnvironmentVariable = (key: string) => {
19321932
return decompress(process.env[key], { inputEncoding: 'Base64' })
19331933
}
19341934
}
1935+
1936+
export const getImageSource = (game: Game): 'aws' | 'imgur' => {
1937+
if (game.awsRegion && game.settings['data::aws'] === 'true') {
1938+
return 'aws'
1939+
} else if (game.mainhash?.length) {
1940+
return 'imgur'
1941+
}
1942+
return 'imgur'
1943+
}

functions/current.mts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import axios from 'axios'
22
import { BikeTagClient, Game } from 'biketag'
33
import { getDomainInfo, getImageSized } from '../src/common'
4-
import { acceptCorsHeaders, getBikeTagClientOpts, getPayloadOpts, log } from './common'
4+
import { acceptCorsHeaders, getBikeTagClientOpts, getImageSource, getPayloadOpts, log } from './common'
55
import { HttpStatusCode } from './common/constants'
66

77
export default async (req: Request) => {
@@ -45,7 +45,7 @@ export default async (req: Request) => {
4545
true,
4646
)
4747

48-
const imageSource = game.awsRegion ? 'aws' : 'imgur'
48+
const imageSource = getImageSource(game)
4949
const currentTagResponse = await biketag.getTag(biketagPayload, { source: imageSource })
5050

5151
if (currentTagResponse.success) {

functions/delete.mts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { BikeTagClient, Game } from 'biketag'
22
import {
33
acceptCorsHeaders,
44
getBikeTagClientOpts,
5+
getImageSource,
56
getPayloadOpts,
67
getProfileAuthorization,
78
HttpStatusCode,
@@ -52,7 +53,7 @@ export default async (req: Request) => {
5253

5354
log('[delete-tag] Prepared biketag payload', deletePayload)
5455

55-
const imageSource = game.awsRegion ? 'aws' : 'imgur'
56+
const imageSource = getImageSource(game)
5657
log('[delete-tag] Using image source', { imageSource })
5758

5859
if (imageSource === 'aws') {

functions/players.mts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { BikeTagClient, Game } from 'biketag'
22
import {
33
acceptCorsHeaders,
44
getBikeTagClientOpts,
5+
getImageSource,
56
getPayloadOpts,
67
HttpStatusCode,
78
log,
@@ -38,7 +39,7 @@ export default async (req: Request) => {
3839
})
3940
log('[get-players] Prepared biketag payload', biketagPayload)
4041

41-
const imageSource = game.awsRegion ? 'aws' : 'imgur'
42+
const imageSource = getImageSource(game)
4243
log('[get-players] Using image source', { imageSource })
4344

4445
if (imageSource === 'aws') {

0 commit comments

Comments
 (0)