0
Fork 0
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:
Juan Picado 2021-10-27 23:06:41 +02:00 committed by GitHub
parent d7bf5453b1
commit cf4489abb1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 1 deletions

View 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;

View file

@ -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();
});

View file

@ -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();