Skip to content
Merged

NKDAV #216

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
5 changes: 0 additions & 5 deletions Sources/NextcloudKit/NKCommon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -407,11 +407,6 @@ public struct NKCommon: Sendable {
return 0
}

public func returnPathfromServerUrl(_ serverUrl: String, urlBase: String, userId: String) -> String {
let home = urlBase + "/remote.php/dav/files/" + userId
return serverUrl.replacingOccurrences(of: home, with: "")
}

public func getSessionErrorFromAFError(_ afError: AFError?) -> NSError? {
if let afError = afError?.asAFError {
switch afError {
Expand Down
38 changes: 38 additions & 0 deletions Sources/NextcloudKit/NKDav.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// SPDX-FileCopyrightText: Nextcloud GmbH
// SPDX-FileCopyrightText: 2026 Marino Faggiana
// SPDX-License-Identifier: GPL-3.0-or-later

/// Utility namespace for constructing Nextcloud WebDAV (DAV) endpoint paths.
///
/// The standard DAV structure in Nextcloud is:
/// `<baseURL>/remote.php/dav/files/<userId>/`
public enum NKDav {

// Base DAV endpoint used by Nextcloud
public static let basePath = "/remote.php/dav/"

// Files namespace within DAV
public static let filesPath = "files/"

/// Builds the user DAV path with trailing slash
/// Example: /remote.php/dav/files/<userId>/
public static func userPath(userId: String) -> String {
basePath + filesPath + userId + "/"
}

/// Builds the user DAV path without trailing slash
/// Example: /remote.php/dav/files/<userId>
public static func userPathNoSlash(userId: String) -> String {
basePath + filesPath + userId
}

/// Full DAV URL (with trailing slash)
public static func homeURLString(urlBase: String, userId: String) -> String {
urlBase + userPath(userId: userId)
}

/// Full DAV URL (without trailing slash)
public static func homeURLStringNoSlash(urlBase: String, userId: String) -> String {
urlBase + userPathNoSlash(userId: userId)
}
}
7 changes: 4 additions & 3 deletions Sources/NextcloudKit/NextcloudKit+Upload.swift
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,10 @@ public extension NextcloudKit {
// Build endpoints and headers
let totalFileSize = self.nkCommonInstance.getFileSize(filePath: directory + "/" + fileName)
let serverUrlChunkFolder = nkSession.urlBase + "/" + nkSession.dav + "/uploads/" + nkSession.userId + "/" + chunkFolder
let serverUrlFileName = nkSession.urlBase + "/" + nkSession.dav + "/files/" + nkSession.userId
+ self.nkCommonInstance.returnPathfromServerUrl(serverUrl, urlBase: nkSession.urlBase, userId: nkSession.userId)
+ "/" + (destinationFileName ?? fileName)
let serverUrlFileName = NKDav.homeURLString(urlBase: nkSession.urlBase, userId: nkSession.userId)
+ serverUrl.replacingOccurrences(of: NKDav.homeURLStringNoSlash(urlBase: nkSession.urlBase, userId: nkSession.userId), with: "")
+ "/"
+ (destinationFileName ?? fileName)

if options.customHeader == nil { options.customHeader = [:] }
options.customHeader?["Destination"] = serverUrlFileName.urlEncoded
Expand Down
Loading