-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: refactor middleware and bufixes (#3922)
- Loading branch information
1 parent
c671faa
commit 43de79d
Showing
33 changed files
with
249 additions
and
509 deletions.
There are no files selected for viewing
Binary file renamed
BIN
+88.1 KB
...6.0.0-6-next.72-32f3afabd4-9880fb08ff.zip → ...6.0.0-6-next.74-fabf8662cb-2cadbd173d.zip
Binary file not shown.
Binary file removed
BIN
-65.5 KB
.yarn/cache/@verdaccio-core-npm-6.0.0-6-next.71-dde7e6d27d-d5c61d9e86.zip
Binary file not shown.
Binary file renamed
BIN
+65.5 KB
...6.0.0-6-next.72-ebaeda159c-785941667f.zip → ...6.0.0-6-next.74-6facca5771-ba4d1524a9.zip
Binary file not shown.
Binary file renamed
BIN
+6.28 KB
...6.0.0-6-next.17-2bc8c7ba9e-fdc2577cef.zip → ...6.0.0-6-next.19-cece039ff5-002cb584e8.zip
Binary file not shown.
Binary file renamed
BIN
+15.7 KB
...6.0.0-6-next.40-cab9c8d239-448bd21ae4.zip → ...6.0.0-6-next.42-83908b28ad-ed1d44557c.zip
Binary file not shown.
Binary file renamed
BIN
+99.8 KB
...6.0.0-6-next.51-d1a57a1720-50b6c0c194.zip → ...6.0.0-6-next.53-0b15f87331-646971454a.zip
Binary file not shown.
Binary file renamed
BIN
+18 KB
...1.0.0-6-next.41-7f527b4078-89a6532b7a.zip → ...1.0.0-6-next.43-e38e0d642e-cd39d065cf.zip
Binary file not shown.
Binary file removed
BIN
-1020 KB
.yarn/cache/@verdaccio-ui-theme-npm-6.0.0-6-next.72-3ad25529a8-2b6c09b823.zip
Binary file not shown.
Binary file added
BIN
+1020 KB
.yarn/cache/@verdaccio-ui-theme-npm-6.0.0-6-next.74-8136215052-7ab99df04a.zip
Binary file not shown.
Binary file renamed
BIN
+17.6 KB
...1.0.0-6-next.38-407f9b96f5-aac9b04e4f.zip → ...1.0.0-6-next.40-f389fd5ab6-77889b1fcb.zip
Binary file not shown.
Binary file renamed
BIN
+35.6 KB
...6.0.0-6-next.40-6d81210b28-8522be67ec.zip → ...6.0.0-6-next.42-132d3a942d-d9ea0d9f9c.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file renamed
BIN
+17.8 KB
...1.0.0-6-next.35-2c3a18a16a-4d94e1b725.zip → ...1.0.0-6-next.37-cc40351c68-8a2babce51.zip
Binary file not shown.
Binary file renamed
BIN
+24.3 KB
...1.0.0-6-next.41-d086703514-768083f3e7.zip → ...1.0.0-6-next.44-4cf4db954e-1ab224615c.zip
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,106 +1,11 @@ | ||
import { API_ERROR, HEADERS } from '../../../lib/constants'; | ||
import { HTTP_STATUS } from '../../../lib/constants'; | ||
import { logger } from '../../../lib/logger'; | ||
import { ErrorCode } from '../../../lib/utils'; | ||
|
||
export default function (route, auth, storage): void { | ||
export default function (route): void { | ||
// searching packages | ||
route.get('/-/all(/since)?', function (req, res, next) { | ||
let received_end = false; | ||
let response_finished = false; | ||
let processing_pkgs = 0; | ||
let firstPackage = true; | ||
logger.warn('/-/all search endpoint is deprecated, might be removed in the next major release'); | ||
res.status(200); | ||
res.set(HEADERS.CONTENT_TYPE, HEADERS.JSON_CHARSET); | ||
|
||
/* | ||
* Offical NPM registry (registry.npmjs.org) no longer return whole database, | ||
* They only return packages matched with keyword in `referer: search pkg-name`, | ||
* And NPM client will request server in every search. | ||
* | ||
* The magic number 99999 was sent by NPM registry. Modify it may caused strange | ||
* behaviour in the future. | ||
* | ||
* BTW: NPM will not return result if user-agent does not contain string 'npm', | ||
* See: method 'request' in up-storage.js | ||
* | ||
* If there is no cache in local, NPM will request /-/all, then get response with | ||
* _updated: 99999, 'Date' in response header was Mon, 10 Oct 1983 00:12:48 GMT, | ||
* this will make NPM always query from server | ||
* | ||
* Data structure also different, whel request /-/all, response is an object, but | ||
* when request /-/all/since, response is an array | ||
*/ | ||
const respShouldBeArray = req.path.endsWith('/since'); | ||
if (!respShouldBeArray) { | ||
res.set('Date', 'Mon, 10 Oct 1983 00:12:48 GMT'); | ||
} | ||
const check_finish = function (): void { | ||
if (!received_end) { | ||
return; | ||
} | ||
if (processing_pkgs) { | ||
return; | ||
} | ||
if (response_finished) { | ||
return; | ||
} | ||
response_finished = true; | ||
if (respShouldBeArray) { | ||
res.end(']\n'); | ||
} else { | ||
res.end('}\n'); | ||
} | ||
}; | ||
|
||
if (respShouldBeArray) { | ||
res.write('['); | ||
} else { | ||
res.write('{"_updated":' + 99999); | ||
} | ||
|
||
const stream = storage.search(req.query.startkey || 0, { req: req }); | ||
|
||
stream.on('data', function each(pkg) { | ||
processing_pkgs++; | ||
|
||
auth.allow_access({ packageName: pkg.name }, req.remote_user, function (err, allowed) { | ||
processing_pkgs--; | ||
|
||
if (err) { | ||
if (err.status && String(err.status).match(/^4\d\d$/)) { | ||
// auth plugin returns 4xx user error, | ||
// that's equivalent of !allowed basically | ||
allowed = false; | ||
} else { | ||
stream.abort(err); | ||
} | ||
} | ||
|
||
if (allowed) { | ||
if (respShouldBeArray) { | ||
res.write(`${firstPackage ? '' : ','}${JSON.stringify(pkg)}\n`); | ||
if (firstPackage) { | ||
firstPackage = false; | ||
} | ||
} else { | ||
res.write(',\n' + JSON.stringify(pkg.name) + ':' + JSON.stringify(pkg)); | ||
} | ||
} | ||
|
||
check_finish(); | ||
}); | ||
}); | ||
|
||
stream.on('error', function (err) { | ||
logger.error('search `/-/all endpoint has failed @{err}', err); | ||
received_end = true; | ||
check_finish(); | ||
}); | ||
|
||
stream.on('end', function () { | ||
received_end = true; | ||
check_finish(); | ||
}); | ||
route.get('/-/all(/since)?', function (_req, res) { | ||
logger.warn('search endpoint has been removed, please use search v1'); | ||
res.status(HTTP_STATUS.NOT_FOUND); | ||
res.json({ error: 'not found, endpoint removed' }); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.