Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-FileCopyrightText: Nextcloud GmbH
// SPDX-FileCopyrightText: 2025 Marino Faggiana
// SPDX-License-Identifier: GPL-3.0-or-later

import Foundation

public enum NKDirectEditingCapabilitiesConverter {

/// Parses and converts raw JSON `Data` into `[NKDirectEditingEditor]` and `[NKDirectEditingCreator]`.
/// - Parameter data: Raw JSON `Data` from the editors/creators endpoint.
/// - Returns: A tuple with editors and creators.
/// - Throws: Decoding error if parsing fails.
public static func from(data: Data) throws -> (editors: [NKDirectEditingEditor], creators: [NKDirectEditingCreator]) {
let decoded = try JSONDecoder().decode(NKDirectEditingCapabilitiesResponse.self, from: data)
let editors = Array(decoded.ocs.data.editors.values)
let creators = Array(decoded.ocs.data.creators.values)

if NKLogFileManager.shared.logLevel == .verbose {
data.printJson()
}

return (editors, creators)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,62 @@

import Foundation

public struct NKEditorDetailsResponse: Codable, Sendable {
public struct NKDirectEditingCapabilitiesResponse: Codable, Sendable {
public let ocs: OCS

public struct OCS: Codable, Sendable {
public let data: DataClass

public struct DataClass: Codable, Sendable {
public let editors: [String: NKEditorDetailsEditor]
public let creators: [String: NKEditorDetailsCreator]
public let editors: [String: NKDirectEditingEditor]
public let creators: [String: NKDirectEditingCreator]
}
}
}

public struct NKEditorTemplateResponse: Codable, Sendable {
public struct NKDirectEditingTemplateResponse: Codable, Sendable {
public let ocs: OCS

public struct OCS: Codable, Sendable {
public let data: DataClass

public struct DataClass: Codable, Sendable {
public let editors: [NKEditorTemplate]
public let templates: [String: NKDirectEditingTemplate]
}
}
}

public struct NKEditorDetailsEditor: Codable, Sendable {
public struct NKDirectEditingTemplate: Codable, Sendable {
public let ext: String
public let identifier: String
public let mimetype: String
public let name: String
public let preview: String?

enum CodingKeys: String, CodingKey {
case ext = "extension"
case identifier = "id"
case mimetype
case name = "title"
case preview
}

public init(
ext: String = "",
identifier: String = "",
mimetype: String = "",
name: String = "",
preview: String? = nil
) {
self.ext = ext
self.identifier = identifier
self.mimetype = mimetype
self.name = name
self.preview = preview
}
}

public struct NKDirectEditingEditor: Codable, Sendable {
public let identifier: String
public let mimetypes: [String]
public let name: String
Expand All @@ -45,7 +75,7 @@ public struct NKEditorDetailsEditor: Codable, Sendable {
}
}

public struct NKEditorDetailsCreator: Codable, Sendable {
public struct NKDirectEditingCreator: Codable, Sendable {
public let identifier: String
public let templates: Bool
public let mimetype: String
Expand All @@ -62,24 +92,3 @@ public struct NKEditorDetailsCreator: Codable, Sendable {
case ext = "extension"
}
}

public struct NKEditorTemplate: Codable, Sendable {
public var ext: String
public var identifier: String
public var name: String
public var preview: String

enum CodingKeys: String, CodingKey {
case ext = "extension"
case identifier = "id"
case name
case preview
}

public init(ext: String = "", identifier: String = "", name: String = "", preview: String = "") {
self.ext = ext
self.identifier = identifier
self.name = name
self.preview = preview
}
}

This file was deleted.

This file was deleted.

48 changes: 23 additions & 25 deletions Sources/NextcloudKit/NextcloudKit+Capabilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -521,32 +521,30 @@ final public class NKCapabilities: Sendable {
///
/// The version of the locking API.
///
public var filesLockVersion: String = "" // NC 24
public var filesComments: Bool = false // NC 20
public var filesBigfilechunking: Bool = false
public var userStatusEnabled: Bool = false
public var userStatusSupportsBusy: Bool = false
public var externalSites: Bool = false
public var activityEnabled: Bool = false
public var governanceEnabled: Bool = false
public var groupfoldersEnabled: Bool = false // NC27
public var assistantEnabled: Bool = false // NC28
public var isLivePhotoServerAvailable: Bool = false // NC28
public var securityGuardDiagnostics = false
public var filesLockVersion: String = "" // NC 24
public var filesComments: Bool = false // NC 20
public var filesBigfilechunking: Bool = false
public var userStatusEnabled: Bool = false
public var userStatusSupportsBusy: Bool = false
public var externalSites: Bool = false
public var activityEnabled: Bool = false
public var governanceEnabled: Bool = false
public var groupfoldersEnabled: Bool = false // NC27
public var assistantEnabled: Bool = false // NC28
public var isLivePhotoServerAvailable: Bool = false // NC28
public var securityGuardDiagnostics = false
/// Only taken into account for major version >= 32
public var windowsCompatibleFilenamesEnabled = false
public var forbiddenFileNames: [String] = []
public var forbiddenFileNameBasenames: [String] = []
public var forbiddenFileNameCharacters: [String] = []
public var forbiddenFileNameExtensions: [String] = []
public var recommendations: Bool = false
public var termsOfService: Bool = false
// public var declarativeUIEnabled: Bool = false
// public var declarativeUIContextMenu: [ContextMenuItem] = []
public var clientIntegration: NKClientIntegration? = nil
public var editorEditors: [NKEditorDetailsEditor] = []
public var editorCreators: [NKEditorDetailsCreator] = []
public var editorTemplates: [NKEditorTemplate] = []
public var windowsCompatibleFilenamesEnabled = false
public var forbiddenFileNames: [String] = []
public var forbiddenFileNameBasenames: [String] = []
public var forbiddenFileNameCharacters: [String] = []
public var forbiddenFileNameExtensions: [String] = []
public var recommendations: Bool = false
public var termsOfService: Bool = false
public var clientIntegration: NKClientIntegration? = nil
public var directEditingEditors: [NKDirectEditingEditor] = []
public var directEditingCreators: [NKDirectEditingCreator] = []
public var directEditingTemplates: [NKDirectEditingTemplate] = []

public init() {}

Expand Down
Loading
Loading