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
7 changes: 0 additions & 7 deletions Networking/HTTPHeader+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@
import Alamofire

extension HTTPHeader {
///
/// Convenience method to initialize a new OCS API request header with the given value.
///
public static func ocsAPIRequest(_ value: Bool) -> HTTPHeader {
HTTPHeader(name: "OCS-APIRequest", value: value ? "true" : "false")
}

///
/// Convenience method to initialize a new If-None-Match header with the given value.
///
Expand Down
43 changes: 14 additions & 29 deletions Networking/NoteSessionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import Alamofire
import Foundation
import NextcloudKit
import UIKit
import SwiftMessages
import os
Expand Down Expand Up @@ -130,39 +131,23 @@ class NoteSessionManager {
session = Session(configuration: configuration, serverTrustManager: NotesServerTrustPolicyManager(allHostsMustBeEvaluated: true, evaluators: [:]))
}

///
/// Fetch the server status.
///
/// - Parameters:
/// - completion: Optional completion handler to call afterwards.
///
func status(completion: SyncCompletionBlock? = nil) {
/// Fetch the server status from `/status.php`.
func status() async {
logger.notice("Fetching status...")

let router = StatusRouter.status
session
.request(router)
.validate(contentType: [Router.applicationJson])
.responseDecodable(of: CloudStatus.self) { response in
switch response.result {
case let .success(result):
KeychainHelper.productVersion = result.versionstring
KeychainHelper.productName = result.productname
case let .failure(error):
print(error.localizedDescription)
}
completion?()
guard let serverUrl = canonicalServerComponents(from: KeychainHelper.server)?.url?.absoluteString else {
logger.error("Cannot fetch status: server URL is empty or invalid.")
return
}
}

///
/// Asynchronous wrapper for ``status(completion:)``.
///
func status() async {
await withCheckedContinuation { continuation in
status {
continuation.resume()
}
let (_, result) = await NextcloudKit.shared.getServerStatusAsync(serverUrl: serverUrl)

switch result {
case let .success(info):
KeychainHelper.productVersion = info.version
KeychainHelper.productName = info.productName
case let .failure(error):
logger.error("Error fetching status: \(error.errorDescription, privacy: .public)")
}
}

Expand Down
83 changes: 0 additions & 83 deletions Networking/OCSRouter.swift

This file was deleted.

14 changes: 11 additions & 3 deletions Networking/Router.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,18 @@ enum Router: URLRequestConvertible {
throw error
}

let baseURLString = "\(server)/index.php/apps/notes/api/v\(apiVersion)"
let url = try baseURLString.asURL()
guard var components = canonicalServerComponents(from: server) else {
throw AFError.parameterEncodingFailed(reason: .missingURL)
}

let basePath = components.path
components.path = basePath + "/index.php/apps/notes/api/v\(apiVersion)" + self.path

guard let url = components.url else {
throw AFError.parameterEncodingFailed(reason: .missingURL)
}

Comment thread
mpivchev marked this conversation as resolved.
var urlRequest = URLRequest(url: url.appendingPathComponent(self.path))
var urlRequest = URLRequest(url: url)
urlRequest.httpMethod = self.method.rawValue
let username = KeychainHelper.username
let password = KeychainHelper.password
Expand Down
13 changes: 11 additions & 2 deletions Networking/ServerStatus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,18 @@ class ServerStatus: NSObject {
}

func check() async throws {
let router = StatusRouter.status
guard var components = canonicalServerComponents(from: KeychainHelper.server) else {
throw NSError(domain: NSURLErrorDomain, code: NSURLErrorBadURL)
}

components.path = components.path + "/status.php"

guard let url = components.url else {
throw NSError(domain: NSURLErrorDomain, code: NSURLErrorBadURL)
}

do {
let (_, _) = try await session.data(for: router.asURLRequest())
let (_, _) = try await session.data(for: URLRequest(url: url))
} catch(let error) {
throw error as NSError
}
Expand Down
82 changes: 0 additions & 82 deletions Networking/StatusRouter.swift

This file was deleted.

17 changes: 16 additions & 1 deletion Utils/UtilityExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ extension UIColor {
static let ph_popoverBackgroundColor = UIColor(named: "PHWhitePopoverBackground")!
static let ph_popoverButtonColor = UIColor(named: "PHWhitePopoverButton")!
static let ph_popoverBorderColor = UIColor(named: "PHWhitePopoverBorder")!
// static let ph_popoverIconColor = UIColor(named: "PHWhitePopoverIcon")!
static let ph_switchTintColor = UIColor(named: "PHWhitePopoverBorder")!
static let ph_selectedTextColor = UIColor(named: "PHSelectedText")!

Expand Down Expand Up @@ -142,3 +141,19 @@ func isNextcloud() -> Bool {
} catch { }
return isNextcloud
}

/// Returns components for `serverAddress` with any trailing `/index.php` or `/` removed.
/// Handles cases where the address may have been received in a bad format, ex. test.com/nextcloud/index.php/index.php
func canonicalServerComponents(from serverAddress: String) -> URLComponents? {
guard let url = URL(string: serverAddress) else { return nil }

let stripped = url.lastPathComponent == "index.php" ? url.deletingLastPathComponent() : url

guard var components = URLComponents(url: stripped, resolvingAgainstBaseURL: false) else { return nil }

if components.path.hasSuffix("/") {
components.path = String(components.path.dropLast())
}
Comment thread
mpivchev marked this conversation as resolved.

return components
}
1 change: 0 additions & 1 deletion iOCNotes.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ CURRENT_PROJECT_VERSION = 1
ENABLE_USER_SCRIPT_SANDBOXING = NO
INFOPLIST_KEY_NSHumanReadableCopyright = Copyright © 2025 Nextcloud GmbH. All rights reserved.
IPHONEOS_DEPLOYMENT_TARGET = 17.0
MARKETING_VERSION = 4.5.0
PRODUCT_BUNDLE_IDENTIFIER = com.peterandlinda.iOCNotes
Loading
Loading