mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-12-20 17:05:52 +01:00
add params validation for sidebar fastify web endpoints (#2655)
* sidebar fastify validation Add params schema validation for sidebar endpoints * reuse types Co-authored-by: Juan Picado <juanpicado19@gmail.com>
This commit is contained in:
parent
8e17d19c92
commit
2a86a46b85
@ -14,20 +14,55 @@ import {
|
||||
|
||||
const debug = buildDebug('verdaccio:web:api:sidebar');
|
||||
export type $SidebarPackage = Package & { latest: Version };
|
||||
const stringType = { type: 'string' };
|
||||
const packageNameSchema = { packageName: stringType };
|
||||
const paramsSchema = {
|
||||
scope: stringType,
|
||||
packageName: stringType,
|
||||
};
|
||||
|
||||
async function sidebarRoute(fastify: FastifyInstance) {
|
||||
fastify.get('/sidebar/(@:scope/)?:packageName', async (request, reply) => {
|
||||
// @ts-ignore
|
||||
const { packageName, scope } = request.params;
|
||||
debug('pkg name %s, scope %s ', packageName, scope);
|
||||
getSidebar(fastify, request, packageName, (err, sidebar) => {
|
||||
if (err) {
|
||||
reply.send(err);
|
||||
} else {
|
||||
reply.code(fastify.statusCode.OK).send(sidebar);
|
||||
}
|
||||
});
|
||||
});
|
||||
fastify.get(
|
||||
'/sidebar/:scope/:packageName',
|
||||
{
|
||||
schema: {
|
||||
params: paramsSchema,
|
||||
},
|
||||
},
|
||||
async (request, reply) => {
|
||||
// @ts-ignore
|
||||
const { packageName, scope } = request.params;
|
||||
debug('pkg name %s, scope %s ', packageName, scope);
|
||||
getSidebar(fastify, request, packageName, (err, sidebar) => {
|
||||
if (err) {
|
||||
reply.send(err);
|
||||
} else {
|
||||
reply.code(fastify.statusCode.OK).send(sidebar);
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
fastify.get(
|
||||
'/sidebar/:packageName',
|
||||
{
|
||||
schema: {
|
||||
params: packageNameSchema,
|
||||
},
|
||||
},
|
||||
async (request, reply) => {
|
||||
// @ts-ignore
|
||||
const { packageName, scope } = request.params;
|
||||
debug('pkg name %s, scope %s ', packageName, scope);
|
||||
getSidebar(fastify, request, packageName, (err, sidebar) => {
|
||||
if (err) {
|
||||
reply.send(err);
|
||||
} else {
|
||||
reply.code(fastify.statusCode.OK).send(sidebar);
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function getSidebar(fastify: FastifyInstance, request: any, packageName, callback) {
|
||||
|
Loading…
Reference in New Issue
Block a user