Skip to content

Commit d046e74

Browse files
authored
Merge pull request #891 from ELEVATE-Project/develop
Develop to staging
2 parents 4f3d0f2 + b7d03c0 commit d046e74

File tree

5 files changed

+28
-11
lines changed

5 files changed

+28
-11
lines changed

src/.env.sample

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ MENTOR_SESSION_EDITED_BY_MANAGER_EMAIL_TEMPLATE= 'mentor_session_edited_by_manag
120120
ALLOWED_HOST = "http://exampleDomain.com"
121121

122122
# Downloadabale url exipres after
123-
DOWNLOAD_URL_EXPIRATION_DURATION = 120000
123+
DOWNLOAD_URL_EXPIRATION_DURATION = 120000 #for gcloud and azure add it minutes as '1m' for aws and oci add only in seconds '60'
124124
# Expiry time for the signed urls
125-
SIGNED_URL_EXPIRY_IN_MILLISECONDS = 120000
125+
SIGNED_URL_EXPIRY_DURATION = 120000 #for gcloud and azure add it minutes as '1m' for aws and oci add only in seconds '60'
126126
#Authentication meathod to be used
127127
AUTH_METHOD=native #or keycloak_public_key
128128

src/envVariables.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ let enviromentVariables = {
233233
optional: true,
234234
default: 300,
235235
},
236-
SIGNED_URL_EXPIRY_IN_SECONDS: {
236+
SIGNED_URL_EXPIRY_DURATION: {
237237
message: 'Required signed url expiration time in seconds',
238238
optional: true,
239239
default: 900,

src/generics/cloud-services.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
const common = require('@constants/common')
2+
const utils = require('@generics/utils')
23
const { cloudClient } = require('@configs/cloud-service')
34

45
module.exports = class FilesHelper {
56
static async getSignedUrl(bucketName, destFilePath, actionType = common.WRITE_ACCESS, expiryTime = '') {
67
try {
8+
let updatedExpiryTime = await utils.convertExpiryTimeToSeconds(expiryTime)
79
const signedUrl = await cloudClient.getSignedUrl(
810
bucketName, //BucketName
911
destFilePath, //FilePath
10-
expiryTime, //Expiry
12+
updatedExpiryTime, //Expiry
1113
actionType //Read[r] or Write[w]
1214
)
1315

1416
return {
15-
signedUrl: signedUrl,
17+
signedUrl: Array.isArray(signedUrl) ? signedUrl[0] : signedUrl,
1618
filePath: destFilePath,
1719
destFilePath,
1820
}

src/generics/utils.js

+19-4
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ const extractEmailTemplate = (input, conditions) => {
8484

8585
const getDownloadableUrl = async (filePath) => {
8686
let bucketName = process.env.CLOUD_STORAGE_BUCKETNAME
87-
let expiryInSeconds = parseInt(process.env.SIGNED_URL_EXPIRY_IN_SECONDS) || 300
88-
89-
let response = await cloudClient.getSignedUrl(bucketName, filePath, expiryInSeconds, common.READ_ACCESS)
90-
return response
87+
let expiryInSeconds = parseInt(process.env.SIGNED_URL_EXPIRY_DURATION) || 300
88+
let updatedExpiryTime = convertExpiryTimeToSeconds(expiryInSeconds)
89+
let response = await cloudClient.getSignedUrl(bucketName, filePath, updatedExpiryTime, common.READ_ACCESS)
90+
return Array.isArray(response) ? response[0] : response
9191
}
9292

9393
const getPublicDownloadableUrl = async (bucketName, filePath) => {
@@ -745,6 +745,20 @@ function validateProfileData(profileData, validationData) {
745745
return profileMandatoryFields
746746
}
747747

748+
function convertExpiryTimeToSeconds(expiryTime) {
749+
expiryTime = String(expiryTime)
750+
const match = expiryTime.match(/^(\d+)([m]?)$/)
751+
if (match) {
752+
const value = parseInt(match[1], 10) // Numeric value
753+
const unit = match[2]
754+
if (unit === 'm') {
755+
return Math.floor(value / 60)
756+
} else {
757+
return value
758+
}
759+
}
760+
}
761+
748762
module.exports = {
749763
hash: hash,
750764
getCurrentMonthRange,
@@ -791,4 +805,5 @@ module.exports = {
791805
transformCustomFields,
792806
validateProfileData,
793807
validateAndBuildFilters,
808+
convertExpiryTimeToSeconds,
794809
}

src/services/files.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module.exports = class FilesHelper {
3131
cloudBucket = process.env.CLOUD_STORAGE_BUCKETNAME
3232
}
3333

34-
const expiryInSeconds = parseInt(process.env.SIGNED_URL_EXPIRY_IN_SECONDS) || 900
34+
const expiryInSeconds = parseInt(process.env.SIGNED_URL_EXPIRY_DURATION) || 900
3535
const response = await cloudServices.getSignedUrl(
3636
cloudBucket,
3737
destFilePath,
@@ -54,7 +54,7 @@ module.exports = class FilesHelper {
5454
try {
5555
let bucketName = process.env.CLOUD_STORAGE_BUCKETNAME
5656
let response
57-
let expiryInSeconds = parseInt(process.env.SIGNED_URL_EXPIRY_IN_SECONDS) || 300
57+
let expiryInSeconds = parseInt(process.env.SIGNED_URL_EXPIRY_DURATION) || 300
5858

5959
// downloadable url for public bucket
6060
if (isAssetBucket || process.env.CLOUD_STORAGE_BUCKET_TYPE != 'private') {

0 commit comments

Comments
 (0)