Skip to content

Commit

Permalink
Version bumped to 3.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
donnywals committed Nov 28, 2024
1 parent 43fa6fc commit c46c28d
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 12 deletions.
6 changes: 4 additions & 2 deletions Sources/TransloaditKit/Transloadit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ public final class Transloadit {
tusClient.remainingUploads
}

private let tusSessionConfig: URLSessionConfiguration
lazy var tusClient: TUSClient = {
let config = URLSessionConfiguration.background(withIdentifier: "com.transloadit.tus.background")
let tusClient = try! TUSClient(server: URL(string:"https://www.transloadit.com")!, sessionIdentifier: "TransloadIt", sessionConfiguration: config, storageDirectory: storageDir)
let tusClient = try! TUSClient(server: URL(string:"https://www.transloadit.com")!, sessionIdentifier: "TransloadIt", sessionConfiguration: tusSessionConfig, storageDirectory: storageDir)
tusClient.delegate = self
return tusClient
}()
Expand All @@ -80,6 +80,7 @@ public final class Transloadit {
public init(credentials: Transloadit.Credentials, session: URLSession, storageDir: URL? = nil) {
self.api = TransloaditAPI(credentials: credentials, session: session)
self.storageDir = storageDir
self.tusSessionConfig = session.configuration.copy(withIdentifier: "com.transloadit.tus.bg")
}

/// Initialize Transloadit
Expand All @@ -92,6 +93,7 @@ public final class Transloadit {
public init(credentials: Transloadit.Credentials, sessionConfiguration: URLSessionConfiguration, storageDir: URL? = nil) {
self.api = TransloaditAPI(credentials: credentials, sessionConfiguration: sessionConfiguration)
self.storageDir = storageDir
self.tusSessionConfig = sessionConfiguration.copy(withIdentifier: "com.transloadit.tus.bg")
}

@discardableResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import Foundation

extension TransloaditAPI: URLSessionDataDelegate {
public func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {
print(error)
guard let completionHandler = callbacks[task] else {
return
}
Expand Down
11 changes: 3 additions & 8 deletions Sources/TransloaditKit/TransloaditAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,7 @@ final class TransloaditAPI: NSObject {

init(credentials: Transloadit.Credentials, session: URLSession) {
self.credentials = credentials
if session.configuration.sessionSendsLaunchEvents {
self.configuration = .background(withIdentifier: "com.transloadit.bgurlsession")
} else {
self.configuration = session.configuration
}
self.configuration = session.configuration.copy(withIdentifier: "com.transloadit.bg")
self.delegateQueue = session.delegateQueue
super.init()
}
Expand Down Expand Up @@ -121,7 +117,6 @@ final class TransloaditAPI: NSObject {
return
}

try! print(Data(contentsOf: request.httpBody))
let task = session.uploadTask(with: request.request, fromFile: request.httpBody)
callbacks[task] = URLSessionCompletionHandler(callback: { result in
switch result {
Expand Down Expand Up @@ -308,7 +303,7 @@ final class TransloaditAPI: NSObject {
return request
}

let task = session.downloadTask(with: makeRequest())
let task = session.dataTask(with: makeRequest())
callbacks[task] = URLSessionCompletionHandler(callback: { result in
switch result {
case .failure:
Expand All @@ -334,7 +329,7 @@ final class TransloaditAPI: NSObject {
return request
}

let task = session.downloadTask(with: makeRequest())
let task = session.dataTask(with: makeRequest())
callbacks[task] = URLSessionCompletionHandler(callback: { result in
switch result {
case .failure:
Expand Down
36 changes: 36 additions & 0 deletions Sources/TransloaditKit/URLSessionConfiguration+Copying.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// URLSessionConfiguration+Copying.swift
// TransloaditKit
//
// Created by Donny Wals on 27/11/2024.
//

import Foundation

extension URLSessionConfiguration {
func copy(withIdentifier newIdentifier: String) -> URLSessionConfiguration {
if let identifier = self.identifier {
let copy = URLSessionConfiguration.background(withIdentifier: newIdentifier)
copy.requestCachePolicy = requestCachePolicy
copy.timeoutIntervalForRequest = timeoutIntervalForRequest
copy.timeoutIntervalForResource = timeoutIntervalForResource
copy.networkServiceType = networkServiceType
copy.allowsCellularAccess = allowsCellularAccess
copy.isDiscretionary = isDiscretionary
copy.connectionProxyDictionary = connectionProxyDictionary
copy.httpShouldUsePipelining = httpShouldUsePipelining
copy.httpShouldSetCookies = httpShouldSetCookies
copy.httpCookieAcceptPolicy = httpCookieAcceptPolicy
copy.httpAdditionalHeaders = httpAdditionalHeaders
copy.httpMaximumConnectionsPerHost = httpMaximumConnectionsPerHost
copy.httpCookieStorage = httpCookieStorage
copy.urlCredentialStorage = urlCredentialStorage
copy.urlCache = urlCache
copy.shouldUseExtendedBackgroundIdleMode = shouldUseExtendedBackgroundIdleMode
copy.protocolClasses = protocolClasses
return copy
} else {
return self.copy() as! URLSessionConfiguration
}
}
}
2 changes: 1 addition & 1 deletion Transloadit.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'Transloadit'
s.version = '3.3.0'
s.version = '3.3.1'
s.summary = 'Transloadit client in Swift'
s.swift_version = '5.0'

Expand Down

0 comments on commit c46c28d

Please sign in to comment.