From d2509b796aef3aed6693a8fbc625aba3f1a87d33 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Sun, 4 Feb 2024 01:05:37 +0100 Subject: [PATCH] fix: Handle not existing photos location Signed-off-by: Ferdinand Thiessen --- src/mixins/UserConfig.js | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/mixins/UserConfig.js b/src/mixins/UserConfig.js index 0c6ece5ca..07ca27700 100644 --- a/src/mixins/UserConfig.js +++ b/src/mixins/UserConfig.js @@ -21,11 +21,14 @@ */ import { emit, subscribe, unsubscribe } from '@nextcloud/event-bus' -import { generateUrl } from '@nextcloud/router' -import { davGetClient, davGetDefaultPropfind, davResultToNode, davRootPath } from '@nextcloud/files' +import { davGetDefaultPropfind, davResultToNode, davRootPath } from '@nextcloud/files' import { loadState } from '@nextcloud/initial-state' -import axios from '@nextcloud/axios' import { joinPaths } from '@nextcloud/paths' +import { generateUrl } from '@nextcloud/router' +import axios from '@nextcloud/axios' +import { davClient } from '../services/DavClient.ts' +import logger from '../services/logger.js' +import { showError } from '@nextcloud/dialogs' const eventName = 'photos:user-config-changed' @@ -44,9 +47,22 @@ export default { async created() { subscribe(eventName, this.updateLocalSetting) - const davClient = davGetClient() - const stat = await davClient.stat(joinPaths(davRootPath, this.photosLocation), { details: true, data: davGetDefaultPropfind() }) - this.photosLocationFolder = davResultToNode(stat.data) + + const location = joinPaths(davRootPath, this.photosLocation) + '/' + try { + const stat = await davClient.stat(location, { details: true, data: davGetDefaultPropfind() }) + this.photosLocationFolder = davResultToNode(stat.data) + } catch (error) { + if (error.response?.status === 404) { + logger.debug('Photo location does not exist, creating it.') + await davClient.createDirectory(location) + const stat = await davClient.stat(location, { details: true, data: davGetDefaultPropfind() }) + this.photosLocationFolder = davResultToNode(stat.data) + } else { + logger.fatal(error) + showError(t('photos', 'Could not load photos folder')) + } + } }, beforeDestroy() {