Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/update #1

Open
wants to merge 49 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
cc9fcee
Update ROADMAP.md
kvz Sep 12, 2022
2fb3909
Update ROADMAP.md
kvz Sep 12, 2022
6e06bc1
Update ROADMAP.md
kvz Sep 12, 2022
ba1bb55
Update ROADMAP.md
kvz Sep 12, 2022
7363264
Fix compile error Xcode 14
tursunovic Sep 12, 2022
c1fba6d
Update changelog for 3.1.4
tursunovic Sep 12, 2022
59011f8
Bump podspec version to 3.1.4
tursunovic Sep 12, 2022
d121656
Fix problem with missing custom headers in request
m3t8d1tr Sep 16, 2022
637ba2d
Update CONTRIBUTING.md
Acconut Sep 19, 2022
72ca914
Merge pull request #143 from m3t8d1tr/patch-1
tursunovic Sep 20, 2022
4a1b2f8
Update ROADMAP.md
kvz Sep 30, 2022
a91a60c
Create unit tests for context param
tursunovic Oct 12, 2022
c4e0d73
Add license
tursunovic Oct 12, 2022
49854ab
Enhance annotation
tursunovic Oct 12, 2022
7900919
Merge branch 'master' of github.com:tus/TUSKit into context-parameters
tursunovic Oct 12, 2022
be29914
Update ROADMAP.md
Acconut Nov 7, 2022
3b8c7d5
iOS 12 crash fix
rick51231 Jan 8, 2023
9333162
Update ROADMAP.md
Acconut Jan 16, 2023
2762850
Update ROADMAP.md
Acconut Jan 16, 2023
1dcece4
Rename master to main
Jan 18, 2023
a1faaeb
Update ROADMAP.md
Acconut Jan 18, 2023
28ea864
Removed whitespace after comma
andreaslindahl Jan 23, 2023
0e8a7ca
Merge pull request #151 from andreaslindahl/TUSAPI_space
donnywals Feb 6, 2023
a67787d
Merge pull request #150 from rick51231/master
donnywals Feb 6, 2023
bb4a8db
Bumps Swift version to 5.7
donnywals Feb 6, 2023
cf8c579
Bumps Swift version to 5.7.1
donnywals Feb 6, 2023
8481dd8
Attempt to auto-resolve Swift version
donnywals Feb 6, 2023
8fe7e36
Optimize uploads for non-sandbox environments on macOS;
MartinLau7 Feb 6, 2023
dd99a72
Updated changelog for 3.1.5
donnywals Feb 6, 2023
cc58700
Bumped podspec to 3.1.5
donnywals Feb 6, 2023
ec1edf4
Merge remote-tracking branch 'origin/main' into upstream
MartinLau7 Feb 14, 2023
e4bb403
removed sandbox environment judgment
MartinLau7 Feb 14, 2023
9c21a93
Remove CI failure notifications in Slack
Acconut Feb 15, 2023
c5c39a4
Merge pull request #152 from MartinLau7/main
donnywals Feb 20, 2023
2ad3209
Fixes a bug with resuming / retrying uploads
donnywals Feb 27, 2023
c93d87b
Updated sample app to have an overview of in progress downloads
donnywals Feb 27, 2023
c45c1bb
Update ROADMAP.md
Acconut Mar 8, 2023
6165a2a
Added info on release process
donnywals Mar 13, 2023
d5ec358
Merge branch 'main' of github.com:tus/TUSKit
donnywals Mar 13, 2023
684cc8a
Updated pod author to Transloadit
donnywals Mar 13, 2023
64972ee
add an implemetation to fetch previous uploads
kiyosoft Mar 27, 2023
7af584d
update naming
kiyosoft Mar 28, 2023
495919f
Merge pull request #156 from kiyosoft/find-previous-uploads
donnywals Mar 29, 2023
44dbf52
Updated podspec and changelog for 3.1.6
donnywals Apr 5, 2023
c319ad1
Adds ability to inspect statuscode for uploads with a non-200 statuscode
donnywals Apr 28, 2023
329b814
Merge pull request #158 from tus/dw/add-statuscode-inspection
donnywals Apr 28, 2023
88f2e5c
Updated podspec and changelog
donnywals Apr 28, 2023
98d4c5f
Add retry callback to the delegate
Jul 4, 2022
9ecde61
bump min iOS to 13, macOS to 11 to fix Xcode 14
Aug 26, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
However to keep things clean and neat we ask you follow these small guidelines to help ensure everything runs smoothly.

## Pull Requests
Please direct all Pull Requests to the `swift-development` branch of the repo, to ensure that master will always match with the CocoaPod.
Please direct all Pull Requests to the `main` branch of the repo.

Also please

Expand Down
8 changes: 1 addition & 7 deletions .github/workflows/tuskit-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
strategy:
matrix:
os: ["macos-latest"]
swift: ["5.5"]
swift: ["5"]
runs-on: ${{ matrix.os }}
steps:
- name: Extract Branch Name
Expand All @@ -19,9 +19,3 @@ jobs:
run: swift build -Xswiftc --disable-experimental-concurrency
- name: Run tests
run: swift test -Xswiftc --disable-experimental-concurrency
- uses: 8398a7/action-slack@v3
if: failure() && env.BRANCH == 'master'
with:
status: failure
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
77 changes: 77 additions & 0 deletions .swiftpm/xcode/xcshareddata/xcschemes/TUSKit.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1420"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "TUSKit"
BuildableName = "TUSKit"
BlueprintName = "TUSKit"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "TUSKitTests"
BuildableName = "TUSKitTests"
BlueprintName = "TUSKitTests"
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "TUSKit"
BuildableName = "TUSKit"
BlueprintName = "TUSKit"
ReferencedContainer = "container:">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
31 changes: 31 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
# 3.1.7

# Enhancements
- It's now possible to inspect the status code for failed uploads that did not have a 200 OK HTTP status code. See the following example from the sample app:

```swift
func uploadFailed(id: UUID, error: Error, context: [String : String]?, client: TUSClient) {
Task { @MainActor in
uploads[id] = .failed(error: error)

if case TUSClientError.couldNotUploadFile(underlyingError: let underlyingError) = error,
case TUSAPIError.failedRequest(let response) = underlyingError {
print("upload failed with response \(response)")
}
}
}
```

# 3.1.6

# Enhancements
- Added ability to fetch in progress / current uploads using `getStoredUploads()` on a `TUSClient` instance.

# 3.1.5
## Fixed
- Fixed issue with missing custom headers.

# 3.1.4
## Fixed
- Fix compile error Xcode 14

# 3.1.3
## Fixed
- Added `supportedExtensions` to client
Expand Down
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2015 tus - Resumable File Uploads

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import PackageDescription

