diff --git a/services/spiget/spiget-base.js b/services/spiget/spiget-base.js index f8d6ed137adbfdca9ca1f05c1c1c72b73c30b7b4..078f633666d9eabb01414ae833b1c787630be53d 100644 --- a/services/spiget/spiget-base.js +++ b/services/spiget/spiget-base.js @@ -6,8 +6,11 @@ const { BaseJsonService } = require('..') const resourceSchema = Joi.object({ downloads: Joi.number().required(), file: Joi.object({ + type: Joi.string().required(), size: Joi.number().required(), - sizeUnit: Joi.string().required(), + sizeUnit: Joi.string() + .allow('') + .required(), }).required(), testedVersions: Joi.array(), rating: Joi.object({ diff --git a/services/spiget/spiget-download-size.service.js b/services/spiget/spiget-download-size.service.js index 410e5fd5ddeb07f583163643515fc4ea5d97a480..3d74cf28259b30d69b6a5539e77396c60c0bfebd 100644 --- a/services/spiget/spiget-download-size.service.js +++ b/services/spiget/spiget-download-size.service.js @@ -35,7 +35,13 @@ module.exports = class SpigetDownloadSize extends BaseSpigetService { } } - static render({ size, unit }) { + static render({ size, unit, type }) { + if (type === 'external') { + return { + message: `resource hosted externally`, + color: 'lightgrey', + } + } return { message: `${size} ${unit}`, } @@ -43,6 +49,10 @@ module.exports = class SpigetDownloadSize extends BaseSpigetService { async handle({ resourceId }) { const { file } = await this.fetch({ resourceId }) - return this.constructor.render({ size: file.size, unit: file.sizeUnit }) + return this.constructor.render({ + size: file.size, + unit: file.sizeUnit, + type: file.type, + }) } } diff --git a/services/spiget/spiget-download-size.tester.js b/services/spiget/spiget-download-size.tester.js index bdcdd3bdecf6b43960bbdbef3610e2320ae7ab69..a5c943d64222afb9f35109510b9f3d8b9fdf6a73 100644 --- a/services/spiget/spiget-download-size.tester.js +++ b/services/spiget/spiget-download-size.tester.js @@ -7,6 +7,13 @@ t.create('EssentialsX (id 9089)') .get('/9089.json') .expectBadge({ label: 'size', message: isFileSize }) +t.create('Advanced Achievements (id 6239)') + .get('/6239.json') + .expectBadge({ + lavel: 'size', + message: 'resource hosted externally', + }) + t.create('Invalid Resource (id 1)') .get('/1.json') .expectBadge({ diff --git a/services/spiget/spiget-tested-versions.tester.js b/services/spiget/spiget-tested-versions.tester.js index cf942beabede1efb2d1af0395bb61abeff14be23..7389e9283c996c51ae0e99937ee99fc72d6e2264 100644 --- a/services/spiget/spiget-tested-versions.tester.js +++ b/services/spiget/spiget-tested-versions.tester.js @@ -27,6 +27,7 @@ t.create('Nock - single version supported') .reply(200, { downloads: 1, file: { + type: '.jar', size: 1, sizeUnit: '1', }, @@ -50,6 +51,7 @@ t.create('Nock - multiple versions supported') .reply(200, { downloads: 1, file: { + type: '.jar', size: 1, sizeUnit: '1', },