Skip to content

Commit

Permalink
fix greasyfork 404 bug (#9632)
Browse files Browse the repository at this point in the history
  • Loading branch information
hymbz committed Oct 16, 2023
1 parent 8e868cd commit 6f2c0a2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
18 changes: 13 additions & 5 deletions services/greasyfork/greasyfork-base.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Joi from 'joi'
import { nonNegativeInteger } from '../validators.js'
import { BaseJsonService } from '../index.js'
import { BaseJsonService, NotFound } from '../index.js'

const schema = Joi.object({
daily_installs: nonNegativeInteger,
Expand All @@ -16,9 +16,17 @@ export default class BaseGreasyForkService extends BaseJsonService {
static defaultBadgeData = { label: 'greasy fork' }

async fetch({ scriptId }) {
return this._requestJson({
schema,
url: `https://greasyfork.org/scripts/${scriptId}.json`,
})
try {
return await this._requestJson({
schema,
url: `https://greasyfork.org/scripts/${scriptId}.json`,
})
} catch (e) {
if (!(e instanceof NotFound)) throw e
return this._requestJson({
schema,
url: `https://sleazyfork.org/scripts/${scriptId}.json`,
})
}
}
}
4 changes: 4 additions & 0 deletions services/greasyfork/greasyfork-downloads.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ t.create('Total Installs')
t.create('Total Installs (not found)')
.get('/dt/000000.json')
.expectBadge({ label: 'installs', message: 'not found' })

t.create('Total Installs (sleazyfork)')
.get('/dt/374903.json')
.expectBadge({ label: 'installs', message: isMetric })

0 comments on commit 6f2c0a2

Please sign in to comment.