Skip to content

Commit

Permalink
fix(imgur): made changes to ensure that the player id and gps end up …
Browse files Browse the repository at this point in the history
…with the right image metadata

The gps coordinates are saved to the found image of the previous tag and the player id is saved into
the mystery image of the current/new tag.
  • Loading branch information
KenEucker committed Jan 6, 2024
1 parent 5227111 commit 23df5d2
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 12 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "biketag",
"version": "3.2.6",
"version": "3.2.7",
"description": "The Javascript client API for BikeTag Games",
"main": "./biketag.node.js",
"browser": "./biketag.js",
Expand Down
21 changes: 17 additions & 4 deletions src/common/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,13 +485,21 @@ export const getImgurFoundDescriptionFromBikeTagData = (
includeDate ? getDateStringForImgurDescription(tag.foundTime) : ''
}`

export const getImgurFoundTitleFromBikeTagData = (tag: Tag): string =>
export const getImgurFoundTitleFromBikeTagData = (
tag: Tag,
fromCombinedTag = false
): string =>
`${
!tag.gps || (tag.gps.lat === 0 && tag.gps.long === 0)
? ''
: `(${tag.gps.lat ?? 0}, ${tag.gps.long ?? 0}, ${tag.gps.alt ?? 0})`
}
${tag.playerId?.length ? `[${tag.playerId}]` : ''}
${
!fromCombinedTag && // don't include the player id from a combined tag in the found tag
tag.playerId?.length
? `[${tag.playerId}]`
: ''
}
${tag.confirmedBoundary ? getConfirmedBoundarySymbol : ''}`

export const getImgurMysteryImageHashFromBikeTagData = (
Expand All @@ -500,9 +508,14 @@ export const getImgurMysteryImageHashFromBikeTagData = (
): string => {
return getImageHashFromText(tag.mysteryImageUrl, cache)
}
export const getImgurMysteryTitleFromBikeTagData = (tag: Tag): string =>
export const getImgurMysteryTitleFromBikeTagData = (
tag: Tag,
fromCombinedTag = false
): string =>
`${
!tag.gps || (tag.gps.lat === 0 && tag.gps.long === 0)
(!fromCombinedTag && // don't include the gps from a combined tag in the mystery
!tag.gps) ||
(tag.gps.lat === 0 && tag.gps.long === 0)
? ''
: `(${tag.gps.lat ?? 0}, ${tag.gps.long ?? 0}, ${tag.gps.alt ?? 0})`
}
Expand Down
7 changes: 4 additions & 3 deletions src/imgur/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -648,15 +648,16 @@ export const isValidUploadTagImagePayload = (

export const getUpdateTagPayloadFromTagData = (
payload: uploadTagImagePayload,
mystery = false
mystery = false,
combined = false
): uploadTagImagePayload => {
return {
imageHash: mystery
? getImgurMysteryImageHashFromBikeTagData(payload as Tag)
: getImgurFoundImageHashFromBikeTagData(payload as Tag),
title: mystery
? getImgurMysteryTitleFromBikeTagData(payload as Tag)
: getImgurFoundTitleFromBikeTagData(payload as Tag),
? getImgurMysteryTitleFromBikeTagData(payload as Tag, combined)
: getImgurFoundTitleFromBikeTagData(payload as Tag, combined),
description: mystery
? getImgurMysteryDescriptionFromBikeTagData(payload as Tag)
: getImgurFoundDescriptionFromBikeTagData(payload as Tag),
Expand Down
12 changes: 10 additions & 2 deletions src/imgur/updateTag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,16 @@ export async function updateTag(
cache?: typeof TinyCache
): Promise<BikeTagApiResponse<Tag>> {
/// Construct imgur payloads for both mystery and found images separately
const imgurMysteryImagePayload = getUpdateTagPayloadFromTagData(payload, true)
const imgurFoundImagePayload = getUpdateTagPayloadFromTagData(payload)
const imgurMysteryImagePayload = getUpdateTagPayloadFromTagData(
payload,
true,
true
)
const imgurFoundImagePayload = getUpdateTagPayloadFromTagData(
payload,
false,
true
)

return new Promise(async (resolve) => {
let success = true
Expand Down

0 comments on commit 23df5d2

Please sign in to comment.