Skip to content
Merged
Prev Previous commit
Next Next commit
Use photosSourceFolder in photos search
Signed-off-by: Louis Chemineau <louis@chmn.me>
  • Loading branch information
artonge committed Feb 15, 2024
commit aec581164f43811bdf0f98859f41e9ea1b9914fe
4 changes: 2 additions & 2 deletions src/components/PhotosPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,11 @@ export default defineComponent({
},

getFiles() {
this.fetchFiles('', {}, this.blacklistIds)
this.fetchFiles({}, this.blacklistIds)
},

refreshFiles() {
this.fetchFiles('', { firstResult: 0 }, [...this.blacklistIds, ...this.fetchedFileIds], true)
this.fetchFiles({ firstResult: 0 }, [...this.blacklistIds, ...this.fetchedFileIds], true)
},

emitPickedEvent() {
Expand Down
5 changes: 2 additions & 3 deletions src/mixins/FetchFilesMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,12 @@ export default {

methods: {
/**
* @param {string} path - Path to pass to getPhotos.
* @param {object} options - Options to pass to getPhotos.
* @param {string[]} [blacklist=[]] - Array of ids to filter out.
* @param {boolean} [force=false] - Force fetching even if doneFetchingFiles is true
* @return {Promise<string[]>} - The next batch of data depending on global offset.
*/
async fetchFiles(path = '', options = {}, blacklist = [], force = false) {
async fetchFiles(options = {}, blacklist = [], force = false) {
if ((this.doneFetchingFiles && !force) || this.loadingFiles) {
return []
}
Expand All @@ -70,7 +69,7 @@ export default {
const numberOfImagesPerBatch = 200

// Load next batch of images
const fetchedFiles = await getPhotos(path, {
const fetchedFiles = await getPhotos({
firstResult: this.fetchedFileIds.length,
nbResults: numberOfImagesPerBatch,
...options,
Expand Down
14 changes: 12 additions & 2 deletions src/services/PhotoSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import moment from '@nextcloud/moment'
* @param {boolean} [options.onlyFavorites=false] get only favorite items
* @return {Promise<object[]>} the file list
*/
export default async function(path = '', options = {}) {
export default async function (options = {}) {
// default function options
options = {
firstResult: 0,
Expand Down Expand Up @@ -95,6 +95,16 @@ export default async function(path = '', options = {}) {
}).join('\n')}</d:or>`
: ''

// TODO: uncomment when SEARCH on multiple folders is implemented.
// const sourceFolders = store.state.userConfig.photosSourceFolder
// .map(folder => `
// <d:scope>
// <d:href>${davRootPath}/${folder}</d:href>
// <d:depth>infinity</d:depth>
// </d:scope>
// `)
// .join('\n')

options = Object.assign({
method: 'SEARCH',
headers: {
Expand All @@ -114,7 +124,7 @@ export default async function(path = '', options = {}) {
</d:select>
<d:from>
<d:scope>
<d:href>${prefixPath}/${path}</d:href>
<d:href>${prefixPath}/${store.state.userConfig.photosSourceFolder ?? '/Photos'}</d:href>
<d:depth>infinity</d:depth>
</d:scope>
</d:from>
Expand Down
2 changes: 2 additions & 0 deletions src/store/userConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { Folder, davGetClient, davGetDefaultPropfind, davResultToNode, davRootPa
import { loadState } from '@nextcloud/initial-state'
import { joinPaths } from '@nextcloud/paths'
import { showError } from '@nextcloud/dialogs'
import { emit } from '@nextcloud/event-bus'
import { translate as t } from '@nextcloud/l10n'
import { generateUrl } from '@nextcloud/router'
import axios from '@nextcloud/axios'
Expand Down Expand Up @@ -83,6 +84,7 @@ const module = {
await axios.put(generateUrl('apps/photos/api/v1/config/' + key), {
value: (typeof value === 'string') ? value : JSON.stringify(value),
})
emit(configChangedEvent, { key, value })
},
},
}
Expand Down
18 changes: 17 additions & 1 deletion src/views/Timeline.vue
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ import ActionFavorite from '../components/Actions/ActionFavorite.vue'
import ActionDownload from '../components/Actions/ActionDownload.vue'
import HeaderNavigation from '../components/HeaderNavigation.vue'
import { translate } from '@nextcloud/l10n'
import { subscribe, unsubscribe } from '@nextcloud/event-bus'
import { configChangedEvent } from '../store/userConfig.js'

export default {
name: 'Timeline',
Expand Down Expand Up @@ -244,6 +246,14 @@ export default {
}
},

mounted() {
subscribe(configChangedEvent, this.handleUserConfigChange)
},

destroyed() {
unsubscribe(configChangedEvent, this.handleUserConfigChange)
},

computed: {
...mapGetters([
'files',
Expand All @@ -257,7 +267,7 @@ export default {
]),

getContent() {
this.fetchFiles('', {
this.fetchFiles({
mimesType: this.mimesType,
onThisDay: this.onThisDay,
onlyFavorites: this.onlyFavorites,
Expand Down Expand Up @@ -291,6 +301,12 @@ export default {
await this.deleteFiles(fileIds)
},

handleUserConfigChange({ key }) {
if (key === 'photosSourceFolder') {
this.resetFetchFilesState()
}
},

t: translate,
},
}
Expand Down