Skip to content
Open
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
11 changes: 9 additions & 2 deletions Networking/ServerStatus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,16 @@ 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.

13 changes: 12 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,15 @@ 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
}
8 changes: 0 additions & 8 deletions iOCNotes.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

/* Begin PBXBuildFile section */
AA182D002DDCD6520058C246 /* CodeScanner in Frameworks */ = {isa = PBXBuildFile; productRef = AA182CFF2DDCD6520058C246 /* CodeScanner */; };
AA3054382E12AF9B00D33159 /* StatusRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA3054372E12AF9800D33159 /* StatusRouter.swift */; };
AA30543A2E12AFFD00D33159 /* OCSRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA3054392E12AFFB00D33159 /* OCSRouter.swift */; };
AA30543C2E12B06F00D33159 /* HTTPHeader+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA30543B2E12B06700D33159 /* HTTPHeader+Extensions.swift */; };
AA83B8AA2DEF080700F35F3E /* SwiftNextcloudUI in Frameworks */ = {isa = PBXBuildFile; productRef = AA83B8A92DEF080700F35F3E /* SwiftNextcloudUI */; };
AAA900B42DE6F37400D3EF0F /* SwiftNextcloudUI in Frameworks */ = {isa = PBXBuildFile; productRef = AAA900B32DE6F37400D3EF0F /* SwiftNextcloudUI */; };
Expand Down Expand Up @@ -113,8 +111,6 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
AA3054372E12AF9800D33159 /* StatusRouter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusRouter.swift; sourceTree = "<group>"; };
AA3054392E12AFFB00D33159 /* OCSRouter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OCSRouter.swift; sourceTree = "<group>"; };
AA30543B2E12B06700D33159 /* HTTPHeader+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "HTTPHeader+Extensions.swift"; sourceTree = "<group>"; };
AA360F442D71E6EF00BDC831 /* iOCNotes.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = iOCNotes.xcconfig; sourceTree = "<group>"; };
AA592A6E2DBBBA3B003A3057 /* .swiftlint.yml */ = {isa = PBXFileReference; lastKnownFileType = text.yaml; path = .swiftlint.yml; sourceTree = "<group>"; };
Expand Down Expand Up @@ -282,8 +278,6 @@
isa = PBXGroup;
children = (
AA30543B2E12B06700D33159 /* HTTPHeader+Extensions.swift */,
AA3054392E12AFFB00D33159 /* OCSRouter.swift */,
AA3054372E12AF9800D33159 /* StatusRouter.swift */,
D07F5E8D2207B6FF00528E90 /* Router.swift */,
D01067DD220BCE3C0047E090 /* NoteSessionManager.swift */,
D0C1C39E2462448D00AAC4A8 /* SyncOperation.swift */,
Expand Down Expand Up @@ -699,7 +693,6 @@
F3E3C8DC2C6B7DA600A80504 /* UIColor+Extension.swift in Sources */,
F3E3C8D92C6B7C2200A80504 /* NCBrand.swift in Sources */,
D095384A1D3313F8006BB78E /* PreviewViewController.swift in Sources */,
AA30543A2E12AFFD00D33159 /* OCSRouter.swift in Sources */,
D0E60F152772D809009CF78F /* SettingsProtocol.swift in Sources */,
BDD015A32353F7D4000BA001 /* PBHSplitViewController.swift in Sources */,
D095AE45245BB25F00A7EF62 /* NoteSessionManager.swift in Sources */,
Expand Down Expand Up @@ -733,7 +726,6 @@
D059F7DB1D40596D00C252F2 /* NoteExporter.swift in Sources */,
BD86DD8522B9CDD500115E5D /* KeychainHelper.swift in Sources */,
F3F7345B2C6FAD80007C8C0B /* BaseUIVIewController.swift in Sources */,
AA3054382E12AF9B00D33159 /* StatusRouter.swift in Sources */,
D08713ED1D18DA40001EAF82 /* HeaderTextView.swift in Sources */,
D0E60F5A277FADD5009CF78F /* UniversalTypes.swift in Sources */,
D0E60F28277801F8009CF78F /* PreviewWebView.swift in Sources */,
Expand Down
13 changes: 2 additions & 11 deletions iOCNotes/Store.swift
Original file line number Diff line number Diff line change
Expand Up @@ -172,17 +172,8 @@ final class Store: Logging, Storing {
return
}

guard let parsedComponents = URLComponents(string: KeychainHelper.server) else {
accounts = []
return
}

var assembledComponents = URLComponents()
assembledComponents.scheme = parsedComponents.scheme
assembledComponents.host = parsedComponents.host
assembledComponents.port = parsedComponents.port

guard let baseURL = assembledComponents.url?.absoluteString else {
guard let assembledComponents = canonicalServerComponents(from: KeychainHelper.server),
let baseURL = assembledComponents.url?.absoluteString else {
accounts = []
return
}
Expand Down
1 change: 1 addition & 0 deletions iOCNotes/Views/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ struct SettingsView: View {
Text("Enter a name for the folder where notes should be saved on the server")
}
.navigationTitle("Settings")
.toolbarTitleDisplayMode(.inline)
}
}
}
Expand Down
Loading