From 4f5e85676cf9ad7625309abea93b61b51dc993e8 Mon Sep 17 00:00:00 2001 From: "saish.borkar" Date: Thu, 1 Aug 2024 22:56:44 +0530 Subject: [PATCH 1/6] feat:savepoint --- module/files/helper.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module/files/helper.js b/module/files/helper.js index bfa23d33..37f80e91 100644 --- a/module/files/helper.js +++ b/module/files/helper.js @@ -60,7 +60,7 @@ module.exports = class FilesHelper { responseObj.filePath = element; // Get the downloadable URL from the cloud client SDK. // {sample response} : https://sunbirdstagingpublic.blob.core.windows.net/sample-name/reports/uploadFile2.jpg?st=2023-08-05T07%3A11%3A25Z&se=2024-02-03T14%3A11%3A25Z&sp=r&sv=2018-03-28&sr=b&sig=k66FWCIJ9NjoZfShccLmml3vOq9Lt%2FDirSrSN55UclU%3D - responseObj.url = await cloudClient.getDownloadableUrl( + responseObj.url = await cloudClient.getSignedUrl( bucketName, element, linkExpireTime, // Link ExpireIn @@ -80,7 +80,7 @@ module.exports = class FilesHelper { let result; // Get the downloadable URL from the cloud client SDK. - result = await cloudClient.getDownloadableUrl( + result = await cloudClient.getSignedUrl( bucketName, // bucket name filePath, // resource file path linkExpireTime, // Link Expire time From 914924c5d67183d6f7ea2cff700ec97d5e14990c Mon Sep 17 00:00:00 2001 From: "saish.borkar" Date: Fri, 2 Aug 2024 09:35:11 +0530 Subject: [PATCH 2/6] feat:take array from req.query --- controllers/v1/cloud-services/files.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/controllers/v1/cloud-services/files.js b/controllers/v1/cloud-services/files.js index 8df0f16e..2c029df5 100644 --- a/controllers/v1/cloud-services/files.js +++ b/controllers/v1/cloud-services/files.js @@ -152,9 +152,16 @@ module.exports = class Files { try { + //allows file array to be takes as query as well as body + if(req.query.filePaths){ + req.query.filePaths = JSON.parse(req.query.filePaths); + } + + let filePaths = req.query.filePaths || req.body.filePaths; + let downloadableUrl = await filesHelpers.getDownloadableUrl( - req.body.filePaths + filePaths ); return resolve(downloadableUrl) From 813513ccc7e9972c3282d30555b8f94888712dc5 Mon Sep 17 00:00:00 2001 From: "saish.borkar" Date: Fri, 2 Aug 2024 09:49:51 +0530 Subject: [PATCH 3/6] feat:clarity on comments --- controllers/v1/cloud-services/files.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/v1/cloud-services/files.js b/controllers/v1/cloud-services/files.js index 2c029df5..8a5fc198 100644 --- a/controllers/v1/cloud-services/files.js +++ b/controllers/v1/cloud-services/files.js @@ -152,7 +152,7 @@ module.exports = class Files { try { - //allows file array to be takes as query as well as body + //allows file array to be taken from req.query as well as req.body if(req.query.filePaths){ req.query.filePaths = JSON.parse(req.query.filePaths); } From 3f52050af287cbed8affebc76662360fac1b3026 Mon Sep 17 00:00:00 2001 From: "saish.borkar" Date: Fri, 2 Aug 2024 10:02:58 +0530 Subject: [PATCH 4/6] feat:added documentation for the api --- controllers/v1/cloud-services/files.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/controllers/v1/cloud-services/files.js b/controllers/v1/cloud-services/files.js index 8a5fc198..0501d447 100644 --- a/controllers/v1/cloud-services/files.js +++ b/controllers/v1/cloud-services/files.js @@ -116,16 +116,19 @@ module.exports = class Files { }); } - /** + /** * @api {post} /kendra/api/v1/cloud-services/files/getDownloadableUrl * Get downloadable URL. * @apiVersion 1.0.0 * @apiGroup Gcp * @apiHeader {String} X-authenticated-user-token Authenticity token - * @apiParamExample {json} Request: + * @apiParam {String[]} [filePaths] An array of file paths, can be sent via query parameters or request body. + * @apiParamExample {json} Request (Body): * { - * "filePaths": [] + * "filePaths": ["file1.jpg","file2.jpg"] * } + * @apiParamExample {json} Request (Query): + * /kendra/api/v1/cloud-services/files/getDownloadableUrl?filePaths=["file1.jpg","file2.jpg"] * @apiSampleRequest /kendra/api/v1/cloud-services/files/getDownloadableUrl * @apiUse successBody * @apiUse errorBody From a233f76de0118a3395510eccceb6733c1f004803 Mon Sep 17 00:00:00 2001 From: "saish.borkar" Date: Fri, 2 Aug 2024 10:51:34 +0530 Subject: [PATCH 5/6] feat:documentation added + req.query modified to take single instring comma separated as input --- controllers/v1/cloud-services/files.js | 27 +++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/controllers/v1/cloud-services/files.js b/controllers/v1/cloud-services/files.js index 0501d447..aea8569f 100644 --- a/controllers/v1/cloud-services/files.js +++ b/controllers/v1/cloud-services/files.js @@ -125,21 +125,30 @@ module.exports = class Files { * @apiParam {String[]} [filePaths] An array of file paths, can be sent via query parameters or request body. * @apiParamExample {json} Request (Body): * { - * "filePaths": ["file1.jpg","file2.jpg"] + * "filePaths": ["survey/5f72f9998925ec7c60f79a91//e7455f6c-468d-4fdf-9f6c-546d6b7d1370/uploadFile.jpg","survey/5f72f9998925ec7c60f79a91//e7455f6c-468d-4fdf-9f6c-546d6b7d1370/uploadFile2.jpg"] * } * @apiParamExample {json} Request (Query): - * /kendra/api/v1/cloud-services/files/getDownloadableUrl?filePaths=["file1.jpg","file2.jpg"] + * /kendra/api/v1/cloud-services/files/getDownloadableUrl?filePaths=survey/5f72f9998925ec7c60f79a91//e7455f6c-468d-4fdf-9f6c-546d6b7d1370/uploadFile.jpg,usurvey/5f72f9998925ec7c60f79a91//e7455f6c-468d-4fdf-9f6c-546d6b7d1370/uploadFile2.jpg * @apiSampleRequest /kendra/api/v1/cloud-services/files/getDownloadableUrl * @apiUse successBody * @apiUse errorBody * @apiParamExample {json} Response: * { - * "status": 200, - * "message": "Url's generated successfully", - * "result": [{ - * "filePath": "5e1c28a050452374e1cf9841/e97b5582-471c-4649-8401-3cc4249359bb/cdv_photo_117.jpg", - * "url": "https://storage.googleapis.com/download/storage/v1/b/sl-dev-storage/o/5e1c28a050452374e1cf9841%2Fe97b5582-471c-4649-8401-3cc4249359bb%2Fcdv_photo_117.jpg?generation=1579240054787924&alt=media" - * }] + * "message": "Url's generated successfully", + * "status": 200, + * "result": [ + * { + * "cloudStorage": "oci", + * "filePath": "survey/5f72f9998925ec7c60f79a91//e7455f6c-468d-4fdf-9f6c-546d6b7d1370/uploadFile.jpg", + * "url": "https://ax2cel5zyviy.compat.objectstorage.ap-hyderabad-1.oraclecloud.com/samiksha/survey/5f72f9998925ec7c60f79a91//e7455f6c-468d-4fdf-9f6c-546d6b7d1370/uploadFile.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=3737771d26e1d8f211a04ec59cfd3037c8d1c6ff%2F20240802%2Fap-hyderabad-1%2Fs3%2Faws4_request&X-Amz-Date=20240802T051354Z&X-Amz-Expires=1800&X-Amz-Signature=4ed5c7327315bb8cba99f4c99a71178fffdbc62156e0f1b2ba471a17533eb4dc&X-Amz-SignedHeaders=host&x-id=GetObject" + * }, + * { + * "cloudStorage": "oci", + * "filePath": "survey/5f72f9998925ec7c60f79a91//e7455f6c-468d-4fdf-9f6c-546d6b7d1370/uploadFile2.jpg", + * "url": "https://ax2cel5zyviy.compat.objectstorage.ap-hyderabad-1.oraclecloud.com/samiksha/survey/5f72f9998925ec7c60f79a91//e7455f6c-468d-4fdf-9f6c-546d6b7d1370/uploadFile2.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=3737771d26e1d8f211a04ec59cfd3037c8d1c6ff%2F20240802%2Fap-hyderabad-1%2Fs3%2Faws4_request&X-Amz-Date=20240802T051354Z&X-Amz-Expires=1800&X-Amz-Signature=6c86d4465d9150af2b7bccd0ce81624367447f67b6a5c9b88c40cfff7b5047f9&X-Amz-SignedHeaders=host&x-id=GetObject" + * } + * ] + * } */ /** @@ -157,7 +166,7 @@ module.exports = class Files { //allows file array to be taken from req.query as well as req.body if(req.query.filePaths){ - req.query.filePaths = JSON.parse(req.query.filePaths); + req.query.filePaths = req.query.filePaths.split(',').map(filePath => filePath.trim()).filter(filePath => filePath.length > 0); } let filePaths = req.query.filePaths || req.body.filePaths; From e49fa33a866c3f427572b913fed6535175f2a61f Mon Sep 17 00:00:00 2001 From: "saish.borkar" Date: Fri, 2 Aug 2024 10:51:37 +0530 Subject: [PATCH 6/6] feat:documentation added + req.query modified to take single instring comma separated as input --- controllers/v1/cloud-services/files.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/v1/cloud-services/files.js b/controllers/v1/cloud-services/files.js index aea8569f..a84d02c0 100644 --- a/controllers/v1/cloud-services/files.js +++ b/controllers/v1/cloud-services/files.js @@ -128,7 +128,7 @@ module.exports = class Files { * "filePaths": ["survey/5f72f9998925ec7c60f79a91//e7455f6c-468d-4fdf-9f6c-546d6b7d1370/uploadFile.jpg","survey/5f72f9998925ec7c60f79a91//e7455f6c-468d-4fdf-9f6c-546d6b7d1370/uploadFile2.jpg"] * } * @apiParamExample {json} Request (Query): - * /kendra/api/v1/cloud-services/files/getDownloadableUrl?filePaths=survey/5f72f9998925ec7c60f79a91//e7455f6c-468d-4fdf-9f6c-546d6b7d1370/uploadFile.jpg,usurvey/5f72f9998925ec7c60f79a91//e7455f6c-468d-4fdf-9f6c-546d6b7d1370/uploadFile2.jpg + * /kendra/api/v1/cloud-services/files/getDownloadableUrl?filePaths=survey/5f72f9998925ec7c60f79a91//e7455f6c-468d-4fdf-9f6c-546d6b7d1370/uploadFile.jpg,survey/5f72f9998925ec7c60f79a91//e7455f6c-468d-4fdf-9f6c-546d6b7d1370/uploadFile2.jpg * @apiSampleRequest /kendra/api/v1/cloud-services/files/getDownloadableUrl * @apiUse successBody * @apiUse errorBody