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
2 changes: 1 addition & 1 deletion Sources/NextcloudKit/Models/NKFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class NKFile: NSObject {
/// Download limits for shares of this file.
///
public var downloadLimits = [NKDownloadLimit]()

public var e2eEncrypted: Bool = false
public var etag = ""
public var favorite: Bool = false
Expand Down
2 changes: 1 addition & 1 deletion Sources/NextcloudKit/NKSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public class NKSession {
#if os(iOS) || targetEnvironment(macCatalyst)
configurationUploadBackgroundExt.multipathServiceType = .handover
#endif

configurationUploadBackgroundExt.httpCookieStorage = HTTPCookieStorage.sharedCookieStorage(forGroupContainerIdentifier: sharedCookieStorage)
sessionUploadBackgroundExt = URLSession(configuration: configurationUploadBackgroundExt, delegate: backgroundSessionDelegate, delegateQueue: OperationQueue.main)
}
Expand Down
70 changes: 70 additions & 0 deletions Sources/NextcloudKit/NextcloudKit+ShareDownloadLimit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,82 @@

import Alamofire
import Foundation
import SwiftyJSON

public extension NextcloudKit {
private func makeEndpoint(with token: String) -> String {
"ocs/v2.php/apps/files_downloadlimit/api/v1/\(token)/limit"
}

func getDownloadLimit(account: String, token: String, completion: @escaping (NKDownloadLimit?, NKError) -> Void) {
let endpoint = makeEndpoint(with: token)
let options = NKRequestOptions()

guard let nkSession = nkCommonInstance.getSession(account: account),
let url = nkCommonInstance.createStandardUrl(serverUrl: nkSession.urlBase, endpoint: endpoint, options: options),
let headers = nkCommonInstance.getStandardHeaders(account: account, options: options) else {
return options.queue.async {
completion(nil, .urlError)
}
}

nkSession
.sessionData
.request(url, method: .get, parameters: nil, encoding: URLEncoding.default, headers: headers, interceptor: nil)
.validate(statusCode: 200..<300)
.responseData(queue: self.nkCommonInstance.backgroundQueue) { response in
if self.nkCommonInstance.levelLog > 0 {
debugPrint(response)
}

switch response.result {
case .failure(let error):
let error = NKError(error: error, afResponse: response, responseData: response.data)

options.queue.async {
completion(nil, error)
}
case .success(let jsonData):
let json = JSON(jsonData)

guard json["ocs"]["meta"]["statuscode"].int == 200 else {
let error = NKError(rootJson: json, fallbackStatusCode: response.response?.statusCode)

options.queue.async {
completion(nil, error)
}

return
}

let count = json["ocs"]["data"]["count"]
let limit = json["ocs"]["data"]["limit"]

guard count.type != .null else {
options.queue.async {
completion(nil, .success)
}

return
}

guard limit.type != .null else {
options.queue.async {
completion(nil, .success)
}

return
}

let downloadLimit = NKDownloadLimit(count: count.intValue, limit: limit.intValue, token: token)

options.queue.async {
completion(downloadLimit, .success)
}
}
}
}

func removeShareDownloadLimit(account: String, token: String, completion: @escaping (_ error: NKError) -> Void) {
let endpoint = makeEndpoint(with: token)
let options = NKRequestOptions()
Expand Down
15 changes: 14 additions & 1 deletion Sources/NextcloudKit/NextcloudKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,20 @@
if nkCommonInstance.nksessions.filter({ $0.account == account }).first != nil {
return updateSession(account: account, urlBase: urlBase, userId: userId, password: password, userAgent: userAgent, nextcloudVersion: nextcloudVersion)
}
let nkSession = NKSession(urlBase: urlBase, user: user, userId: userId, password: password, account: account, userAgent: userAgent, nextcloudVersion: nextcloudVersion, groupIdentifier: groupIdentifier, httpMaximumConnectionsPerHost: httpMaximumConnectionsPerHost, httpMaximumConnectionsPerHostInDownload: httpMaximumConnectionsPerHostInDownload, httpMaximumConnectionsPerHostInUpload: httpMaximumConnectionsPerHostInUpload)

Check warning on line 71 in Sources/NextcloudKit/NextcloudKit.swift

View workflow job for this annotation

GitHub Actions / Lint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
let nkSession = NKSession(
urlBase: urlBase,
user: user,
userId: userId,
password: password,
account: account,
userAgent: userAgent,
nextcloudVersion: nextcloudVersion,
groupIdentifier: groupIdentifier,
httpMaximumConnectionsPerHost: httpMaximumConnectionsPerHost,
httpMaximumConnectionsPerHostInDownload: httpMaximumConnectionsPerHostInDownload,
httpMaximumConnectionsPerHostInUpload: httpMaximumConnectionsPerHostInUpload
)

nkCommonInstance.nksessions.append(nkSession)
}
Expand Down
Loading