@@ -35,12 +28,14 @@ import 'ace-builds/webpack-resolver'
import HeaderBar from '@/components/header/HeaderBar'
import Action from '@/components/header/Action'
+import Breadcrumbs from '@/components/Breadcrumbs'
export default {
name: 'editor',
components: {
HeaderBar,
- Action
+ Action,
+ Breadcrumbs
},
data: function () {
return {}
From edb9e85efd7664f805fc4e6688419b74b9d725cf Mon Sep 17 00:00:00 2001
From: Ramires Viana <59319979+ramiresviana@users.noreply.github.com>
Date: Wed, 3 Mar 2021 17:46:37 +0000
Subject: [PATCH 11/12] chore: share view logic responsability
---
frontend/src/api/files.js | 10 ++---
frontend/src/api/index.js | 2 +
frontend/src/api/pub.js | 37 ++++++++++++++++
frontend/src/api/share.js | 6 ---
frontend/src/api/utils.js | 6 +--
frontend/src/components/files/ListingItem.vue | 15 ++++---
frontend/src/components/prompts/Download.vue | 42 +++++++------------
frontend/src/store/getters.js | 1 -
frontend/src/store/index.js | 5 +--
frontend/src/store/mutations.js | 16 ++-----
frontend/src/views/Share.vue | 35 +++++++++++-----
frontend/src/views/files/Listing.vue | 18 +++++++-
12 files changed, 113 insertions(+), 80 deletions(-)
create mode 100644 frontend/src/api/pub.js
diff --git a/frontend/src/api/files.js b/frontend/src/api/files.js
index bada7c7c..89d21a54 100644
--- a/frontend/src/api/files.js
+++ b/frontend/src/api/files.js
@@ -58,7 +58,7 @@ export async function put (url, content = '') {
}
export function download (format, ...files) {
- let url = store.getters['isSharing'] ? `${baseURL}/api/public/dl/${store.state.hash}` : `${baseURL}/api/raw`
+ let url = `${baseURL}/api/raw`
if (files.length === 1) {
url += removePrefix(files[0]) + '?'
@@ -74,15 +74,13 @@ export function download (format, ...files) {
url += `/?files=${arg}&`
}
- if (format !== null) {
+ if (format) {
url += `algo=${format}&`
}
- if (store.state.jwt !== ''){
+
+ if (store.state.jwt){
url += `auth=${store.state.jwt}&`
}
- if (store.state.token !== ''){
- url += `token=${store.state.token}`
- }
window.open(url)
}
diff --git a/frontend/src/api/index.js b/frontend/src/api/index.js
index 11bb49d9..5dd59ae7 100644
--- a/frontend/src/api/index.js
+++ b/frontend/src/api/index.js
@@ -2,6 +2,7 @@ import * as files from './files'
import * as share from './share'
import * as users from './users'
import * as settings from './settings'
+import * as pub from './pub'
import search from './search'
import commands from './commands'
@@ -10,6 +11,7 @@ export {
share,
users,
settings,
+ pub,
commands,
search
}
diff --git a/frontend/src/api/pub.js b/frontend/src/api/pub.js
new file mode 100644
index 00000000..5afd0913
--- /dev/null
+++ b/frontend/src/api/pub.js
@@ -0,0 +1,37 @@
+import { fetchJSON, removePrefix } from './utils'
+import { baseURL } from '@/utils/constants'
+
+export async function fetch(hash, password = "") {
+ return fetchJSON(`/api/public/share/${hash}`, {
+ headers: {'X-SHARE-PASSWORD': password},
+ })
+}
+
+export function download(format, hash, token, ...files) {
+ let url = `${baseURL}/api/public/dl/${hash}`
+
+ const prefix = `/share/${hash}`
+ if (files.length === 1) {
+ url += removePrefix(files[0], prefix) + '?'
+ } else {
+ let arg = ''
+
+ for (let file of files) {
+ arg += removePrefix(file, prefix) + ','
+ }
+
+ arg = arg.substring(0, arg.length - 1)
+ arg = encodeURIComponent(arg)
+ url += `/?files=${arg}&`
+ }
+
+ if (format) {
+ url += `algo=${format}&`
+ }
+
+ if (token) {
+ url += `token=${token}&`
+ }
+
+ window.open(url)
+}
\ No newline at end of file
diff --git a/frontend/src/api/share.js b/frontend/src/api/share.js
index 4e6c40db..fbeecd70 100644
--- a/frontend/src/api/share.js
+++ b/frontend/src/api/share.js
@@ -4,12 +4,6 @@ export async function list() {
return fetchJSON('/api/shares')
}
-export async function getHash(hash, password = "") {
- return fetchJSON(`/api/public/share/${hash}`, {
- headers: {'X-SHARE-PASSWORD': password},
- })
-}
-
export async function get(url) {
url = removePrefix(url)
return fetchJSON(`/api/share${url}`)
diff --git a/frontend/src/api/utils.js b/frontend/src/api/utils.js
index 68337d10..ffe7844c 100644
--- a/frontend/src/api/utils.js
+++ b/frontend/src/api/utils.js
@@ -33,11 +33,11 @@ export async function fetchJSON (url, opts) {
}
}
-export function removePrefix (url) {
+export function removePrefix (url, prefix) {
if (url.startsWith('/files')) {
url = url.slice(6)
- } else if (store.getters['isSharing']) {
- url = url.slice(7 + store.state.hash.length)
+ } else if (prefix) {
+ url = url.replace(prefix, '')
}
if (url === '') url = '/'
diff --git a/frontend/src/components/files/ListingItem.vue b/frontend/src/components/files/ListingItem.vue
index 596ce736..8f4bb8ba 100644
--- a/frontend/src/components/files/ListingItem.vue
+++ b/frontend/src/components/files/ListingItem.vue
@@ -13,7 +13,7 @@
:aria-label="name"
:aria-selected="isSelected">
-
+
{{ icon }}
@@ -45,13 +45,12 @@ export default {
touches: 0
}
},
- props: ['name', 'isDir', 'url', 'type', 'size', 'modified', 'index'],
+ props: ['name', 'isDir', 'url', 'type', 'size', 'modified', 'index', 'readOnly'],
computed: {
...mapState(['user', 'selected', 'req', 'jwt']),
- ...mapGetters(['selectedCount', 'isSharing']),
+ ...mapGetters(['selectedCount']),
singleClick () {
- if (this.isSharing) return false
- return this.user.singleClick
+ return this.readOnly == undefined && this.user.singleClick
},
isSelected () {
return (this.selected.indexOf(this.index) !== -1)
@@ -64,10 +63,10 @@ export default {
return 'insert_drive_file'
},
isDraggable () {
- return !this.isSharing && this.user.perm.rename
+ return this.readOnly == undefined && this.user.perm.rename
},
canDrop () {
- if (!this.isDir || this.isSharing) return false
+ if (!this.isDir || this.readOnly == undefined) return false
for (let i of this.selected) {
if (this.req.items[i].url === this.url) {
@@ -139,7 +138,7 @@ export default {
to: this.url + this.req.items[i].name,
name: this.req.items[i].name
})
- }
+ }
let base = el.querySelector('.name').innerHTML + '/'
let path = this.$route.path + base
diff --git a/frontend/src/components/prompts/Download.vue b/frontend/src/components/prompts/Download.vue
index fa129590..743bfd41 100644
--- a/frontend/src/components/prompts/Download.vue
+++ b/frontend/src/components/prompts/Download.vue
@@ -7,43 +7,29 @@
{{ $t('prompts.downloadMessage') }}
-
-
-
-
-
-
-
+
diff --git a/frontend/src/store/getters.js b/frontend/src/store/getters.js
index 72e6db8d..0c466f9d 100644
--- a/frontend/src/store/getters.js
+++ b/frontend/src/store/getters.js
@@ -2,7 +2,6 @@ const getters = {
isLogged: state => state.user !== null,
isFiles: state => !state.loading && state.route.name === 'Files',
isListing: (state, getters) => getters.isFiles && state.req.isDir,
- isSharing: state => !state.loading && state.route.name === 'Share',
selectedCount: state => state.selected.length,
progress : state => {
if (state.upload.progress.length == 0) {
diff --git a/frontend/src/store/index.js b/frontend/src/store/index.js
index 118b84ee..937f4266 100644
--- a/frontend/src/store/index.js
+++ b/frontend/src/store/index.js
@@ -22,10 +22,7 @@ const state = {
multiple: false,
show: null,
showShell: false,
- showMessage: null,
- showConfirm: null,
- hash: '',
- token: ''
+ showConfirm: null
}
export default new Vuex.Store({
diff --git a/frontend/src/store/mutations.js b/frontend/src/store/mutations.js
index 963c3780..9e3d98d1 100644
--- a/frontend/src/store/mutations.js
+++ b/frontend/src/store/mutations.js
@@ -4,7 +4,7 @@ import moment from 'moment'
const mutations = {
closeHovers: state => {
state.show = null
- state.showMessage = null
+ state.showConfirm = null
},
toggleShell: (state) => {
state.showShell = !state.showShell
@@ -16,16 +16,13 @@ const mutations = {
}
state.show = value.prompt
- state.showMessage = value.message
state.showConfirm = value.confirm
},
- showError: (state, value) => {
+ showError: (state) => {
state.show = 'error'
- state.showMessage = value
},
- showSuccess: (state, value) => {
+ showSuccess: (state) => {
state.show = 'success'
- state.showMessage = value
},
setLoading: (state, value) => { state.loading = value },
setReload: (state, value) => { state.reload = value },
@@ -46,12 +43,8 @@ const mutations = {
state.user = value
},
setJWT: (state, value) => (state.jwt = value),
- setToken: (state, value ) => (state.token = value),
multiple: (state, value) => (state.multiple = value),
addSelected: (state, value) => (state.selected.push(value)),
- addPlugin: (state, value) => {
- state.plugins.push(value)
- },
removeSelected: (state, value) => {
let i = state.selected.indexOf(value)
if (i === -1) return
@@ -84,8 +77,7 @@ const mutations = {
resetClipboard: (state) => {
state.clipboard.key = ''
state.clipboard.items = []
- },
- setHash: (state, value) => (state.hash = value),
+ }
}
export default mutations
diff --git a/frontend/src/views/Share.vue b/frontend/src/views/Share.vue
index 3de84b0d..e3897fad 100644
--- a/frontend/src/views/Share.vue
+++ b/frontend/src/views/Share.vue
@@ -47,7 +47,8 @@
v-bind:url="item.url"
v-bind:modified="item.modified"
v-bind:type="item.type"
- v-bind:size="item.size">
+ v-bind:size="item.size"
+ readOnly>