mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-12-16 21:56:25 -05:00
feat: download tarball endpoint fastify (#2600)
This commit is contained in:
parent
d7bf5453b1
commit
cf4489abb1
3 changed files with 27 additions and 1 deletions
24
packages/core/server/src/endpoints/tarball.ts
Normal file
24
packages/core/server/src/endpoints/tarball.ts
Normal file
|
@ -0,0 +1,24 @@
|
|||
import { FastifyInstance } from 'fastify';
|
||||
import buildDebug from 'debug';
|
||||
|
||||
const debug = buildDebug('verdaccio:api:tarball');
|
||||
|
||||
async function tarballRoute(fastify: FastifyInstance) {
|
||||
fastify.get('/:package/-/:filename', async (request, reply) => {
|
||||
// @ts-ignore
|
||||
const { package: pkg, filename } = request.params;
|
||||
debug('stream tarball for %s@%s', pkg, filename);
|
||||
const stream = fastify.storage.getTarball(pkg, filename);
|
||||
return reply.send(stream);
|
||||
});
|
||||
|
||||
fastify.get('/:scopedPackage/-/:scope/:filename', async (request, reply) => {
|
||||
// @ts-ignore
|
||||
const { scopedPackage, filename } = request.params;
|
||||
debug('stream scope tarball for %s@%s', scopedPackage, filename);
|
||||
const stream = fastify.storage.getTarball(scopedPackage, filename);
|
||||
return reply.send(stream);
|
||||
});
|
||||
}
|
||||
|
||||
export default tarballRoute;
|
|
@ -12,6 +12,7 @@ import configPlugin from './plugins/config';
|
|||
import ping from './endpoints/ping';
|
||||
import user from './endpoints/user';
|
||||
import whoami from './endpoints/whoami';
|
||||
import tarball from './endpoints/tarball';
|
||||
|
||||
const debug = buildDebug('verdaccio:fastify');
|
||||
|
||||
|
@ -32,6 +33,7 @@ async function startServer({ logger, config }) {
|
|||
instance.register(user, { prefix: '/-/user' });
|
||||
instance.register(search);
|
||||
instance.register(whoami);
|
||||
instance.register(tarball);
|
||||
done();
|
||||
});
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ class Storage {
|
|||
|
||||
public async init(config: Config, filters: IPluginFilters = []): Promise<void> {
|
||||
if (this.localStorage === null) {
|
||||
this.filters = filters;
|
||||
this.filters = filters || [];
|
||||
debug('filters available %o', filters);
|
||||
this.localStorage = new LocalStorage(this.config, logger);
|
||||
await this.localStorage.init();
|
||||
|
|
Loading…
Reference in a new issue