Skip to content

Commit

Permalink
Fix nomedia excludion
Browse files Browse the repository at this point in the history
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
Signed-off-by: nextcloud-command <nextcloud-command@users.noreply.github.com>
  • Loading branch information
skjnldsv authored and artonge committed Oct 19, 2022
1 parent 91d7e88 commit 3da0082
Show file tree
Hide file tree
Showing 14 changed files with 41 additions and 37 deletions.
4 changes: 2 additions & 2 deletions js/photos-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/photos-main.js.map

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/photos-src_views_Folders_vue.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/photos-src_views_Folders_vue.js.map

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions src/Photos.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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() {
Expand Down
6 changes: 4 additions & 2 deletions src/mixins/FilesByMonthMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions src/services/DavClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 3 additions & 6 deletions src/services/FileInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
9 changes: 3 additions & 6 deletions src/services/FolderInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
10 changes: 4 additions & 6 deletions src/services/TaggedImages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions src/store/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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(/&quot;/g, '"') ?? '{}')
file.fileMetadataSizeParsed.width = file.fileMetadataSizeParsed?.width ?? 256
Expand All @@ -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,
}
},

Expand Down
3 changes: 1 addition & 2 deletions src/views/Folders.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@
<script>
import { mapGetters } from 'vuex'
import { UploadPicker } from '@nextcloud/upload'
import { getCurrentUser } from '@nextcloud/auth'
import { NcEmptyContent } from '@nextcloud/vue'
import VirtualGrid from 'vue-virtual-grid'

import FileLegacy from '../components/FileLegacy.vue'
import Folder from '../components/Folder.vue'
import HeaderNavigation from '../components/HeaderNavigation.vue'

import { prefixPath } from '../services/DavClient.js'
import allowedMimes from '../services/AllowedMimes.js'
import getAlbumContent from '../services/AlbumContent.js'

Expand Down Expand Up @@ -266,7 +266,6 @@ export default {
* @param {Upload[]} uploads the newly uploaded files
*/
onUpload(uploads) {
const prefixPath = `/files/${getCurrentUser().uid}`
uploads.forEach(async upload => {
const relPath = upload.path.split(prefixPath).pop()
const file = await getFileInfo(relPath)
Expand Down

0 comments on commit 3da0082

Please sign in to comment.