|
@@ -1,129 +0,0 @@
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-import UIKit
|
|
|
-import KTVHTTPCache
|
|
|
-
|
|
|
-class NCKTVHTTPCache: NSObject {
|
|
|
- @objc static let shared: NCKTVHTTPCache = {
|
|
|
- let instance = NCKTVHTTPCache()
|
|
|
- instance.setupHTTPCache()
|
|
|
- return instance
|
|
|
- }()
|
|
|
-
|
|
|
- func getVideoURL(metadata: tableMetadata) -> URL? {
|
|
|
-
|
|
|
- if CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) {
|
|
|
-
|
|
|
- return URL(fileURLWithPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView))
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
- guard let stringURL = (metadata.serverUrl + "/" + metadata.fileName).addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) else { return nil }
|
|
|
-
|
|
|
- return NCKTVHTTPCache.shared.getProxyURL(stringURL: stringURL)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- func startProxy(user: String, password: String, metadata: tableMetadata) {
|
|
|
-
|
|
|
- guard let authData = (user + ":" + password).data(using: .utf8) else { return }
|
|
|
-
|
|
|
- let authValue = "Basic " + authData.base64EncodedString(options: [])
|
|
|
- KTVHTTPCache.downloadSetAdditionalHeaders(["Authorization":authValue, "User-Agent":CCUtility.getUserAgent()])
|
|
|
-
|
|
|
- if !KTVHTTPCache.proxyIsRunning() {
|
|
|
- do {
|
|
|
- try KTVHTTPCache.proxyStart()
|
|
|
- } catch let error {
|
|
|
- print("Proxy Start error : \(error)")
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- func stopProxy(metadata: tableMetadata) {
|
|
|
-
|
|
|
- if KTVHTTPCache.proxyIsRunning() {
|
|
|
- KTVHTTPCache.proxyStop()
|
|
|
- }
|
|
|
-
|
|
|
- saveCache(metadata: metadata)
|
|
|
- }
|
|
|
-
|
|
|
- func getProxyURL(stringURL: String) -> URL {
|
|
|
-
|
|
|
- return KTVHTTPCache.proxyURL(withOriginalURL: URL(string: stringURL))
|
|
|
- }
|
|
|
-
|
|
|
- func getCacheCompleteFileURL(videoURL: URL?) -> URL? {
|
|
|
-
|
|
|
- return KTVHTTPCache.cacheCompleteFileURL(with: videoURL)
|
|
|
- }
|
|
|
-
|
|
|
- func deleteCache(videoURL: URL?) {
|
|
|
-
|
|
|
- KTVHTTPCache.cacheDelete(with: videoURL)
|
|
|
- }
|
|
|
-
|
|
|
- func saveCache(metadata: tableMetadata) {
|
|
|
-
|
|
|
- if !CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView:metadata.fileNameView) {
|
|
|
-
|
|
|
- guard let stringURL = (metadata.serverUrl + "/" + metadata.fileName).addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) else { return }
|
|
|
-
|
|
|
- let videoURL = URL(string: stringURL)
|
|
|
- guard let url = KTVHTTPCache.cacheCompleteFileURL(with: videoURL) else { return }
|
|
|
-
|
|
|
- CCUtility.copyFile(atPath: url.path, toPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView))
|
|
|
- NCManageDatabase.shared.addLocalFile(metadata: metadata)
|
|
|
- KTVHTTPCache.cacheDelete(with: videoURL)
|
|
|
-
|
|
|
- NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterReloadDataSource, userInfo: ["ocId":metadata.ocId, "serverUrl":metadata.serverUrl])
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private func setupHTTPCache() {
|
|
|
-
|
|
|
- KTVHTTPCache.cacheSetMaxCacheLength(NCGlobal.shared.maxHTTPCache)
|
|
|
-
|
|
|
- if ProcessInfo.processInfo.environment["SIMULATOR_DEVICE_NAME"] != nil {
|
|
|
- KTVHTTPCache.logSetConsoleLogEnable(true)
|
|
|
- }
|
|
|
-
|
|
|
- do {
|
|
|
- try KTVHTTPCache.proxyStart()
|
|
|
- } catch let error {
|
|
|
- print("Proxy Start error : \(error)")
|
|
|
- }
|
|
|
-
|
|
|
- KTVHTTPCache.encodeSetURLConverter { (url) -> URL? in
|
|
|
- print("URL Filter reviced URL : " + String(describing: url))
|
|
|
- return url
|
|
|
- }
|
|
|
-
|
|
|
- KTVHTTPCache.downloadSetUnacceptableContentTypeDisposer { (url, contentType) -> Bool in
|
|
|
- print("Unsupport Content-Type Filter reviced URL : " + String(describing: url) + " " + String(describing: contentType))
|
|
|
- return false
|
|
|
- }
|
|
|
- }
|
|
|
-}
|