mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-12-16 21:56:25 -05:00
fix dist.tarball replacement logic
This commit is contained in:
parent
bad7aee4ec
commit
06bb301bab
2 changed files with 7 additions and 33 deletions
|
@ -3,6 +3,7 @@ var Crypto = require('crypto')
|
|||
var fs = require('fs')
|
||||
var Error = require('http-errors')
|
||||
var Path = require('path')
|
||||
var URL = require('url')
|
||||
var fs_storage = require('./local-fs')
|
||||
var Logger = require('./logger')
|
||||
var Search = require('./search')
|
||||
|
@ -148,14 +149,11 @@ Storage.prototype.update_versions = function(name, newdata, callback) {
|
|||
data.versions[ver] = verdata
|
||||
|
||||
if (verdata.dist && verdata.dist.tarball) {
|
||||
var url = Utils.parse_tarball_url(
|
||||
/*verdata.dist.__sinopia_orig_tarball ||*/ verdata.dist.tarball
|
||||
)
|
||||
|
||||
var filename = URL.parse(verdata.dist.tarball).pathname.replace(/^.*\//, '')
|
||||
// we do NOT overwrite any existing records
|
||||
if (url != null && data._distfiles[url.filename] == null) {
|
||||
data._distfiles[url.filename] = {
|
||||
url: /*verdata.dist.__sinopia_orig_tarball ||*/ verdata.dist.tarball,
|
||||
if (data._distfiles[filename] == null) {
|
||||
data._distfiles[filename] = {
|
||||
url: verdata.dist.tarball,
|
||||
sha: verdata.dist.shasum,
|
||||
}
|
||||
}
|
||||
|
|
28
lib/utils.js
28
lib/utils.js
|
@ -55,35 +55,11 @@ module.exports.validate_metadata = function(object, name) {
|
|||
return object
|
||||
}
|
||||
|
||||
module.exports.parse_tarball_url = function(_url) {
|
||||
var url = URL.parse(_url)
|
||||
|
||||
var path = url.path.replace(/^\//, '').split('/')
|
||||
if (path.length >= 3 && path[path.length-2] === '-') {
|
||||
var filename = path.pop()
|
||||
var pkgpath = '/' + filename // tarball name
|
||||
pkgpath = '/' + path.pop() + pkgpath // "-"
|
||||
pkgpath = '/' + path.pop() + pkgpath // package.name
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
|
||||
return {
|
||||
protocol : url.protocol,
|
||||
host : url.host,
|
||||
prepath : '/' + path.join('/'),
|
||||
pkgpath : pkgpath,
|
||||
filename : filename,
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.filter_tarball_urls = function(pkg, req, config) {
|
||||
function filter(_url) {
|
||||
if (!req.headers.host) return _url
|
||||
|
||||
var url = module.exports.parse_tarball_url(_url)
|
||||
// weird url, just return it
|
||||
if (url == null) return _url
|
||||
var filename = URL.parse(_url).pathname.replace(/^.*\//, '')
|
||||
|
||||
if (config.url_prefix != null) {
|
||||
var result = config.url_prefix.replace(/\/$/, '')
|
||||
|
@ -91,7 +67,7 @@ module.exports.filter_tarball_urls = function(pkg, req, config) {
|
|||
var result = req.protocol + '://' + req.headers.host
|
||||
}
|
||||
|
||||
return result + url.pkgpath
|
||||
return result + '/' + pkg.name.replace(/\//g, '%2f') + '/-/' + filename
|
||||
}
|
||||
|
||||
for (var ver in pkg.versions) {
|
||||
|
|
Loading…
Reference in a new issue