let package = Package(
name: "TUSKit",
platforms: [.iOS(.v10), .macOS(.v10_10)],
platforms: [.iOS(.v13), .macOS(.v11)],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
Expand Down
13 changes: 13 additions & 0 deletions ROADMAP.md
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
# Roadmap

- [x] Release version with latest changes (changes: https://github.com/tus/TUSKit/compare/3.1.4...main, relevant issues: https://github.com/tus/TUSKit/issues/138, https://github.com/tus/TUSKit/issues/141 and https://community.transloadit.com/t/ios-tus-client-version-update/16395/3)
- [ ] Create a documentation describing the release process (pods, swift package manager?)
- [ ] Update metadata (author, language, repo) in CocoaPods: https://cocoapods.org/pods/TUSKit
- [ ] Create an example app where TUSKit is used in (would show you how to use the client from a customer’s point of view. Should help evolve the API)
- [x] Add pause / resume functionality
- [x] Add progress indicator
- [x] Add ability to resume uploads from previous app session
- [ ] Add ability to upload files in background
- [ ] Review and address issues & PRs in GitHub until there are zero
- [ ] ~~Create a release blog post on tus.io with the changes from 2.x to 3.x and some usage examples~~
- [ ] Fix CI tests
- [ ] Think about automating releasing using CI
21 changes: 16 additions & 5 deletions Sources/TUSKit/Files.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,16 @@ final class Files {
}

static private var documentsDirectory: URL {
#if os(macOS)
var directory = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask)[0]
if let bundleId = Bundle.main.bundleIdentifier {
directory = directory.appendingPathComponent(bundleId)
}
return directory
#else
return FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
#endif

}

/// Loads all metadata (decoded plist files) from the target directory.
Expand All @@ -80,7 +89,6 @@ final class Files {
/// - Returns: An array of UploadMetadata types
func loadAllMetadata() throws -> [UploadMetadata] {
try queue.sync {

let directoryContents = try FileManager.default.contentsOfDirectory(at: storageDirectory, includingPropertiesForKeys: nil)

// if you want to filter the directory contents you can do like this:
Expand Down Expand Up @@ -153,11 +161,14 @@ final class Files {
/// - Throws: Any error from FileManager when removing a file.
func removeFileAndMetadata(_ metaData: UploadMetadata) throws {
let filePath = metaData.filePath
let metaDataPath = metaData.filePath.appendingPathExtension("plist")
let fileName = filePath.lastPathComponent
let metaDataPath = storageDirectory.appendingPathComponent(fileName).appendingPathExtension("plist")

try queue.sync {
try FileManager.default.removeItem(at: filePath)
try FileManager.default.removeItem(at: metaDataPath)
#if os(iOS)
try FileManager.default.removeItem(at: filePath)
#endif
}
}

Expand All @@ -174,8 +185,8 @@ final class Files {
// Could not find the file that's related to this metadata.
throw FilesError.relatedFileNotFound
}

let targetLocation = metaData.filePath.appendingPathExtension("plist")
let fileName = metaData.filePath.lastPathComponent
let targetLocation = storageDirectory.appendingPathComponent(fileName).appendingPathExtension("plist")
try self.makeDirectoryIfNeeded()

let encoder = PropertyListEncoder()
Expand Down
22 changes: 20 additions & 2 deletions Sources/TUSKit/TUSAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
import Foundation

/// The errors a TUSAPI can return
enum TUSAPIError: Error {
public enum TUSAPIError: Error {
case underlyingError(Error)
case couldNotFetchStatus
case couldNotRetrieveOffset
case couldNotRetrieveLocation
case failedRequest(HTTPURLResponse)
}

/// The status of an upload.
Expand Down Expand Up @@ -51,6 +52,10 @@ final class TUSAPI {
processResult(completion: completion) {
let (_, response) = try result.get()

guard (200...299).contains(response.statusCode) else {
throw TUSAPIError.failedRequest(response)
}

guard let lengthStr = response.allHeaderFields[caseInsensitive: "upload-Length"] as? String,
let length = Int(lengthStr),
let offsetStr = response.allHeaderFields[caseInsensitive: "upload-Offset"] as? String,
Expand Down Expand Up @@ -78,6 +83,10 @@ final class TUSAPI {
let task = session.dataTask(request: request) { (result: Result<(Data?, HTTPURLResponse), Error>) in
processResult(completion: completion) {
let (_, response) = try result.get()

guard (200...299).contains(response.statusCode) else {
throw TUSAPIError.failedRequest(response)
}

guard let location = response.allHeaderFields[caseInsensitive: "location"] as? String,
let locationURL = URL(string: location, relativeTo: metaData.uploadURL) else {
Expand All @@ -104,6 +113,11 @@ final class TUSAPI {
if let mimeType = metaData.mimeType, !mimeType.isEmpty {
metaDataDict["filetype"] = mimeType
}

if let context = metaData.context {
metaDataDict = metaDataDict.merging(context) { _, new in new }
}

return metaDataDict
}

Expand All @@ -114,7 +128,7 @@ final class TUSAPI {
for (key, value) in dict {
let appendingStr: String
if !str.isEmpty {
str += ", "
str += ","
}
appendingStr = "\(key) \(value.toBase64())"
str = str + appendingStr
Expand Down Expand Up @@ -169,6 +183,10 @@ final class TUSAPI {
processResult(completion: completion) {
let (_, response) = try result.get()

guard (200...299).contains(response.statusCode) else {
throw TUSAPIError.failedRequest(response)
}

guard let offsetStr = response.allHeaderFields[caseInsensitive: "upload-offset"] as? String,
let offset = Int(offsetStr) else {
throw TUSAPIError.couldNotRetrieveOffset
Expand Down
1 change: 0 additions & 1 deletion Sources/TUSKit/TUSBackground.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import Foundation
import BackgroundTasks

#if os(iOS)
@available(iOS 13.0, *)
/// Perform background uploading
final class TUSBackground {

Expand Down
Loading