Skip to content

Commit

Permalink
fix(imgur): resolves errors with the returning success of the deleteT…
Browse files Browse the repository at this point in the history
…ag method for the imgur adapter
  • Loading branch information
KenEucker committed Mar 7, 2022
1 parent 62e819d commit 2926c73
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
6 changes: 6 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ export class BikeTagClient extends EventEmitter {
// Only exclude PUT, PATCH and DELETE methods from cache
methods: ['put', 'patch', 'delete'],
},
// Attempt reading stale cache data when response status is either 4xx or 5xx
readOnError: (error) => {
return error.response.status >= 400 && error.response.status < 600
},
// Deactivate `clearOnStale` option so that we can actually read stale cache data
clearOnStale: false,
},
headers,
responseType,
Expand Down
28 changes: 14 additions & 14 deletions src/common/payloads.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Tag } from './schema'
import { CommonData } from './types'
import { CommonPayloadData } from './types'

export type SortOptions = 'new' | 'relevance' | 'hot' | 'top' | 'comments'

Expand All @@ -13,13 +13,13 @@ export type getTagsPayload = {
sort?: SortOptions
limit?: number
tagnumbers: number[]
} & CommonData
} & CommonPayloadData

export type deleteTagsPayload = {
slugs?: string[]
tagnumbers: number[]
tags?: Partial<Tag>[]
} & CommonData
} & CommonPayloadData

export type getTagPayload = {
tagnumber: number
Expand All @@ -31,7 +31,7 @@ export type getTagPayload = {
account?: string
slug: string
fields?: string[]
} & CommonData
} & CommonPayloadData

export type updateTagPayload = {
hash?: string
Expand All @@ -52,7 +52,7 @@ export type uploadTagImagePayload = {
type: 'found' | 'mystery'
slug?: string
stream: ReadableStream
} & CommonData
} & CommonPayloadData

export type ImgurUploadPayload = {
image: string
Expand All @@ -68,7 +68,7 @@ export type getGamePayload = {
name: string
hash?: string
fields?: string[]
} & CommonData
} & CommonPayloadData

export type getPlayersPayload = {
fields?: string[]
Expand All @@ -78,49 +78,49 @@ export type getPlayersPayload = {
limit?: number
account?: string
subreddit?: string
} & CommonData
} & CommonPayloadData

export type getPlayerPayload = {
fields?: string[]
slug?: string
hash?: string
account?: string
subreddit?: string
} & CommonData
} & CommonPayloadData

export type getSettingPayload = {
fields?: string[]
slug?: string
} & CommonData
} & CommonPayloadData

export type getSettingsPayload = {
fields?: string[]
sort?: SortOptions
limit?: number
slugs?: string[]
} & CommonData
} & CommonPayloadData

export type getAmbassadorsPayload = {
fields?: string[]
limit?: number
sort?: SortOptions
slugs?: string[]
} & CommonData
} & CommonPayloadData
export type getAmbassadorPayload = {
fields?: string[]
slug?: string
} & CommonData
} & CommonPayloadData

export type importTagPayload = Pick<
Tag,
'discussionUrl' | 'mysteryImageUrl' | 'foundImageUrl' | 'mentionUrl'
> &
CommonData
CommonPayloadData

export type getQueuePayload = {
hash?: string
queuehash?: string
} & CommonData
} & CommonPayloadData

export type queueTagPayload = {
queuehash?: string
Expand Down
2 changes: 2 additions & 0 deletions src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ export interface CommonData {
concise?: boolean
cached?: boolean
}

export type CommonPayloadData = CommonData
export interface AccessToken {
accessToken: string
}
Expand Down
5 changes: 4 additions & 1 deletion src/imgur/deleteTag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export async function deleteTag(
const hashes = []
const hasImageUrls = payload.foundImageUrl || payload.mysteryImageUrl
let tag = payload

if (!hasImageUrls && (payload.tagnumber || payload.slug)) {
tag = await this.getTags(payload.tagnumber ?? payload.slug)
}
Expand All @@ -37,7 +38,9 @@ export async function deleteTag(

return {
data: responses,
success: true,
success: responses.reduce((o, r) => {
return o && (typeof r === 'boolean') && !!r
}, true),
source: AvailableApis[AvailableApis.imgur],
status: HttpStatusCode.Ok,
}
Expand Down

0 comments on commit 2926c73

Please sign in to comment.