Skip to content

Commit ce91513

Browse files
committed
upload limit
1 parent 6220da3 commit ce91513

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

lib/rubysky/raw/client.rb

+8
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ def ensure_success(res:, expected_code: "200", called_from: nil)
4444

4545
POST_COLLECTION = "app.bsky.feed.post"
4646

47+
# app.bsky.embed.images lexicon
48+
UPLOAD_SIZE_LIMIT = 10_000_000
49+
4750
attr_reader :pds, :session
4851

4952
def self.create_session(identifier:, password:, pds:)
@@ -95,6 +98,11 @@ def post(text:, embed: nil, created_at: DateTime.now.iso8601)
9598

9699
def upload_blob(file:, mime_type:)
97100
body = file.read
101+
if body.size > UPLOAD_SIZE_LIMIT
102+
raise Error,
103+
"upload image size shoule be less than #{UPLOAD_SIZE_LIMIT} bytes(got #{body.size} bytes)"
104+
end
105+
98106
res = send_post(pds: @pds, path: UPLOAD_BLOB_PATH,
99107
body:,
100108
headers: {

sig/rubysky.rbs

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ module RubySky
3939
CREATE_RECORD_PATH: String
4040
UPLOAD_BLOB_PATH: String
4141
POST_COLLECTION: String
42+
UPLOAD_SIZE_LIMIT: Integer
4243

4344
type embed = Raw::ImageEmbed
4445
type facet = { index: { byteStart: Integer, byteEnd: Integer }, features: Array[Hash[Symbol, untyped]] }

0 commit comments

Comments
 (0)