Skip to content

Commit ce3755b

Browse files
committed
feat(PhotoPicker): Do not show non-owned files
Signed-off-by: Louis Chemineau <louis@chmn.me>
1 parent 32b84fc commit ce3755b

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

src/components/PhotosPicker.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,15 @@ export default defineComponent({
218218
},
219219
220220
getFiles() {
221-
this.fetchFiles({}, this.blacklistIds)
221+
this.fetchFiles({}, this.shouldShowFile)
222222
},
223223
224224
refreshFiles() {
225-
this.fetchFiles({ firstResult: 0 }, [...this.blacklistIds, ...this.fetchedFileIds], true)
225+
this.fetchFiles({ firstResult: 0 }, this.shouldShowFile, true)
226+
},
227+
228+
shouldShowFile(file: File) {
229+
return file.attributes['mount-type'] === '' && !this.blacklistIds.includes(file.fileid?.toString() ?? '')
226230
},
227231
228232
emitPickedEvent() {

src/mixins/FetchFilesMixin.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ export default {
3737
methods: {
3838
/**
3939
* @param {object} options - Options to pass to getPhotos.
40-
* @param {string[]} [blacklist=[]] - Array of ids to filter out.
40+
* @param {Function} [filter] - Function to filter out some files.
4141
* @param {boolean} [force=false] - Force fetching even if doneFetchingFiles is true
4242
* @return {Promise<string[]>} - The next batch of data depending on global offset.
4343
*/
44-
async fetchFiles(options = {}, blacklist = [], force = false) {
44+
async fetchFiles(options = {}, filter = undefined, force = false) {
4545
if ((this.doneFetchingFiles && !force) || this.loadingFiles) {
4646
return []
4747
}
@@ -55,7 +55,7 @@ export default {
5555
const numberOfImagesPerBatch = 200
5656

5757
// Load next batch of images
58-
const fetchedFiles = await getPhotos({
58+
let fetchedFiles = await getPhotos({
5959
firstResult: this.fetchedFileIds.length,
6060
nbResults: numberOfImagesPerBatch,
6161
...options,
@@ -67,6 +67,10 @@ export default {
6767
this.doneFetchingFiles = true
6868
}
6969

70+
if (filter !== undefined) {
71+
fetchedFiles = fetchedFiles.filter(filter)
72+
}
73+
7074
const fileIds = fetchedFiles
7175
.map(file => file.fileid)
7276
.filter(fileId => !this.fetchedFileIds.includes(fileId.toString())) // Filter to prevent duplicate fileIds.

0 commit comments

Comments
 (0)