{"version":3,"file":"FetchCollectionContentMixin-NK9nekKH.chunk.mjs","sources":["../src/mixins/FetchCollectionContentMixin.ts"],"sourcesContent":["/**\n * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\n\nimport type { File } from '@nextcloud/files'\nimport type { WebDAVClient } from 'webdav'\n\nimport { showError } from '@nextcloud/dialogs'\nimport { t } from '@nextcloud/l10n'\nimport { defineComponent } from 'vue'\nimport {\n\ttype Collection,\n\n\tfetchCollection, fetchCollectionFiles,\n} from '../services/collectionFetcher.js'\nimport logger from '../services/logger.js'\nimport { collectionFilesExtraProps } from '../store/collections.js'\nimport SemaphoreWithPriority from '../utils/semaphoreWithPriority.js'\nimport AbortControllerMixin from './AbortControllerMixin.js'\n\nexport default defineComponent({\n\tname: 'FetchCollectionContentMixin',\n\n\tdata() {\n\t\treturn {\n\t\t\tfetchSemaphore: new SemaphoreWithPriority(1),\n\t\t\tloadingCollection: false,\n\t\t\tloadingCollectionFiles: false,\n\t\t\terrorFetchingCollection: null as null | number | Error | unknown,\n\t\t\terrorFetchingCollectionFiles: null as null | number | Error | unknown,\n\t\t}\n\t},\n\n\tmixins: [AbortControllerMixin],\n\n\tmethods: {\n\t\tasync fetchCollection(collectionFileName: string, extraProps: string[], client?: WebDAVClient): Promise {\n\t\t\tif (this.loadingCollection) {\n\t\t\t\treturn null\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tthis.loadingCollection = true\n\t\t\t\tthis.errorFetchingCollection = null\n\n\t\t\t\tconst collection = await fetchCollection(collectionFileName, { signal: this.abortController.signal }, extraProps, client)\n\t\t\t\tthis.$store.dispatch('addCollections', { collections: [collection] })\n\t\t\t\treturn collection\n\t\t\t} catch (error) {\n\t\t\t\tif (error.response?.status === 404) {\n\t\t\t\t\tthis.errorFetchingCollection = 404\n\t\t\t\t\treturn null\n\t\t\t\t}\n\n\t\t\t\tthis.errorFetchingCollection = error\n\t\t\t\tlogger.error('[PublicCollectionContent] Error fetching collection', { error })\n\t\t\t\tshowError(t('photos', 'Failed to fetch collection.'))\n\t\t\t} finally {\n\t\t\t\tthis.loadingCollection = false\n\t\t\t}\n\n\t\t\treturn null\n\t\t},\n\n\t\tasync fetchCollectionFiles(collectionFileName: string, extraProps: string[] = [], client?: WebDAVClient): Promise {\n\t\t\tif (this.loadingCollectionFiles) {\n\t\t\t\treturn []\n\t\t\t}\n\n\t\t\textraProps = [...extraProps, ...collectionFilesExtraProps]\n\n\t\t\tconst fetchSemaphoreSymbol = await this.fetchSemaphore.acquire()\n\n\t\t\ttry {\n\t\t\t\tthis.errorFetchingCollectionFiles = null\n\t\t\t\tthis.loadingCollectionFiles = true\n\n\t\t\t\tconst fetchedFiles = await fetchCollectionFiles(collectionFileName, { signal: this.abortController.signal }, extraProps, client)\n\t\t\t\tconst fileIds = fetchedFiles.map((file) => file.fileid?.toString())\n\n\t\t\t\tthis.$store.dispatch('appendFiles', fetchedFiles)\n\n\t\t\t\tawait this.$store.commit('setCollectionFiles', { collectionFileName, fileIds })\n\n\t\t\t\treturn fetchedFiles\n\t\t\t} catch (error) {\n\t\t\t\tif (error.response?.status === 404) {\n\t\t\t\t\tthis.errorFetchingCollectionFiles = 404\n\t\t\t\t\treturn []\n\t\t\t\t}\n\n\t\t\t\tthis.errorFetchingCollectionFiles = error\n\n\t\t\t\tshowError(t('photos', 'Failed to fetch collections list.'))\n\t\t\t\tlogger.error('[PublicCollectionContent] Error fetching collection files', { error })\n\t\t\t} finally {\n\t\t\t\tthis.loadingCollectionFiles = false\n\t\t\t\tthis.fetchSemaphore.release(fetchSemaphoreSymbol)\n\t\t\t}\n\n\t\t\treturn []\n\t\t},\n\t},\n})\n"],"names":["FetchCollectionContentMixin","defineComponent","SemaphoreWithPriority","AbortControllerMixin","collectionFileName","extraProps","client","collection","fetchCollection","error","logger","showError","t","collectionFilesExtraProps","fetchSemaphoreSymbol","fetchedFiles","fetchCollectionFiles","fileIds","file"],"mappings":"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