Skip to content

Commit

Permalink
upload limit
Browse files Browse the repository at this point in the history
  • Loading branch information
nna774 committed Dec 27, 2024
1 parent 6220da3 commit ce91513
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/rubysky/raw/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ def ensure_success(res:, expected_code: "200", called_from: nil)

POST_COLLECTION = "app.bsky.feed.post"

# app.bsky.embed.images lexicon
UPLOAD_SIZE_LIMIT = 10_000_000

attr_reader :pds, :session

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

def upload_blob(file:, mime_type:)
body = file.read
if body.size > UPLOAD_SIZE_LIMIT
raise Error,
"upload image size shoule be less than #{UPLOAD_SIZE_LIMIT} bytes(got #{body.size} bytes)"
end

res = send_post(pds: @pds, path: UPLOAD_BLOB_PATH,
body:,
headers: {
Expand Down
1 change: 1 addition & 0 deletions sig/rubysky.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ module RubySky
CREATE_RECORD_PATH: String
UPLOAD_BLOB_PATH: String
POST_COLLECTION: String
UPLOAD_SIZE_LIMIT: Integer

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

0 comments on commit ce91513

Please sign in to comment.