* Build(deps-dev): bump eslint-plugin-import from 2.20.1 to 2.20.2 Bumps [eslint-plugin-import](https://github.com/benmosher/eslint-plugin-import) from 2.20.1 to 2.20.2. - [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.20.1...v2.20.2) Signed-off-by: dependabot-preview[bot] <support@dependabot.com> * Fixes * refactor: combine imports * refactor: combine imports * refactor: combine imports * refactor: update import ordering Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com> Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com> Co-authored-by: Paul Melnikow <email@paulmelnikow.com> Co-authored-by: Caleb Cartwright <calebcartwright@users.noreply.github.com> Co-authored-by: Caleb Cartwright <caleb.cartwright@outlook.com>
68 lines
1.6 KiB
JavaScript
68 lines
1.6 KiB
JavaScript
'use strict'
|
|
|
|
const Joi = require('@hapi/joi')
|
|
const prettyBytes = require('pretty-bytes')
|
|
const { nonNegativeInteger } = require('../validators')
|
|
const { NotFound } = require('..')
|
|
const { GithubAuthV3Service } = require('./github-auth-service')
|
|
const { documentation, errorMessagesFor } = require('./github-helpers')
|
|
|
|
const schema = Joi.alternatives(
|
|
Joi.object({
|
|
size: nonNegativeInteger,
|
|
}).required(),
|
|
Joi.array().required()
|
|
)
|
|
|
|
module.exports = class GithubSize extends GithubAuthV3Service {
|
|
static get category() {
|
|
return 'size'
|
|
}
|
|
|
|
static get route() {
|
|
return {
|
|
base: 'github/size',
|
|
pattern: ':user/:repo/:path*',
|
|
}
|
|
}
|
|
|
|
static get examples() {
|
|
return [
|
|
{
|
|
title: 'GitHub file size in bytes',
|
|
namedParams: {
|
|
user: 'webcaetano',
|
|
repo: 'craft',
|
|
path: 'build/phaser-craft.min.js',
|
|
},
|
|
staticPreview: this.render({ size: 9170 }),
|
|
keywords: ['repo'],
|
|
documentation,
|
|
},
|
|
]
|
|
}
|
|
|
|
static render({ size }) {
|
|
return {
|
|
message: prettyBytes(size),
|
|
color: 'blue',
|
|
}
|
|
}
|
|
|
|
async fetch({ user, repo, path }) {
|
|
return this._requestJson({
|
|
url: `/repos/${user}/${repo}/contents/${path}`,
|
|
schema,
|
|
errorMessages: errorMessagesFor('repo or file not found'),
|
|
})
|
|
}
|
|
|
|
async handle({ user, repo, path }) {
|
|
const body = await this.fetch({ user, repo, path })
|
|
if (Array.isArray(body)) {
|
|
throw new NotFound({ prettyMessage: 'not a regular file' })
|
|
}
|
|
return this.constructor.render({ size: body.size })
|
|
}
|
|
}
|