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’ll 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 15 commits
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
112 changes: 112 additions & 0 deletions frontend/src/components/files/SharedItem.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<template>
<div class="item"
role="button"
tabindex="0"
@click="click"
@dblclick="dblclick"
@touchstart="touchstart"
:data-dir="isDir"
:aria-label="name"
:aria-selected="isSelected">
<div>
<i class="material-icons">{{ icon }}</i>
</div>

<div>
<p class="name">{{ name }}</p>

<p v-if="isDir" class="size" data-order="-1">&mdash;</p>
<p v-else class="size" :data-order="humanSize()">{{ humanSize() }}</p>

<p class="modified">
<time :datetime="modified">{{ humanTime() }}</time>
</p>
</div>
</div>
</template>

<script>
import { mapMutations, mapGetters, mapState } from 'vuex'
import filesize from 'filesize'
import moment from 'moment'

export default {
name: 'sharedItem',
data: function () {
return {
touches: 0
}
},
props: ['name', 'isDir', 'url', 'type', 'size', 'modified', 'index'],
computed: {
...mapState(['shared']),
...mapGetters(['sharedSelectedCount']),
isSelected () {
return (this.shared.selected.indexOf(this.index) !== -1)
},
icon () {
if (this.isDir) return 'folder'
if (this.type === 'image') return 'insert_photo'
if (this.type === 'audio') return 'volume_up'
if (this.type === 'video') return 'movie'
return 'insert_drive_file'
}
},
methods: {
...mapMutations(['addSharedSelected', 'removeSharedSelected', 'resetSharedSelected']),
humanSize: function () {
return filesize(this.size)
},
humanTime: function () {
return moment(this.modified).fromNow()
},
click: function (event) {
if (this.sharedSelectedCount !== 0) event.preventDefault()
if (this.$store.state.shared.selected.indexOf(this.index) !== -1) {
this.removeSharedSelected(this.index)
return
}

if (event.shiftKey && this.shared.selected.length > 0) {
let fi = 0
let la = 0

if (this.index > this.shared.selected[0]) {
fi = this.shared.selected[0] + 1
la = this.index
} else {
fi = this.index
la = this.shared.selected[0] - 1
}

for (; fi <= la; fi++) {
if (this.$store.state.shared.selected.indexOf(fi) == -1) {
this.addSharedSelected(fi)
}
}

return
}

if (!event.ctrlKey && !event.metaKey && !this.$store.state.shared.multiple) this.resetSharedSelected()
this.addSharedSelected(this.index)
},
dblclick: function () {
this.open()
},
touchstart () {
setTimeout(() => {
this.touches = 0
}, 300)

this.touches++
if (this.touches > 1) {
this.open()
}
},
open: function () {
this.$router.push({path: this.url})
}
}
}
</script>
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
14 changes: 12 additions & 2 deletions frontend/src/css/_share.css
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,23 @@
}

.share__box__items #listing.list .item {
cursor: auto;
cursor: pointer;
border-left: 0;
border-right: 0;
border-bottom: 0;
border-top: 1px solid rgba(0, 0, 0, 0.1);
-webkit-user-select:none;
-khtml-user-select:none;
-moz-user-select:none;
-ms-user-select:none;
-o-user-select:none;
user-select:none;
}

.share__box__items #listing.list .item .name {
width: auto;
width: 50%;
}

.share__box__items #listing.list .item .modified {
width: 25%;
}
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
3 changes: 2 additions & 1 deletion frontend/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@
},
"download": {
"downloadFile": "Download File",
"downloadFolder": "Download Folder"
"downloadFolder": "Download Folder",
"downloadSelected": "Download Selected"
}
}
3 changes: 2 additions & 1 deletion frontend/src/i18n/zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@
},
"download": {
"downloadFile": "下载文件",
"downloadFolder": "下载文件夹"
"downloadFolder": "下载文件夹",
"downloadSelected": "下载已选"
}
}
4 changes: 3 additions & 1 deletion 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 All @@ -12,7 +13,8 @@ const getters = {

let sum = state.upload.progress.reduce((acc, val) => acc + val)
return Math.ceil(sum / state.upload.size * 100);
}
},
sharedSelectedCount: state => state.shared.selected.length
}

export default getters
9 changes: 8 additions & 1 deletion frontend/src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ const state = {
showShell: false,
showMessage: null,
showConfirm: null,
previewMode: false
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
}
}

export default new Vuex.Store({
Expand Down