Skip to content

Commit c449d93

Browse files
authored
Merge pull request #256 from KenEucker/develop
Adding method for deleting all images in the queue
2 parents a885de0 + e641fa2 commit c449d93

File tree

5 files changed

+114
-57
lines changed

5 files changed

+114
-57
lines changed

functions/autopost-clear.ts

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ export const autoClearQueue = async (event): Promise<BackgroundProcessResults> =
1919
}
2020

2121
let errors = false
22-
const forceNotify = event.queryStringParameters.force === 'true'
22+
const forceClear = event.queryStringParameters.force === 'true'
23+
const clearAll = event.queryStringParameters.all === 'true'
2324
let results: any = []
2425
const nonAdminBiketagOpts = getBikeTagClientOpts(event, true)
2526
const nonAdminBiketag = new BikeTagClient(nonAdminBiketagOpts)
@@ -33,7 +34,7 @@ export const autoClearQueue = async (event): Promise<BackgroundProcessResults> =
3334
const { data: mostRecentTag } = await adminBiketag.getTag(undefined, { source: 'imgur' })
3435
const twentyFourHoursAgo = new Date().getTime() - 60 * 60 * 24 * 1000
3536

36-
if (twentyFourHoursAgo > mostRecentTag.mysteryTime * 1000 && !forceNotify) {
37+
if (twentyFourHoursAgo > mostRecentTag.mysteryTime * 1000 && !forceClear) {
3738
const errorMessage =
3839
'Most recent tag was created more than 24 hours ago. Please clear the queue manually.'
3940
console.log(errorMessage)
@@ -43,17 +44,44 @@ export const autoClearQueue = async (event): Promise<BackgroundProcessResults> =
4344
}
4445
}
4546

