@@ -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
498508export 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 }
0 commit comments