From 18e9fb6e36af2505c79962c7d616cd864ffff9bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6?= Date: Thu, 1 Sep 2022 16:11:42 +0200 Subject: [PATCH] Properly append uploaded photos without fetchiung for the full folder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ --- src/services/FileInfo.js | 47 ++++++++++++++++++++++++++++++++++++++++ src/store/folders.js | 31 ++++++++++++++++++++++++++ src/views/Folders.vue | 1 + 3 files changed, 79 insertions(+) create mode 100644 src/services/FileInfo.js diff --git a/src/services/FileInfo.js b/src/services/FileInfo.js new file mode 100644 index 0000000000..2dadf14ee5 --- /dev/null +++ b/src/services/FileInfo.js @@ -0,0 +1,47 @@ +/** + * @copyright Copyright (c) 2019 John Molakvoæ + * + * @author John Molakvoæ + * + * @license AGPL-3.0-or-later + * + * 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 . + * + */ + +import { getCurrentUser } from '@nextcloud/auth' +import client from './DavClient' +import request from './DavRequest' +import { genFileInfo } from '../utils/fileUtils' + +/** + * Get a file info + * + * @param {string} path the path relative to the user root + * @return {FileInfo} the file info + */ +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) +} diff --git a/src/store/folders.js b/src/store/folders.js index e4f8ff52f7..1984882414 100644 --- a/src/store/folders.js +++ b/src/store/folders.js @@ -63,6 +63,25 @@ const mutations = { Vue.set(state.paths, path, fileid) } }, + + /** + * Append files to a folder + * + * @param {object} state vuex state + * @param {object} data destructuring object + * @param {number} data.fileid id of this folder + * @param {Array} data.files list of files to add + */ + addFilesToFolder(state, { fileid, files }) { + if (fileid >= 0 && files.length > 0) { + // and sort by last modified + const list = files + .sort((a, b) => sortCompare(a, b, 'lastmod')) + .filter(file => file.fileid >= 0) + .map(file => file.fileid) + Vue.set(state.folders, fileid, [...list, ...state.folders[fileid]]) + } + }, } const getters = { @@ -99,6 +118,18 @@ const actions = { addPath(context, { path, fileid }) { context.commit('addPath', { path, fileid }) }, + + /** + * Append files to a folder + * + * @param {object} context vuex context + * @param {object} data destructuring object + * @param {number} data.fileid id of this folder + * @param {Array} data.files list of files to add + */ + addFilesToFolder(context, { fileid, files }) { + context.commit('addFilesToFolder', { fileid, files }) + }, } export default { state, mutations, getters, actions } diff --git a/src/views/Folders.vue b/src/views/Folders.vue index 997dc94dad..bfbdc3682d 100644 --- a/src/views/Folders.vue +++ b/src/views/Folders.vue @@ -64,6 +64,7 @@