diff --git a/src/components/MediaSettings/VideoBackgroundEditor.vue b/src/components/MediaSettings/VideoBackgroundEditor.vue index 5d21dfac901..082c3d7b518 100644 --- a/src/components/MediaSettings/VideoBackgroundEditor.vue +++ b/src/components/MediaSettings/VideoBackgroundEditor.vue @@ -92,7 +92,7 @@ import { imagePath, generateUrl } from '@nextcloud/router' import { VIRTUAL_BACKGROUND } from '../../constants.js' import BrowserStorage from '../../services/BrowserStorage.js' -import client from '../../services/DavClient.js' +import { getDavClient } from '../../services/DavClient.js' import { findUniquePath } from '../../utils/fileUpload.js' const canUploadBackgrounds = getCapabilities()?.spreed?.config?.call?.['can-upload-background'] @@ -176,6 +176,7 @@ export default { try { // Create the backgrounds folder if it doesn't exist + const client = getDavClient() if (await client.exists(absoluteBackgroundsFolderPath) === false) { await client.createDirectory(absoluteBackgroundsFolderPath) } @@ -219,6 +220,7 @@ export default { const filePath = this.$store.getters.getAttachmentFolder() + '/Backgrounds/' + file.name + const client = getDavClient() // Get a unique relative path based on the previous path variable const uniquePath = await findUniquePath(client, userRoot, filePath) diff --git a/src/services/DavClient.js b/src/services/DavClient.js index 59e36991314..769557ec00c 100644 --- a/src/services/DavClient.js +++ b/src/services/DavClient.js @@ -26,8 +26,8 @@ import { getRequestToken } from '@nextcloud/auth' import { generateRemoteUrl } from '@nextcloud/router' // init webdav client on default dav endpoint -const client = createClient(generateRemoteUrl('dav'), - { headers: { requesttoken: getRequestToken() || '' } }, -) - -export default client +export const getDavClient = () => { + return createClient(generateRemoteUrl('dav'), + { headers: { requesttoken: getRequestToken() || '' } }, + ) +} diff --git a/src/store/fileUploadStore.js b/src/store/fileUploadStore.js index a167927bff0..f2c095c6ee8 100644 --- a/src/store/fileUploadStore.js +++ b/src/store/fileUploadStore.js @@ -26,7 +26,7 @@ import { showError } from '@nextcloud/dialogs' import { loadState } from '@nextcloud/initial-state' import moment from '@nextcloud/moment' -import client from '../services/DavClient.js' +import { getDavClient } from '../services/DavClient.js' import { EventBus } from '../services/EventBus.js' import { getFileTemplates, @@ -312,6 +312,7 @@ const actions = { const fileName = (currentFile.newName || currentFile.name) // Candidate rest of the path const path = getters.getAttachmentFolder() + '/' + fileName + const client = getDavClient() // Get a unique relative path based on the previous path variable const uniquePath = await findUniquePath(client, userRoot, path) try { diff --git a/src/store/fileUploadStore.spec.js b/src/store/fileUploadStore.spec.js index cf1762f6e41..8e6fbe3be0e 100644 --- a/src/store/fileUploadStore.spec.js +++ b/src/store/fileUploadStore.spec.js @@ -5,14 +5,14 @@ import Vuex from 'vuex' import { showError } from '@nextcloud/dialogs' -import client from '../services/DavClient.js' +import { getDavClient } from '../services/DavClient.js' import { shareFile } from '../services/filesSharingServices.js' import { setAttachmentFolder } from '../services/settingsService.js' import { findUniquePath, getFileExtension } from '../utils/fileUpload.js' import fileUploadStore from './fileUploadStore.js' jest.mock('../services/DavClient', () => ({ - putFileContents: jest.fn(), + getDavClient: jest.fn(), })) jest.mock('../utils/fileUpload', () => ({ findUniquePath: jest.fn(), @@ -79,11 +79,15 @@ describe('fileUploadStore', () => { describe('uploading', () => { let restoreConsole + const client = { + putFileContents: jest.fn(), + } beforeEach(() => { storeConfig.getters.getAttachmentFolder = jest.fn().mockReturnValue(() => '/Talk') store = new Vuex.Store(storeConfig) restoreConsole = mockConsole(['error', 'debug']) + getDavClient.mockReturnValue(client) }) afterEach(() => { @@ -153,7 +157,6 @@ describe('fileUploadStore', () => { const uniqueFileName = '/Talk/' + file.name + 'uniq' findUniquePath.mockResolvedValueOnce(uniqueFileName) - client.putFileContents.mockResolvedValue() shareFile.mockResolvedValue() await store.dispatch('uploadFiles', { uploadId: 'upload-id1', caption: 'text-caption' }) @@ -201,7 +204,6 @@ describe('fileUploadStore', () => { findUniquePath .mockResolvedValueOnce('/Talk/' + files[0].name + 'uniq') .mockResolvedValueOnce('/Talk/' + files[1].name + 'uniq') - client.putFileContents.mockResolvedValue() shareFile .mockResolvedValueOnce({ data: { ocs: { data: { id: '1' } } } }) .mockResolvedValueOnce({ data: { ocs: { data: { id: '2' } } } }) @@ -280,7 +282,6 @@ describe('fileUploadStore', () => { findUniquePath .mockResolvedValueOnce('/Talk/' + files[0].name + 'uniq') - client.putFileContents.mockResolvedValue() shareFile.mockRejectedValueOnce({ response: { status: 403,