Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

download shared subdirectory #1184

Merged
merged 20 commits into from
Dec 28, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions frontend/src/api/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ export async function put (url, content = '') {
}

export function download (format, ...files) {
let url = `${baseURL}/api/raw`
const isSharing = store.getters['isSharing']
let url = isSharing ? `${baseURL}/api/public/dl/${store.state.shared.hash}` : `${baseURL}/api/raw`

if (files.length === 1) {
url += removePrefix(files[0]) + '?'
Expand All @@ -78,7 +79,9 @@ export function download (format, ...files) {
url += `algo=${format}&`
}

url += `auth=${store.state.jwt}`
if (!isSharing) {
url += `auth=${store.state.jwt}`
}
window.open(url)
}

Expand Down
2 changes: 2 additions & 0 deletions frontend/src/api/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export async function fetchJSON (url, opts) {
export function removePrefix (url) {
if (url.startsWith('/files')) {
url = url.slice(6)
} else if (store.getters['isSharing']) {
url = url.slice(7 + store.state.shared.hash.length)
}

if (url === '') url = '/'
Expand Down
26 changes: 22 additions & 4 deletions frontend/src/components/Header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</div>

<!-- This buttons are shown on a dropdown on mobile phones -->
<div id="dropdown" :class="{ active: showMore }">
<div class="dropdown" :class="{ active: showMore }">
<div v-if="!isListing || !isMobile">
<share-button v-show="showShareButton"></share-button>
<rename-button v-show="showRenameButton"></rename-button>
Expand All @@ -49,6 +49,17 @@
</button>
</div>
</template>
<template v-if="isSharing">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of creating a whole new dropdown, lets use the v-show directive on the wanted elements.

<!-- This buttons are shown on a dropdown on mobile phones -->
<div class="dropdown" :class="{ active: showMore }">
<download-button v-if="sharedSelectedCount > 0"></download-button>

<button @click="toggleSharedMultipleSelection" :aria-label="$t('buttons.selectMultiple')" :title="$t('buttons.selectMultiple')" class="action" >
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we reuse the existing selection toggle and download buttons?

<i class="material-icons">check_circle</i>
<span>{{ $t('buttons.select') }}</span>
</button>
</div>
</template>

<div v-show="showOverlay" @click="resetPrompts" class="overlay"></div>
</div>
Expand Down Expand Up @@ -110,14 +121,17 @@ export default {
'isEditor',
'isPreview',
'isListing',
'isLogged'
'isLogged',
'isSharing',
'sharedSelectedCount'
]),
...mapState([
'req',
'user',
'loading',
'reload',
'multiple'
'multiple',
'shared'
]),
logoURL: () => logoURL,
isExecEnabled: () => enableExec,
Expand Down Expand Up @@ -156,7 +170,7 @@ export default {
: this.user.perm.create)
},
showMore () {
return this.isFiles && this.$store.state.show === 'more'
return (this.isFiles || this.isSharing) && this.$store.state.show === 'more'
},
showOverlay () {
return this.showMore
Expand All @@ -176,6 +190,10 @@ export default {
this.$store.commit('multiple', !this.multiple)
this.resetPrompts()
},
toggleSharedMultipleSelection () {
this.$store.commit('sharedMultiple', !this.shared.multiple)
this.resetPrompts()
},
resetPrompts () {
this.$store.commit('closeHovers')
}
Expand Down
12 changes: 9 additions & 3 deletions frontend/src/components/buttons/Download.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<i class="material-icons">file_download</i>
<span>{{ $t('buttons.download') }}</span>
<span v-if="selectedCount > 0" class="counter">{{ selectedCount }}</span>
<span v-else-if="isSharing && sharedSelectedCount > 0" class="counter">{{ sharedSelectedCount }}</span>
</button>
</template>

Expand All @@ -13,12 +14,12 @@ import { files as api } from '@/api'
export default {
name: 'download-button',
computed: {
...mapState(['req', 'selected']),
...mapGetters(['isListing', 'selectedCount'])
...mapState(['req', 'selected', 'shared']),
...mapGetters(['isListing', 'selectedCount', 'isSharing', 'sharedSelectedCount'])
},
methods: {
download: function () {
if (!this.isListing) {
if (!this.isListing && !this.isSharing) {
api.download(null, this.$route.path)
return
}
Expand All @@ -28,6 +29,11 @@ export default {
return
}

if (this.sharedSelectedCount === 1 && !this.shared.req.items[this.shared.selected[0]].isDir) {
api.download(null, this.shared.req.items[this.shared.selected[0]].url)
return
}

this.$store.commit('showHover', 'download')
}
}
Expand Down
14 changes: 11 additions & 3 deletions frontend/src/components/prompts/Download.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,20 @@ import { files as api } from '@/api'
export default {
name: 'download',
computed: {
...mapState(['selected', 'req']),
...mapGetters(['selectedCount'])
...mapState(['selected', 'req', 'shared']),
...mapGetters(['selectedCount', 'isSharing' ,'sharedSelectedCount'])
},
methods: {
download: function (format) {
if (this.selectedCount === 0) {
if (this.isSharing) {
let files = []

for (let i of this.shared.selected) {
files.push(this.shared.req.items[i].url)
}

api.download(format, ...files)
} else if (this.selectedCount === 0) {
api.download(format, this.$route.path)
} else {
let files = []
Expand Down
12 changes: 6 additions & 6 deletions frontend/src/css/mobile.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
height: 100%;
background-color: rgba(0, 0, 0, 0.1);
}
#dropdown {
.dropdown {
position: fixed;
top: 1em;
right: 1em;
Expand All @@ -40,23 +40,23 @@
transform-origin: top right;
z-index: 99999;
}
#dropdown > div {
.dropdown > div {
display: block;
}
#dropdown.active {
.dropdown.active {
transform: scale(1);
}
#dropdown .action {
.dropdown .action {
display: flex;
align-items: center;
border-radius: 0;
width: 100%;
}
#dropdown .action span:not(.counter) {
.dropdown .action span:not(.counter) {
display: inline-block;
padding: .4em;
}
#dropdown .counter {
.dropdown .counter {
left: 2.25em;
}
#file-selection {
Expand Down
1 change: 1 addition & 0 deletions frontend/src/store/getters.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const getters = {
isListing: (state, getters) => getters.isFiles && state.req.isDir,
isEditor: (state, getters) => getters.isFiles && (state.req.type === 'text' || state.req.type === 'textImmutable'),
isPreview: state => state.previewMode,
isSharing: state => state.shared.loaded && state.route.name === 'Share',
selectedCount: state => state.selected.length,
progress : state => {
if (state.upload.progress.length == 0) {
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ const state = {
showConfirm: null,
previewMode: false,
shared: {
req: {},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can reuse the current existing state properties. Also you can make the hash work as a getter using only the req state.

hash: '',
loaded: false,
selected: [],
multiple: false
}
Expand Down
13 changes: 10 additions & 3 deletions frontend/src/store/mutations.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ const mutations = {
state.show = 'success'
state.showMessage = value
},
setLoading: (state, value) => { state.loading = value },
setReload: (state, value) => { state.reload = value },
setLoading: (state, value) => {
state.loading = value
},
setReload: (state, value) => {
state.reload = value
},
setUser: (state, value) => {
if (value === null) {
state.user = null
Expand Down Expand Up @@ -96,7 +100,10 @@ const mutations = {
resetSharedSelected: (state) => {
state.shared.selected = []
},
sharedMultiple: (state, value) => (state.shared.multiple = value)
sharedMultiple: (state, value) => (state.shared.multiple = value),
updateSharedRequest: (state, value) => (state.shared.req = value),
setSharedHash: (state, value) => (state.shared.hash = value),
toggleSharedLoaded: (state, value) => (state.shared.loaded = value)
}

export default mutations