From c3dfcfa1e7971b2571e91b87b4f61379651da044 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Thu, 30 Nov 2023 14:43:41 +0700 Subject: [PATCH] feat: limit file name length --- Services/server/src/controllers/fileController.ts | 8 ++++++++ .../server/src/controllers/subFolderFileController.ts | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/Services/server/src/controllers/fileController.ts b/Services/server/src/controllers/fileController.ts index af3d0b3..5cc2089 100644 --- a/Services/server/src/controllers/fileController.ts +++ b/Services/server/src/controllers/fileController.ts @@ -84,6 +84,10 @@ export class FileController extends Controller { @Path() drawerName: string, @Path() folderName: string, ) { + if (body.file.length > 85) { + throw new HttpError(HttpStatusCode.BAD_REQUEST, "ชื่อไฟล์ยาวเิกนกำหนด"); + } + const basePath = `${cabinetName}/${drawerName}/${folderName}/`; const pathname = `${basePath}${body.file}`; @@ -167,6 +171,10 @@ export class FileController extends Controller { keyword?: string; }, ): Promise { + if (body.file && body.file.length > 85) { + throw new HttpError(HttpStatusCode.BAD_REQUEST, "ชื่อไฟล์ยาวเิกนกำหนด"); + } + const basePath = `${cabinetName}/${drawerName}/${folderName}/`; const pathname = `${basePath}${fileName}`; diff --git a/Services/server/src/controllers/subFolderFileController.ts b/Services/server/src/controllers/subFolderFileController.ts index d2371ba..3c99af6 100644 --- a/Services/server/src/controllers/subFolderFileController.ts +++ b/Services/server/src/controllers/subFolderFileController.ts @@ -88,6 +88,10 @@ export class SubFolderFileController extends Controller { @Path() folderName: string, @Path() subFolderName: string, ) { + if (body.file && body.file.length > 85) { + throw new HttpError(HttpStatusCode.BAD_REQUEST, "ชื่อไฟล์ยาวเิกนกำหนด"); + } + const basePath = `${cabinetName}/${drawerName}/${folderName}/${subFolderName}/`; const pathname = `${basePath}${body.file}`; @@ -171,6 +175,10 @@ export class SubFolderFileController extends Controller { keyword?: string; }, ) { + if (body.file && body.file.length > 85) { + throw new HttpError(HttpStatusCode.BAD_REQUEST, "ชื่อไฟล์ยาวเิกนกำหนด"); + } + const basePath = `${cabinetName}/${drawerName}/${folderName}/${subFolderName}/`; const pathname = `${basePath}${fileName}`;