feat(ifc/frontend/backend): re #426, adds authorised download button for original files
This commit is contained in:
@@ -2,7 +2,10 @@
|
||||
<v-card class="my-4 elevation-1" :loading="$apollo.loading">
|
||||
<div v-if="!$apollo.loading && file">
|
||||
<v-toolbar dense flat color="transparent">
|
||||
<v-app-bar-nav-icon>
|
||||
<v-app-bar-nav-icon
|
||||
v-tooltip="`Download the original file`"
|
||||
@click="downloadOriginalFile()"
|
||||
>
|
||||
<v-icon>mdi-download</v-icon>
|
||||
</v-app-bar-nav-icon>
|
||||
<v-toolbar-title>
|
||||
@@ -104,6 +107,24 @@ export default {
|
||||
mounted() {
|
||||
this.$apollo.queries.file.startPolling(1000)
|
||||
},
|
||||
methods: {}
|
||||
methods: {
|
||||
async downloadOriginalFile() {
|
||||
let res = await fetch(`/api/file/${this.fileId}`, {
|
||||
headers: {
|
||||
Authorization: localStorage.getItem('AuthToken')
|
||||
}
|
||||
})
|
||||
let blob = await res.blob()
|
||||
let file = window.URL.createObjectURL(blob)
|
||||
|
||||
let a = document.createElement('a')
|
||||
document.body.appendChild(a)
|
||||
a.style = 'display: none'
|
||||
a.href = file
|
||||
a.download = this.file.fileName
|
||||
a.click()
|
||||
window.URL.revokeObjectURL(file)
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -53,7 +53,9 @@ exports.init = async ( app, options ) => {
|
||||
if ( process.env.DISABLE_FILE_UPLOADS ) {
|
||||
return res.status( 503 ).send( 'File uploads are disabled on this server' )
|
||||
}
|
||||
|
||||
let fileInfo = await getFileInfo( { fileId: req.params.fileId } )
|
||||
|
||||
if ( !fileInfo )
|
||||
return res.status( 404 ).send( 'File not found' )
|
||||
|
||||
@@ -85,7 +87,7 @@ exports.init = async ( app, options ) => {
|
||||
|
||||
let fileStream = await getFileStream( { fileId: req.params.fileId } )
|
||||
|
||||
res.writeHead( 200, { 'Content-Type': 'application/octet-stream', 'Content-Disposition': 'attachment' } )
|
||||
res.writeHead( 200, { 'Content-Type': 'application/octet-stream', 'Content-Disposition': `attachment; filename="${fileInfo.fileName}"`, } )
|
||||
|
||||
fileStream.pipe( res )
|
||||
} ),
|
||||
|
||||
@@ -21,10 +21,9 @@ async function contextApiTokenHelper( { req, res, connection } ) {
|
||||
|
||||
if ( connection && connection.context.token ) { // Websockets (subscriptions)
|
||||
token = connection.context.token
|
||||
} else if ( req && req.headers.authorization ) { // Standard http
|
||||
} else if ( req && req.headers.authorization ) { // Standard http post
|
||||
token = req.headers.authorization
|
||||
}
|
||||
|
||||
}
|
||||
if ( token && token.includes( 'Bearer ' ) ) {
|
||||
token = token.split( ' ' )[ 1 ]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user