Basic file preview

This commit is contained in:
Milos Stojanovic
2020-02-20 14:03:51 +01:00
parent 37dbc2b76b
commit b8f7d000fb
6 changed files with 107 additions and 10 deletions

View File

@@ -0,0 +1,65 @@
/* eslint-disable */
<template>
<div class="modal-card">
<header class="modal-card-head">
<p class="modal-card-title">
{{ item.name }}
</p>
</header>
<section class="modal-card-body preview">
<textarea v-if="isText()" v-model="content" class="textarea" name="content" rows="20" />
<div v-if="isImage()" class="image">
<img :src="content">
</div>
</section>
<footer class="modal-card-foot">
<button class="button" type="button" @click="$parent.close()">
{{ lang('Close') }}
</button>
</footer>
</div>
</template>
<script>
import api from '../../api/api'
export default {
name: 'Preview',
props: [ 'item' ],
data() {
return {
content: '',
}
},
mounted() {
if (this.isText()) {
api.downloadItem({
path: this.item.path,
})
.then((res) => {
this.content = res
})
.catch(error => this.handleError(error))
} else if (this.isImage()) {
this.content =this.getDownloadLink(this.item.path)
}
},
methods: {
isText() {
return this.hasExtension(['.txt', '.html', '.css', '.js', '.ts', '.php'])
},
isImage() {
return this.hasExtension(['.jpg', '.jpeg', '.gif', '.png'])
},
hasExtension(exts) {
return (new RegExp('(' + exts.join('|').replace(/\./g, '\\.') + ')$', 'i')).test(this.item.path)
},
},
}
</script>
<style scoped>
.preview {
min-height: 450px;
}
</style>