46-
const { queuedTags } = await getActiveQueueForGame(game, adminBiketag)
47+
if (clearAll) {
48+
const allTags = (await nonAdminBiketag.getQueue({ game: adminBiketagOpts.game })).data
4749

48-
if (queuedTags.length) {
49-
console.log('non-winning tag(s) found', { game, queuedTags })
50-
const archiveAndClearQueueResults = await archiveAndClearQueue(queuedTags)
51-
results = archiveAndClearQueueResults.results
52-
errors = archiveAndClearQueueResults.errors
50+
if (allTags.length) {
51+
console.log('all tags found', { game, allTags })
52+
const archiveAndClearQueueResults = await archiveAndClearQueue(
53+
allTags,
54+
game,
55+
adminBiketag,
56+
undefined,
57+
true,
58+
)
59+
results = archiveAndClearQueueResults.results
60+
errors = archiveAndClearQueueResults.errors
61+
} else {
62+
const nothingToDoMessage = 'no tags found'
63+
console.log(nothingToDoMessage)
64+
results.push(nothingToDoMessage)
65+
}
5366
} else {
54-
const nothingToDoMessage = 'no non-winning tags found'
55-
console.log(nothingToDoMessage)
56-
results.push(nothingToDoMessage)
67+
const { queuedTags } = await getActiveQueueForGame(game, adminBiketag)
68+
69+
if (queuedTags.length) {
70+
console.log('non-winning tag(s) found', { game, queuedTags })
71+
const archiveAndClearQueueResults = await archiveAndClearQueue(
72+
queuedTags,
73+
game,
74+
adminBiketag,
75+
undefined,
76+
forceClear,
77+
)
78+
results = archiveAndClearQueueResults.results
79+
errors = archiveAndClearQueueResults.errors
80+
} else {
81+
const nothingToDoMessage = 'no non-winning tags found'
82+
console.log(nothingToDoMessage)
83+
results.push(nothingToDoMessage)
84+
}
5785
}
5886

5987
return {

functions/common/methods.ts

Lines changed: 69 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ export const getPayloadAuthorization = async (event: any): Promise<any> => {
412412
const basic = 'Basic '
413413
const bearer = 'Bearer '
414414
const client = 'Client-ID '
415+
let authProfile
415416

416417
const authorizationType: string | null =
417418
authorizationString?.indexOf(basic) === 0
@@ -469,30 +470,39 @@ export const getPayloadAuthorization = async (event: any): Promise<any> => {
469470
}
470471
}
471472

472-
/// DEBUG: uncomment to check incoming authorization credentials
473-
// console.log({ orign: event.headers.authorization, authorizationType, authorizationString })
474-
475473
switch (authorizationType) {
476474
case 'basic':
477475
authorizationString = authorizationString.substring(basic.length)
478-
return getBasicAuthProfile(authorizationString)
476+
authProfile = await getBasicAuthProfile(authorizationString)
477+
break
479478
case 'netlify':
480479
authorizationString = authorizationString.substring(client.length)
481-
return getNetlifyAuthProfile(authorizationString)
480+
authProfile = await getNetlifyAuthProfile(authorizationString)
481+
break
482482
case 'client':
483483
authorizationString = authorizationString.substring(client.length)
484-
return getAuth0AuthProfile(authorizationString)
484+
authProfile = await getAuth0AuthProfile(authorizationString)
485+
break
485486
case 'bearer':
486487
authorizationString = authorizationString.substring(bearer.length)
487-
return getAuth0AuthProfile(authorizationString)
488+
authProfile = await getAuth0AuthProfile(authorizationString)
489+
break
488490
default:
489-
authorizationString = authorizationString?.length
490-
? 'authorization type not supported'
491-
: authorizationString
491+
authProfile = authorizationString?.length ? 'authorization type not supported' : null
492492
break
493493
}
494494

495-
return null
495+
/// DEBUG: uncomment to check incoming authorization credentials
496+
if (process.env.DEBUG_A) {
497+
console.log({
498+
orign: event.headers.authorization,
499+
authorizationType,
500+
authorizationString,
501+
authProfile,
502+
})
503+
}
504+
505+
return authProfile
496506
}
497507

498508
export const defaultLogo = '/images/BikeTag.svg'
@@ -729,6 +739,7 @@ export const archiveAndClearQueue = async (
729739
game?: Game | null,
730740
adminBiketag?: BikeTagClient,
731741
nonAdminBikeTag?: BikeTagClient,
742+
noArchive = false,
732743
): Promise<BackgroundProcessResults> => {
733744
const results: any = []
734745
let errors = false
@@ -747,7 +758,6 @@ export const archiveAndClearQueue = async (
747758
if (queuedTags.length && game) {
748759
const nonAdminBikeTagOpts = getBikeTagClientOpts(undefined, true)
749760
const gameName = game.name.toLocaleLowerCase()
750-
console.log('archiving remaining queued tags', { game: gameName, queuedTags })
751761
nonAdminBikeTagOpts.game = gameName
752762
nonAdminBikeTagOpts.imgur.hash = game.queuehash
753763

@@ -757,50 +767,67 @@ export const archiveAndClearQueue = async (
757767
nonAdminBikeTag.config(nonAdminBikeTagOpts, false)
758768
}
759769

760-
const currentBikeTag = (await adminBiketag.getTag({ limit: 1 })).data
761-
for (const nonWinningTag of queuedTags) {
762-
/// If there are remnants of tags from the currently posted biketag, don't archive them
763-
if (
764-
nonWinningTag.mysteryPlayer !== currentBikeTag?.mysteryPlayer &&
765-
nonWinningTag.foundPlayer !== currentBikeTag?.mysteryPlayer
766-
) {
767-
/* Archive using ambassador credentials (mainhash and archivehash are both ambassador albums) */
768-
const archiveTagResult = await adminBiketag.archiveTag({
769-
...nonWinningTag,
770-
archivehash: game.archivehash,
771-
})
772-
if (archiveTagResult.success) {
770+
if (!noArchive) {
771+
console.log('archiving remaining queued tags', { game: gameName, queuedTags })
772+
773+
const currentBikeTag = (await adminBiketag.getTag({ limit: 1 })).data
774+
for (const nonWinningTag of queuedTags) {
775+
/// If there are remnants of tags from the currently posted biketag, don't archive them
776+
if (
777+
nonWinningTag.mysteryPlayer !== currentBikeTag?.mysteryPlayer &&
778+
nonWinningTag.foundPlayer !== currentBikeTag?.mysteryPlayer
779+
) {
780+
/* Archive using ambassador credentials (mainhash and archivehash are both ambassador albums) */
781+
const archiveTagResult = await adminBiketag.archiveTag({
782+
...nonWinningTag,
783+
archivehash: game.archivehash,
784+
})
785+
if (archiveTagResult.success) {
786+
results.push({
787+
message: 'non-winning found image archived',
788+
game: gameName,
789+
tag: nonWinningTag,
790+
})
791+
} else {
792+
// console.log({ archiveTagResult })
793+
results.push({
794+
message: 'error archiving non-winning found image',
795+
game: gameName,
796+
tag: nonWinningTag,
797+
})
798+
errors = true
799+
}
800+
}
801+
/* delete using player credentials (queuehash is player album) */
802+
const deleteArchivedTagFromQueueResult = await nonAdminBikeTag.deleteTag(nonWinningTag)
803+
if (deleteArchivedTagFromQueueResult.success) {
773804
results.push({
774-
message: 'non-winning found image archived',
805+
message: 'non-winning tag deleted from queue',
775806
game: gameName,
776807
tag: nonWinningTag,
777808
})
778809
} else {
779-
// console.log({ archiveTagResult })
810+
// console.log({ deleteArchivedTagFromQueueResult })
780811
results.push({
781-
message: 'error archiving non-winning found image',
812+
message: 'error deleting non-winning tag from the queue',
782813
game: gameName,
783814
tag: nonWinningTag,
784815
})
785-
errors = true
816+
/// No error here?
786817
}
787818
}
788-
/* delete using player credentials (queuehash is player album) */
789-
const deleteArchivedTagFromQueueResult = await nonAdminBikeTag.deleteTag(nonWinningTag)
790-
if (deleteArchivedTagFromQueueResult.success) {
791-
results.push({
792-
message: 'non-winning tag deleted from queue',
793-
game: gameName,
794-
tag: nonWinningTag,
795-
})
796-
} else {
797-
// console.log({ deleteArchivedTagFromQueueResult })
819+
} else {
820+
// Just remove all tags from the queue
821+
for (const queuedTag of queuedTags) {
822+
const deletedTagResult = await nonAdminBikeTag.deleteTag(queuedTag)
823+
798824
results.push({
799-
message: 'error deleting non-winning tag from the queue',
825+
message: deletedTagResult.success
826+
? 'tag deleted from queue'
827+
: 'error deleting tag from the queue',
800828
game: gameName,
801-
tag: nonWinningTag,
829+
tag: queuedTag,
802830
})
803-
/// No error here?
804831
}
805832
}
806833
}

src/App.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ created()
189189
.spacer-bottom {
190190
margin-bottom: 50px;
191191
}
192+
192193
.spacer-less {
193194
height: 0;
194195
}

src/common/methods.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,15 @@ export const ordinalSuffixOf = (n: number) => {
3737
}
3838
export const getBikeTagHash = (val: string): string => md5(`${val}${process.env.HOST_KEY}`)
3939

40-
export const getImgurImageSized = (imgurUrl = '', size = 'm') =>
41-
imgurUrl
42-
.replace('.jpeg', `${size}.jpg`)
40+
export const getImgurImageSized = (imgurUrl = '', size = 'm') => {
41+
return imgurUrl
4342
.replace('.jpg', `${size}.jpg`)
43+
.replace('.jpeg', `${size}.jpg`)
4444
.replace('.gif', `${size}.gif`)
4545
.replace('.png', `${size}.png`)
4646
.replace('.webp', `${size}.webp`)
4747
.replace('.mp4', `${size}.mp4`)
48+
}
4849

4950
export const getDomainInfo = (req: any): DomainInfo => {
5051
const nonSubdomainHosts = [

src/views/Round.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
</div>
2828
</template>
2929

30-
<script setup name="QueueBikeTagView">
30+
<script setup name="RoundView">
3131
import { BiketagQueueFormSteps } from '@/common/types'
3232
import { useBikeTagStore } from '@/store/index'
3333
import { computed, onMounted, ref } from 'vue'

0 commit comments

Comments
 (0)