Skip to content
Snippets Groups Projects
Unverified Commit 6f2c0a22 authored by hymbz's avatar hymbz Committed by GitHub
Browse files

fix greasyfork 404 bug (#9632)

parent 8e868cda
No related branches found
No related tags found
No related merge requests found
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,
......@@ -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`,
})
}
}
}
......@@ -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% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment