"use strict"; (self["webpackChunkphotos"] = self["webpackChunkphotos"] || []).push([["src_mixins_FetchFilesMixin_js-src_mixins_FilesSelectionMixin_js"],{ /***/ "./src/mixins/FetchFilesMixin.js": /*!***************************************!*\ !*** ./src/mixins/FetchFilesMixin.js ***! \***************************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) /* harmony export */ }); /* harmony import */ var vuex__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! vuex */ "./node_modules/vuex/dist/vuex.esm.js"); /* harmony import */ var _services_logger_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../services/logger.js */ "./src/services/logger.js"); /* harmony import */ var _services_PhotoSearch_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../services/PhotoSearch.js */ "./src/services/PhotoSearch.js"); /* harmony import */ var _utils_CancelableRequest_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../utils/CancelableRequest.js */ "./src/utils/CancelableRequest.js"); /* harmony import */ var _utils_semaphoreWithPriority_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../utils/semaphoreWithPriority.js */ "./src/utils/semaphoreWithPriority.js"); /** * @copyright Copyright (c) 2019 Louis Chemineau * * @author Louis Chemineau * * @license AGPL-3.0-or-later * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . * */ /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({ name: 'FetchFilesMixin', data() { return { errorFetchingFiles: null, loadingFiles: false, nbFetchedFiles: 0, doneFetchingFiles: false, cancelFilesRequest: () => {}, semaphore: new _utils_semaphoreWithPriority_js__WEBPACK_IMPORTED_MODULE_3__["default"](30), semaphoreSymbol: null }; }, beforeDestroy() { this.cancelFilesRequest('Changed view'); }, computed: { ...(0,vuex__WEBPACK_IMPORTED_MODULE_4__.mapGetters)(['files']) }, methods: { /** * @param {string} path * @return {Promise} - The next batch of data depending on global offset. async fetchFiles(path = '', options = { }) { */ async fetchFiles() { let path = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; if (this.doneFetchingFiles || this.loadingFiles) { return []; } try { this.errorFetchingFiles = null; this.loadingFiles = true; this.semaphoreSymbol = await this.semaphore.acquire(() => 0, 'fetchFiles'); const { request, cancel } = (0,_utils_CancelableRequest_js__WEBPACK_IMPORTED_MODULE_2__["default"])(_services_PhotoSearch_js__WEBPACK_IMPORTED_MODULE_1__["default"]); this.cancelFilesRequest = cancel; const numberOfImagesPerBatch = 1000; // Load next batch of images const files = await request(path, { // 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). // Some files will be fetched twice, but we have less loading time when switching between tabs. firstResult: this.nbFetchedFiles, nbResults: numberOfImagesPerBatch, ...options }); // If we get less files than requested that means we got to the end if (files.length !== numberOfImagesPerBatch) { this.doneFetchingFiles = true; } this.nbFetchedFiles += files.length; this.$store.dispatch('appendFiles', files); return files; } catch (error) { if (error.response && error.response.status) { if (error.response.status === 404) { this.errorFetchingFiles = 404; } else { this.errorFetchingFiles = error; } } // cancelled request, moving on... _services_logger_js__WEBPACK_IMPORTED_MODULE_0__["default"].error('Error fetching files', error); } finally { this.loadingFiles = false; this.cancelFilesRequest = () => {}; this.semaphore.release(this.semaphoreSymbol); this.semaphoreSymbol = null; } return []; }, resetState() { this.doneFetchingFiles = false; this.errorFetchingFiles = null; this.loadingFiles = false; this.nbFetchedFiles = 0; } } }); /***/ }), /***/ "./src/mixins/FilesSelectionMixin.js": /*!*******************************************!*\ !*** ./src/mixins/FilesSelectionMixin.js ***! \*******************************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) /* harmony export */ }); /** * @copyright Copyright (c) 2019 Louis Chemineau * * @author Louis Chemineau * * @license AGPL-3.0-or-later * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . * */ /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({ name: 'FilesSelectionMixin', data() { return { /** @type {Object} */ selection: {}, /** @type {Object} */ sections: {} // To be override by the component that use the mixin. }; }, methods: { onFileSelectToggle(_ref) { let { id, value } = _ref; this.$set(this.selection, id, value); }, /** * @param {string[]} filesIds - The ids of the files to uncheck. */ onUncheckFiles(filesIds) { filesIds.forEach(( /** @type {string} */ filesId) => this.$set(this.selectedFiles, filesId, false)); } }, computed: { /** * @return {string[]} */ selectedFileIds() { return Object.keys(this.selection).filter(fileId => this.selection[fileId]); } } }); /***/ }), /***/ "./src/services/PhotoSearch.js": /*!*************************************!*\ !*** ./src/services/PhotoSearch.js ***! \*************************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "default": () => (/* export default binding */ __WEBPACK_DEFAULT_EXPORT__) /* harmony export */ }); /* harmony import */ var _utils_fileUtils_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../utils/fileUtils.js */ "./src/utils/fileUtils.js"); /* harmony import */ var _nextcloud_auth__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @nextcloud/auth */ "./node_modules/@nextcloud/auth/dist/index.js"); /* harmony import */ var _AllowedMimes_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./AllowedMimes.js */ "./src/services/AllowedMimes.js"); /* harmony import */ var _DavClient_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./DavClient.js */ "./src/services/DavClient.js"); /* harmony import */ var _DavRequest_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./DavRequest.js */ "./src/services/DavRequest.js"); /* harmony import */ var _nextcloud_moment__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @nextcloud/moment */ "./node_modules/@nextcloud/moment/dist/index.js"); /* harmony import */ var _nextcloud_moment__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_nextcloud_moment__WEBPACK_IMPORTED_MODULE_5__); /** * @copyright Copyright (c) 2019 John Molakvoæ * * @author John Molakvoæ * * @license AGPL-3.0-or-later * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . * */ /** * List files from a folder and filter out unwanted mimes * * @param {object} path the lookup path * @param {object} [options] used for the cancellable requests * @param {number} [options.firstResult=0] Index of the first result that we want (starts at 0) * @param {number} [options.nbResults=200] The number of file to fetch * @param {string[]} [options.mimesType=allMimes] Mime type of the files * @param {boolean} [options.full=false] get full data of the files * @param {boolean} [options.onThisDay=false] get only items from this day of year * @param {boolean} [options.onlyFavorites=false] get only favorie items * @return {Promise} the file list */ /* harmony default export */ async function __WEBPACK_DEFAULT_EXPORT__() { let path = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; // default function options options = { firstResult: 0, nbResults: 200, mimesType: _AllowedMimes_js__WEBPACK_IMPORTED_MODULE_2__.allMimes, onThisDay: false, onlyFavorites: false, ...options }; const prefixPath = `/files/${(0,_nextcloud_auth__WEBPACK_IMPORTED_MODULE_1__.getCurrentUser)().uid}`; // generating the search or condition // based on the allowed mimetypes const orMime = options.mimesType.reduce((str, mime) => `${str} ${mime} `, ''); const eqFavorites = options.onlyFavorites ? ` 1 ` : ''; const onThisDay = options.onThisDay ? `${Array(20).fill(1).map((_, years) => { const start = _nextcloud_moment__WEBPACK_IMPORTED_MODULE_5___default()(Date.now()).startOf('day').subtract(3, 'd').subtract(years + 1, 'y'); const end = _nextcloud_moment__WEBPACK_IMPORTED_MODULE_5___default()(Date.now()).endOf('day').add(3, 'd').subtract(years + 1, 'y'); return ` ${start.format((_nextcloud_moment__WEBPACK_IMPORTED_MODULE_5___default().defaultFormatUtc))} ${end.format((_nextcloud_moment__WEBPACK_IMPORTED_MODULE_5___default().defaultFormatUtc))} `; }).join('\n')}` : ''; options = Object.assign({ method: 'SEARCH', headers: { 'content-Type': 'text/xml' }, data: ` ${_DavRequest_js__WEBPACK_IMPORTED_MODULE_4__.props} ${prefixPath}/${path} infinity ${orMime} ${eqFavorites} ${onThisDay} ${options.nbResults} ${options.firstResult} `, deep: true, details: true }, options); const response = await _DavClient_js__WEBPACK_IMPORTED_MODULE_3__["default"].getDirectoryContents('', options); return response.data.map(data => (0,_utils_fileUtils_js__WEBPACK_IMPORTED_MODULE_0__.genFileInfo)(data)) // remove prefix path from full file path .map(data => ({ ...data, filename: data.filename.replace(prefixPath, '') })); } /***/ }) }]); //# sourceMappingURL=photos-src_mixins_FetchFilesMixin_js-src_mixins_FilesSelectionMixin_js.js.map?v=f8b0ec433ba3144eb8ff