Skip to content

Commit

Permalink
fix: auto fix /v or / not 'v' prefix (cnpm#239)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 authored Mar 28, 2020
1 parent 5215d0d commit 32700e4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ init-mysql:
@mysql -uroot -e 'DROP DATABASE IF EXISTS mirrors_test;'
@mysql -uroot -e 'CREATE DATABASE mirrors_test;'

test: install init-database
test: init-database
@NODE_ENV=test DB=${DB} node_modules/.bin/mocha \
--reporter $(REPORTER) \
--timeout $(TIMEOUT) \
Expand Down
10 changes: 10 additions & 0 deletions controllers/dist.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ module.exports = function* () {
function* download(category, name) {
// download file
var info = yield Dist.getfile(category, name);
if (!info || !info.url) {
// auto fix /vX.X.X => /X.X.X
// HTTPError: Response code 404 (Not Found) for http://npm.taobao.org/mirrors/electron/v8.2.0/electron-v8.2.0-darwin-x64.zip
// fix to => http://npm.taobao.org/mirrors/electron/8.2.0/electron-v8.2.0-darwin-x64.zip
if (/^\/v\d+\.\d+\.\d+/.test(name)) {
info = yield Dist.getfile(category, name.replace('/v', '/'));
} else if (/^\/\d+\.\d+\.\d+/.test(name)) {
info = yield Dist.getfile(category, name.replace('/', '/v'));
}
}
if (!info || !info.url) {
debug('file %s:%s not exist', category, name);
return this.status = 404;
Expand Down

0 comments on commit 32700e4

Please sign in to comment.