Merge pull request #57 from evilutioner/master
Fixed outdated OneDrive API
This commit is contained in:
@@ -224,13 +224,14 @@ open class OneDriveFileProvider: FileProviderBasicRemote {
|
||||
}
|
||||
return driveURL
|
||||
}
|
||||
|
||||
rpath = (rpath.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? rpath)
|
||||
let driveURL = baseURL!.appendingPathComponent("drive/\(drive):/")
|
||||
rpath = rpath.trimmingCharacters(in: pathTrimSet)
|
||||
if let modifier = modifier {
|
||||
rpath = rpath + ":/" + modifier
|
||||
}
|
||||
return URL(string: rpath, relativeTo: driveURL) ?? driveURL
|
||||
// fixed, don't work with symbol ":" in relative path
|
||||
// URL(string: rpath, relativeTo: driveURL) ?? driveURL
|
||||
return driveURL.appendingPathComponent(rpath) ?? driveURL
|
||||
}
|
||||
|
||||
open func isReachable(completionHandler: @escaping (Bool) -> Void) {
|
||||
|
||||
@@ -18,12 +18,17 @@ public struct FileProviderOneDriveError: FileProviderHTTPError {
|
||||
/// Containts path, url and attributes of a OneDrive file or resource.
|
||||
public final class OneDriveFileObject: FileObject {
|
||||
internal init(baseURL: URL?, name: String, path: String) {
|
||||
var rpath = path.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? path
|
||||
// fixed, not need proc + append
|
||||
// var rpath = path.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? path
|
||||
var rpath = (URL(string:path)?.appendingPathComponent(name).absoluteString)!
|
||||
if rpath.hasPrefix("/") {
|
||||
_=rpath.characters.removeFirst()
|
||||
}
|
||||
let url = URL(string: rpath, relativeTo: baseURL) ?? URL(string: rpath)!
|
||||
super.init(url: url, name: name, path: path)
|
||||
|
||||
// fixed, wrong path
|
||||
//super.init(url: url, name: name, path: path)
|
||||
super.init(url: url, name: name, path: rpath)
|
||||
}
|
||||
|
||||
internal convenience init? (baseURL: URL?, drive: String, jsonStr: String) {
|
||||
@@ -34,14 +39,18 @@ public final class OneDriveFileObject: FileObject {
|
||||
internal convenience init? (baseURL: URL?, drive: String, json: [String: AnyObject]) {
|
||||
guard let name = json["name"] as? String else { return nil }
|
||||
guard let path = (json["parentReference"] as? NSDictionary)?["path"] as? String else { return nil }
|
||||
var lPath = path.replacingOccurrences(of: "/drive/\(drive)", with: "/", options: .anchored, range: nil)
|
||||
// fixed, wrong using 'root:'
|
||||
// var lPath = path.replacingOccurrences(of: "/drive/\(drive):", with: "/", options: .anchored, range: nil)
|
||||
var lPath = path.replacingOccurrences(of: "/drive/\(drive):", with: "/", options: .anchored, range: nil)
|
||||
lPath = lPath.replacingOccurrences(of: "/:", with: "", options: .anchored)
|
||||
lPath = lPath.replacingOccurrences(of: "//", with: "", options: .anchored)
|
||||
self.init(baseURL: baseURL, name: name, path: lPath)
|
||||
self.size = (json["size"] as? NSNumber)?.int64Value ?? -1
|
||||
self.modifiedDate = Date(rfcString: json["lastModifiedDateTime"] as? String ?? "")
|
||||
self.creationDate = Date(rfcString: json["createdDateTime"] as? String ?? "")
|
||||
self.type = (json["folder"] as? String) != nil ? .directory : .regular
|
||||
// fixed, wrong folder type
|
||||
// (json["folder"] as? String) != nil ? .directory : .regular
|
||||
self.type = json["folder"] != nil ? .directory : .regular
|
||||
self.id = json["id"] as? String
|
||||
self.entryTag = json["eTag"] as? String
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user