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