Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix default usable state
Signed-off-by: John Molakvoæ (skjnldsv) <[email protected]>
  • Loading branch information
skjnldsv committed Nov 14, 2019
commit 00ec425d5a0cc897b62d9bbaccc0baaf8f646cea
12 changes: 9 additions & 3 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,19 @@
return [
'routes' => [
['name' => 'page#index', 'url' => '/', 'verb' => 'GET'],
//['name' => 'page#index', 'url' => '/{path}', 'verb' => 'GET', 'postfix' => 'folder', 'requirements' => ['path' => '.+']],
['name' => 'page#index', 'url' => '/albums', 'verb' => 'GET', 'postfix' => 'albums'],
['name' => 'page#index', 'url' => '/albums/{tag}', 'verb' => 'GET', 'postfix' => 'albumsx'],
['name' => 'page#index', 'url' => '/favorites', 'verb' => 'GET', 'postfix' => 'favorites'],
['name' => 'page#index', 'url' => '/shared', 'verb' => 'GET', 'postfix' => 'shared'],
['name' => 'page#index', 'url' => '/tags/{tag}', 'verb' => 'GET', 'postfix' => 'tags', 'requirements' => ['tag' => '.*']],

// apis
[
'name' => 'albums#myAlbums',
'url' => '/api/v1/albums/{path}',
'verb' => 'GET',
'requirements' => [
'path' => '.+',
'path' => '.*',
],
'defaults' => [
'path' => '',
Expand All @@ -41,7 +47,7 @@
'url' => '/api/v1/shared/{path}',
'verb' => 'GET',
'requirements' => [
'path' => '.+',
'path' => '.*',
],
'defaults' => [
'path' => '',
Expand Down
9 changes: 8 additions & 1 deletion lib/Controller/AlbumsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,14 @@ private function formatData(iterable $nodes): array {
$result = [];
/** @var Node $node */
foreach ($nodes as $node) {
$result[] = $node->getName();
$result[] = [
'id' => $node->getName(),
'basename' => $node->getName(),
'id' => $node->getName(),
'id' => $node->getName(),
'id' => $node->getName(),
'id' => $node->getName(),
]
}

return $result;
Expand Down
6 changes: 3 additions & 3 deletions src/components/File.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default {
type: String,
required: true,
},
id: {
fileid: {
type: Number,
required: true,
},
Expand All @@ -87,7 +87,7 @@ export default {
return generateRemoteUrl(`dav/files/${getCurrentUser().uid}`) + this.filename
},
ariaUuid() {
return `image-${this.id}`
return `image-${this.fileid}`
},
ariaLabel() {
return t('photos', 'Open the full size "{name}" image', { name: this.basename })
Expand All @@ -97,7 +97,7 @@ export default {
created() {
// Allow us to cancel the img loading on destroy
// use etag to force cache reload if file changed
this.img.src = generateUrl(`/core/preview?fileId=${this.id}&x=${1024}&y=${1024}&a=true&v=${this.etag}`)
this.img.src = generateUrl(`/core/preview?fileId=${this.fileid}&x=${1024}&y=${1024}&a=true&v=${this.etag}`)
this.img.addEventListener('load', () => {
this.src = this.img.src
})
Expand Down
22 changes: 11 additions & 11 deletions src/components/Folder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
class="folder-content"
role="none">
<img v-for="file in fileList"
:key="file.id"
:key="file.fileid"
:src="generateImgSrc(file)"
alt=""
@load="loaded = true">
Expand Down Expand Up @@ -70,7 +70,7 @@ export default {
type: String,
required: true,
},
id: {
fileid: {
type: Number,
required: true,
},
Expand All @@ -96,7 +96,7 @@ export default {

// files list of the current folder
folderContent() {
return this.folders[this.id]
return this.folders[this.fileid]
},
fileList() {
return this.folderContent
Expand All @@ -113,7 +113,7 @@ export default {
},

ariaUuid() {
return `folder-${this.id}`
return `folder-${this.fileid}`
},
ariaLabel() {
return t('photos', 'Open the "{name}" sub-directory', { name: this.basename })
Expand Down Expand Up @@ -142,10 +142,10 @@ export default {

try {
// get data
const { files, folders } = await request(this.filename)
// this.cancelRequest('Stop!')
this.$store.dispatch('updateFolders', { id: this.id, files, folders })
this.$store.dispatch('updateFiles', { folder: this.folder, files, folders })
const { folder, folders, files } = await request(this.filename)
console.info(folder, folders, files);
this.$store.dispatch('updateFolders', { fileid: folder.fileid, files, folders })
this.$store.dispatch('updateFiles', { folder, files, folders })
} catch (error) {
if (error.response && error.response.status) {
console.error('Failed to get folder content', this.folder, error.response)
Expand All @@ -155,13 +155,13 @@ export default {
},

beforeDestroy() {
this.cancelRequest()
this.cancelRequest('Navigated away')
},

methods: {
generateImgSrc({ id, etag }) {
generateImgSrc({ fileid, etag }) {
// use etag to force cache reload if file changed
return generateUrl(`/core/preview?fileId=${id}&x=${256}&y=${256}&a=true&v=${etag}`)
return generateUrl(`/core/preview?fileId=${fileid}&x=${256}&y=${256}&a=true&v=${etag}`)
},

fetch() {
Expand Down
4 changes: 0 additions & 4 deletions src/components/Navigation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ export default {
type: String,
default: t('photos', 'Photos'),
},
id: {
type: Number,
required: true,
},
},

computed: {
Expand Down
45 changes: 45 additions & 0 deletions src/services/AlbumContent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* @copyright Copyright (c) 2019 John Molakvoæ <[email protected]>
*
* @author John Molakvoæ <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

import { generateUrl } from '@nextcloud/router'
import { genFileInfo } from '../utils/fileUtils'

/**
* List files from a folder and filter out unwanted mimes
*
* @param {String} path the path relative to the user root
* @returns {Array} the file list
*/
export default async function(path) {
// getDirectoryContents doesn't accept / for root
const fixedPath = path === '/' ? '' : path

const prefixPath = `/files/${getCurrentUser().uid}`

// fetch listing
const response = await client.stat(prefixPath + fixedPath, {
data: request,
details: true,
})

return genFileInfo(response.data, prefixPath)
}
2 changes: 1 addition & 1 deletion src/services/DavClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { generateRemoteUrl } from '@nextcloud/router'
const patcher = webdav.getPatcher()
patcher.patch('request', axios)

// init webdav client
// init webdav client on default dav endpoint
const remote = generateRemoteUrl(`dav`)
const client = webdav.createClient(remote)

Expand Down
12 changes: 8 additions & 4 deletions src/services/FileList.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { getSingleValue, getValueForKey, parseXML, propsToStat } from 'webdav/di
import { handleResponseCode, processResponsePayload } from 'webdav/dist/response'
import { normaliseHREF, normalisePath } from 'webdav/dist/url'
import client, { remotePath } from './DavClient'
import request from './DavRequest'
import pathPosix from 'path-posix'
import { genFileInfo } from '../utils/fileUtils'

Expand All @@ -37,17 +38,18 @@ import { genFileInfo } from '../utils/fileUtils'
*/
export default async function(path, options) {

console.trace();
options = Object.assign({
method: 'PROPFIND',
headers: {
Accept: 'text/plain',
Depth: options.deep ? 'infinity' : 1,
},
data: request,
responseType: 'text',
details: true,
}, options)

// we also use the davclient for other endpoints than /files (like tags)
const prefixPath = `/files/${getCurrentUser().uid}`

/**
Expand All @@ -65,7 +67,7 @@ export default async function(path, options) {
return res.data
})
.then(parseXML)
.then(result => getDirectoryFiles(result, remotePath, options.details))
.then(result => getDirectoryFiles(result, remotePath + prefixPath, options.details))
.then(files => processResponsePayload(response, files, options.details))

const list = data.map(data => genFileInfo(data, prefixPath))
Expand All @@ -75,6 +77,7 @@ export default async function(path, options) {
const folders = []
const files = []
for (const entry of list) {
// is this the current provided path ?
if (entry.filename === path) {
folder = entry
} else if (entry.type === 'directory') {
Expand All @@ -89,7 +92,8 @@ export default async function(path, options) {
}

/**
* Modified function to include the root requested folder
* ! Modified function to include the root requested folder
* ! See webdav library
* Into the returned data
*
* @param {Object} result the request result
Expand All @@ -104,7 +108,7 @@ function getDirectoryFiles(result, serverBasePath, isDetailed = false) {
const responseItems = getValueForKey('response', multiStatus)
return (
responseItems
// Map all items to a consistent output structure (results)
// Map all items to a consistent output structure (results)
.map(item => {
// HREF is the file path (in full)
let href = getSingleValue(getValueForKey('href', item))
Expand Down
17 changes: 11 additions & 6 deletions src/store/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ const mutations = {
*/
updateFiles(state, files) {
files.forEach(file => {
Vue.set(state.files, file.id, file)
if (file.fileid >= 0) {
Vue.set(state.files, file.fileid, file)
}
})
},

Expand All @@ -43,12 +45,15 @@ const mutations = {
*
* @param {Object} state the store mutations
* @param {Object} data destructuring object
* @param {number} data.id current folder id
* @param {number} data.fileid current folder id
* @param {Array} data.folders list of folders
*/
setSubFolders(state, { id, folders }) {
if (state.files[id]) {
Vue.set(state.files[id], 'folders', [...folders.map(folder => folder.id)])
setSubFolders(state, { fileid, folders }) {
if (state.files[fileid]) {
const subfolders = folders
.map(folder => folder.fileid)
.filter(id => id >= 0)
Vue.set(state.files[fileid], 'folders', subfolders)
}
},
}
Expand All @@ -71,7 +76,7 @@ const actions = {
const t0 = performance.now()
// we want all the FileInfo! Folders included!
context.commit('updateFiles', [folder, ...files, ...folders])
context.commit('setSubFolders', { id: folder.id, folders })
context.commit('setSubFolders', { fileid: folder.fileid, folders })
const t1 = performance.now()
console.debug('perf: updateFiles', `${t1 - t0}ms`)
},
Expand Down
34 changes: 19 additions & 15 deletions src/store/folders.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,19 @@ const mutations = {
*
* @param {Object} state vuex state
* @param {Object} data destructuring object
* @param {number} data.id current folder id
* @param {number} data.fileid current folder id
* @param {Array} data.files list of files
*/
updateFolders(state, { id, files }) {
updateFolders(state, { fileid, files }) {
if (files.length > 0) {
const t0 = performance.now()
// sort by last modified
const list = files.sort((a, b) => sortCompare(a, b, 'lastmod'))
const list = files
.sort((a, b) => sortCompare(a, b, 'lastmod'))
.filter(file => file.fileid >= 0)

// Set folder list
Vue.set(state.folders, id, list.map(file => file.id))
Vue.set(state.folders, fileid, list.map(file => file.fileid))
const t1 = performance.now()
console.debug('perf: updateFolders', `${t1 - t0}ms`)
}
Expand All @@ -55,16 +57,18 @@ const mutations = {
* @param {Object} state vuex state
* @param {Object} data destructuring object
* @param {string} data.path path of this folder
* @param {number} data.id id of this folder
* @param {number} data.fileid id of this folder
*/
addPath(state, { path, id }) {
Vue.set(state.paths, path, id)
addPath(state, { path, fileid }) {
if (fileid >= 0) {
Vue.set(state.paths, path, fileid)
}
},
}

const getters = {
folders: state => state.folders,
folder: state => id => state.folders[id],
folder: state => fileid => state.folders[fileid],
folderId: state => path => state.paths[path],
}

Expand All @@ -74,15 +78,15 @@ const actions = {
*
* @param {Object} context vuex context
* @param {Object} data destructuring object
* @param {number} data.id current folder id
* @param {number} data.fileid current folder id
* @param {Array} data.files list of files
* @param {Array} data.folders list of folders
*/
updateFolders(context, { id, files, folders }) {
context.commit('updateFolders', { id, files })
updateFolders(context, { fileid, files, folders }) {
context.commit('updateFolders', { fileid, files })

// then add each folders path indexes
folders.forEach(folder => context.commit('addPath', { path: folder.filename, id: folder.id }))
folders.forEach(folder => context.commit('addPath', { path: folder.filename, fileid: folder.fileid }))
},

/**
Expand All @@ -91,10 +95,10 @@ const actions = {
* @param {Object} context vuex context
* @param {Object} data destructuring object
* @param {string} data.path path of this folder
* @param {number} data.id id of this folder
* @param {number} data.fileid id of this folder
*/
addPath(context, { path, id }) {
context.commit('addPath', { path, id })
addPath(context, { path, fileid }) {
context.commit('addPath', { path, fileid })
},
}

Expand Down
Loading