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AAa,6BAAD,OAA8BV,EAAQJ,OAAM,gBAAgBI,GAAQ,kBAEzEA,GAAO,sCAEiB,OAAb,QAAd,OAAM5B,gBAAQ,aAAd,EAAgBuC,QAAc,iBACjC,EAAKlC,mBAAqB,IAAG,2BACJ,iBAAf,KAAMmC,KAAuB,0CAChC,IAAE,QAET,EAAKnC,mBAAqB,EAAH,GAAQ,QAIhCiC,EAAAA,EAAAA,MAAa,uBAAwB,CAAEG,MAAK,OAC5CC,EAAQD,MAAM,EAAD,IAAO,QAI6B,OAJ7B,UAEpB,EAAKnC,cAAe,EACpB,EAAKE,UAAUmC,QAAQhC,GACvB,EAAKD,eAAeiC,QAAQtB,GAAqB,8CAG3C,IAAE,gEA7DgD,EA8D1D,EAEAL,qBAAoB,WACnBD,KAAKR,mBAAoB,EACzBQ,KAAKV,mBAAqB,KAC1BU,KAAKT,cAAe,EACpBS,KAAKH,eAAiB,EACvB","sources":["webpack:///photos/src/services/PhotoSearch.js","webpack:///photos/src/mixins/FetchFilesMixin.js"],"sourcesContent":["/**\n * @copyright Copyright (c) 2019 John Molakvoæ \n *\n * @author John Molakvoæ \n *\n * @license AGPL-3.0-or-later\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU Affero General Public License as\n * published by the Free Software Foundation, either version 3 of the\n * License, or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU Affero General Public License for more details.\n *\n * You should have received a copy of the GNU Affero General Public License\n * along with this program. If not, see .\n *\n */\n\nimport { genFileInfo } from '../utils/fileUtils.js'\nimport { getCurrentUser } from '@nextcloud/auth'\nimport { allMimes } from './AllowedMimes.js'\nimport client from './DavClient.js'\nimport { props } from './DavRequest.js'\nimport moment from '@nextcloud/moment'\n\n/**\n * List files from a folder and filter out unwanted mimes\n *\n * @param {object} path the lookup path\n * @param {object} [options] used for the cancellable requests\n * @param {number} [options.firstResult=0] Index of the first result that we want (starts at 0)\n * @param {number} [options.nbResults=200] The number of file to fetch\n * @param {string[]} [options.mimesType=allMimes] Mime type of the files\n * @param {boolean} [options.full=false] get full data of the files\n * @param {boolean} [options.onThisDay=false] get only items from this day of year\n * @param {boolean} [options.onlyFavorites=false] get only favorite items\n * @return {Promise} the file list\n */\nexport default async function(path = '', options = {}) {\n\t// default function options\n\toptions = {\n\t\tfirstResult: 0,\n\t\tnbResults: 200,\n\t\tmimesType: allMimes,\n\t\tonThisDay: false,\n\t\tonlyFavorites: false,\n\t\t...options,\n\t}\n\n\tconst prefixPath = `/files/${getCurrentUser().uid}`\n\n\t// generating the search or condition\n\t// based on the allowed mimetypes\n\tconst orMime = options.mimesType.reduce((str, mime) => `${str}\n\t\t\n\t\t\t\n\t\t\t\t\n\t\t\t\n\t\t\t${mime}\n\t\t\n\t`, '')\n\n\tconst eqFavorites = options.onlyFavorites\n\t\t? `\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t1\n\t\t\t`\n\t\t: ''\n\n\tconst onThisDay = options.onThisDay\n\t\t? `${Array(20).fill(1)\n\t\t\t.map((_, years) => {\n\t\t\t\tconst start = moment(Date.now()).startOf('day').subtract(3, 'd').subtract(years + 1, 'y')\n\t\t\t\tconst end = moment(Date.now()).endOf('day').add(3, 'd').subtract(years + 1, 'y')\n\t\t\t\treturn `\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t${start.format(moment.defaultFormatUtc)}\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t${end.format(moment.defaultFormatUtc)}\n\t\t\t\t\n\t\t\t`\n\t\t\t}).join('\\n')}`\n\t\t: ''\n\n\toptions = Object.assign({\n\t\tmethod: 'SEARCH',\n\t\theaders: {\n\t\t\t'content-Type': 'text/xml',\n\t\t},\n\t\tdata: `\n\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\t${props}\n\t\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\t${prefixPath}/${path}\n\t\t\t\t\t\t\tinfinity\n\t\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t${orMime}\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t${eqFavorites}\n\t\t\t\t\t\t\t${onThisDay}\n\t\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\t${options.nbResults}\n\t\t\t\t\t\t${options.firstResult}\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t`,\n\t\tdeep: true,\n\t\tdetails: true,\n\t}, options)\n\n\tconst response = await client.getDirectoryContents('', options)\n\n\treturn response.data.map(data => genFileInfo(data))\n}\n","/**\n * @copyright Copyright (c) 2022 Louis Chemineau \n *\n * @author Louis Chemineau \n *\n * @license AGPL-3.0-or-later\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU Affero General Public License as\n * published by the Free Software Foundation, either version 3 of the\n * License, or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU Affero General Public License for more details.\n *\n * You should have received a copy of the GNU Affero General Public License\n * along with this program. If not, see .\n *\n */\n\nimport logger from '../services/logger.js'\nimport getPhotos from '../services/PhotoSearch.js'\nimport SemaphoreWithPriority from '../utils/semaphoreWithPriority.js'\nimport AbortControllerMixin from './AbortControllerMixin.js'\n\nexport default {\n\tname: 'FetchFilesMixin',\n\n\tmixins: [\n\t\tAbortControllerMixin,\n\t],\n\n\tdata() {\n\t\treturn {\n\t\t\terrorFetchingFiles: null,\n\t\t\tloadingFiles: false,\n\t\t\tdoneFetchingFiles: false,\n\t\t\tsemaphore: new SemaphoreWithPriority(30),\n\t\t\tfetchSemaphore: new SemaphoreWithPriority(1),\n\t\t\tsemaphoreSymbol: null,\n\t\t\tfetchedFileIds: [],\n\t\t}\n\t},\n\n\twatch: {\n\t\t$route() {\n\t\t\tthis.resetFetchFilesState()\n\t\t},\n\t},\n\n\tmethods: {\n\t\t/**\n\t\t * @param {string} path - Path to pass to getPhotos.\n\t\t * @param {object} options - Options to pass to getPhotos.\n\t\t * @param {string[]} [blacklist=[]] - Array of ids to filter out.\n\t\t * @return {Promise} - The next batch of data depending on global offset.\n\t\t */\n\t\tasync fetchFiles(path = '', options = {}, blacklist = []) {\n\t\t\tif (this.doneFetchingFiles || this.loadingFiles) {\n\t\t\t\treturn []\n\t\t\t}\n\n\t\t\tconst semaphoreSymbol = await this.semaphore.acquire(() => 0, 'fetchFiles')\n\t\t\tconst fetchSemaphoreSymbol = await this.fetchSemaphore.acquire()\n\n\t\t\ttry {\n\t\t\t\tthis.errorFetchingFiles = null\n\t\t\t\tthis.loadingFiles = true\n\t\t\t\tthis.semaphoreSymbol = semaphoreSymbol\n\n\t\t\t\tconst numberOfImagesPerBatch = 200\n\n\t\t\t\t// Load next batch of images\n\t\t\t\tconst fetchedFiles = await getPhotos(path, {\n\t\t\t\t\tfirstResult: this.fetchedFileIds.length,\n\t\t\t\t\tnbResults: numberOfImagesPerBatch,\n\t\t\t\t\t...options,\n\t\t\t\t\tsignal: this.abortController.signal,\n\t\t\t\t})\n\n\t\t\t\t// If we get less files than requested that means we got to the end\n\t\t\t\tif (fetchedFiles.length !== numberOfImagesPerBatch) {\n\t\t\t\t\tthis.doneFetchingFiles = true\n\t\t\t\t}\n\n\t\t\t\tconst fileIds = fetchedFiles\n\t\t\t\t\t.map(file => file.fileid)\n\t\t\t\t\t.filter(fileId => !this.fetchedFileIds.includes(fileId)) // Filter to prevent duplicate fileIds.\n\n\t\t\t\tthis.fetchedFileIds.push(\n\t\t\t\t\t...fileIds\n\t\t\t\t\t\t.map((fileId) => fileId.toString())\n\t\t\t\t\t\t.filter((fileId) => !blacklist.includes(fileId))\n\t\t\t\t)\n\n\t\t\t\tthis.$store.dispatch('appendFiles', fetchedFiles)\n\n\t\t\t\tlogger.debug(`[FetchFilesMixin] Fetched ${fileIds.length} new files: `, fileIds)\n\n\t\t\t\treturn fileIds\n\t\t\t} catch (error) {\n\t\t\t\tif (error.response?.status === 404) {\n\t\t\t\t\tthis.errorFetchingFiles = 404\n\t\t\t\t} else if (error.code === 'ERR_CANCELED') {\n\t\t\t\t\treturn []\n\t\t\t\t} else {\n\t\t\t\t\tthis.errorFetchingFiles = error\n\t\t\t\t}\n\n\t\t\t\t// cancelled request, moving on...\n\t\t\t\tlogger.error('Error fetching files', { error })\n\t\t\t\tconsole.error(error)\n\t\t\t} finally {\n\t\t\t\tthis.loadingFiles = false\n\t\t\t\tthis.semaphore.release(semaphoreSymbol)\n\t\t\t\tthis.fetchSemaphore.release(fetchSemaphoreSymbol)\n\t\t\t}\n\n\t\t\treturn []\n\t\t},\n\n\t\tresetFetchFilesState() {\n\t\t\tthis.doneFetchingFiles = false\n\t\t\tthis.errorFetchingFiles = null\n\t\t\tthis.loadingFiles = false\n\t\t\tthis.fetchedFileIds = []\n\t\t},\n\t},\n}\n"],"names":["path","options","firstResult","nbResults","mimesType","allMimes","onThisDay","onlyFavorites","prefixPath","getCurrentUser","uid","orMime","reduce","str","mime","eqFavorites","Array","fill","map","_","years","start","moment","Date","now","startOf","subtract","end","endOf","add","format","join","Object","assign","method","headers","data","props","deep","details","client","response","genFileInfo","name","mixins","AbortControllerMixin","errorFetchingFiles","loadingFiles","doneFetchingFiles","semaphore","SemaphoreWithPriority","fetchSemaphore","semaphoreSymbol","fetchedFileIds","watch","$route","this","resetFetchFilesState","methods","fetchFiles","blacklist","acquire","fetchSemaphoreSymbol","numberOfImagesPerBatch","getPhotos","length","signal","abortController","fetchedFiles","fileIds","file","fileid","filter","fileId","includes","push","toString","$store","dispatch","logger","status","code","error","console","release"],"sourceRoot":""}