Skip to content

Commit 63a1e52

Browse files
author
Ruben Nine
committed
Adding currentUploaders and isUploading to Client so SDK users can obtain the uploaders currently (e.g. to cancel or query progress.)
1 parent ebdeffb commit 63a1e52

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

Sources/FilestackSDK/Internal/Config.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@
88

99
import Foundation
1010

11-
struct Config {
11+
class Config {
1212
let apiKey: String
1313
let security: Security?
14+
var currentUploaders: [Uploader] = []
15+
16+
init(apiKey: String, security: Security? = nil) {
17+
self.apiKey = apiKey
18+
self.security = security
19+
}
1420
}

Sources/FilestackSDK/Internal/Uploaders/MultipartUpload.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ private extension MultipartUpload {
122122
func upload() {
123123
guard let uploadables = uploadables else { return }
124124

125+
config.currentUploaders.append(self)
125126
state = .inProgress
126127

127128
var results: [JSONResponse] = []
@@ -189,6 +190,8 @@ private extension MultipartUpload {
189190
state = .completed
190191
}
191192

193+
config.currentUploaders.removeAll { $0 == self }
194+
192195
queue.async {
193196
self.completionHandler?(results)
194197
self.completionHandler = nil

Sources/FilestackSDK/Public/Models/Client.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ public extension Client {
4646

4747
/// A `Security` object. `nil` by default.
4848
@objc var security: Security? { config.security }
49+
50+
/// Returns an array containing the `Uploader` instances currently running.
51+
@objc var currentUploaders: [Uploader] { config.currentUploaders }
52+
53+
/// Returns whether there's at least a single `Uploader` instance currently running.
54+
@objc var isUploading: Bool { config.currentUploaders.count > 0 }
4955
}
5056

5157
// MARK: - Public Functions

0 commit comments

Comments
 (0)