Skip to content

Commit d192518

Browse files
Merge pull request #248 from nextcloud/editors
refactor: separate Direct Editing and legacy Richdocuments APIs
2 parents 59d27f8 + 9ec408d commit d192518

7 files changed

Lines changed: 242 additions & 237 deletions
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// SPDX-FileCopyrightText: Nextcloud GmbH
2+
// SPDX-FileCopyrightText: 2025 Marino Faggiana
3+
// SPDX-License-Identifier: GPL-3.0-or-later
4+
5+
import Foundation
6+
7+
public enum NKDirectEditingCapabilitiesConverter {
8+
9+
/// Parses and converts raw JSON `Data` into `[NKDirectEditingEditor]` and `[NKDirectEditingCreator]`.
10+
/// - Parameter data: Raw JSON `Data` from the editors/creators endpoint.
11+
/// - Returns: A tuple with editors and creators.
12+
/// - Throws: Decoding error if parsing fails.
13+
public static func from(data: Data) throws -> (editors: [NKDirectEditingEditor], creators: [NKDirectEditingCreator]) {
14+
let decoded = try JSONDecoder().decode(NKDirectEditingCapabilitiesResponse.self, from: data)
15+
let editors = Array(decoded.ocs.data.editors.values)
16+
let creators = Array(decoded.ocs.data.creators.values)
17+
18+
if NKLogFileManager.shared.logLevel == .verbose {
19+
data.printJson()
20+
}
21+
22+
return (editors, creators)
23+
}
24+
}

Sources/NextcloudKit/Models/EditorDetails/NKEditorDetailsResponse.swift renamed to Sources/NextcloudKit/Models/DirectEditing/NKDirectEditingCapabilitiesResponse.swift

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,62 @@
44

55
import Foundation
66

