diff --git a/src/.env.sample b/src/.env.sample index 405ccac49..2bac7a8f1 100644 --- a/src/.env.sample +++ b/src/.env.sample @@ -120,9 +120,9 @@ MENTOR_SESSION_EDITED_BY_MANAGER_EMAIL_TEMPLATE= 'mentor_session_edited_by_manag ALLOWED_HOST = "http://exampleDomain.com" # Downloadabale url exipres after -DOWNLOAD_URL_EXPIRATION_DURATION = 120000 +DOWNLOAD_URL_EXPIRATION_DURATION = 120000 #for gcloud and azure add it minutes as '1m' for aws and oci add only in seconds '60' # Expiry time for the signed urls -SIGNED_URL_EXPIRY_IN_MILLISECONDS = 120000 +SIGNED_URL_EXPIRY_DURATION = 120000 #for gcloud and azure add it minutes as '1m' for aws and oci add only in seconds '60' #Authentication meathod to be used AUTH_METHOD=native #or keycloak_public_key diff --git a/src/envVariables.js b/src/envVariables.js index e8275993a..12c649078 100644 --- a/src/envVariables.js +++ b/src/envVariables.js @@ -233,7 +233,7 @@ let enviromentVariables = { optional: true, default: 300, }, - SIGNED_URL_EXPIRY_IN_SECONDS: { + SIGNED_URL_EXPIRY_DURATION: { message: 'Required signed url expiration time in seconds', optional: true, default: 900, diff --git a/src/generics/cloud-services.js b/src/generics/cloud-services.js index 5e66d92be..d6545cf28 100644 --- a/src/generics/cloud-services.js +++ b/src/generics/cloud-services.js @@ -1,18 +1,20 @@ const common = require('@constants/common') +const utils = require('@generics/utils') const { cloudClient } = require('@configs/cloud-service') module.exports = class FilesHelper { static async getSignedUrl(bucketName, destFilePath, actionType = common.WRITE_ACCESS, expiryTime = '') { try { + let updatedExpiryTime = await utils.convertExpiryTimeToSeconds(expiryTime) const signedUrl = await cloudClient.getSignedUrl( bucketName, //BucketName destFilePath, //FilePath - expiryTime, //Expiry + updatedExpiryTime, //Expiry actionType //Read[r] or Write[w] ) return { - signedUrl: signedUrl, + signedUrl: Array.isArray(signedUrl) ? signedUrl[0] : signedUrl, filePath: destFilePath, destFilePath, } diff --git a/src/generics/utils.js b/src/generics/utils.js index 4f7936609..7f997ffdb 100644 --- a/src/generics/utils.js +++ b/src/generics/utils.js @@ -84,10 +84,10 @@ const extractEmailTemplate = (input, conditions) => { const getDownloadableUrl = async (filePath) => { let bucketName = process.env.CLOUD_STORAGE_BUCKETNAME - let expiryInSeconds = parseInt(process.env.SIGNED_URL_EXPIRY_IN_SECONDS) || 300 - - let response = await cloudClient.getSignedUrl(bucketName, filePath, expiryInSeconds, common.READ_ACCESS) - return response + let expiryInSeconds = parseInt(process.env.SIGNED_URL_EXPIRY_DURATION) || 300 + let updatedExpiryTime = convertExpiryTimeToSeconds(expiryInSeconds) + let response = await cloudClient.getSignedUrl(bucketName, filePath, updatedExpiryTime, common.READ_ACCESS) + return Array.isArray(response) ? response[0] : response } const getPublicDownloadableUrl = async (bucketName, filePath) => { @@ -745,6 +745,20 @@ function validateProfileData(profileData, validationData) { return profileMandatoryFields } +function convertExpiryTimeToSeconds(expiryTime) { + expiryTime = String(expiryTime) + const match = expiryTime.match(/^(\d+)([m]?)$/) + if (match) { + const value = parseInt(match[1], 10) // Numeric value + const unit = match[2] + if (unit === 'm') { + return Math.floor(value / 60) + } else { + return value + } + } +} + module.exports = { hash: hash, getCurrentMonthRange, @@ -791,4 +805,5 @@ module.exports = { transformCustomFields, validateProfileData, validateAndBuildFilters, + convertExpiryTimeToSeconds, } diff --git a/src/services/files.js b/src/services/files.js index d7bf702b1..d1d3ad976 100644 --- a/src/services/files.js +++ b/src/services/files.js @@ -31,7 +31,7 @@ module.exports = class FilesHelper { cloudBucket = process.env.CLOUD_STORAGE_BUCKETNAME } - const expiryInSeconds = parseInt(process.env.SIGNED_URL_EXPIRY_IN_SECONDS) || 900 + const expiryInSeconds = parseInt(process.env.SIGNED_URL_EXPIRY_DURATION) || 900 const response = await cloudServices.getSignedUrl( cloudBucket, destFilePath, @@ -54,7 +54,7 @@ module.exports = class FilesHelper { try { let bucketName = process.env.CLOUD_STORAGE_BUCKETNAME let response - let expiryInSeconds = parseInt(process.env.SIGNED_URL_EXPIRY_IN_SECONDS) || 300 + let expiryInSeconds = parseInt(process.env.SIGNED_URL_EXPIRY_DURATION) || 300 // downloadable url for public bucket if (isAssetBucket || process.env.CLOUD_STORAGE_BUCKET_TYPE != 'private') {