photos/js/photos-src_mixins_FetchFile...

1 line
13 KiB
XML

{"version":3,"file":"photos-src_mixins_FetchFilesMixin_js-src_mixins_FilesSelectionMixin_js.js?v=f8b0ec433ba3144eb8ff","mappings":";;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;ACvHA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;;;;AC/DA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","sources":["webpack:///photos/src/mixins/FetchFilesMixin.js","webpack:///photos/src/mixins/FilesSelectionMixin.js","webpack:///photos/src/services/PhotoSearch.js"],"sourcesContent":["/**\n * @copyright Copyright (c) 2019 Louis Chemineau <louis@chmn.me>\n *\n * @author Louis Chemineau <louis@chmn.me>\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 <http://www.gnu.org/licenses/>.\n *\n */\nimport { mapGetters } from 'vuex';\nimport logger from '../services/logger.js';\nimport getPhotos from '../services/PhotoSearch.js';\nimport cancelableRequest from '../utils/CancelableRequest.js';\nimport SemaphoreWithPriority from '../utils/semaphoreWithPriority.js';\nexport default {\n name: 'FetchFilesMixin',\n\n data() {\n return {\n errorFetchingFiles: null,\n loadingFiles: false,\n nbFetchedFiles: 0,\n doneFetchingFiles: false,\n cancelFilesRequest: () => {},\n semaphore: new SemaphoreWithPriority(30),\n semaphoreSymbol: null\n };\n },\n\n beforeDestroy() {\n this.cancelFilesRequest('Changed view');\n },\n\n computed: { ...mapGetters(['files'])\n },\n methods: {\n /**\n * @param {string} path\n * @return {Promise<Array>} - The next batch of data depending on global offset.\n async fetchFiles(path = '', options = {\n }) {\n */\n async fetchFiles() {\n let path = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';\n let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n\n if (this.doneFetchingFiles || this.loadingFiles) {\n return [];\n }\n\n try {\n this.errorFetchingFiles = null;\n this.loadingFiles = true;\n this.semaphoreSymbol = await this.semaphore.acquire(() => 0, 'fetchFiles');\n const {\n request,\n cancel\n } = cancelableRequest(getPhotos);\n this.cancelFilesRequest = cancel;\n const numberOfImagesPerBatch = 1000; // Load next batch of images\n\n const files = await request(path, {\n // We reuse already fetched files in the store when moving from one tab to another, but to make sure that we have all the files, we keep an internal counter (nbFetchedFiles).\n // Some files will be fetched twice, but we have less loading time when switching between tabs.\n firstResult: this.nbFetchedFiles,\n nbResults: numberOfImagesPerBatch,\n ...options\n }); // If we get less files than requested that means we got to the end\n\n if (files.length !== numberOfImagesPerBatch) {\n this.doneFetchingFiles = true;\n }\n\n this.nbFetchedFiles += files.length;\n this.$store.dispatch('appendFiles', files);\n return files;\n } catch (error) {\n if (error.response && error.response.status) {\n if (error.response.status === 404) {\n this.errorFetchingFiles = 404;\n } else {\n this.errorFetchingFiles = error;\n }\n } // cancelled request, moving on...\n\n\n logger.error('Error fetching files', error);\n } finally {\n this.loadingFiles = false;\n\n this.cancelFilesRequest = () => {};\n\n this.semaphore.release(this.semaphoreSymbol);\n this.semaphoreSymbol = null;\n }\n\n return [];\n },\n\n resetState() {\n this.doneFetchingFiles = false;\n this.errorFetchingFiles = null;\n this.loadingFiles = false;\n this.nbFetchedFiles = 0;\n }\n\n }\n};","/**\n * @copyright Copyright (c) 2019 Louis Chemineau <louis@chmn.me>\n *\n * @author Louis Chemineau <louis@chmn.me>\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 <http://www.gnu.org/licenses/>.\n *\n */\nexport default {\n name: 'FilesSelectionMixin',\n\n data() {\n return {\n /** @type {Object<string, boolean>} */\n selection: {},\n\n /** @type {Object<string, string[]>} */\n sections: {} // To be override by the component that use the mixin.\n\n };\n },\n\n methods: {\n onFileSelectToggle(_ref) {\n let {\n id,\n value\n } = _ref;\n this.$set(this.selection, id, value);\n },\n\n /**\n * @param {string[]} filesIds - The ids of the files to uncheck.\n */\n onUncheckFiles(filesIds) {\n filesIds.forEach((\n /** @type {string} */\n filesId) => this.$set(this.selectedFiles, filesId, false));\n }\n\n },\n computed: {\n /**\n * @return {string[]}\n */\n selectedFileIds() {\n return Object.keys(this.selection).filter(fileId => this.selection[fileId]);\n }\n\n }\n};","/**\n * @copyright Copyright (c) 2019 John Molakvoæ <skjnldsv@protonmail.com>\n *\n * @author John Molakvoæ <skjnldsv@protonmail.com>\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 <http://www.gnu.org/licenses/>.\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 * 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 favorie items\n * @return {Promise<object[]>} the file list\n */\n\nexport default async function () {\n let path = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';\n let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n // default function options\n options = {\n firstResult: 0,\n nbResults: 200,\n mimesType: allMimes,\n onThisDay: false,\n onlyFavorites: false,\n ...options\n };\n const prefixPath = `/files/${getCurrentUser().uid}`; // generating the search or condition\n // based on the allowed mimetypes\n\n const orMime = options.mimesType.reduce((str, mime) => `${str}\n\t\t<d:eq>\n\t\t\t<d:prop>\n\t\t\t\t<d:getcontenttype/>\n\t\t\t</d:prop>\n\t\t\t<d:literal>${mime}</d:literal>\n\t\t</d:eq>\n\t`, '');\n const eqFavorites = options.onlyFavorites ? `<d:eq>\n\t\t\t\t<d:prop>\n\t\t\t\t\t<oc:favorite/>\n\t\t\t\t</d:prop>\n\t\t\t\t<d:literal>1</d:literal>\n\t\t\t</d:eq>` : '';\n const onThisDay = options.onThisDay ? `<d:or>${Array(20).fill(1).map((_, years) => {\n const start = moment(Date.now()).startOf('day').subtract(3, 'd').subtract(years + 1, 'y');\n const end = moment(Date.now()).endOf('day').add(3, 'd').subtract(years + 1, 'y');\n return `<d:and>\n\t\t\t\t<d:gt>\n\t\t\t\t\t<d:prop>\n\t\t\t\t\t\t<d:getlastmodified />\n\t\t\t\t\t</d:prop>\n\t\t\t\t\t<d:literal>${start.format(moment.defaultFormatUtc)}</d:literal>\n\t\t\t\t</d:gt>\n\t\t\t\t<d:lt>\n\t\t\t\t\t<d:prop>\n\t\t\t\t\t\t<d:getlastmodified />\n\t\t\t\t\t</d:prop>\n\t\t\t\t\t<d:literal>${end.format(moment.defaultFormatUtc)}</d:literal>\n\t\t\t\t</d:lt>\n\t\t\t</d:and>`;\n }).join('\\n')}</d:or>` : '';\n options = Object.assign({\n method: 'SEARCH',\n headers: {\n 'content-Type': 'text/xml'\n },\n data: `<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\t\t\t<d:searchrequest xmlns:d=\"DAV:\"\n\t\t\t\txmlns:oc=\"http://owncloud.org/ns\"\n\t\t\t\txmlns:nc=\"http://nextcloud.org/ns\"\n\t\t\t\txmlns:ns=\"https://github.com/icewind1991/SearchDAV/ns\"\n\t\t\t\txmlns:ocs=\"http://open-collaboration-services.org/ns\">\n\t\t\t\t<d:basicsearch>\n\t\t\t\t\t<d:select>\n\t\t\t\t\t\t<d:prop>\n\t\t\t\t\t\t\t${props}\n\t\t\t\t\t\t</d:prop>\n\t\t\t\t\t</d:select>\n\t\t\t\t\t<d:from>\n\t\t\t\t\t\t<d:scope>\n\t\t\t\t\t\t\t<d:href>${prefixPath}/${path}</d:href>\n\t\t\t\t\t\t\t<d:depth>infinity</d:depth>\n\t\t\t\t\t\t</d:scope>\n\t\t\t\t\t</d:from>\n\t\t\t\t\t<d:where>\n\t\t\t\t\t\t<d:and>\n\t\t\t\t\t\t\t<d:or>\n\t\t\t\t\t\t\t\t${orMime}\n\t\t\t\t\t\t\t</d:or>\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</d:and>\n\t\t\t\t\t</d:where>\n\t\t\t\t\t<d:orderby>\n\t\t\t\t\t\t<d:order>\n\t\t\t\t\t\t\t<d:prop><d:getlastmodified/></d:prop>\n\t\t\t\t\t\t\t<d:descending/>\n\t\t\t\t\t\t</d:order>\n\t\t\t\t\t</d:orderby>\n\t\t\t\t\t<d:limit>\n\t\t\t\t\t\t<d:nresults>${options.nbResults}</d:nresults>\n\t\t\t\t\t\t<ns:firstresult>${options.firstResult}</ns:firstresult>\n\t\t\t\t\t</d:limit>\n\t\t\t\t</d:basicsearch>\n\t\t\t</d:searchrequest>`,\n deep: true,\n details: true\n }, options);\n const response = await client.getDirectoryContents('', options);\n return response.data.map(data => genFileInfo(data)) // remove prefix path from full file path\n .map(data => ({ ...data,\n filename: data.filename.replace(prefixPath, '')\n }));\n}"],"names":[],"sourceRoot":""}