diff --git a/app.js b/app.js index 97bc0ff..fb37762 100644 --- a/app.js +++ b/app.js @@ -138,6 +138,28 @@ function getMimeType(filename) { return mime } +// getPublicURL returns the public URL of the file. If the file is private and +// the signed parameter is set to true a presigned URL will be created +function getPublicURL(signed = false) { + let pub = $('#acl').data('public') + let filename = $('#filename').val() + + if (pub) { + return window.past3_config.base_url + getFilePrefix() + filename + } + + if (signed) { + let s3 = new AWS.S3() + return s3.getSignedUrl('getObject', { + Bucket: window.past3_config.bucket, + Expires: window.past3_config.private_share_expiry, + Key: getFilePrefix() + filename, + }) + } + + return 'File is private, no URL available' +} + // info displays the info in the frontend function info(msg) { showAlert('info', msg, 10000) @@ -250,6 +272,12 @@ function init() { return false } }) + + new ClipboardJS('#copyURL', { + text: () => { + return getPublicURL(true) + } + }) } // listFiles triggers a reload of the file list @@ -401,11 +429,11 @@ function updateFileURL() { setEditorMime(filename) + $('#file-url').val(getPublicURL(false)) + if (pub) { - $('#file-url').val(window.past3_config.base_url + getFilePrefix() + filename) $('#acl').find('i').removeClass('fa-unlock').addClass('fa-lock') } else { - $('#file-url').val('File is private, no URL available') $('#acl').find('i').removeClass('fa-lock').addClass('fa-unlock') } } diff --git a/config.yml b/config.yml index b18fed0..a001f3a 100644 --- a/config.yml +++ b/config.yml @@ -25,3 +25,7 @@ identity_pool_id: 'eu-west-1:8605f42e-f1e2-4c71-a796-a96ed9e79930' # AWS region of the bucket region: eu-west-1 + +# Expiry in seconds set on pre-signed URLs for private files +# Minimum is 1s, maximum 604800s (seven days) +private_share_expiry: 900 diff --git a/index.html b/index.html index f68fa38..fc2bada 100644 --- a/index.html +++ b/index.html @@ -92,7 +92,8 @@
- + +
@@ -167,6 +168,9 @@ + +