mirror of
https://github.com/filebrowser/filebrowser.git
synced 2025-05-08 19:22:57 +00:00

Former-commit-id: e4f0afef51c437bd55c58f12f2f45ce8e8c84bb0 [formerly 549235edf9d6c43d1454a8a00d7b6f832bb8a3ca] [formerly 12d099aa44bff7d995b05680e405d8040f1e1850 [formerly fc9ca4f6a4eb9a9ed89e35c413158e801a18e25e]] Former-commit-id: e9666db20e2b473095f21c03d59f2a8fbf07929e [formerly 87ee9eb83daed5180c6a3714c0ddc861668d747b] Former-commit-id: 5a15b05320c1eb28324e50cad7ca980d3eebcb02
140 lines
3.9 KiB
Vue
140 lines
3.9 KiB
Vue
<template>
|
|
<div id="previewer">
|
|
<div class="bar">
|
|
<button @click="back" class="action" :title="$t('files.closePreview')" :aria-label="$t('files.closePreview')" id="close">
|
|
<i class="material-icons">close</i>
|
|
</button>
|
|
|
|
<rename-button v-if="allowEdit()"></rename-button>
|
|
<delete-button v-if="allowEdit()"></delete-button>
|
|
<download-button></download-button>
|
|
<info-button></info-button>
|
|
</div>
|
|
|
|
<button class="action" @click="prev" v-show="hasPrevious" :aria-label="$t('buttons.previous')" :title="$t('buttons.previous')">
|
|
<i class="material-icons">chevron_left</i>
|
|
</button>
|
|
<button class="action" @click="next" v-show="hasNext" :aria-label="$t('buttons.next')" :title="$t('buttons.next')">
|
|
<i class="material-icons">chevron_right</i>
|
|
</button>
|
|
|
|
<div class="preview">
|
|
<img v-if="req.type == 'image'" :src="raw()">
|
|
<audio v-else-if="req.type == 'audio'" :src="raw()" controls></audio>
|
|
<video v-else-if="req.type == 'video'" :src="raw()" controls>
|
|
Sorry, your browser doesn't support embedded videos,
|
|
but don't worry, you can <a :href="download()">download it</a>
|
|
and watch it with your favorite video player!
|
|
</video>
|
|
<object v-else-if="req.extension == '.pdf'" class="pdf" :data="raw()"></object>
|
|
<a v-else-if="req.type == 'blob'" :href="download()">
|
|
<h2 class="message">{{ $t('buttons.download') }} <i class="material-icons">file_download</i></h2>
|
|
</a>
|
|
<pre v-else >{{ req.content }}</pre>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
import { mapState } from 'vuex'
|
|
import url from '@/utils/url'
|
|
import * as api from '@/utils/api'
|
|
import InfoButton from '@/components/buttons/Info'
|
|
import DeleteButton from '@/components/buttons/Delete'
|
|
import RenameButton from '@/components/buttons/Rename'
|
|
import DownloadButton from '@/components/buttons/Download'
|
|
|
|
export default {
|
|
name: 'preview',
|
|
components: {
|
|
InfoButton,
|
|
DeleteButton,
|
|
RenameButton,
|
|
DownloadButton
|
|
},
|
|
data: function () {
|
|
return {
|
|
previousLink: '',
|
|
nextLink: '',
|
|
listing: null
|
|
}
|
|
},
|
|
computed: {
|
|
...mapState(['req', 'oldReq']),
|
|
hasPrevious () {
|
|
return (this.previousLink !== '')
|
|
},
|
|
hasNext () {
|
|
return (this.nextLink !== '')
|
|
}
|
|
},
|
|
mounted () {
|
|
window.addEventListener('keyup', this.key)
|
|
api.fetch(url.removeLastDir(this.$route.path))
|
|
.then(req => {
|
|
this.listing = req
|
|
this.updateLinks()
|
|
})
|
|
.catch(this.$showError)
|
|
},
|
|
beforeDestroy () {
|
|
window.removeEventListener('keyup', this.key)
|
|
},
|
|
methods: {
|
|
download () {
|
|
let url = `${this.$store.state.baseURL}/api/download`
|
|
url += this.req.url.slice(6)
|
|
|
|
return url
|
|
},
|
|
raw () {
|
|
return `${this.download()}?&inline=true`
|
|
},
|
|
back (event) {
|
|
let uri = url.removeLastDir(this.$route.path) + '/'
|
|
this.$router.push({ path: uri })
|
|
},
|
|
prev () {
|
|
this.$router.push({ path: this.previousLink })
|
|
},
|
|
next () {
|
|
this.$router.push({ path: this.nextLink })
|
|
},
|
|
key (event) {
|
|
event.preventDefault()
|
|
|
|
if (event.which === 13 || event.which === 39) { // right arrow
|
|
if (this.hasNext) this.next()
|
|
} else if (event.which === 37) { // left arrow
|
|
if (this.hasPrevious) this.prev()
|
|
}
|
|
},
|
|
updateLinks () {
|
|
let pos = null
|
|
|
|
for (let i = 0; i < this.listing.items.length; i++) {
|
|
if (this.listing.items[i].name === this.req.name) {
|
|
pos = i
|
|
break
|
|
}
|
|
}
|
|
|
|
if (pos === null) {
|
|
return
|
|
}
|
|
|
|
if (pos !== 0) {
|
|
this.previousLink = this.listing.items[pos - 1].url
|
|
}
|
|
|
|
if (pos !== this.listing.items.length - 1) {
|
|
this.nextLink = this.listing.items[pos + 1].url
|
|
}
|
|
},
|
|
allowEdit (event) {
|
|
return this.$store.state.user.allowEdit
|
|
}
|
|
}
|
|
}
|
|
</script>
|