Move legacy services from server.js into services/ (#1958)

This builds on the work of #1931 by moving the legacy services into `services/`.
This commit is contained in:
Paul Melnikow
2018-08-27 13:29:54 -04:00
committed by GitHub
parent f3037c5e15
commit bedba47d77
151 changed files with 9074 additions and 6813 deletions

View File

@@ -0,0 +1,35 @@
'use strict'
const LegacyService = require('../legacy-service')
const { makeBadgeData: getBadgeData } = require('../../lib/badge-data')
module.exports = class Sourcegraph extends LegacyService {
static registerLegacyRouteHandler({ camp, cache }) {
camp.route(
/^\/sourcegraph\/rrc\/([\s\S]+)\.(svg|png|gif|jpg|json)$/,
cache((data, match, sendBadge, request) => {
const repo = match[1]
const format = match[2]
const apiUrl =
'https://sourcegraph.com/.api/repos/' + repo + '/-/shield'
const badgeData = getBadgeData('used by', data)
request(apiUrl, (err, res, buffer) => {
if (err != null) {
badgeData.text[1] = 'inaccessible'
sendBadge(format, badgeData)
return
}
try {
badgeData.colorscheme = 'brightgreen'
const data = JSON.parse(buffer)
badgeData.text[1] = data.value
sendBadge(format, badgeData)
} catch (e) {
badgeData.text[1] = 'invalid'
sendBadge(format, badgeData)
}
})
})
)
}
}