UNPKG

@verdaccio/web

Version:
86 lines (82 loc) 2.79 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "$NextFunctionVer", { enumerable: true, get: function () { return _middleware.$NextFunctionVer; } }); Object.defineProperty(exports, "$RequestExtend", { enumerable: true, get: function () { return _middleware.$RequestExtend; } }); Object.defineProperty(exports, "$ResponseExtend", { enumerable: true, get: function () { return _middleware.$ResponseExtend; } }); exports.default = exports.NOT_README_FOUND = void 0; var _debug = _interopRequireDefault(require("debug")); var _express = require("express"); var _core = require("@verdaccio/core"); var _logger = require("@verdaccio/logger"); var _middleware = require("@verdaccio/middleware"); var _webUtils = require("../web-utils"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } // Was required by other packages // TODO: review this type, should be on @verdacid/types const NOT_README_FOUND = 'ERROR: No README data found!'; exports.NOT_README_FOUND = NOT_README_FOUND; const debug = (0, _debug.default)('verdaccio:web:api:readme'); const getReadme = readme => { if (typeof readme === 'string' && readme.length === 0) { return NOT_README_FOUND; } if (typeof readme !== 'string') { return NOT_README_FOUND; } else { return readme; } }; function addReadmeWebApi(storage, auth) { debug('initialized readme web api'); const can = (0, _middleware.allow)(auth, { beforeAll: (a, b) => _logger.logger.trace(a, b), afterAll: (a, b) => _logger.logger.trace(a, b) }); const pkgRouter = (0, _express.Router)(); /* eslint new-cap: 0 */ pkgRouter.get('/package/readme/(@:scope/)?:package/:version?', can('access'), async function (req, res, next) { debug('readme hit'); const name = req.params.scope ? (0, _webUtils.addScope)(req.params.scope, req.params.package) : req.params.package; debug('readme name %o', name); const requestOptions = { protocol: req.protocol, headers: req.headers, // FIXME: if we migrate to req.hostname, the port is not longer included. host: req.host, remoteAddress: req.socket.remoteAddress }; try { const manifest = await storage.getPackageByOptions({ name, uplinksLook: true, abbreviated: false, requestOptions }); debug('readme pkg %o', manifest === null || manifest === void 0 ? void 0 : manifest.name); res.set(_core.HEADER_TYPE.CONTENT_TYPE, _core.HEADERS.TEXT_PLAIN_UTF8); next(getReadme(manifest.readme)); } catch (err) { next(err); } }); return pkgRouter; } var _default = addReadmeWebApi; exports.default = _default; //# sourceMappingURL=readme.js.map