* Build(deps-dev): bump eslint-plugin-import from 2.17.3 to 2.18.0 Bumps [eslint-plugin-import](https://github.com/benmosher/eslint-plugin-import) from 2.17.3 to 2.18.0. - [Release notes](https://github.com/benmosher/eslint-plugin-import/releases) - [Changelog](https://github.com/benmosher/eslint-plugin-import/blob/master/CHANGELOG.md) - [Commits](https://github.com/benmosher/eslint-plugin-import/compare/v2.17.3...v2.18.0) Signed-off-by: dependabot-preview[bot] <support@dependabot.com> * Autofixes
88 lines
1.7 KiB
JavaScript
88 lines
1.7 KiB
JavaScript
'use strict'
|
|
|
|
const { URL } = require('url')
|
|
const Joi = require('@hapi/joi')
|
|
const { errorMessages } = require('../dynamic-common')
|
|
const { optionalUrl } = require('../validators')
|
|
const { fetchEndpointData } = require('../endpoint-common')
|
|
const { BaseJsonService, InvalidParameter } = require('..')
|
|
|
|
const blockedDomains = ['github.com', 'shields.io']
|
|
|
|
const queryParamSchema = Joi.object({
|
|
url: optionalUrl.required(),
|
|
}).required()
|
|
|
|
module.exports = class Endpoint extends BaseJsonService {
|
|
static get category() {
|
|
return 'dynamic'
|
|
}
|
|
|
|
static get route() {
|
|
return {
|
|
base: 'endpoint',
|
|
pattern: '',
|
|
queryParamSchema,
|
|
}
|
|
}
|
|
|
|
static get _cacheLength() {
|
|
return 300
|
|
}
|
|
|
|
static get defaultBadgeData() {
|
|
return {
|
|
label: 'custom badge',
|
|
}
|
|
}
|
|
|
|
static render({
|
|
isError,
|
|
label,
|
|
message,
|
|
color,
|
|
labelColor,
|
|
namedLogo,
|
|
logoSvg,
|
|
logoColor,
|
|
logoWidth,
|
|
logoPosition,
|
|
style,
|
|
cacheSeconds,
|
|
}) {
|
|
return {
|
|
isError,
|
|
label,
|
|
message,
|
|
color,
|
|
labelColor,
|
|
namedLogo,
|
|
logoSvg,
|
|
logoColor,
|
|
logoWidth,
|
|
logoPosition,
|
|
style,
|
|
cacheSeconds,
|
|
}
|
|
}
|
|
|
|
async handle(namedParams, { url }) {
|
|
const { protocol, hostname } = new URL(url)
|
|
if (protocol !== 'https:') {
|
|
throw new InvalidParameter({ prettyMessage: 'please use https' })
|
|
}
|
|
if (blockedDomains.some(domain => hostname.endsWith(domain))) {
|
|
throw new InvalidParameter({ prettyMessage: 'domain is blocked' })
|
|
}
|
|
|
|
const validated = await fetchEndpointData(this, {
|
|
url,
|
|
errorMessages,
|
|
validationPrettyErrorMessage: 'invalid properties',
|
|
includeKeys: true,
|
|
})
|
|
|
|
return this.constructor.render(validated)
|
|
}
|
|
}
|