Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable27] fix(DAVClient): wrap DAV client creation in a function #10891

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/components/MediaSettings/VideoBackgroundEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -220,6 +221,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)

Expand Down
10 changes: 5 additions & 5 deletions src/services/DavClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() || '' } },
)
}
3 changes: 2 additions & 1 deletion src/store/fileUploadStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 6 additions & 4 deletions src/store/fileUploadStore.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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(() => {
Expand Down Expand Up @@ -163,7 +167,6 @@ describe('fileUploadStore', () => {
findUniquePath
.mockResolvedValueOnce('/Talk/' + files[0].name + 'uniq')
.mockResolvedValueOnce('/Talk/' + files[1].name + 'uniq')
client.putFileContents.mockResolvedValue()
shareFile.mockResolvedValue()

await store.dispatch('uploadFiles', 'upload-id1')
Expand Down Expand Up @@ -240,7 +243,6 @@ describe('fileUploadStore', () => {

findUniquePath
.mockResolvedValueOnce('/Talk/' + files[0].name + 'uniq')
client.putFileContents.mockResolvedValue()
shareFile.mockRejectedValueOnce({
response: {
status: 403,
Expand Down
Loading