@verdaccio/web
Version:
web ui middleware
96 lines (94 loc) • 3.39 kB
JavaScript
;
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 = 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 _tarball = require("@verdaccio/tarball");
var _utils = require("@verdaccio/utils");
var _webUtils = require("../web-utils");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// Was required by other packages
const debug = (0, _debug.default)('verdaccio:web:api:sidebar');
function addSidebarWebApi(config, storage, auth) {
debug('initialized sidebar web api');
const router = (0, _express.Router)(); /* eslint new-cap: 0 */
const can = (0, _middleware.allow)(auth, {
beforeAll: (a, b) => _logger.logger.trace(a, b),
afterAll: (a, b) => _logger.logger.trace(a, b)
});
// Get package readme
router.get('/sidebar/(@:scope/)?:package', can('access'), async function (req, res, next) {
const name = req.params.scope ? (0, _webUtils.addScope)(req.params.scope, req.params.package) : req.params.package;
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 info = await storage.getPackageByOptions({
name,
uplinksLook: true,
keepUpLinkData: true,
requestOptions
});
const {
v
} = req.query;
let sideBarInfo = {
...info
};
sideBarInfo.versions = (0, _tarball.convertDistRemoteToLocalTarballUrls)(info, {
protocol: req.protocol,
headers: req.headers,
host: req.hostname
}, config.url_prefix).versions;
// TODO: review this implementation
if (typeof v === 'string' && (0, _utils.isVersionValid)(info, v)) {
// @ts-ignore
sideBarInfo.latest = sideBarInfo.versions[v];
// @ts-ignore
sideBarInfo.latest.author = (0, _utils.formatAuthor)(sideBarInfo.latest.author);
} else {
// @ts-ignore
sideBarInfo.latest = sideBarInfo.versions[info[_core.DIST_TAGS].latest];
// @ts-ignore
sideBarInfo.latest.author = (0, _utils.formatAuthor)(sideBarInfo.latest.author);
}
sideBarInfo = (0, _webUtils.deleteProperties)(['readme', '_attachments', '_rev', 'name'], sideBarInfo);
const authorAvatar = config.web ? (0, _utils.addGravatarSupport)(sideBarInfo, config.web.gravatar) : (0, _utils.addGravatarSupport)(sideBarInfo);
next(authorAvatar);
} catch (err) {
res.status(_core.HTTP_STATUS.NOT_FOUND);
res.end();
}
});
return router;
}
var _default = addSidebarWebApi;
exports.default = _default;
//# sourceMappingURL=sidebar.js.map