-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Marino Faggiana <[email protected]>
- Loading branch information
1 parent
638e3d1
commit e7b19b0
Showing
3 changed files
with
87 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// | ||
// NextcloudKit+Livephoto.swift | ||
// NextcloudKit | ||
// | ||
// Created by Marino Faggiana on 09/11/2023. | ||
// Copyright © 2023 Marino Faggiana. All rights reserved. | ||
// | ||
// Author Marino Faggiana <[email protected]> | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
// | ||
|
||
import Foundation | ||
import Alamofire | ||
|
||
extension NextcloudKit { | ||
|
||
public func setLivephoto(fileNamePath: String, | ||
livePhoto: String, | ||
options: NKRequestOptions = NKRequestOptions(), | ||
completion: @escaping (_ account: String, _ error: NKError) -> Void) { | ||
|
||
let account = self.nkCommonInstance.account | ||
let urlBase = self.nkCommonInstance.urlBase | ||
let dav = self.nkCommonInstance.dav | ||
let userId = self.nkCommonInstance.userId | ||
let serverUrlEndpoint = urlBase + "/" + dav + "files/" + userId + "/" + fileNamePath | ||
|
||
guard let url = serverUrlEndpoint.encodedToUrl else { | ||
return options.queue.async { completion(account, .urlError) } | ||
} | ||
|
||
let method = HTTPMethod(rawValue: "PROPPATCH") | ||
let headers = self.nkCommonInstance.getStandardHeaders(options.customHeader, customUserAgent: options.customUserAgent, contentType: "application/xml") | ||
|
||
var urlRequest: URLRequest | ||
do { | ||
try urlRequest = URLRequest(url: url, method: method, headers: headers) | ||
let parameters = String(format: NKDataFileXML(nkCommonInstance: self.nkCommonInstance).requestBodyLivephoto, livePhoto) | ||
urlRequest.httpBody = parameters.data(using: .utf8) | ||
} catch { | ||
return options.queue.async { completion(account, NKError(error: error)) } | ||
} | ||
|
||
sessionManager.request(urlRequest).validate(statusCode: 200..<300).response(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(account, error) } | ||
case .success: | ||
options.queue.async { completion(account, .success) } | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters