Skip to content

Commit

Permalink
Merge pull request #891 from ELEVATE-Project/develop
Browse files Browse the repository at this point in the history
Develop to staging
  • Loading branch information
nevil-mathew authored Aug 7, 2024
2 parents 4f3d0f2 + b7d03c0 commit d046e74
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/envVariables.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions src/generics/cloud-services.js
Original file line number Diff line number Diff line change
@@ -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,
}
Expand Down
23 changes: 19 additions & 4 deletions src/generics/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -791,4 +805,5 @@ module.exports = {
transformCustomFields,
validateProfileData,
validateAndBuildFilters,
convertExpiryTimeToSeconds,
}
4 changes: 2 additions & 2 deletions src/services/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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') {
Expand Down

0 comments on commit d046e74

Please sign in to comment.