Skip to content

Commit

Permalink
fix: Handle not existing photos location
Browse files Browse the repository at this point in the history
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
  • Loading branch information
susnux committed Feb 4, 2024
1 parent 3f18ec3 commit 8731f8a
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/mixins/UserConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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() {
Expand Down

0 comments on commit 8731f8a

Please sign in to comment.