0
Fork 0
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:
Alex Kocharin 2014-12-05 09:12:09 +03:00
parent bad7aee4ec
commit 06bb301bab
2 changed files with 7 additions and 33 deletions

View file

@ -3,6 +3,7 @@ var Crypto = require('crypto')
var fs = require('fs') var fs = require('fs')
var Error = require('http-errors') var Error = require('http-errors')
var Path = require('path') var Path = require('path')
var URL = require('url')
var fs_storage = require('./local-fs') var fs_storage = require('./local-fs')
var Logger = require('./logger') var Logger = require('./logger')
var Search = require('./search') var Search = require('./search')
@ -148,14 +149,11 @@ Storage.prototype.update_versions = function(name, newdata, callback) {
data.versions[ver] = verdata data.versions[ver] = verdata
if (verdata.dist && verdata.dist.tarball) { if (verdata.dist && verdata.dist.tarball) {
var url = Utils.parse_tarball_url( var filename = URL.parse(verdata.dist.tarball).pathname.replace(/^.*\//, '')
/*verdata.dist.__sinopia_orig_tarball ||*/ verdata.dist.tarball
)
// we do NOT overwrite any existing records // we do NOT overwrite any existing records
if (url != null && data._distfiles[url.filename] == null) { if (data._distfiles[filename] == null) {
data._distfiles[url.filename] = { data._distfiles[filename] = {
url: /*verdata.dist.__sinopia_orig_tarball ||*/ verdata.dist.tarball, url: verdata.dist.tarball,
sha: verdata.dist.shasum, sha: verdata.dist.shasum,
} }
} }

View file

@ -55,35 +55,11 @@ module.exports.validate_metadata = function(object, name) {
return object 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) { module.exports.filter_tarball_urls = function(pkg, req, config) {
function filter(_url) { function filter(_url) {
if (!req.headers.host) return _url if (!req.headers.host) return _url
var url = module.exports.parse_tarball_url(_url) var filename = URL.parse(_url).pathname.replace(/^.*\//, '')
// weird url, just return it
if (url == null) return _url
if (config.url_prefix != null) { if (config.url_prefix != null) {
var result = config.url_prefix.replace(/\/$/, '') 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 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) { for (var ver in pkg.versions) {