mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-12-24 21:15:51 +01:00
dist-tags endpoint fastify (#2638)
* Create dist-tags.ts * feat:migrate dist-tags to fastify * Update storage.ts Uncomment self.filters code * add changeset
This commit is contained in:
parent
18dc5f1f2f
commit
20c9e43edc
7
.changeset/ten-parents-breathe.md
Normal file
7
.changeset/ten-parents-breathe.md
Normal file
@ -0,0 +1,7 @@
|
||||
---
|
||||
'@verdaccio/auth': minor
|
||||
'@verdaccio/fastify-migration': minor
|
||||
'@verdaccio/web': minor
|
||||
---
|
||||
|
||||
dist tags Implementation on Fastify
|
55
packages/core/server/src/endpoints/dist-tags.ts
Normal file
55
packages/core/server/src/endpoints/dist-tags.ts
Normal file
@ -0,0 +1,55 @@
|
||||
import buildDebug from 'debug';
|
||||
import { FastifyInstance } from 'fastify';
|
||||
|
||||
const debug = buildDebug('verdaccio:api:dist-tags');
|
||||
|
||||
async function distTagsRoute(fastify: FastifyInstance) {
|
||||
fastify.get('/-/package/:packageName/dist-tags', async (request, reply) => {
|
||||
// @ts-ignore
|
||||
const { packageName } = request.params;
|
||||
debug('dist-tags: response %o', packageName);
|
||||
fastify.storage.getPackage({
|
||||
name: packageName,
|
||||
uplinksLook: true,
|
||||
req: request.raw,
|
||||
callback: function (err, info): void {
|
||||
if (err) {
|
||||
reply.send(err);
|
||||
}
|
||||
reply.code(fastify.statusCode.OK).send(info[fastify.constants.DIST_TAGS]);
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
fastify.post('/-/package/:packageName/dist-tags', async (request, reply) => {
|
||||
// @ts-ignore
|
||||
const { packageName } = request.params;
|
||||
// @ts-ignore
|
||||
fastify.storage.mergeTags(packageName, request.body, function (err): void {
|
||||
if (err) {
|
||||
reply.send(err);
|
||||
}
|
||||
reply
|
||||
.code(fastify.statusCode.CREATED)
|
||||
.send({ ok: fastify.constants.API_MESSAGE.TAG_UPDATED });
|
||||
});
|
||||
});
|
||||
|
||||
fastify.delete('/-/package/:packageName/dist-tags', async (request, reply) => {
|
||||
// @ts-ignore
|
||||
const { packageName } = request.params;
|
||||
fastify.storage.getPackage({
|
||||
name: packageName,
|
||||
uplinksLook: true,
|
||||
req: request.raw,
|
||||
callback: function (err, info): void {
|
||||
if (err) {
|
||||
reply.send(err);
|
||||
}
|
||||
reply.send(info[fastify.constants.DIST_TAGS]);
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export default distTagsRoute;
|
@ -1,11 +1,19 @@
|
||||
import fp from 'fastify-plugin';
|
||||
|
||||
import { API_ERROR, API_MESSAGE, HTTP_STATUS, errorUtils, validatioUtils } from '@verdaccio/core';
|
||||
import {
|
||||
API_ERROR,
|
||||
API_MESSAGE,
|
||||
HTTP_STATUS,
|
||||
constants,
|
||||
errorUtils,
|
||||
validatioUtils,
|
||||
} from '@verdaccio/core';
|
||||
|
||||
export default fp(
|
||||
async function (fastify) {
|
||||
fastify.decorate('errorUtils', errorUtils);
|
||||
fastify.decorate('apiError', API_ERROR);
|
||||
fastify.decorate('constants', constants);
|
||||
fastify.decorate('apiMessage', API_MESSAGE);
|
||||
fastify.decorate('validatioUtils', validatioUtils);
|
||||
fastify.decorate('statusCode', HTTP_STATUS);
|
||||
@ -21,5 +29,6 @@ declare module 'fastify' {
|
||||
apiMessage: typeof API_MESSAGE;
|
||||
statusCode: typeof HTTP_STATUS;
|
||||
errorUtils: typeof errorUtils;
|
||||
constants: typeof constants;
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import fastify from 'fastify';
|
||||
import { Config as AppConfig, createAnonymousRemoteUser } from '@verdaccio/config';
|
||||
import { Config as IConfig, RemoteUser } from '@verdaccio/types';
|
||||
|
||||
import distTags from './endpoints/dist-tags';
|
||||
import ping from './endpoints/ping';
|
||||
import search from './endpoints/search';
|
||||
import tarball from './endpoints/tarball';
|
||||
@ -37,6 +38,7 @@ async function startServer({ logger, config }) {
|
||||
instance.register(search);
|
||||
instance.register(whoami);
|
||||
instance.register(tarball);
|
||||
instance.register(distTags);
|
||||
instance.register(readme, { prefix: '/-/verdaccio' });
|
||||
instance.register(sidebar, { prefix: '/-/verdaccio' });
|
||||
instance.register(login, { prefix: '/-/verdaccio' });
|
||||
|
Loading…
Reference in New Issue
Block a user