only number

This commit is contained in:
monoid 2021-01-01 03:28:42 +09:00
parent 5a733b747f
commit eb771fb5b7

View File

@ -7,9 +7,6 @@ import {sendError} from './error_handler';
const ContentIDHandler = (controller: ContentAccessor) => async (ctx: Context,next: Next)=>{ const ContentIDHandler = (controller: ContentAccessor) => async (ctx: Context,next: Next)=>{
const num = Number.parseInt(ctx.params['num']); const num = Number.parseInt(ctx.params['num']);
if (num === NaN){
return await next();
}
let content = await controller.findById(num,true); let content = await controller.findById(num,true);
if (content == undefined){ if (content == undefined){
sendError(404,"content does not exist."); sendError(404,"content does not exist.");
@ -21,9 +18,6 @@ const ContentIDHandler = (controller: ContentAccessor) => async (ctx: Context,ne
}; };
const ContentTagIDHandler = (controller: ContentAccessor) => async (ctx: Context,next: Next)=>{ const ContentTagIDHandler = (controller: ContentAccessor) => async (ctx: Context,next: Next)=>{
const num = Number.parseInt(ctx.params['num']); const num = Number.parseInt(ctx.params['num']);
if (num === NaN){
return await next();
}
let content = await controller.findById(num,true); let content = await controller.findById(num,true);
if (content == undefined){ if (content == undefined){
sendError(404,"content does not exist."); sendError(404,"content does not exist.");
@ -73,9 +67,6 @@ const CreateContentHandler = (controller : ContentAccessor) => async (ctx: Conte
const AddTagHandler = (controller: ContentAccessor)=>async (ctx: Context, next: Next)=>{ const AddTagHandler = (controller: ContentAccessor)=>async (ctx: Context, next: Next)=>{
let tag_name = ctx.params['tag']; let tag_name = ctx.params['tag'];
const num = Number.parseInt(ctx.params['num']); const num = Number.parseInt(ctx.params['num']);
if (num === NaN){
return await next();
}
if(typeof tag_name === undefined){ if(typeof tag_name === undefined){
sendError(400,"??? Unreachable"); sendError(400,"??? Unreachable");
} }
@ -92,9 +83,6 @@ const AddTagHandler = (controller: ContentAccessor)=>async (ctx: Context, next:
const DelTagHandler = (controller: ContentAccessor)=>async (ctx: Context, next: Next)=>{ const DelTagHandler = (controller: ContentAccessor)=>async (ctx: Context, next: Next)=>{
let tag_name = ctx.params['tag']; let tag_name = ctx.params['tag'];
const num = Number.parseInt(ctx.params['num']); const num = Number.parseInt(ctx.params['num']);
if (num === NaN){
return await next();
}
if(typeof tag_name === undefined){ if(typeof tag_name === undefined){
sendError(400,"?? Unreachable"); sendError(400,"?? Unreachable");
} }
@ -110,9 +98,6 @@ const DelTagHandler = (controller: ContentAccessor)=>async (ctx: Context, next:
} }
const DeleteContentHandler = (controller : ContentAccessor) => async (ctx: Context, next: Next) => { const DeleteContentHandler = (controller : ContentAccessor) => async (ctx: Context, next: Next) => {
const num = Number.parseInt(ctx.params['num']); const num = Number.parseInt(ctx.params['num']);
if (num === NaN){
return await next();
}
const r = await controller.del(num); const r = await controller.del(num);
ctx.body = {"ret":r}; ctx.body = {"ret":r};
ctx.type = 'json'; ctx.type = 'json';
@ -120,12 +105,13 @@ const DeleteContentHandler = (controller : ContentAccessor) => async (ctx: Conte
export const getContentRouter = (controller: ContentAccessor)=>{ export const getContentRouter = (controller: ContentAccessor)=>{
const ret = new Router(); const ret = new Router();
ret.get("/search",ContentQueryHandler(controller)); ret.get("/search",ContentQueryHandler(controller));
ret.get("/:num",ContentIDHandler(controller)); ret.get("/:num(\\d+)",ContentIDHandler(controller));
//ret.get("/:num(\\d+)/:content_type");
ret.post("/",CreateContentHandler(controller)); ret.post("/",CreateContentHandler(controller));
ret.get("/:num/tags",ContentTagIDHandler(controller)); ret.get("/:num(\\d+)/tags",ContentTagIDHandler(controller));
ret.post("/:num/tags/:tag",AddTagHandler(controller)); ret.post("/:num(\\d+)/tags/:tag",AddTagHandler(controller));
ret.del("/:num/tags/:tag",DelTagHandler(controller)); ret.del("/:num(\\d+)/tags/:tag",DelTagHandler(controller));
ret.del("/:num",DeleteContentHandler(controller)); ret.del("/:num(\\d+)",DeleteContentHandler(controller));
//ret.get("/"); //ret.get("/");
return ret; return ret;
} }