7-
public struct NKEditorDetailsResponse: Codable, Sendable {
7+
public struct NKDirectEditingCapabilitiesResponse: Codable, Sendable {
88
public let ocs: OCS
99

1010
public struct OCS: Codable, Sendable {
1111
public let data: DataClass
1212

1313
public struct DataClass: Codable, Sendable {
14-
public let editors: [String: NKEditorDetailsEditor]
15-
public let creators: [String: NKEditorDetailsCreator]
14+
public let editors: [String: NKDirectEditingEditor]
15+
public let creators: [String: NKDirectEditingCreator]
1616
}
1717
}
1818
}
1919

20-
public struct NKEditorTemplateResponse: Codable, Sendable {
20+
public struct NKDirectEditingTemplateResponse: Codable, Sendable {
2121
public let ocs: OCS
2222

2323
public struct OCS: Codable, Sendable {
2424
public let data: DataClass
2525

2626
public struct DataClass: Codable, Sendable {
27-
public let editors: [NKEditorTemplate]
27+
public let templates: [String: NKDirectEditingTemplate]
2828
}
2929
}
3030
}
3131

32-
public struct NKEditorDetailsEditor: Codable, Sendable {
32+
public struct NKDirectEditingTemplate: Codable, Sendable {
33+
public let ext: String
34+
public let identifier: String
35+
public let mimetype: String
36+
public let name: String
37+
public let preview: String?
38+
39+
enum CodingKeys: String, CodingKey {
40+
case ext = "extension"
41+
case identifier = "id"
42+
case mimetype
43+
case name = "title"
44+
case preview
45+
}
46+
47+
public init(
48+
ext: String = "",
49+
identifier: String = "",
50+
mimetype: String = "",
51+
name: String = "",
52+
preview: String? = nil
53+
) {
54+
self.ext = ext
55+
self.identifier = identifier
56+
self.mimetype = mimetype
57+
self.name = name
58+
self.preview = preview
59+
}
60+
}
61+
62+
public struct NKDirectEditingEditor: Codable, Sendable {
3363
public let identifier: String
3464
public let mimetypes: [String]
3565
public let name: String
@@ -45,7 +75,7 @@ public struct NKEditorDetailsEditor: Codable, Sendable {
4575
}
4676
}
4777

48-
public struct NKEditorDetailsCreator: Codable, Sendable {
78+
public struct NKDirectEditingCreator: Codable, Sendable {
4979
public let identifier: String
5080
public let templates: Bool
5181
public let mimetype: String
@@ -62,24 +92,3 @@ public struct NKEditorDetailsCreator: Codable, Sendable {
6292
case ext = "extension"
6393
}
6494
}
65-
66-
public struct NKEditorTemplate: Codable, Sendable {
67-
public var ext: String
68-
public var identifier: String
69-
public var name: String
70-
public var preview: String
71-
72-
enum CodingKeys: String, CodingKey {
73-
case ext = "extension"
74-
case identifier = "id"
75-
case name
76-
case preview
77-
}
78-
79-
public init(ext: String = "", identifier: String = "", name: String = "", preview: String = "") {
80-
self.ext = ext
81-
self.identifier = identifier
82-
self.name = name
83-
self.preview = preview
84-
}
85-
}

Sources/NextcloudKit/Models/EditorDetails/NKEditorDetailsConverter.swift

Lines changed: 0 additions & 24 deletions
This file was deleted.

Sources/NextcloudKit/Models/EditorDetails/NKEditorDetailsResponse+NKConversion.swift

Lines changed: 0 additions & 15 deletions
This file was deleted.

Sources/NextcloudKit/NextcloudKit+Capabilities.swift

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -521,32 +521,30 @@ final public class NKCapabilities: Sendable {
521521
///
522522
/// The version of the locking API.
523523
///
524-
public var filesLockVersion: String = "" // NC 24
525-
public var filesComments: Bool = false // NC 20
526-
public var filesBigfilechunking: Bool = false
527-
public var userStatusEnabled: Bool = false
528-
public var userStatusSupportsBusy: Bool = false
529-
public var externalSites: Bool = false
530-
public var activityEnabled: Bool = false
531-
public var governanceEnabled: Bool = false
532-
public var groupfoldersEnabled: Bool = false // NC27
533-
public var assistantEnabled: Bool = false // NC28
534-
public var isLivePhotoServerAvailable: Bool = false // NC28
535-
public var securityGuardDiagnostics = false
524+
public var filesLockVersion: String = "" // NC 24
525+
public var filesComments: Bool = false // NC 20
526+
public var filesBigfilechunking: Bool = false
527+
public var userStatusEnabled: Bool = false
528+
public var userStatusSupportsBusy: Bool = false
529+
public var externalSites: Bool = false
530+
public var activityEnabled: Bool = false
531+
public var governanceEnabled: Bool = false
532+
public var groupfoldersEnabled: Bool = false // NC27
533+
public var assistantEnabled: Bool = false // NC28
534+
public var isLivePhotoServerAvailable: Bool = false // NC28
535+
public var securityGuardDiagnostics = false
536536
/// Only taken into account for major version >= 32
537-
public var windowsCompatibleFilenamesEnabled = false
538-
public var forbiddenFileNames: [String] = []
539-
public var forbiddenFileNameBasenames: [String] = []
540-
public var forbiddenFileNameCharacters: [String] = []
541-
public var forbiddenFileNameExtensions: [String] = []
542-
public var recommendations: Bool = false
543-
public var termsOfService: Bool = false
544-
// public var declarativeUIEnabled: Bool = false
545-
// public var declarativeUIContextMenu: [ContextMenuItem] = []
546-
public var clientIntegration: NKClientIntegration? = nil
547-
public var editorEditors: [NKEditorDetailsEditor] = []
548-
public var editorCreators: [NKEditorDetailsCreator] = []
549-
public var editorTemplates: [NKEditorTemplate] = []
537+
public var windowsCompatibleFilenamesEnabled = false
538+
public var forbiddenFileNames: [String] = []
539+
public var forbiddenFileNameBasenames: [String] = []
540+
public var forbiddenFileNameCharacters: [String] = []
541+
public var forbiddenFileNameExtensions: [String] = []
542+
public var recommendations: Bool = false
543+
public var termsOfService: Bool = false
544+
public var clientIntegration: NKClientIntegration? = nil
545+
public var directEditingEditors: [NKDirectEditingEditor] = []
546+
public var directEditingCreators: [NKDirectEditingCreator] = []
547+
public var directEditingTemplates: [NKDirectEditingTemplate] = []
550548

551549
public init() {}
552550

0 commit comments

Comments
 (0)