Skip to content

Commit

Permalink
fix: upload and source asset state handling (#109)
Browse files Browse the repository at this point in the history
* fix: use the file URL for source asset

instead of the upload URL, which is the wrong URL

* fix: upload cancelled while standardizing shouldn't proceed to the transport stage

not needed because if automatically synthesized will default to non-public visibility

* refactor: represent source internally as AVURLAsset

* update docc plugin
  • Loading branch information
andrewjl-mux authored Jun 10, 2024
1 parent 268a823 commit 38a3e31
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-docc-plugin",
"state" : {
"revision" : "9b1258905c21fc1b97bf03d1b4ca12c4ec4e5fda",
"version" : "1.2.0"
"revision" : "26ac5758409154cc448d7ab82389c520fa8a8247",
"version" : "1.3.0"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ class UploadInputStandardizationWorker {
var standardizedInput: AVAsset?

func standardize(
sourceAsset: AVAsset,
sourceAsset: AVURLAsset,
rescalingDetails: UploadInputFormatInspectionResult.RescalingDetails,
outputURL: URL,
completion: @escaping (AVAsset, AVAsset?, Error?) -> ()
completion: @escaping (AVURLAsset, AVAsset?, Error?) -> ()
) {

let availableExportPresets = AVAssetExportSession.allExportPresets()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ class UploadInputStandardizer {

func standardize(
id: String,
sourceAsset: AVAsset,
sourceAsset: AVURLAsset,
rescalingDetails: UploadInputFormatInspectionResult.RescalingDetails,
outputURL: URL,
completion: @escaping (AVAsset, AVAsset?, Error?) -> ()
completion: @escaping (AVURLAsset, AVAsset?, Error?) -> ()
) {
let worker = UploadInputStandardizationWorker()

Expand Down
72 changes: 36 additions & 36 deletions Sources/MuxUploadSDK/InternalUtilities/UploadInput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,26 @@ import Foundation
struct UploadInput {

internal enum Status {
case ready(AVAsset, UploadInfo)
case started(AVAsset, UploadInfo)
case underInspection(AVAsset, UploadInfo)
case standardizing(AVAsset, UploadInfo)
case ready(AVURLAsset, UploadInfo)
case started(AVURLAsset, UploadInfo)
case underInspection(AVURLAsset, UploadInfo)
case standardizing(AVURLAsset, UploadInfo)
case standardizationSucceeded(
source: AVAsset,
standardized: AVAsset?,
source: AVURLAsset,
standardized: AVURLAsset?,
uploadInfo: UploadInfo
)
case standardizationFailed(AVAsset, UploadInfo)
case awaitingUploadConfirmation(UploadInfo)
case uploadInProgress(UploadInfo, DirectUpload.TransportStatus)
case uploadPaused(UploadInfo, DirectUpload.TransportStatus)
case uploadSucceeded(UploadInfo, DirectUpload.SuccessDetails)
case uploadFailed(UploadInfo, DirectUploadError)
case standardizationFailed(AVURLAsset, UploadInfo)
case awaitingUploadConfirmation(AVURLAsset,UploadInfo)
case uploadInProgress(AVURLAsset, UploadInfo, DirectUpload.TransportStatus)
case uploadPaused(AVURLAsset, UploadInfo, DirectUpload.TransportStatus)
case uploadSucceeded(AVURLAsset, UploadInfo, DirectUpload.SuccessDetails)
case uploadFailed(AVURLAsset, UploadInfo, DirectUploadError)
}

var status: Status

var sourceAsset: AVAsset {
var sourceAsset: AVURLAsset {
switch status {
case .ready(let sourceAsset, _):
return sourceAsset
Expand All @@ -43,16 +43,16 @@ struct UploadInput {
return sourceAsset
case .standardizationFailed(let sourceAsset, _):
return sourceAsset
case .awaitingUploadConfirmation(let uploadInfo):
return uploadInfo.sourceAsset()
case .uploadInProgress(let uploadInfo, _):
return uploadInfo.sourceAsset()
case .uploadSucceeded(let uploadInfo, _):
return uploadInfo.sourceAsset()
case .uploadFailed(let uploadInfo, _):
return uploadInfo.sourceAsset()
case .uploadPaused(let uploadInfo, _):
return uploadInfo.sourceAsset()
case .awaitingUploadConfirmation(let sourceAsset, _):
return sourceAsset
case .uploadInProgress(let sourceAsset, _, _):
return sourceAsset
case .uploadSucceeded(let sourceAsset, _, _):
return sourceAsset
case .uploadFailed(let sourceAsset, _, _):
return sourceAsset
case .uploadPaused(let sourceAsset, _, _):
return sourceAsset
}
}

Expand All @@ -70,15 +70,15 @@ struct UploadInput {
return uploadInfo
case .standardizationFailed(_, let uploadInfo):
return uploadInfo
case .awaitingUploadConfirmation(let uploadInfo):
case .awaitingUploadConfirmation(_, let uploadInfo):
return uploadInfo
case .uploadInProgress(let uploadInfo, _):
case .uploadInProgress(_, let uploadInfo, _):
return uploadInfo
case .uploadPaused(let uploadInfo, _):
case .uploadPaused(_, let uploadInfo, _):
return uploadInfo
case .uploadSucceeded(let uploadInfo, _):
case .uploadSucceeded(_, let uploadInfo, _):
return uploadInfo
case .uploadFailed(let uploadInfo, _):
case .uploadFailed(_, let uploadInfo, _):
return uploadInfo
}
}
Expand All @@ -99,11 +99,11 @@ struct UploadInput {
return nil
case .awaitingUploadConfirmation:
return nil
case .uploadInProgress(_, let transportStatus):
case .uploadInProgress(_, _, let transportStatus):
return transportStatus
case .uploadPaused(_, let transportStatus):
case .uploadPaused(_, _, let transportStatus):
return transportStatus
case .uploadSucceeded(_, let successDetails):
case .uploadSucceeded(_, _, let successDetails):
return successDetails.finalState
case .uploadFailed:
return nil
Expand All @@ -125,7 +125,7 @@ extension UploadInput {
startingTransportStatus: DirectUpload.TransportStatus
) {
if case UploadInput.Status.underInspection = status {
status = .uploadInProgress(uploadInfo, startingTransportStatus)
status = .uploadInProgress(sourceAsset, uploadInfo, startingTransportStatus)
} else {
return
}
Expand All @@ -134,15 +134,15 @@ extension UploadInput {
mutating func processUploadSuccess(
transportStatus: DirectUpload.TransportStatus
) {
if case UploadInput.Status.uploadInProgress(let info, _) = status {
status = .uploadSucceeded(info, DirectUpload.SuccessDetails(finalState: transportStatus))
if case UploadInput.Status.uploadInProgress(let asset, let info, _) = status {
status = .uploadSucceeded(asset, info, DirectUpload.SuccessDetails(finalState: transportStatus))
} else {
return
}
}

mutating func processUploadFailure(error: DirectUploadError) {
status = .uploadFailed(uploadInfo, error)
status = .uploadFailed(sourceAsset, uploadInfo, error)
}

}
Expand All @@ -151,7 +151,7 @@ extension UploadInput.Status: Equatable { }

extension UploadInput {
init(
asset: AVAsset,
asset: AVURLAsset,
info: UploadInfo
) {
self.status = .ready(asset, info)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,16 @@ extension DirectUpload {
inputAsset: AVAsset,
options: DirectUploadOptions
) {
guard let urlAsset = inputAsset as? AVURLAsset else {
precondition(
false,
"Only assets with URLs can be uploaded"
)
}

self.init(
input: UploadInput(
asset: inputAsset,
asset: urlAsset,
info: UploadInfo(
uploadURL: uploadURL,
options: options
Expand Down
Loading

0 comments on commit 38a3e31

Please sign in to comment.