Skip to content

refactor(BackupManager, WebDav): streamline WebDAV client initialization and enhance directory listing functionality #6784

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

Merged
merged 1 commit into from
Jun 4, 2025
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
10 changes: 3 additions & 7 deletions src/main/services/BackupManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Logger from 'electron-log'
import * as fs from 'fs-extra'
import StreamZip from 'node-stream-zip'
import * as path from 'path'
import { createClient, CreateDirectoryOptions, FileStat } from 'webdav'
import { CreateDirectoryOptions, FileStat } from 'webdav'

import WebDav from './WebDav'
import { windowService } from './WindowService'
Expand Down Expand Up @@ -340,12 +340,8 @@ class BackupManager {

listWebdavFiles = async (_: Electron.IpcMainInvokeEvent, config: WebDavConfig) => {
try {
const client = createClient(config.webdavHost, {
username: config.webdavUser,
password: config.webdavPass
})

const response = await client.getDirectoryContents(config.webdavPath)
const client = new WebDav(config)
const response = await client.getDirectoryContents()
const files = Array.isArray(response) ? response : response.data

return files
Expand Down
17 changes: 16 additions & 1 deletion src/main/services/WebDav.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { WebDavConfig } from '@types'
import Logger from 'electron-log'
import Stream from 'stream'
import https from 'https'
import {
BufferLike,
createClient,
Expand All @@ -20,7 +21,8 @@ export default class WebDav {
username: params.webdavUser,
password: params.webdavPass,
maxBodyLength: Infinity,
maxContentLength: Infinity
maxContentLength: Infinity,
httpsAgent: new https.Agent({ rejectUnauthorized: false })
})

this.putFileContents = this.putFileContents.bind(this)
Expand Down Expand Up @@ -74,6 +76,19 @@ export default class WebDav {
}
}

public getDirectoryContents = async () => {
if (!this.instance) {
throw new Error('WebDAV client not initialized')
}

try {
return await this.instance.getDirectoryContents(this.webdavPath)
} catch (error) {
Logger.error('[WebDAV] Error getting directory contents on WebDAV:', error)
throw error
}
}

public checkConnection = async () => {
if (!this.instance) {
throw new Error('WebDAV client not initialized')
Expand Down
Loading