1
0
mirror of https://github.com/Luzifer/past3.git synced 2024-09-20 17:32:58 +00:00

Allow sharing private files through pre-signed URLs

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2018-09-25 12:04:26 +02:00
parent 5436e4d332
commit c02a115c1a
Signed by: luzifer
GPG Key ID: DC2729FDD34BE99E
3 changed files with 39 additions and 3 deletions

32
app.js
View File

@ -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')
}
}

View File

@ -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

View File

@ -92,7 +92,8 @@
</div>
<input type="text" class="form-control" id="file-url" placeholder="n/a" readonly>
<div class="input-group-append">
<button type="button" class="btn btn-secondary" id="acl" title="Change ACL (Ctrl + L)"><i class="fas fa-fw fa-lock"></i></button>
<button type="button" class="btn btn-outline-info" id="acl" title="Change ACL (Ctrl + L)"><i class="fas fa-fw fa-lock"></i></button>
<button type="button" class="btn btn-primary" id="copyURL" title="Copy share URL"><i class="fas fa-fw fa-clipboard"></i></button>
</div>
</div>
@ -167,6 +168,9 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.40.2/mode/meta.min.js"
integrity="sha256-+YoTLm1iuD8g9GwmNrGt+xLBvrfbd2B+6C38qtkNE28=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.1/clipboard.min.js"
integrity="sha256-hIvIxeqhGZF+VVeM55k0mJvWpQ6gTkWk3Emc+NmowYA=" crossorigin="anonymous"></script>
<script src="app.js"></script>
<script src="https://apis.google.com/js/platform.js?onload=renderButton" async defer></script>
</body>