Skip to content

Commit

Permalink
Make com.atproto.repo.uploadBlob work
Browse files Browse the repository at this point in the history
Fixes #2
  • Loading branch information
mnogu committed May 8, 2023
1 parent 713c75e commit 9378a38
Show file tree
Hide file tree
Showing 35 changed files with 166 additions and 106 deletions.
4 changes: 3 additions & 1 deletion chitose/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from .link import Link
from .blob import Blob
from .object import Object
from .record import Record
from .xrpc import call

__all__ = ['Object', 'Record', 'call']
__all__ = ['Blob', 'Link', 'Object', 'Record', 'call']
8 changes: 4 additions & 4 deletions chitose/app/bsky/actor/defs.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(self, did: str, handle: str, display_name: typing.Optional[str]=Non
self.labels = labels

def to_dict(self) -> dict:
return {'did': self.did, 'handle': self.handle, 'displayName': self.display_name, 'avatar': self.avatar, 'viewer': self.viewer, 'labels': self.labels}
return {'did': self.did, 'handle': self.handle, 'displayName': self.display_name, 'avatar': self.avatar, 'viewer': self.viewer, 'labels': self.labels, '$type': 'app.bsky.actor.defs#profileViewBasic'}

class ProfileView(chitose.Object):
""""""
Expand All @@ -34,7 +34,7 @@ def __init__(self, did: str, handle: str, display_name: typing.Optional[str]=Non
self.labels = labels

def to_dict(self) -> dict:
return {'did': self.did, 'handle': self.handle, 'displayName': self.display_name, 'description': self.description, 'avatar': self.avatar, 'indexedAt': self.indexed_at, 'viewer': self.viewer, 'labels': self.labels}
return {'did': self.did, 'handle': self.handle, 'displayName': self.display_name, 'description': self.description, 'avatar': self.avatar, 'indexedAt': self.indexed_at, 'viewer': self.viewer, 'labels': self.labels, '$type': 'app.bsky.actor.defs#profileView'}

class ProfileViewDetailed(chitose.Object):
""""""
Expand All @@ -54,7 +54,7 @@ def __init__(self, did: str, handle: str, display_name: typing.Optional[str]=Non
self.labels = labels

def to_dict(self) -> dict:
return {'did': self.did, 'handle': self.handle, 'displayName': self.display_name, 'description': self.description, 'avatar': self.avatar, 'banner': self.banner, 'followersCount': self.followers_count, 'followsCount': self.follows_count, 'postsCount': self.posts_count, 'indexedAt': self.indexed_at, 'viewer': self.viewer, 'labels': self.labels}
return {'did': self.did, 'handle': self.handle, 'displayName': self.display_name, 'description': self.description, 'avatar': self.avatar, 'banner': self.banner, 'followersCount': self.followers_count, 'followsCount': self.follows_count, 'postsCount': self.posts_count, 'indexedAt': self.indexed_at, 'viewer': self.viewer, 'labels': self.labels, '$type': 'app.bsky.actor.defs#profileViewDetailed'}

class ViewerState(chitose.Object):
""""""
Expand All @@ -67,4 +67,4 @@ def __init__(self, muted: typing.Optional[str]=None, blocked_by: typing.Optional
self.followed_by = followed_by

def to_dict(self) -> dict:
return {'muted': self.muted, 'blockedBy': self.blocked_by, 'blocking': self.blocking, 'following': self.following, 'followedBy': self.followed_by}
return {'muted': self.muted, 'blockedBy': self.blocked_by, 'blocking': self.blocking, 'following': self.following, 'followedBy': self.followed_by, '$type': 'app.bsky.actor.defs#viewerState'}
4 changes: 2 additions & 2 deletions chitose/app/bsky/actor/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
class Profile(chitose.Record):
""""""

def __init__(self, display_name: typing.Optional[str]=None, description: typing.Optional[str]=None, avatar: typing.Optional[typing.Any]=None, banner: typing.Optional[typing.Any]=None) -> None:
def __init__(self, display_name: typing.Optional[str]=None, description: typing.Optional[str]=None, avatar: typing.Optional[chitose.Blob]=None, banner: typing.Optional[chitose.Blob]=None) -> None:
self.display_name = display_name
self.description = description
self.avatar = avatar
self.banner = banner

def to_dict(self) -> dict:
return {'displayName': self.display_name, 'description': self.description, 'avatar': self.avatar, 'banner': self.banner}
return {'displayName': self.display_name, 'description': self.description, 'avatar': self.avatar, 'banner': self.banner, '$type': 'app.bsky.actor.profile'}
10 changes: 5 additions & 5 deletions chitose/app/bsky/embed/external.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ def __init__(self, external: chitose.app.bsky.embed.external.ExternalExternal) -
self.external = external

def to_dict(self) -> dict:
return {'external': self.external}
return {'external': self.external, '$type': 'app.bsky.embed.external'}

class ExternalExternal(chitose.Object):
""""""

def __init__(self, uri: str, title: str, description: str, thumb: typing.Optional[typing.Any]=None) -> None:
def __init__(self, uri: str, title: str, description: str, thumb: typing.Optional[chitose.Blob]=None) -> None:
self.uri = uri
self.title = title
self.description = description
self.thumb = thumb

def to_dict(self) -> dict:
return {'uri': self.uri, 'title': self.title, 'description': self.description, 'thumb': self.thumb}
return {'uri': self.uri, 'title': self.title, 'description': self.description, 'thumb': self.thumb, '$type': 'app.bsky.embed.external#external'}

class View(chitose.Object):
""""""
Expand All @@ -33,7 +33,7 @@ def __init__(self, external: chitose.app.bsky.embed.external.ViewExternal) -> No
self.external = external

def to_dict(self) -> dict:
return {'external': self.external}
return {'external': self.external, '$type': 'app.bsky.embed.external#view'}

class ViewExternal(chitose.Object):
""""""
Expand All @@ -45,4 +45,4 @@ def __init__(self, uri: str, title: str, description: str, thumb: typing.Optiona
self.thumb = thumb

def to_dict(self) -> dict:
return {'uri': self.uri, 'title': self.title, 'description': self.description, 'thumb': self.thumb}
return {'uri': self.uri, 'title': self.title, 'description': self.description, 'thumb': self.thumb, '$type': 'app.bsky.embed.external#viewExternal'}
11 changes: 5 additions & 6 deletions chitose/app/bsky/embed/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from __future__ import annotations
import chitose
import chitose.app.bsky.embed.images
import typing

class Images(chitose.Object):
""""""
Expand All @@ -12,17 +11,17 @@ def __init__(self, images: list[chitose.app.bsky.embed.images.Image]) -> None:
self.images = images

def to_dict(self) -> dict:
return {'images': self.images}
return {'images': self.images, '$type': 'app.bsky.embed.images'}

class Image(chitose.Object):
""""""

def __init__(self, image: typing.Any, alt: str) -> None:
def __init__(self, image: chitose.Blob, alt: str) -> None:
self.image = image
self.alt = alt

def to_dict(self) -> dict:
return {'image': self.image, 'alt': self.alt}
return {'image': self.image, 'alt': self.alt, '$type': 'app.bsky.embed.images#image'}

class View(chitose.Object):
""""""
Expand All @@ -31,7 +30,7 @@ def __init__(self, images: list[chitose.app.bsky.embed.images.ViewImage]) -> Non
self.images = images

def to_dict(self) -> dict:
return {'images': self.images}
return {'images': self.images, '$type': 'app.bsky.embed.images#view'}

class ViewImage(chitose.Object):
""""""
Expand All @@ -42,4 +41,4 @@ def __init__(self, thumb: str, fullsize: str, alt: str) -> None:
self.alt = alt

def to_dict(self) -> dict:
return {'thumb': self.thumb, 'fullsize': self.fullsize, 'alt': self.alt}
return {'thumb': self.thumb, 'fullsize': self.fullsize, 'alt': self.alt, '$type': 'app.bsky.embed.images#viewImage'}
10 changes: 5 additions & 5 deletions chitose/app/bsky/embed/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(self, record: chitose.com.atproto.repo.strong_ref.StrongRef) -> Non
self.record = record

def to_dict(self) -> dict:
return {'record': self.record}
return {'record': self.record, '$type': 'app.bsky.embed.record'}

class View(chitose.Object):
""""""
Expand All @@ -27,7 +27,7 @@ def __init__(self, record: typing.Union[chitose.app.bsky.embed.record.ViewRecord
self.record = record

def to_dict(self) -> dict:
return {'record': self.record}
return {'record': self.record, '$type': 'app.bsky.embed.record#view'}

class ViewRecord(chitose.Object):
""""""
Expand All @@ -42,7 +42,7 @@ def __init__(self, uri: str, cid: str, author: chitose.app.bsky.actor.defs.Profi
self.embeds = embeds

def to_dict(self) -> dict:
return {'uri': self.uri, 'cid': self.cid, 'author': self.author, 'value': self.value, 'indexedAt': self.indexed_at, 'labels': self.labels, 'embeds': self.embeds}
return {'uri': self.uri, 'cid': self.cid, 'author': self.author, 'value': self.value, 'indexedAt': self.indexed_at, 'labels': self.labels, 'embeds': self.embeds, '$type': 'app.bsky.embed.record#viewRecord'}

class ViewNotFound(chitose.Object):
""""""
Expand All @@ -51,7 +51,7 @@ def __init__(self, uri: str) -> None:
self.uri = uri

def to_dict(self) -> dict:
return {'uri': self.uri}
return {'uri': self.uri, '$type': 'app.bsky.embed.record#viewNotFound'}

class ViewBlocked(chitose.Object):
""""""
Expand All @@ -60,4 +60,4 @@ def __init__(self, uri: str) -> None:
self.uri = uri

def to_dict(self) -> dict:
return {'uri': self.uri}
return {'uri': self.uri, '$type': 'app.bsky.embed.record#viewBlocked'}
4 changes: 2 additions & 2 deletions chitose/app/bsky/embed/record_with_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def __init__(self, record: chitose.app.bsky.embed.record.Record, media: typing.U
self.media = media

def to_dict(self) -> dict:
return {'record': self.record, 'media': self.media}
return {'record': self.record, 'media': self.media, '$type': 'app.bsky.embed.recordWithMedia'}

class View(chitose.Object):
""""""
Expand All @@ -25,4 +25,4 @@ def __init__(self, record: chitose.app.bsky.embed.record.View, media: typing.Uni
self.media = media

def to_dict(self) -> dict:
return {'record': self.record, 'media': self.media}
return {'record': self.record, 'media': self.media, '$type': 'app.bsky.embed.recordWithMedia#view'}
16 changes: 8 additions & 8 deletions chitose/app/bsky/feed/defs.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self, uri: str, cid: str, author: chitose.app.bsky.actor.defs.Profi
self.labels = labels

def to_dict(self) -> dict:
return {'uri': self.uri, 'cid': self.cid, 'author': self.author, 'record': self.record, 'indexedAt': self.indexed_at, 'embed': self.embed, 'replyCount': self.reply_count, 'repostCount': self.repost_count, 'likeCount': self.like_count, 'viewer': self.viewer, 'labels': self.labels}
return {'uri': self.uri, 'cid': self.cid, 'author': self.author, 'record': self.record, 'indexedAt': self.indexed_at, 'embed': self.embed, 'replyCount': self.reply_count, 'repostCount': self.repost_count, 'likeCount': self.like_count, 'viewer': self.viewer, 'labels': self.labels, '$type': 'app.bsky.feed.defs#postView'}

class ViewerState(chitose.Object):
""""""
Expand All @@ -38,7 +38,7 @@ def __init__(self, repost: typing.Optional[str]=None, like: typing.Optional[str]
self.like = like

def to_dict(self) -> dict:
return {'repost': self.repost, 'like': self.like}
return {'repost': self.repost, 'like': self.like, '$type': 'app.bsky.feed.defs#viewerState'}

class FeedViewPost(chitose.Object):
""""""
Expand All @@ -49,7 +49,7 @@ def __init__(self, post: chitose.app.bsky.feed.defs.PostView, reply: typing.Opti
self.reason = reason

def to_dict(self) -> dict:
return {'post': self.post, 'reply': self.reply, 'reason': self.reason}
return {'post': self.post, 'reply': self.reply, 'reason': self.reason, '$type': 'app.bsky.feed.defs#feedViewPost'}

class ReplyRef(chitose.Object):
""""""
Expand All @@ -59,7 +59,7 @@ def __init__(self, root: chitose.app.bsky.feed.defs.PostView, parent: chitose.ap
self.parent = parent

def to_dict(self) -> dict:
return {'root': self.root, 'parent': self.parent}
return {'root': self.root, 'parent': self.parent, '$type': 'app.bsky.feed.defs#replyRef'}

class ReasonRepost(chitose.Object):
""""""
Expand All @@ -69,7 +69,7 @@ def __init__(self, by: chitose.app.bsky.actor.defs.ProfileViewBasic, indexed_at:
self.indexed_at = indexed_at

def to_dict(self) -> dict:
return {'by': self.by, 'indexedAt': self.indexed_at}
return {'by': self.by, 'indexedAt': self.indexed_at, '$type': 'app.bsky.feed.defs#reasonRepost'}

class ThreadViewPost(chitose.Object):
""""""
Expand All @@ -80,7 +80,7 @@ def __init__(self, post: chitose.app.bsky.feed.defs.PostView, parent: typing.Opt
self.replies = replies

def to_dict(self) -> dict:
return {'post': self.post, 'parent': self.parent, 'replies': self.replies}
return {'post': self.post, 'parent': self.parent, 'replies': self.replies, '$type': 'app.bsky.feed.defs#threadViewPost'}

class NotFoundPost(chitose.Object):
""""""
Expand All @@ -90,7 +90,7 @@ def __init__(self, uri: str, not_found: str) -> None:
self.not_found = not_found

def to_dict(self) -> dict:
return {'uri': self.uri, 'notFound': self.not_found}
return {'uri': self.uri, 'notFound': self.not_found, '$type': 'app.bsky.feed.defs#notFoundPost'}

class BlockedPost(chitose.Object):
""""""
Expand All @@ -100,4 +100,4 @@ def __init__(self, uri: str, blocked: str) -> None:
self.blocked = blocked

def to_dict(self) -> dict:
return {'uri': self.uri, 'blocked': self.blocked}
return {'uri': self.uri, 'blocked': self.blocked, '$type': 'app.bsky.feed.defs#blockedPost'}
2 changes: 1 addition & 1 deletion chitose/app/bsky/feed/get_likes.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ def __init__(self, indexed_at: str, created_at: str, actor: chitose.app.bsky.act
self.actor = actor

def to_dict(self) -> dict:
return {'indexedAt': self.indexed_at, 'createdAt': self.created_at, 'actor': self.actor}
return {'indexedAt': self.indexed_at, 'createdAt': self.created_at, 'actor': self.actor, '$type': 'app.bsky.feed.getLikes#like'}
2 changes: 1 addition & 1 deletion chitose/app/bsky/feed/like.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ def __init__(self, subject: chitose.com.atproto.repo.strong_ref.StrongRef, creat
self.created_at = created_at

def to_dict(self) -> dict:
return {'subject': self.subject, 'createdAt': self.created_at}
return {'subject': self.subject, 'createdAt': self.created_at, '$type': 'app.bsky.feed.like'}
8 changes: 4 additions & 4 deletions chitose/app/bsky/feed/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(self, text: str, created_at: str, entities: typing.Optional[list[ch
self.embed = embed

def to_dict(self) -> dict:
return {'text': self.text, 'createdAt': self.created_at, 'entities': self.entities, 'facets': self.facets, 'reply': self.reply, 'embed': self.embed}
return {'text': self.text, 'createdAt': self.created_at, 'entities': self.entities, 'facets': self.facets, 'reply': self.reply, 'embed': self.embed, '$type': 'app.bsky.feed.post'}

class ReplyRef(chitose.Object):
""""""
Expand All @@ -37,7 +37,7 @@ def __init__(self, root: chitose.com.atproto.repo.strong_ref.StrongRef, parent:
self.parent = parent

def to_dict(self) -> dict:
return {'root': self.root, 'parent': self.parent}
return {'root': self.root, 'parent': self.parent, '$type': 'app.bsky.feed.post#replyRef'}

class Entity(chitose.Object):
"""
Expand All @@ -52,7 +52,7 @@ def __init__(self, index: chitose.app.bsky.feed.post.TextSlice, type: str, value
self.value = value

def to_dict(self) -> dict:
return {'index': self.index, 'type': self.type, 'value': self.value}
return {'index': self.index, 'type': self.type, 'value': self.value, '$type': 'app.bsky.feed.post#entity'}

class TextSlice(chitose.Object):
""""""
Expand All @@ -62,4 +62,4 @@ def __init__(self, start: int, end: int) -> None:
self.end = end

def to_dict(self) -> dict:
return {'start': self.start, 'end': self.end}
return {'start': self.start, 'end': self.end, '$type': 'app.bsky.feed.post#textSlice'}
2 changes: 1 addition & 1 deletion chitose/app/bsky/feed/repost.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ def __init__(self, subject: chitose.com.atproto.repo.strong_ref.StrongRef, creat
self.created_at = created_at

def to_dict(self) -> dict:
return {'subject': self.subject, 'createdAt': self.created_at}
return {'subject': self.subject, 'createdAt': self.created_at, '$type': 'app.bsky.feed.repost'}
2 changes: 1 addition & 1 deletion chitose/app/bsky/graph/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ def __init__(self, subject: str, created_at: str) -> None:
self.created_at = created_at

def to_dict(self) -> dict:
return {'subject': self.subject, 'createdAt': self.created_at}
return {'subject': self.subject, 'createdAt': self.created_at, '$type': 'app.bsky.graph.block'}
2 changes: 1 addition & 1 deletion chitose/app/bsky/graph/follow.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ def __init__(self, subject: str, created_at: str) -> None:
self.created_at = created_at

def to_dict(self) -> dict:
return {'subject': self.subject, 'createdAt': self.created_at}
return {'subject': self.subject, 'createdAt': self.created_at, '$type': 'app.bsky.graph.follow'}
2 changes: 1 addition & 1 deletion chitose/app/bsky/notification/list_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ def __init__(self, uri: str, cid: str, author: chitose.app.bsky.actor.defs.Profi
self.labels = labels

def to_dict(self) -> dict:
return {'uri': self.uri, 'cid': self.cid, 'author': self.author, 'reason': self.reason, 'record': self.record, 'isRead': self.is_read, 'indexedAt': self.indexed_at, 'reasonSubject': self.reason_subject, 'labels': self.labels}
return {'uri': self.uri, 'cid': self.cid, 'author': self.author, 'reason': self.reason, 'record': self.record, 'isRead': self.is_read, 'indexedAt': self.indexed_at, 'reasonSubject': self.reason_subject, 'labels': self.labels, '$type': 'app.bsky.notification.listNotifications#notification'}
8 changes: 4 additions & 4 deletions chitose/app/bsky/richtext/facet.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __init__(self, index: chitose.app.bsky.richtext.facet.ByteSlice, features: l
self.features = features

def to_dict(self) -> dict:
return {'index': self.index, 'features': self.features}
return {'index': self.index, 'features': self.features, '$type': 'app.bsky.richtext.facet'}

class Mention(chitose.Object):
""""""
Expand All @@ -22,7 +22,7 @@ def __init__(self, did: str) -> None:
self.did = did

def to_dict(self) -> dict:
return {'did': self.did}
return {'did': self.did, '$type': 'app.bsky.richtext.facet#mention'}

class Link(chitose.Object):
""""""
Expand All @@ -31,7 +31,7 @@ def __init__(self, uri: str) -> None:
self.uri = uri

def to_dict(self) -> dict:
return {'uri': self.uri}
return {'uri': self.uri, '$type': 'app.bsky.richtext.facet#link'}

class ByteSlice(chitose.Object):
""""""
Expand All @@ -41,4 +41,4 @@ def __init__(self, byte_start: int, byte_end: int) -> None:
self.byte_end = byte_end

def to_dict(self) -> dict:
return {'byteStart': self.byte_start, 'byteEnd': self.byte_end}
return {'byteStart': self.byte_start, 'byteEnd': self.byte_end, '$type': 'app.bsky.richtext.facet#byteSlice'}
Loading

0 comments on commit 9378a38

Please sign in to comment.