From 3da00822d0846b3e56b7aee736b6e7679e3bf3c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6?= Date: Fri, 14 Oct 2022 09:52:24 +0200 Subject: Fix nomedia excludion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ Signed-off-by: nextcloud-command --- src/Photos.vue | 8 +++++--- src/mixins/FilesByMonthMixin.js | 6 ++++-- src/services/DavClient.js | 2 ++ src/services/FileInfo.js | 9 +++------ src/services/FolderInfo.js | 9 +++------ src/services/TaggedImages.js | 10 ++++------ src/store/files.js | 13 ++++++++++--- src/views/Folders.vue | 3 +-- 8 files changed, 32 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/Photos.vue b/src/Photos.vue index 7c7e76d2..fe0b8f0d 100644 --- a/src/Photos.vue +++ b/src/Photos.vue @@ -164,6 +164,11 @@ export default { }, async beforeMount() { + // Register excluded paths + const files = loadState('photos', 'nomedia-paths', []) + this.$store.dispatch('setNomediaPaths', files) + logger.debug('Known .nomedia and .noimage paths', { files }) + if ('serviceWorker' in navigator) { // Use the window load event to keep the page load performant window.addEventListener('load', () => { @@ -181,9 +186,6 @@ export default { } else { console.debug('Service Worker is not enabled on this browser.') } - - const files = loadState('photos', 'nomedia-paths', []) - this.$store.dispatch('setNomediaPaths', files) }, beforeDestroy() { diff --git a/src/mixins/FilesByMonthMixin.js b/src/mixins/FilesByMonthMixin.js index 650a79e0..cf2ba251 100644 --- a/src/mixins/FilesByMonthMixin.js +++ b/src/mixins/FilesByMonthMixin.js @@ -31,8 +31,10 @@ export default { const filesByMonth = {} for (const fileId of this.fetchedFileIds) { const file = this.files[fileId] - filesByMonth[file.month] = filesByMonth[file.month] ?? [] - filesByMonth[file.month].push(file.fileid) + if (file) { + filesByMonth[file.month] = filesByMonth[file.month] ?? [] + filesByMonth[file.month].push(file.fileid) + } } // Sort files in sections. diff --git a/src/services/DavClient.js b/src/services/DavClient.js index 2d4da082..72c2daf5 100644 --- a/src/services/DavClient.js +++ b/src/services/DavClient.js @@ -24,8 +24,10 @@ import { createClient, getPatcher } from 'webdav' import axios from '@nextcloud/axios' import parseUrl from 'url-parse' import { generateRemoteUrl } from '@nextcloud/router' +import { getCurrentUser } from '@nextcloud/auth' export const rootPath = 'dav' +export const prefixPath = `/files/${getCurrentUser().uid}` // force our axios const patcher = getPatcher() diff --git a/src/services/FileInfo.js b/src/services/FileInfo.js index 2dadf14e..06959038 100644 --- a/src/services/FileInfo.js +++ b/src/services/FileInfo.js @@ -20,10 +20,9 @@ * */ -import { getCurrentUser } from '@nextcloud/auth' -import client from './DavClient' -import request from './DavRequest' -import { genFileInfo } from '../utils/fileUtils' +import client, { prefixPath } from './DavClient.js' +import request from './DavRequest.js' +import { genFileInfo } from '../utils/fileUtils.js' /** * Get a file info @@ -35,8 +34,6 @@ 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, diff --git a/src/services/FolderInfo.js b/src/services/FolderInfo.js index dd5425ae..9cf94c76 100644 --- a/src/services/FolderInfo.js +++ b/src/services/FolderInfo.js @@ -20,10 +20,9 @@ * */ -import { getCurrentUser } from '@nextcloud/auth' -import client from './DavClient' -import request from './DavRequest' -import { genFileInfo } from '../utils/fileUtils' +import client, { prefixPath } from './DavClient.js' +import request from './DavRequest.js' +import { genFileInfo } from '../utils/fileUtils.js' /** * List files from a folder and filter out unwanted mimes @@ -35,8 +34,6 @@ 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, diff --git a/src/services/TaggedImages.js b/src/services/TaggedImages.js index 01579314..a0611e4f 100644 --- a/src/services/TaggedImages.js +++ b/src/services/TaggedImages.js @@ -20,11 +20,10 @@ * */ -import { genFileInfo } from '../utils/fileUtils' -import { getCurrentUser } from '@nextcloud/auth' -import { props } from './DavRequest' -import allowedMimes from './AllowedMimes' -import client from './DavClient' +import { genFileInfo } from '../utils/fileUtils.js' +import { props } from './DavRequest.js' +import allowedMimes from './AllowedMimes.js' +import client, { prefixPath } from './DavClient.js' /** * Get tagged files based on provided tag id @@ -53,7 +52,6 @@ export default async function(id, options = {}) { details: true, }, options) - const prefixPath = `/files/${getCurrentUser().uid}` const response = await client.getDirectoryContents(prefixPath, options) return response.data diff --git a/src/store/files.js b/src/store/files.js index f0681860..6559ce69 100644 --- a/src/store/files.js +++ b/src/store/files.js @@ -25,7 +25,7 @@ import moment from '@nextcloud/moment' import { showError } from '@nextcloud/dialogs' import logger from '../services/logger.js' -import client from '../services/DavClient.js' +import client, { prefixPath } from '../services/DavClient.js' import Semaphore from '../utils/semaphoreWithPriority.js' const state = { @@ -41,10 +41,14 @@ const mutations = { * @param {Array} newFiles the store mutations */ updateFiles(state, newFiles) { + const files = {} newFiles.forEach(file => { - if (state.nomediaPaths.some(nomediaPath => file.filename.startsWith(nomediaPath))) { + // Ignore the file if the path is excluded + if (state.nomediaPaths.some(nomediaPath => file.filename.startsWith(nomediaPath) + || file.filename.startsWith(prefixPath + nomediaPath))) { return } + if (file.fileid >= 0) { file.fileMetadataSizeParsed = JSON.parse(file.fileMetadataSize?.replace(/"/g, '"') ?? '{}') file.fileMetadataSizeParsed.width = file.fileMetadataSizeParsed?.width ?? 256 @@ -58,11 +62,14 @@ const mutations = { file.timestamp = moment(file.lastmod).unix() // For sorting file.month = moment(file.lastmod).format('YYYYMM') // For grouping by month file.day = moment(file.lastmod).format('MMDD') // For On this day + + // Schedule the file to add + files[file.fileid] = file }) state.files = { ...state.files, - ...newFiles.reduce((files, file) => ({ ...files, [file.fileid]: file }), {}), + ...files, } }, diff --git a/src/views/Folders.vue b/src/views/Folders.vue index 21f9f725..a5f26374 100644 --- a/src/views/Folders.vue +++ b/src/views/Folders.vue @@ -64,7 +64,6 @@