photos/js/photos-src_mixins_FetchFile...

1 line
17 KiB
XML

{"version":3,"file":"photos-src_mixins_FetchFilesMixin_js-src_mixins_FilesByMonthMixin_js-src_components_Actions_ActionDo-a6eb03.js?v=c553c993a1b81dc8447c","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;;;;;;;;;;;;;;;;;;;AC9DA;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;;;;;;;;;;;;;;ACtHA;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;;;;;;;;;;;;;;;;;;;;;;ACjDA;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;;;;;;;;;;;;;;;;;AC5IA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAkBA;AACA;;;;;;;;;;;;;;;ACtCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AEAA;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/components/Actions/ActionDownload.vue?vue&type=script&lang=js&","webpack:///photos/src/mixins/FetchFilesMixin.js","webpack:///photos/src/mixins/FilesByMonthMixin.js","webpack:///photos/src/services/PhotoSearch.js","webpack:///photos/src/components/Actions/ActionDownload.vue","webpack://photos/./src/components/Actions/ActionDownload.vue?56d1","webpack:///photos/src/components/Actions/ActionDownload.vue?vue&type=template&id=1aefa300&","webpack://photos/./src/components/Actions/ActionDownload.vue?9b4a"],"sourcesContent":["//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\nimport { mapGetters } from 'vuex';\nimport { generateUrl } from '@nextcloud/router';\nimport { NcActionLink } from '@nextcloud/vue';\nexport default {\n name: 'ActionDownload',\n components: {\n NcActionLink\n },\n props: {\n title: {\n type: String,\n required: true\n },\n selectedFileIds: {\n type: Array,\n required: true\n }\n },\n computed: { ...mapGetters(['files']),\n\n downloadUrl() {\n const params = new URLSearchParams();\n params.append('files', JSON.stringify(this.fileNames));\n return generateUrl(`/apps/files/ajax/download.php?${params}`);\n },\n\n fileNames() {\n return this.selectedFileIds.map(fileId => this.files[fileId].filename);\n }\n\n }\n};","/**\n * @copyright Copyright (c) 2022 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 logger from '../services/logger.js';\nimport getPhotos from '../services/PhotoSearch.js';\nimport SemaphoreWithPriority from '../utils/semaphoreWithPriority.js';\nimport AbortControllerMixin from './AbortControllerMixin.js';\nexport default {\n name: 'FetchFilesMixin',\n mixins: [AbortControllerMixin],\n\n data() {\n return {\n errorFetchingFiles: null,\n loadingFiles: false,\n doneFetchingFiles: false,\n semaphore: new SemaphoreWithPriority(30),\n fetchSemaphore: new SemaphoreWithPriority(1),\n semaphoreSymbol: null,\n fetchedFileIds: []\n };\n },\n\n watch: {\n $route() {\n this.resetFetchFilesState();\n }\n\n },\n methods: {\n /**\n * @param {string} path - Path to pass to getPhotos.\n * @param {object} options - Options to pass to getPhotos.\n * @param {string[]} [blacklist=[]] - Array of ids to filter out.\n * @return {Promise<string[]>} - The next batch of data depending on global offset.\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 let blacklist = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];\n\n if (this.doneFetchingFiles || this.loadingFiles) {\n return [];\n }\n\n const semaphoreSymbol = await this.semaphore.acquire(() => 0, 'fetchFiles');\n const fetchSemaphoreSymbol = await this.fetchSemaphore.acquire();\n\n try {\n this.errorFetchingFiles = null;\n this.loadingFiles = true;\n this.semaphoreSymbol = semaphoreSymbol;\n const numberOfImagesPerBatch = 200; // Load next batch of images\n\n const fetchedFiles = await getPhotos(path, {\n firstResult: this.fetchedFileIds.length,\n nbResults: numberOfImagesPerBatch,\n ...options,\n signal: this.abortController.signal\n }); // If we get less files than requested that means we got to the end\n\n if (fetchedFiles.length !== numberOfImagesPerBatch) {\n this.doneFetchingFiles = true;\n }\n\n const fileIds = fetchedFiles.map(file => file.fileid).filter(fileId => !this.fetchedFileIds.includes(fileId)); // Filter to prevent duplicate fileIds.\n\n this.fetchedFileIds.push(...fileIds.map(fileId => fileId.toString()).filter(fileId => !blacklist.includes(fileId)));\n this.$store.dispatch('appendFiles', fetchedFiles);\n logger.debug(`[FetchFilesMixin] Fetched ${fileIds.length} new files: `, fileIds);\n return fileIds;\n } catch (error) {\n if (error.response?.status === 404) {\n this.errorFetchingFiles = 404;\n } else if (error.code === 'ERR_CANCELED') {\n return [];\n } else {\n this.errorFetchingFiles = error;\n } // cancelled request, moving on...\n\n\n logger.error('Error fetching files', error);\n console.error(error);\n } finally {\n this.loadingFiles = false;\n this.semaphore.release(semaphoreSymbol);\n this.fetchSemaphore.release(fetchSemaphoreSymbol);\n }\n\n return [];\n },\n\n resetFetchFilesState() {\n this.doneFetchingFiles = false;\n this.errorFetchingFiles = null;\n this.loadingFiles = false;\n this.fetchedFileIds = [];\n }\n\n }\n};","/**\n * @copyright Copyright (c) 2022 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: 'FilesByMonthMixin',\n computed: {\n /**\n * @return {object<String, []>}\n */\n fileIdsByMonth() {\n const filesByMonth = {};\n\n for (const fileId of this.fetchedFileIds) {\n const file = this.files[fileId];\n filesByMonth[file.month] = filesByMonth[file.month] ?? [];\n filesByMonth[file.month].push(file.fileid);\n } // Sort files in sections.\n\n\n Object.keys(filesByMonth).forEach(month => filesByMonth[month].sort(this.sortFilesByTimestamp));\n return filesByMonth;\n },\n\n /**\n * @return {string[]}\n */\n monthsList() {\n return Object.keys(this.fileIdsByMonth).sort((month1, month2) => month1 > month2 ? -1 : 1);\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';\nimport { generateRemoteUrl } from '@nextcloud/router';\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<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)).map(file => ({ ...file,\n source: generateRemoteUrl(`dav${file.filename}`)\n }));\n}","import { render, staticRenderFns } from \"./ActionDownload.vue?vue&type=template&id=1aefa300&\"\nimport script from \"./ActionDownload.vue?vue&type=script&lang=js&\"\nexport * from \"./ActionDownload.vue?vue&type=script&lang=js&\"\n\n\n/* normalize component */\nimport normalizer from \"!../../../node_modules/vue-loader/lib/runtime/componentNormalizer.js\"\nvar component = normalizer(\n script,\n render,\n staticRenderFns,\n false,\n null,\n null,\n null\n \n)\n\n/* hot reload */\nif (module.hot) {\n var api = require(\"/home/louis/workspace/nextcloud/apps/photos/node_modules/vue-hot-reload-api/dist/index.js\")\n api.install(require('vue'))\n if (api.compatible) {\n module.hot.accept()\n if (!api.isRecorded('1aefa300')) {\n api.createRecord('1aefa300', component.options)\n } else {\n api.reload('1aefa300', component.options)\n }\n module.hot.accept(\"./ActionDownload.vue?vue&type=template&id=1aefa300&\", function () {\n api.rerender('1aefa300', {\n render: render,\n staticRenderFns: staticRenderFns\n })\n })\n }\n}\ncomponent.options.__file = \"src/components/Actions/ActionDownload.vue\"\nexport default component.exports","import mod from \"-!../../../node_modules/babel-loader/lib/index.js!../../../node_modules/vue-loader/lib/index.js??vue-loader-options!./ActionDownload.vue?vue&type=script&lang=js&\"; export default mod; export * from \"-!../../../node_modules/babel-loader/lib/index.js!../../../node_modules/vue-loader/lib/index.js??vue-loader-options!./ActionDownload.vue?vue&type=script&lang=js&\"","export * from \"-!../../../node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!../../../node_modules/vue-loader/lib/index.js??vue-loader-options!./ActionDownload.vue?vue&type=template&id=1aefa300&\"","var render = function () {\n var _vm = this\n var _h = _vm.$createElement\n var _c = _vm._self._c || _h\n return _c(\n \"NcActionLink\",\n {\n attrs: {\n \"close-after-click\": true,\n href: _vm.downloadUrl,\n download: _vm.downloadUrl,\n \"aria-label\": _vm.title,\n },\n },\n [\n _vm._v(\"\\n\\t\" + _vm._s(_vm.title) + \"\\n\\t\"),\n _vm._t(\"icon\", null, { slot: \"icon\" }),\n ],\n 2\n )\n}\nvar staticRenderFns = []\nrender._withStripped = true\n\nexport { render, staticRenderFns }"],"names":[],"sourceRoot":""}