Nextcloud Login refactoring

This commit is contained in:
VincentMeilinger
2025-05-31 11:12:14 +02:00
parent 5acf3b9c4f
commit 48b31a7997
29 changed files with 1277 additions and 720 deletions

View File

@@ -20,10 +20,9 @@ class NextcloudApi {
/// - `LoginV2Request?`: An object containing the necessary information for the second step of the login process, if successful.
/// - `NetworkError?`: An error encountered during the network request, if any.
static func loginV2Request() async -> (LoginV2Request?, NetworkError?) {
let path = UserSettings.shared.serverProtocol + UserSettings.shared.serverAddress
static func loginV2Request(_ baseAddress: String) async -> (LoginV2Request?, NetworkError?) {
let request = ApiRequest(
path: path + "/index.php/login/v2",
path: baseAddress + "/index.php/login/v2",
method: .POST
)
@@ -52,16 +51,16 @@ class NextcloudApi {
/// - `LoginV2Response?`: An object representing the response of the login process, if successful.
/// - `NetworkError?`: An error encountered during the network request, if any.
static func loginV2Response(req: LoginV2Request) async -> (LoginV2Response?, NetworkError?) {
static func loginV2Poll(pollURL: String, pollToken: String) async -> (LoginV2Response?, NetworkError?) {
let request = ApiRequest(
path: req.poll.endpoint,
path: pollURL,
method: .POST,
headerFields: [
HeaderField.ocsRequest(value: true),
HeaderField.accept(value: .JSON),
HeaderField.contentType(value: .FORM)
],
body: "token=\(req.poll.token)".data(using: .utf8)
body: "token=\(pollToken)".data(using: .utf8)
)
let (data, error) = await request.send(pathCompletion: false)