diff --git a/_assets/src/components/DeletePrompt.vue b/_assets/src/components/DeletePrompt.vue
index 97e581ea..55453d35 100644
--- a/_assets/src/components/DeletePrompt.vue
+++ b/_assets/src/components/DeletePrompt.vue
@@ -49,7 +49,7 @@ export default {
let promises = []
for (let index of this.selected) {
- promises.push(webdav.trash(this.req.data.items[index].url))
+ promises.push(webdav.trash(this.req.items[index].url))
}
Promise.all(promises)
diff --git a/_assets/src/components/DownloadPrompt.vue b/_assets/src/components/DownloadPrompt.vue
index d7db7eb5..5da0fb86 100644
--- a/_assets/src/components/DownloadPrompt.vue
+++ b/_assets/src/components/DownloadPrompt.vue
@@ -27,7 +27,7 @@ export default {
let files = ''
for (let i of this.selected) {
- files += this.req.data.items[i].url.replace(window.location.pathname, '') + ','
+ files += this.req.items[i].url.replace(window.location.pathname, '') + ','
}
files = files.substring(0, files.length - 1)
diff --git a/_assets/src/components/Editor.vue b/_assets/src/components/Editor.vue
index 5f893880..09009859 100644
--- a/_assets/src/components/Editor.vue
+++ b/_assets/src/components/Editor.vue
@@ -6,7 +6,7 @@
@@ -19,7 +19,7 @@ export default {
computed: {
...mapState(['req']),
hasMetadata: function () {
- return (this.req.data.metadata !== undefined && this.req.data.metadata !== null)
+ return (this.req.metadata !== undefined && this.req.metadata !== null)
}
},
data: function () {
diff --git a/_assets/src/components/InfoPrompt.vue b/_assets/src/components/InfoPrompt.vue
index 79884301..c8ce2b1c 100644
--- a/_assets/src/components/InfoPrompt.vue
+++ b/_assets/src/components/InfoPrompt.vue
@@ -9,8 +9,8 @@
Last Modified: {{ humanTime() }}
- Number of files: {{ req.data.numFiles }}
- Number of directories: {{ req.data.numDirs }}
+ Number of files: {{ req.numFiles }}
+ Number of directories: {{ req.numDirs }}
@@ -40,30 +40,30 @@ export default {
methods: {
humanSize: function () {
if (this.selectedCount === 0 || this.req.kind !== 'listing') {
- return filesize(this.req.data.size)
+ return filesize(this.req.size)
}
var sum = 0
for (let i = 0; i < this.selectedCount; i++) {
- sum += this.req.data.items[this.selected[i]].size
+ sum += this.req.items[this.selected[i]].size
}
return filesize(sum)
},
humanTime: function () {
if (this.selectedCount === 0) {
- return moment(this.req.data.modified).fromNow()
+ return moment(this.req.modified).fromNow()
}
- return moment(this.req.data.items[this.selected[0]]).fromNow()
+ return moment(this.req.items[this.selected[0]]).fromNow()
},
name: function () {
if (this.selectedCount === 0) {
- return this.req.data.name
+ return this.req.name
}
- return this.req.data.items[this.selected[0]].name
+ return this.req.items[this.selected[0]].name
},
dir: function () {
if (this.selectedCount > 1) {
@@ -72,10 +72,10 @@ export default {
}
if (this.selectedCount === 0) {
- return this.req.data.isDir
+ return this.req.isDir
}
- return this.req.data.items[this.selected[0]].isDir
+ return this.req.items[this.selected[0]].isDir
},
checksum: function (event, hash) {
event.preventDefault()
@@ -84,7 +84,7 @@ export default {
let link
if (this.selectedCount) {
- link = this.req.data.items[this.selected[0]].url
+ link = this.req.items[this.selected[0]].url
} else {
link = window.location.pathname
}
diff --git a/_assets/src/components/Listing.vue b/_assets/src/components/Listing.vue
index 8b08a6cb..ce37f556 100644
--- a/_assets/src/components/Listing.vue
+++ b/_assets/src/components/Listing.vue
@@ -1,6 +1,6 @@
@@ -8,13 +8,13 @@
-
It feels lonely here :'(
+
It feels lonely here :'(
-
Folders
-
-
- Folders
+
+ -
- Files
-
-
- Files
+
+ - {
+ next()
+ })
+ .catch(error => {
+ // TODO: 404, 403 and 500!
+ console.log(error)
+ window.alert('Something went wrong. Please reload.')
+ })
+ },
+ beforeRouteUpdate (to, from, next) {
+ console.log('hey')
+ },
+ mounted () {
updateColumnSizes()
window.addEventListener('resize', updateColumnSizes)
@@ -157,7 +172,7 @@ export default {
this.plugins = window.plugins
}
- document.title = this.req.data.name
+ document.title = this.req.name
window.history.replaceState({
url: window.location.pathname,
name: document.title
diff --git a/_assets/src/components/MovePrompt.vue b/_assets/src/components/MovePrompt.vue
index 72313067..c8003658 100644
--- a/_assets/src/components/MovePrompt.vue
+++ b/_assets/src/components/MovePrompt.vue
@@ -39,7 +39,7 @@ export default {
}
if (this.req.kind === 'listing') {
- for (let item of this.req.data.items) {
+ for (let item of this.req.items) {
if (!item.isDir) continue
this.items.push({
@@ -66,8 +66,8 @@ export default {
}
for (let item of this.selected) {
- let from = this.req.data.items[item].url
- let to = dest + '/' + encodeURIComponent(this.req.data.items[item].name)
+ let from = this.req.items[item].url
+ let to = dest + '/' + encodeURIComponent(this.req.items[item].name)
to = to.replace('//', '/')
promises.push(webdav.move(from, to))
@@ -100,7 +100,7 @@ export default {
}
let req = JSON.parse(data)
- for (let item of req.data.items) {
+ for (let item of req.items) {
if (!item.isDir) continue
this.items.push({
diff --git a/_assets/src/components/Preview.vue b/_assets/src/components/Preview.vue
index 653e4167..deb5b0be 100644
--- a/_assets/src/components/Preview.vue
+++ b/_assets/src/components/Preview.vue
@@ -12,18 +12,18 @@
-
-
-
@@ -47,7 +47,7 @@ export default {
computed: mapState(['req']),
methods: {
raw: function () {
- return this.req.data.url + '?raw=true'
+ return this.req.url + '?raw=true'
},
back: function (event) {
let url = page.removeLastDir(window.location.pathname) + '/'
diff --git a/_assets/src/components/RenamePrompt.vue b/_assets/src/components/RenamePrompt.vue
index 6999d669..c4190d9d 100644
--- a/_assets/src/components/RenamePrompt.vue
+++ b/_assets/src/components/RenamePrompt.vue
@@ -29,7 +29,7 @@ export default {
},
oldName: function () {
if (this.req.kind !== 'listing') {
- return this.req.data.name
+ return this.req.name
}
if (this.selectedCount === 0 || this.selectedCount > 1) {
@@ -37,16 +37,16 @@ export default {
return
}
- return this.req.data.items[this.selected[0]].name
+ return this.req.items[this.selected[0]].name
},
submit: function (event) {
let oldLink = ''
let newLink = ''
if (this.req.kind !== 'listing') {
- oldLink = this.req.data.url
+ oldLink = this.req.url
} else {
- oldLink = this.req.data.items[this.selected[0]].url
+ oldLink = this.req.items[this.selected[0]].url
}
this.name = encodeURIComponent(this.name)
diff --git a/_assets/src/components/SwitchViewButton.vue b/_assets/src/components/SwitchViewButton.vue
index f9f98aee..3342a910 100644
--- a/_assets/src/components/SwitchViewButton.vue
+++ b/_assets/src/components/SwitchViewButton.vue
@@ -12,7 +12,7 @@ export default {
change: function (event) {
let display = 'mosaic'
- if (this.$store.state.req.data.display === 'mosaic') {
+ if (this.$store.state.req.display === 'mosaic') {
display = 'list'
}
@@ -20,7 +20,7 @@ export default {
document.cookie = `display=${display}; max-age=31536000; path=${this.$store.state.baseURL}`
},
icon: function () {
- if (this.$store.state.req.data.display === 'mosaic') return 'view_list'
+ if (this.$store.state.req.display === 'mosaic') return 'view_list'
return 'view_module'
}
}
diff --git a/_assets/src/router/index.js b/_assets/src/router/index.js
index c17eb508..25f0fd78 100644
--- a/_assets/src/router/index.js
+++ b/_assets/src/router/index.js
@@ -21,6 +21,7 @@ const router = new Router({
next({ path: '/files' })
})
.catch(() => {
+ document.title = 'Login'
next()
})
}
@@ -33,7 +34,7 @@ const router = new Router({
},
children: [
{
- path: '/files/*',
+ path: '/files*',
name: 'Files',
component: Files
},
diff --git a/_assets/src/store/mutations.js b/_assets/src/store/mutations.js
index 7fea1859..ce786409 100644
--- a/_assets/src/store/mutations.js
+++ b/_assets/src/store/mutations.js
@@ -18,6 +18,7 @@ const mutations = {
state.showDownload = false
},
setUser: (state, value) => (state.user = value),
+ setJWT: (state, value) => (state.jwt = value),
multiple: (state, value) => (state.multiple = value),
addSelected: (state, value) => (state.selected.push(value)),
removeSelected: (state, value) => {
@@ -29,11 +30,10 @@ const mutations = {
state.selected = []
},
listingDisplay: (state, value) => {
- state.req.data.display = value
+ state.req.display = value
},
updateRequest: (state, value) => {
- state.req.kind = value.kind
- state.req.data = value.data
+ state.req = value
}
}
diff --git a/_assets/src/store/store.js b/_assets/src/store/store.js
index 330b9d5b..2f6c24cc 100644
--- a/_assets/src/store/store.js
+++ b/_assets/src/store/store.js
@@ -10,6 +10,7 @@ const state = {
req: {},
baseURL: document.querySelector('meta[name="base"]').getAttribute('content'),
ssl: (window.location.protocol === 'https:'),
+ jwt: '',
selected: [],
multiple: false,
showInfo: false,
diff --git a/_assets/src/utils/api.js b/_assets/src/utils/api.js
new file mode 100644
index 00000000..0074aecd
--- /dev/null
+++ b/_assets/src/utils/api.js
@@ -0,0 +1,27 @@
+import store from '../store/store'
+
+function fetch (url) {
+ return new Promise((resolve, reject) => {
+ let request = new window.XMLHttpRequest()
+ request.open('GET', `${store.state.baseURL}/api/resource${url}`, true)
+ request.setRequestHeader('Authorization', `Bearer ${store.state.jwt}`)
+
+ request.onload = () => {
+ if (request.status === 200) {
+ let req = JSON.parse(request.responseText)
+ store.commit('updateRequest', req)
+ console.log(req)
+ document.title = req.name
+ resolve()
+ } else {
+ reject()
+ }
+ }
+ request.onerror = () => reject()
+ request.send()
+ })
+}
+
+export default {
+ fetch
+}
diff --git a/_assets/src/utils/auth.js b/_assets/src/utils/auth.js
index df2a2eaf..5de3cb75 100644
--- a/_assets/src/utils/auth.js
+++ b/_assets/src/utils/auth.js
@@ -6,6 +6,7 @@ function parseToken (token) {
document.cookie = `auth=${token}; max-age=86400; path=${store.state.baseURL}`
let res = token.split('.')
let user = JSON.parse(window.atob(res[1]))
+ store.commit('setJWT', token)
store.commit('setUser', user)
}