Download centralized on api.js
parent
fc71509dd0
commit
c6348931e0
|
@ -1,5 +1,5 @@
|
||||||
<template>
|
<template>
|
||||||
<nav>
|
<nav :class="{active}">
|
||||||
<router-link class="action" to="/files/" aria-label="My Files" title="My Files">
|
<router-link class="action" to="/files/" aria-label="My Files" title="My Files">
|
||||||
<i class="material-icons">folder</i>
|
<i class="material-icons">folder</i>
|
||||||
<span>My Files</span>
|
<span>My Files</span>
|
||||||
|
@ -48,7 +48,8 @@ export default {
|
||||||
name: 'sidebar',
|
name: 'sidebar',
|
||||||
data: () => {
|
data: () => {
|
||||||
return {
|
return {
|
||||||
plugins: []
|
plugins: [],
|
||||||
|
active: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: mapState(['user']),
|
computed: mapState(['user']),
|
||||||
|
|
|
@ -8,20 +8,23 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import {mapGetters, mapState} from 'vuex'
|
import {mapGetters, mapState} from 'vuex'
|
||||||
|
import api from '@/utils/api'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'download-button',
|
name: 'download-button',
|
||||||
computed: {
|
computed: {
|
||||||
...mapState(['req']),
|
...mapState(['req', 'selected']),
|
||||||
...mapGetters(['selectedCount'])
|
...mapGetters(['selectedCount'])
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
download: function (event) {
|
download: function (event) {
|
||||||
if (this.req.kind !== 'listing') {
|
if (this.req.kind !== 'listing') {
|
||||||
let url = this.$route.params[0]
|
api.download(null, this.$route.path)
|
||||||
url = this.$store.state.baseURL + '/api/download/' + url
|
return
|
||||||
url += '?token=' + this.$store.state.jwt
|
}
|
||||||
window.open(url)
|
|
||||||
|
if (this.selectedCount === 1) {
|
||||||
|
api.download(null, this.req.items[this.selected[0]].url)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import {mapGetters, mapState} from 'vuex'
|
import {mapGetters, mapState} from 'vuex'
|
||||||
|
import api from '@/utils/api'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'download',
|
name: 'download',
|
||||||
|
@ -21,24 +22,18 @@ export default {
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
download: function (format) {
|
download: function (format) {
|
||||||
let uri = this.$route.params[0]
|
if (this.selectedCount === 0) {
|
||||||
uri = this.$store.state.baseURL + '/api/download/' + uri
|
api.download(format, this.$route.path)
|
||||||
uri += `?token=${this.$store.state.jwt}`
|
} else {
|
||||||
uri += `&format=${format}`
|
let files = []
|
||||||
|
|
||||||
if (this.selectedCount > 0) {
|
|
||||||
let files = ''
|
|
||||||
|
|
||||||
for (let i of this.selected) {
|
for (let i of this.selected) {
|
||||||
files += this.req.items[i].url.replace(window.location.pathname, '') + ','
|
files.push(this.req.items[i].url)
|
||||||
}
|
}
|
||||||
|
|
||||||
files = files.substring(0, files.length - 1)
|
api.download(format, ...files)
|
||||||
files = encodeURIComponent(files)
|
|
||||||
uri += `&files=${files}`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
window.open(uri)
|
|
||||||
this.$store.commit('closePrompts')
|
this.$store.commit('closePrompts')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -122,6 +122,11 @@ main {
|
||||||
border-top: 1px solid rgba(0, 0, 0, 0.075);
|
border-top: 1px solid rgba(0, 0, 0, 0.075);
|
||||||
border-right: 1px solid rgba(0, 0, 0, 0.075);
|
border-right: 1px solid rgba(0, 0, 0, 0.075);
|
||||||
box-shadow: 0 5px 5px rgba(0, 0, 0, 0.1);
|
box-shadow: 0 5px 5px rgba(0, 0, 0, 0.1);
|
||||||
|
transition: .2s ease left;
|
||||||
|
left: -16em;
|
||||||
|
}
|
||||||
|
nav.active {
|
||||||
|
left: 0;
|
||||||
}
|
}
|
||||||
main {
|
main {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|
|
@ -141,6 +141,32 @@ function search (url, search, onmessage, onclose) {
|
||||||
conn.onclose = onclose
|
conn.onclose = onclose
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function download (format, ...files) {
|
||||||
|
let url = `${store.state.baseURL}/api/download`
|
||||||
|
|
||||||
|
if (files.length === 1) {
|
||||||
|
url += removePrefix(files[0]) + '?'
|
||||||
|
} else {
|
||||||
|
let arg = ''
|
||||||
|
|
||||||
|
for (let file of files) {
|
||||||
|
arg += removePrefix(file) + ','
|
||||||
|
}
|
||||||
|
|
||||||
|
arg = arg.substring(0, arg.length - 1)
|
||||||
|
arg = encodeURIComponent(arg)
|
||||||
|
url += `/?files=${arg}&`
|
||||||
|
}
|
||||||
|
|
||||||
|
url += `token=${store.state.jwt}`
|
||||||
|
|
||||||
|
if (format !== null) {
|
||||||
|
url += `&format=${format}`
|
||||||
|
}
|
||||||
|
|
||||||
|
window.open(url)
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
delete: rm,
|
delete: rm,
|
||||||
fetch,
|
fetch,
|
||||||
|
@ -148,5 +174,6 @@ export default {
|
||||||
move,
|
move,
|
||||||
put,
|
put,
|
||||||
command,
|
command,
|
||||||
search
|
search,
|
||||||
|
download
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue