fix greasyfork 404 bug (#9632)

This commit is contained in:
hymbz
2023-10-17 02:45:09 +08:00
committed by GitHub
parent 8e868cda4e
commit 6f2c0a22e9
2 changed files with 17 additions and 5 deletions

View File

@@ -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,
@@ -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`,
})
}
}
}

View File

@@ -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 })