@@ -7,6 +7,15 @@ import Alamofire
77import SwiftyJSON
88
99public extension NextcloudKit {
10+ // Requests a URL for editing or viewing a file via the Richdocuments (Collabora/OnlyOffice) app.
11+ //
12+ // Parameters:
13+ // - fileID: The unique identifier of the file for which the document URL is requested.
14+ // - account: The Nextcloud account performing the request.
15+ // - options: Optional configuration such as custom headers, queue, or API version.
16+ // - taskHandler: Callback invoked when the underlying URLSessionTask is created.
17+ // - completion: Completion handler returning the account, document URL (if available),
18+ // the raw HTTP response, and an NKError object.
1019 func createUrlRichdocuments( fileID: String ,
1120 account: String ,
1221 options: NKRequestOptions = NKRequestOptions ( ) ,
@@ -40,6 +49,47 @@ public extension NextcloudKit {
4049 }
4150 }
4251
52+ /// Asynchronously retrieves the URL for opening a file in Richdocuments (e.g., Collabora or OnlyOffice).
53+ ///
54+ /// - Parameters:
55+ /// - fileID: The identifier of the target file.
56+ /// - account: The Nextcloud account used for the operation.
57+ /// - options: Request configuration (headers, queue, version, etc.).
58+ /// - taskHandler: Optional handler to observe the URLSessionTask.
59+ /// - Returns: A tuple containing the account, the richdocument URL (if any), the raw response data, and any NKError.
60+ func createUrlRichdocumentsAsync( fileID: String ,
61+ account: String ,
62+ options: NKRequestOptions = NKRequestOptions ( ) ,
63+ taskHandler: @escaping ( _ task: URLSessionTask ) -> Void = { _ in }
64+ ) async -> (
65+ account: String ,
66+ url: String ? ,
67+ responseData: AFDataResponse < Data > ? ,
68+ error: NKError
69+ ) {
70+ await withCheckedContinuation { continuation in
71+ createUrlRichdocuments ( fileID: fileID,
72+ account: account,
73+ options: options,
74+ taskHandler: taskHandler) { account, url, responseData, error in
75+ continuation. resume ( returning: (
76+ account: account,
77+ url: url,
78+ responseData: responseData,
79+ error: error
80+ ) )
81+ }
82+ }
83+ }
84+
85+ // Retrieves the list of Richdocuments templates of a given type (e.g., "document", "spreadsheet").
86+ //
87+ // Parameters:
88+ // - typeTemplate: The type of template to retrieve (e.g., "document", "presentation").
89+ // - account: The Nextcloud account performing the request.
90+ // - options: Optional configuration (headers, queue, API version, etc.).
91+ // - taskHandler: Callback invoked when the underlying URLSessionTask is created.
92+ // - completion: Completion handler returning the account, array of templates, response data, and NKError.
4393 func getTemplatesRichdocuments( typeTemplate: String ,
4494 account: String ,
4595 options: NKRequestOptions = NKRequestOptions ( ) ,
@@ -84,16 +134,48 @@ public extension NextcloudKit {
84134 }
85135 }
86136
137+ /// Asynchronously fetches Richdocuments templates filtered by type.
138+ ///
139+ /// - Parameters:
140+ /// - typeTemplate: The type of template to retrieve (e.g., "document").
141+ /// - account: The Nextcloud account for which templates are requested.
142+ /// - options: Optional request configuration.
143+ /// - taskHandler: Optional handler to observe the `URLSessionTask`.
144+ /// - Returns: A tuple containing the account, array of templates, raw response data, and any NKError.
87145 func getTemplatesRichdocumentsAsync( typeTemplate: String ,
88146 account: String ,
89- options: NKRequestOptions = NKRequestOptions ( ) ) async -> ( account: String , templates: [ NKRichdocumentsTemplate ] ? , responseData: AFDataResponse < Data > ? , error: NKError ) {
90- await withUnsafeContinuation ( { continuation in
91- NextcloudKit . shared. getTemplatesRichdocuments ( typeTemplate: typeTemplate, account: account, options: options) { account, templates, responseData, error in
92- continuation. resume ( returning: ( account: account, templates: templates, responseData: responseData, error: error) )
147+ options: NKRequestOptions = NKRequestOptions ( ) ,
148+ taskHandler: @escaping ( _ task: URLSessionTask ) -> Void = { _ in }
149+ ) async -> (
150+ account: String ,
151+ templates: [ NKRichdocumentsTemplate ] ? ,
152+ responseData: AFDataResponse < Data > ? ,
153+ error: NKError
154+ ) {
155+ await withCheckedContinuation { continuation in
156+ getTemplatesRichdocuments ( typeTemplate: typeTemplate,
157+ account: account,
158+ options: options,
159+ taskHandler: taskHandler) { account, templates, responseData, error in
160+ continuation. resume ( returning: (
161+ account: account,
162+ templates: templates,
163+ responseData: responseData,
164+ error: error
165+ ) )
93166 }
94- } )
167+ }
95168 }
96169
170+ // Creates a new Richdocuments file using a specific template.
171+ //
172+ // Parameters:
173+ // - path: The target path where the new document should be created.
174+ // - templateId: The ID of the Richdocuments template to use.
175+ // - account: The Nextcloud account performing the request.
176+ // - options: Optional request configuration (headers, queue, API version, etc.).
177+ // - taskHandler: Callback invoked when the underlying URLSessionTask is created.
178+ // - completion: Completion handler returning the account, resulting file URL, raw response, and NKError.
97179 func createRichdocuments( path: String ,
98180 templateId: String ,
99181 account: String ,
@@ -128,6 +210,50 @@ public extension NextcloudKit {
128210 }
129211 }
130212
213+ /// Asynchronously creates a new Richdocuments file from a given template.
214+ ///
215+ /// - Parameters:
216+ /// - path: Destination path for the new document.
217+ /// - templateId: Template ID used to generate the new file.
218+ /// - account: The Nextcloud account performing the operation.
219+ /// - options: Optional request parameters.
220+ /// - taskHandler: Optional monitoring of the underlying task.
221+ /// - Returns: A tuple with account, resulting URL (if successful), raw response, and error result.
222+ func createRichdocumentsAsync( path: String ,
223+ templateId: String ,
224+ account: String ,
225+ options: NKRequestOptions = NKRequestOptions ( ) ,
226+ taskHandler: @escaping ( _ task: URLSessionTask ) -> Void = { _ in }
227+ ) async -> (
228+ account: String ,
229+ url: String ? ,
230+ responseData: AFDataResponse < Data > ? ,
231+ error: NKError
232+ ) {
233+ await withCheckedContinuation { continuation in
234+ createRichdocuments ( path: path,
235+ templateId: templateId,
236+ account: account,
237+ options: options,
238+ taskHandler: taskHandler) { account, url, responseData, error in
239+ continuation. resume ( returning: (
240+ account: account,
241+ url: url,
242+ responseData: responseData,
243+ error: error
244+ ) )
245+ }
246+ }
247+ }
248+
249+ // Creates a new Richdocuments file based on a default asset (no template).
250+ //
251+ // Parameters:
252+ // - path: The destination path where the asset will be created.
253+ // - account: The Nextcloud account initiating the creation.
254+ // - options: Optional configuration for the request (e.g. headers, queue, API version).
255+ // - taskHandler: Callback invoked when the underlying URLSessionTask is created.
256+ // - completion: Completion handler returning account, resulting file URL, raw response data, and NKError.
131257 func createAssetRichdocuments( path: String ,
132258 account: String ,
133259 options: NKRequestOptions = NKRequestOptions ( ) ,
@@ -156,4 +282,37 @@ public extension NextcloudKit {
156282 }
157283 }
158284 }
285+
286+ /// Asynchronously creates a Richdocuments asset file at a specified path.
287+ ///
288+ /// - Parameters:
289+ /// - path: Target path for the asset document.
290+ /// - account: The Nextcloud account performing the operation.
291+ /// - options: Optional request customization.
292+ /// - taskHandler: Optional monitoring of the underlying task.
293+ /// - Returns: A tuple with account, resulting URL, raw response, and error.
294+ func createAssetRichdocumentsAsync( path: String ,
295+ account: String ,
296+ options: NKRequestOptions = NKRequestOptions ( ) ,
297+ taskHandler: @escaping ( _ task: URLSessionTask ) -> Void = { _ in }
298+ ) async -> (
299+ account: String ,
300+ url: String ? ,
301+ responseData: AFDataResponse < Data > ? ,
302+ error: NKError
303+ ) {
304+ await withCheckedContinuation { continuation in
305+ createAssetRichdocuments ( path: path,
306+ account: account,
307+ options: options,
308+ taskHandler: taskHandler) { account, url, responseData, error in
309+ continuation. resume ( returning: (
310+ account: account,
311+ url: url,
312+ responseData: responseData,
313+ error: error
314+ ) )
315+ }
316+ }
317+ }
159318}
0 commit comments