Skip to content

Commit 801bb5f

Browse files
committed
Check file size of video in ATProtoBluesky
1 parent 72312a3 commit 801bb5f

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

Sources/ATProtoKit/APIReference/ATProtoBlueskyAPI/PostRecord/CreatePostRecord.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,12 @@ extension ATProtoBluesky {
476476
public func buildVideo(_ video: Data, with captions: [Caption]? = nil, altText: String? = nil,
477477
aspectRatio: AppBskyLexicon.Embed.AspectRatioDefinition? = nil, pollingFrequency: Int = 3, pdsURL: String = "https://bsky.social",
478478
accessToken: String) async throws -> ATUnion.PostEmbedUnion {
479+
// Check if the size of the video is small enough.
480+
let sizeLimit = 100 * 1024 * 1024 // 100MB in bytes
481+
if video.count >= sizeLimit {
482+
throw ATJobStatusError.videoSizeTooLarge(message: "The video file is too large. The maximum file size is currently 100MB.")
483+
}
484+
479485

480486
var videoBlob: ComAtprotoLexicon.Repository.UploadBlobOutput? = nil
481487
var captionReferences: [AppBskyLexicon.Embed.VideoDefinition.Caption] = []

Sources/ATProtoKit/Errors/ATProtoError.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ public enum ATJobStatusError: Decodable, ATProtoError {
148148
/// - Parameter message: The message for the error.
149149
case videoLimitExceeded(message: String)
150150

151+
/// The video can't be uploaded because the size of the video is too big.
152+
///
153+
/// - Parameter message: The message for the error.
154+
case videoSizeTooLarge(message: String)
155+
151156
/// The video can't be uploaded because the user account either has the ability to upload
152157
/// videos disabld or because they have been banned from doing so.
153158
///

0 commit comments

Comments
 (0)