mirror of
https://github.com/filegator/filegator.git
synced 2025-08-12 17:44:26 +02:00
refactoring
This commit is contained in:
@@ -122,6 +122,18 @@ const funcs = {
|
||||
getDownloadLink(path) {
|
||||
return Vue.config.baseURL+'/download&path='+encodeURIComponent(Base64.encode(path))
|
||||
},
|
||||
hasPreview(name) {
|
||||
return this.isText(name) || this.isImage(name)
|
||||
},
|
||||
isText(name) {
|
||||
return this.hasExtension(name, ['.txt', '.html', '.css', '.js', '.ts', '.php'])
|
||||
},
|
||||
isImage(name) {
|
||||
return this.hasExtension(name, ['.jpg', '.jpeg', '.gif', '.png'])
|
||||
},
|
||||
hasExtension(name, exts) {
|
||||
return (new RegExp('(' + exts.join('|').replace(/\./g, '\\.') + ')$', 'i')).test(name)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -113,7 +113,7 @@
|
||||
<b-dropdown-item v-if="props.row.type == 'file' && can('download')" aria-role="listitem" @click="download(props.row)">
|
||||
<b-icon icon="download" size="is-small" /> {{ lang('Download') }}
|
||||
</b-dropdown-item>
|
||||
<b-dropdown-item v-if="props.row.type == 'file' && can(['read', 'download'])" aria-role="listitem" @click="preview(props.row)">
|
||||
<b-dropdown-item v-if="props.row.type == 'file' && can(['download']) && hasPreview(props.row.path)" aria-role="listitem" @click="preview(props.row)">
|
||||
<b-icon icon="file-alt" size="is-small" /> {{ lang('View') }}
|
||||
</b-dropdown-item>
|
||||
<b-dropdown-item v-if="can('write')" aria-role="listitem" @click="copy($event, props.row)">
|
||||
@@ -252,8 +252,10 @@ export default {
|
||||
itemClick(item) {
|
||||
if (item.type == 'dir' || item.type == 'back') {
|
||||
this.goTo(item.path)
|
||||
} else if (this.can(['read', 'download'])) {
|
||||
} else if (this.can(['download']) && this.hasPreview(item.path)) {
|
||||
this.preview(item)
|
||||
} else if (this.can(['download'])) {
|
||||
this.download(item)
|
||||
}
|
||||
},
|
||||
selectDir() {
|
||||
|
@@ -7,13 +7,13 @@
|
||||
</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">
|
||||
<textarea v-if="isText(item.path)" v-model="content" class="textarea" name="content" rows="20" />
|
||||
<div v-if="isImage(item.path)" class="image">
|
||||
<img :src="content">
|
||||
</div>
|
||||
</section>
|
||||
<footer class="modal-card-foot">
|
||||
<button v-if="isText() && can(['write'])" class="button" type="button" @click="saveFile()">
|
||||
<button v-if="isText(item.path) && can(['write'])" class="button" type="button" @click="saveFile()">
|
||||
{{ lang('Save') }}
|
||||
</button>
|
||||
<button class="button" type="button" @click="$parent.close()">
|
||||
@@ -35,7 +35,7 @@ export default {
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
if (this.isText()) {
|
||||
if (this.isText(this.item.path)) {
|
||||
api.downloadItem({
|
||||
path: this.item.path,
|
||||
})
|
||||
@@ -43,20 +43,11 @@ export default {
|
||||
this.content = res
|
||||
})
|
||||
.catch(error => this.handleError(error))
|
||||
} else if (this.isImage()) {
|
||||
} else if (this.isImage(this.item.path)) {
|
||||
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)
|
||||
},
|
||||
saveFile() {
|
||||
api.saveContent({
|
||||
name: this.item.name,
|
||||
|
Reference in New Issue
Block a user