From 71fbd32dd6e3e79d2563ec43003dff3d134987b9 Mon Sep 17 00:00:00 2001 From: ThibaultBee Date: Fri, 9 Dec 2022 13:16:04 +0000 Subject: [PATCH] fix(ios): fix the way RequestTaskQueue operation is synchronous --- .github/workflows/build.yml | 63 +++++++++++++++++++ ApiVideoUploader.podspec | 4 +- CHANGELOG.md | 5 ++ README.md | 4 +- Sources/APIs.swift | 2 +- Sources/APIs/VideosAPI.swift | 37 +++++++++-- .../ProgressiveUploadSessionProtocol.swift | 14 +++-- Sources/Upload/RequestTaskQueue.swift | 19 +++--- .../Upload/UploadChunkRequestTaskQueue.swift | 16 +---- project.yml | 2 +- 10 files changed, 123 insertions(+), 43 deletions(-) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..7dd4b89 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,63 @@ +name: Build + +on: [push] + +jobs: + build-swift: + name: Build with swift + runs-on: macos-12 + + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: xcode version + uses: maxim-lobanov/setup-xcode@v1 + with: + xcode-version: '13.4.1' + - name: Build Package with swift + run: swift build + + build-xcodebuild: + name: Build with xcodebuild + runs-on: macos-12 + + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: xcode version + uses: maxim-lobanov/setup-xcode@v1 + with: + xcode-version: '13.4.1' + - name: Set Default Scheme + run: | + scheme_list=$(xcodebuild -list -json | tr -d "\n") + default=$(echo $scheme_list | ruby -e "require 'json'; puts JSON.parse(STDIN.gets)['workspace']['schemes'][0]") + echo $default | cat >default + echo Using default scheme: $default + - name: Build Package with xcodebuild + env: + scheme: ${{ 'default' }} + run: | + if [ $scheme = default ]; then scheme=$(cat default); fi + xcodebuild -scheme $scheme -destination 'platform=iOS Simulator,name=iPhone 13' + - name: Build Example + env: + scheme: ${{ 'default' }} + run: | + if [ $scheme = default ]; then scheme=$(cat default); fi + xcodebuild clean build -project Example/Example.xcodeproj -scheme $scheme -sdk iphoneos + + cocoapods: + name: Verify cocopods podspec + needs: [ build-xcodebuild ] + runs-on: macos-12 + + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: xcode version + uses: maxim-lobanov/setup-xcode@v1 + with: + xcode-version: '13.4.1' + - name: Verify cocoapods + run: pod lib lint --allow-warnings diff --git a/ApiVideoUploader.podspec b/ApiVideoUploader.podspec index 5b13879..45afc63 100644 --- a/ApiVideoUploader.podspec +++ b/ApiVideoUploader.podspec @@ -5,8 +5,8 @@ Pod::Spec.new do |s| s.tvos.deployment_target = '10.0' # Add back when CocoaPods/CocoaPods#11558 is released #s.watchos.deployment_target = '3.0' - s.version = '1.1.0' - s.source = { :git => 'https://github.com/apivideo/api.video-ios-uploader', :tag => 'v1.1.0' } + s.version = '1.1.1' + s.source = { :git => 'https://github.com/apivideo/api.video-ios-uploader', :tag => 'v1.1.1' } s.authors = { 'Ecosystem Team' => 'ecosystem@api.video' } s.license = { :type => 'MIT' } s.homepage = 'https://docs.api.video' diff --git a/CHANGELOG.md b/CHANGELOG.md index 5743a37..72f5541 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # Changelog All changes to this project will be documented in this file. +## [1.1.1] - 2022-12-09 +- Fix on upload by chunk and progressive upload. +- Add test on progressive upload. +- Add a `build.yml` CI workflow. + ## [1.1.0] - 2022-12-06 - Refactor upload by chunk and progressive upload. It is now possible to cancel an upload. - Add timeout API diff --git a/README.md b/README.md index 40f15c4..6acaa85 100644 --- a/README.md +++ b/README.md @@ -39,14 +39,14 @@ It allows you to upload videos in two ways: Specify it in your `Cartfile`: ``` -github "apivideo/api.video-ios-uploader" ~> 1.1.0 +github "apivideo/api.video-ios-uploader" ~> 1.1.1 ``` Run `carthage update` ### CocoaPods -Add `pod 'ApiVideoUploader', '1.1.0'` in your `Podfile` +Add `pod 'ApiVideoUploader', '1.1.1'` in your `Podfile` Run `pod install` diff --git a/Sources/APIs.swift b/Sources/APIs.swift index 6e786e7..8b068ee 100644 --- a/Sources/APIs.swift +++ b/Sources/APIs.swift @@ -8,7 +8,7 @@ import Foundation public class ApiVideoUploader { public static var apiKey: String? = nil public static var basePath = "https://ws.api.video" - internal static var customHeaders:[String: String] = ["AV-Origin-Client": "ios-uploader:1.1.0"] + internal static var customHeaders:[String: String] = ["AV-Origin-Client": "ios-uploader:1.1.1"] private static var chunkSize: Int = 50 * 1024 * 1024 internal static var requestBuilderFactory: RequestBuilderFactory = AlamofireRequestBuilderFactory() internal static var credential = ApiVideoCredential() diff --git a/Sources/APIs/VideosAPI.swift b/Sources/APIs/VideosAPI.swift index 419574d..03eabad 100644 --- a/Sources/APIs/VideosAPI.swift +++ b/Sources/APIs/VideosAPI.swift @@ -40,7 +40,7 @@ open class VideosAPI { /** * Create a progressive upload session * - * - returns: a progressive upload session + - returns: a progressive upload session */ public class func buildProgressiveUploadSession(videoId: String) -> ProgressiveUploadSession { ProgressiveUploadSession(videoId: videoId) @@ -55,6 +55,7 @@ open class VideosAPI { self.videoId = videoId super.init(queueLabel: videoId) } + public func uploadPart(file: URL, onProgressReady: ((Progress) -> Void)? = nil, apiResponseQueue: DispatchQueue = ApiVideoUploader.apiResponseQueue, completion: @escaping ((_ data: Video?, _ error: Error?) -> Void)) -> RequestTask { let chunkId = partId @@ -82,13 +83,14 @@ open class VideosAPI { numOfChunks = partId } let requestBuilder = uploadWithRequestBuilder(videoId: videoId, file: file, chunkId: partId, numOfChunks: numOfChunks, onProgressReady: onProgressReady) - execute(requestBuilder, apiResponseQueue: apiResponseQueue, completion: completion) + execute(requestBuilder, apiResponseQueue: apiResponseQueue) { data, error in + completion(data, error) + } return requestBuilder.requestTask } } - /** Upload a video - POST /videos/{videoId}/source @@ -233,7 +235,7 @@ The latter allows you to split a video source into X chunks and send those chunk /** * Create a progressive uploadWithUploadToken session * - * - returns: a progressive uploadWithUploadToken session + - returns: a progressive uploadWithUploadToken session */ public class func buildProgressiveUploadWithUploadTokenSession(token: String) -> ProgressiveUploadWithUploadTokenSession { ProgressiveUploadWithUploadTokenSession(token: token) @@ -249,6 +251,12 @@ The latter allows you to split a video source into X chunks and send those chunk self.token = token super.init(queueLabel: token) } + + override func willExecuteRequestBuilder(requestBuilder: RequestBuilder