Something something like soundcloud but not like soundcloud.
Log in, upload records, done.
Simple, easy, KISS.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

models.py 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. import datetime
  2. import os
  3. from flask import current_app
  4. from flask_security import SQLAlchemyUserDatastore, UserMixin, RoleMixin
  5. from flask_sqlalchemy import SQLAlchemy
  6. from slugify import slugify
  7. from sqlalchemy import UniqueConstraint
  8. from sqlalchemy import event
  9. from sqlalchemy.ext.hybrid import Comparator
  10. from sqlalchemy.ext.hybrid import hybrid_property
  11. from sqlalchemy.sql import func
  12. from sqlalchemy_searchable import make_searchable
  13. from sqlalchemy_utils.types.choice import ChoiceType
  14. from sqlalchemy_utils.types.url import URLType
  15. from sqlalchemy_utils.types.json import JSONType
  16. from little_boxes.key import Key as LittleBoxesKey
  17. from activitypub.utils import ap_url
  18. from sqlalchemy.dialects.postgresql import UUID
  19. from sqlalchemy import text as sa_text
  20. from little_boxes import activitypub as ap
  21. from urllib.parse import urlparse
  22. db = SQLAlchemy()
  23. make_searchable(db.metadata)
  24. # #### Base ####
  25. class CaseInsensitiveComparator(Comparator):
  26. def __eq__(self, other):
  27. return func.lower(self.__clause_element__()) == func.lower(other)
  28. class Config(db.Model):
  29. __tablename__ = "config"
  30. id = db.Column(db.Integer, primary_key=True)
  31. app_name = db.Column(db.String(255), default=None)
  32. app_description = db.Column(db.Text)
  33. # #### User ####
  34. roles_users = db.Table(
  35. "roles_users",
  36. db.Column("user_id", db.Integer(), db.ForeignKey("user.id")),
  37. db.Column("role_id", db.Integer(), db.ForeignKey("role.id")),
  38. )
  39. class Role(db.Model, RoleMixin):
  40. id = db.Column(db.Integer(), primary_key=True)
  41. name = db.Column(db.String(80), unique=True, nullable=False, info={"label": "Name"})
  42. description = db.Column(db.String(255), info={"label": "Description"})
  43. __mapper_args__ = {"order_by": name}
  44. class User(db.Model, UserMixin):
  45. id = db.Column(db.Integer, primary_key=True)
  46. email = db.Column(db.String(255), unique=True, nullable=False, info={"label": "Email"})
  47. name = db.Column(db.String(255), unique=True, nullable=False, info={"label": "Username"})
  48. password = db.Column(db.String(255), nullable=False, info={"label": "Password"})
  49. active = db.Column(db.Boolean())
  50. confirmed_at = db.Column(db.DateTime())
  51. display_name = db.Column(db.String(30), nullable=True, info={"label": "Display name"})
  52. locale = db.Column(db.String(5), default="en")
  53. timezone = db.Column(db.String(255), nullable=False, default="UTC") # Managed and fed by pytz
  54. slug = db.Column(db.String(255), unique=True, nullable=True)
  55. roles = db.relationship("Role", secondary=roles_users, backref=db.backref("users", lazy="dynamic"))
  56. apitokens = db.relationship("Apitoken", backref="user", lazy="dynamic", cascade="delete")
  57. user_loggings = db.relationship("UserLogging", backref="user", lazy="dynamic", cascade="delete")
  58. loggings = db.relationship("Logging", backref="user", lazy="dynamic", cascade="delete")
  59. sounds = db.relationship("Sound", backref="user", lazy="dynamic", cascade="delete")
  60. albums = db.relationship("Album", backref="user", lazy="dynamic", cascade="delete")
  61. __mapper_args__ = {"order_by": name}
  62. def join_roles(self, string):
  63. return string.join([i.description for i in self.roles])
  64. @staticmethod
  65. def generate_slug(target, value, oldvalue, initiator):
  66. if value and (not target.slug or value != oldvalue):
  67. target.slug = target.name
  68. @hybrid_property
  69. def name_insensitive(self):
  70. return self.name.lower()
  71. @name_insensitive.comparator
  72. def name_insensitive(cls):
  73. return CaseInsensitiveComparator(cls.name)
  74. def __repr__(self):
  75. return f"<User(id='{self.id}', name='{self.name}')>"
  76. def username(self):
  77. if not self.display_name:
  78. return self.name
  79. elif len(self.display_name) > 0:
  80. return self.display_name
  81. else:
  82. return self.name
  83. event.listen(User.name, "set", User.generate_slug, retval=False)
  84. class Apitoken(db.Model):
  85. id = db.Column(db.Integer, primary_key=True)
  86. user_id = db.Column(db.Integer(), db.ForeignKey("user.id"), nullable=False)
  87. token = db.Column(db.String(255), unique=True, nullable=False, info={"label": "Token"})
  88. secret = db.Column(db.String(255), unique=True, nullable=False, info={"label": "Secret"})
  89. user_datastore = SQLAlchemyUserDatastore(db, User, Role)
  90. # #### Logging ####
  91. class Logging(db.Model):
  92. __tablename__ = "logging"
  93. id = db.Column(db.Integer, primary_key=True)
  94. category = db.Column(db.String(255), nullable=False, default="General")
  95. level = db.Column(db.String(255), nullable=False, default="INFO")
  96. message = db.Column(db.Text, nullable=False)
  97. timestamp = db.Column(
  98. db.DateTime(timezone=False), default=datetime.datetime.utcnow, onupdate=datetime.datetime.utcnow
  99. )
  100. user_id = db.Column(db.Integer(), db.ForeignKey("user.id"), nullable=True)
  101. __mapper_args__ = {"order_by": timestamp.desc()}
  102. class UserLogging(db.Model):
  103. __tablename__ = "user_logging"
  104. id = db.Column(db.Integer, primary_key=True)
  105. category = db.Column(db.String(255), nullable=False, default="General")
  106. level = db.Column(db.String(255), nullable=False, default="INFO")
  107. message = db.Column(db.Text, nullable=False)
  108. timestamp = db.Column(
  109. db.DateTime(timezone=False), default=datetime.datetime.utcnow, onupdate=datetime.datetime.utcnow
  110. )
  111. item_id = db.Column(db.Integer(), nullable=True)
  112. user_id = db.Column(db.Integer(), db.ForeignKey("user.id"), nullable=False)
  113. __mapper_args__ = {"order_by": timestamp.desc()}
  114. # #### Tracks ####
  115. class SoundInfo(db.Model):
  116. __tablename__ = "sound_info"
  117. id = db.Column(db.Integer, primary_key=True)
  118. duration = db.Column(db.Float, nullable=True)
  119. format = db.Column(db.String(255), nullable=True)
  120. rate = db.Column(db.String(255), nullable=True)
  121. channels = db.Column(db.Integer, nullable=True)
  122. codec = db.Column(db.String(255), nullable=True)
  123. waveform = db.Column(db.Text, nullable=True)
  124. waveform_error = db.Column(db.Boolean, default=False)
  125. bitrate = db.Column(db.Integer, nullable=True)
  126. bitrate_mode = db.Column(db.String(10), nullable=True)
  127. type = db.Column(db.String(20), nullable=True)
  128. type_human = db.Column(db.String(20), nullable=True)
  129. # States markers
  130. done_basic = db.Column(db.Boolean, default=False)
  131. done_waveform = db.Column(db.Boolean, default=False)
  132. sound_id = db.Column(db.Integer(), db.ForeignKey("sound.id"), nullable=False)
  133. class Sound(db.Model):
  134. __tablename__ = "sound"
  135. TRANSCODE_WAITING = 0
  136. TRANSCODE_PROCESSING = 1
  137. TRANSCODE_DONE = 2
  138. TRANSCODE_ERROR = 3
  139. id = db.Column(db.Integer, primary_key=True)
  140. title = db.Column(db.String(255), nullable=True)
  141. uploaded = db.Column(db.DateTime(timezone=False), default=datetime.datetime.utcnow)
  142. updated = db.Column(
  143. db.DateTime(timezone=False), default=datetime.datetime.utcnow, onupdate=datetime.datetime.utcnow
  144. )
  145. # TODO genre
  146. # TODO tags
  147. # TODO picture ?
  148. licence = db.Column(db.Integer, nullable=False, server_default="0")
  149. description = db.Column(db.UnicodeText(), nullable=True)
  150. private = db.Column(db.Boolean(), default=False, nullable=True)
  151. slug = db.Column(db.String(255), unique=True, nullable=True)
  152. filename = db.Column(db.String(255), unique=False, nullable=True)
  153. filename_transcoded = db.Column(db.String(255), unique=False, nullable=True)
  154. filename_orig = db.Column(db.String(255), unique=False, nullable=True)
  155. album_order = db.Column(db.Integer, nullable=True)
  156. transcode_needed = db.Column(db.Boolean(), default=False, nullable=True)
  157. transcode_state = db.Column(db.Integer(), default=0, nullable=False)
  158. # 0 nothing / default / waiting, 1 processing, 2 done, 3 error
  159. user_id = db.Column(db.Integer(), db.ForeignKey("user.id"), nullable=False)
  160. album_id = db.Column(db.Integer(), db.ForeignKey("album.id"), nullable=True)
  161. sound_infos = db.relationship("SoundInfo", backref="sound_info", lazy="dynamic", cascade="delete")
  162. timeline = db.relationship("Timeline", uselist=False, back_populates="sound")
  163. __mapper_args__ = {"order_by": uploaded.desc()}
  164. def elapsed(self):
  165. print("db: {0}, now: {1}".format(self.uploaded, datetime.datetime.utcnow()))
  166. el = datetime.datetime.utcnow() - self.uploaded
  167. return el.total_seconds()
  168. def path_waveform(self):
  169. return os.path.join(self.user.slug, "{0}.png".format(self.filename))
  170. def path_sound(self, orig=False):
  171. if self.transcode_needed and self.transcode_state == self.TRANSCODE_DONE and not orig:
  172. return os.path.join(self.user.slug, self.filename_transcoded)
  173. else:
  174. return os.path.join(self.user.slug, self.filename)
  175. def licence_info(self):
  176. return licences[self.licence]
  177. def get_title(self):
  178. if not self.title:
  179. return self.filename
  180. return self.title
  181. def processing_done(self):
  182. return self.transcode_state == self.TRANSCODE_DONE
  183. class Album(db.Model):
  184. __tablename__ = "album"
  185. id = db.Column(db.Integer, primary_key=True)
  186. title = db.Column(db.String(255), nullable=True)
  187. created = db.Column(db.DateTime(timezone=False), default=datetime.datetime.utcnow)
  188. updated = db.Column(
  189. db.DateTime(timezone=False), default=datetime.datetime.utcnow, onupdate=datetime.datetime.utcnow
  190. )
  191. # TODO tags
  192. description = db.Column(db.UnicodeText(), nullable=True)
  193. private = db.Column(db.Boolean(), default=False, nullable=True)
  194. slug = db.Column(db.String(255), unique=True, nullable=True)
  195. user_id = db.Column(db.Integer(), db.ForeignKey("user.id"), nullable=False)
  196. sounds = db.relationship("Sound", backref="album", lazy="dynamic")
  197. timeline = db.relationship("Timeline", uselist=False, back_populates="album")
  198. __mapper_args__ = {"order_by": created.desc()}
  199. def elapsed(self):
  200. el = datetime.datetime.utcnow() - self.created
  201. return el.total_seconds()
  202. class Timeline(db.Model):
  203. __tablename__ = "timeline"
  204. id = db.Column(db.Integer, primary_key=True)
  205. timestamp = db.Column(db.DateTime(timezone=False), default=datetime.datetime.utcnow)
  206. private = db.Column(db.Boolean, default=False)
  207. sound_id = db.Column(db.Integer(), db.ForeignKey("user.id"), nullable=False)
  208. album_id = db.Column(db.Integer(), db.ForeignKey("album.id"), nullable=False)
  209. user_id = db.Column(db.Integer(), db.ForeignKey("sound.id"), nullable=False)
  210. album = db.relationship("Album", back_populates="timeline")
  211. sound = db.relationship("Sound", back_populates="timeline")
  212. __mapper_args__ = {"order_by": timestamp.desc()}
  213. licences = {
  214. 0: {"name": "Not Specified", "id": 0, "link": "", "icon": ""},
  215. 1: {
  216. "name": "CC Attribution",
  217. "id": 1,
  218. "link": "https://creativecommons.org/licenses/by/4.0/",
  219. "icon": "creative-commons",
  220. },
  221. 2: {
  222. "name": "CC Attribution Share Alike",
  223. "id": 2,
  224. "link": "https://creativecommons.org/licenses/by-sa/4.0",
  225. "icon": "creative-commons",
  226. },
  227. 3: {
  228. "name": "CC Attribution No Derivatives",
  229. "id": 3,
  230. "link": "https://creativecommons.org/licenses/by-nd/4.0",
  231. "icon": "creative-commons",
  232. },
  233. 4: {
  234. "name": "CC Attribution Non Commercial",
  235. "id": 4,
  236. "link": "https://creativecommons.org/licenses/by-nc/4.0",
  237. "icon": "creative-commons",
  238. },
  239. 5: {
  240. "name": "CC Attribution Non Commercial - Share Alike",
  241. "id": 5,
  242. "link": "https://creativecommons.org/licenses/by-nc-sa/4.0",
  243. "icon": "creative-commons",
  244. },
  245. 6: {
  246. "name": "CC Attribution Non Commercial - No Derivatives",
  247. "id": 6,
  248. "link": "https://creativecommons.org/licenses/by-nc-nd/4.0",
  249. "icon": "creative-commons",
  250. },
  251. 7: {"name": "Public Domain Dedication", "id": 7, "link": "", "icon": ""},
  252. }
  253. @event.listens_for(Sound, "after_update")
  254. @event.listens_for(Sound, "after_insert")
  255. def make_sound_slug(mapper, connection, target):
  256. if not target.title or target.title == "":
  257. title = "{0} {1}".format(target.id, target.filename_orig)
  258. else:
  259. if slugify(target.title) == "":
  260. title = "{0} {1}".format(target.id, target.filename_orig)
  261. else:
  262. title = "{0} {1}".format(target.id, target.title)
  263. slug = slugify(title[:255])
  264. connection.execute(Sound.__table__.update().where(Sound.__table__.c.id == target.id).values(slug=slug))
  265. @event.listens_for(Album, "after_update")
  266. @event.listens_for(Album, "after_insert")
  267. def make_album_slug(mapper, connection, target):
  268. title = "{0} {1}".format(target.id, target.title)
  269. slug = slugify(title[:255])
  270. connection.execute(Album.__table__.update().where(Album.__table__.c.id == target.id).values(slug=slug))
  271. @event.listens_for(User, "after_update")
  272. def update_user_actor(mapper, connection, target):
  273. connection.execute(
  274. Actor.__table__.update().where(Actor.__table__.c.user_id == target.id).values(name=target.display_name)
  275. )
  276. # #### Federation ####
  277. ACTOR_TYPE_CHOICES = [
  278. ("Person", "Person"),
  279. ("Application", "Application"),
  280. ("Group", "Group"),
  281. ("Organization", "Organization"),
  282. ("Service", "Service"),
  283. ]
  284. # This table keeps followings in every way
  285. # (remote to local, local to local, to remote...)
  286. # Query this table directly to get list for a specific actor or target
  287. class Follower(db.Model):
  288. __tablename__ = "followers"
  289. id = db.Column(db.Integer, primary_key=True)
  290. uuid = db.Column(UUID(as_uuid=True), server_default=sa_text("uuid_generate_v4()"), unique=True)
  291. actor_id = db.Column(db.Integer, db.ForeignKey("actor.id"))
  292. target_id = db.Column(db.Integer, db.ForeignKey("actor.id"))
  293. activity_url = db.Column(URLType(), unique=True, nullable=True)
  294. creation_date = db.Column(db.DateTime(timezone=False), default=datetime.datetime.utcnow)
  295. modification_date = db.Column(db.DateTime(timezone=False), onupdate=datetime.datetime.now)
  296. actor = db.relationship("Actor", foreign_keys=[actor_id])
  297. target = db.relationship("Actor", foreign_keys=[target_id])
  298. __table_args__ = (UniqueConstraint("actor_id", "target_id", name="unique_following"),)
  299. def __repr__(self):
  300. return f"<Follower(id='{self.id}', actor_id='{self.actor_id}', target_id='{self.target_id}')>"
  301. class Actor(db.Model):
  302. __tablename__ = "actor"
  303. ap_type = "Actor"
  304. id = db.Column(db.Integer, primary_key=True)
  305. url = db.Column(URLType(), unique=True, index=True)
  306. outbox_url = db.Column(URLType())
  307. inbox_url = db.Column(URLType())
  308. following_url = db.Column(URLType(), nullable=True)
  309. followers_url = db.Column(URLType(), nullable=True)
  310. shared_inbox_url = db.Column(URLType(), nullable=True)
  311. type = db.Column(ChoiceType(ACTOR_TYPE_CHOICES), server_default="Person")
  312. name = db.Column(db.String(200), nullable=True)
  313. domain = db.Column(db.String(1000), nullable=False)
  314. summary = db.Column(db.String(500), nullable=True)
  315. preferred_username = db.Column(db.String(200), nullable=True)
  316. public_key = db.Column(db.String(5000), nullable=True)
  317. private_key = db.Column(db.String(5000), nullable=True)
  318. creation_date = db.Column(db.DateTime(timezone=False), default=datetime.datetime.utcnow)
  319. last_fetch_date = db.Column(db.DateTime(timezone=False), default=datetime.datetime.utcnow)
  320. manually_approves_followers = db.Column(db.Boolean, nullable=True, server_default=None)
  321. # Who follows self
  322. followers = db.relationship("Follower", backref="followers", primaryjoin=id == Follower.target_id)
  323. # Who self follows
  324. followings = db.relationship("Follower", backref="followings", primaryjoin=id == Follower.actor_id)
  325. # Relation on itself, intermediary with actor and target
  326. # By using an Association Object, which isn't possible except by using
  327. # two relations. This may be better than only one, and some hackish things
  328. # by querying directly the old db.Table definition
  329. user_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=True)
  330. user = db.relationship("User", backref=db.backref("actor"))
  331. __table_args__ = (UniqueConstraint("domain", "preferred_username", name="_domain_pref_username_uc"),)
  332. def __repr__(self):
  333. return f"<Actor(id='{self.id}', user_id='{self.user_id}', preferredUsername='{self.preferred_username}', domain='{self.domain}')>"
  334. def webfinger_subject(self):
  335. return f"{self.preferred_username}@{self.domain}"
  336. def private_key_id(self):
  337. return f"{self.url}#main-key"
  338. def mention_username(self):
  339. return f"@{self.preferred_username}@{self.domain}"
  340. def is_local(self):
  341. return self.domain == current_app.config["AP_DOMAIN"]
  342. def follow(self, activity_url, target):
  343. current_app.logger.debug(f"saving: {self.id} following {target.id}")
  344. rel = Follower.query.filter(Follower.actor_id == self.id, Follower.target_id == target.id).first()
  345. if not rel:
  346. rel = Follower()
  347. rel.actor_id = self.id
  348. rel.target_id = target.id
  349. rel.activity_url = activity_url
  350. db.session.add(rel)
  351. db.session.commit()
  352. def unfollow(self, target):
  353. current_app.logger.debug(f"saving: {self.id} unfollowing {target.id}")
  354. rel = Follower.query.filter(Follower.actor_id == self.id, Follower.target_id == target.id).first()
  355. if rel:
  356. db.session.delete(rel)
  357. db.session.commit()
  358. def to_dict(self):
  359. return {
  360. "@context": ["https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1"],
  361. "id": self.url,
  362. "type": self.type.code,
  363. "preferredUsername": self.preferred_username,
  364. "name": self.name,
  365. "inbox": self.inbox_url,
  366. "outbox": self.outbox_url,
  367. "manuallyApprovesFollowers": self.manually_approves_followers,
  368. "publicKey": {"id": self.private_key_id(), "owner": self.url, "publicKeyPem": self.public_key},
  369. "endpoints": {"sharedInbox": self.shared_inbox_url},
  370. }
  371. class Activity(db.Model):
  372. __tablename__ = "activity"
  373. id = db.Column(db.Integer, primary_key=True)
  374. actor = db.Column(db.Integer, db.ForeignKey("actor.id"))
  375. uuid = db.Column(UUID(as_uuid=True), server_default=sa_text("uuid_generate_v4()"), unique=True)
  376. url = db.Column(URLType(), unique=True, nullable=True)
  377. type = db.Column(db.String(100), index=True)
  378. box = db.Column(db.String(100))
  379. payload = db.Column(JSONType())
  380. creation_date = db.Column(db.DateTime(timezone=False), default=datetime.datetime.utcnow)
  381. delivered = db.Column(db.Boolean, default=None, nullable=True)
  382. delivered_date = db.Column(db.DateTime(timezone=False), nullable=True)
  383. local = db.Column(db.Boolean, default=True)
  384. def create_actor(user):
  385. """
  386. :param user: an User object
  387. :return: an Actor object
  388. """
  389. actor = Actor()
  390. # Init a new Keypair for this user
  391. key = LittleBoxesKey(owner=user.name)
  392. key.new()
  393. actor.preferred_username = user.name
  394. actor.domain = current_app.config["AP_DOMAIN"]
  395. actor.type = "Person"
  396. actor.name = user.display_name
  397. actor.manually_approves_followers = False
  398. actor.url = ap_url("url", user.name)
  399. actor.shared_inbox_url = ap_url("shared_inbox", user.name)
  400. actor.inbox_url = ap_url("inbox", user.name)
  401. actor.outbox_url = ap_url("outbox", user.name)
  402. actor.private_key = key.privkey_pem
  403. actor.public_key = key.pubkey_pem
  404. return actor
  405. def create_remote_actor(activity_actor: ap.BaseActivity):
  406. """
  407. :param activity_actor: a Little Boxes Actor object
  408. :return: an Actor object
  409. """
  410. actor = Actor()
  411. actor.preferred_username = activity_actor.preferredUsername
  412. domain = urlparse(activity_actor.url)
  413. actor.domain = domain.netloc
  414. actor.type = "Person"
  415. # FIXME: test for .name, it won't exist if not set (at least for mastodon)
  416. actor.name = activity_actor.preferredUsername # mastodon don't have .name
  417. actor.manually_approves_followers = False
  418. actor.url = activity_actor.id # FIXME: or .id ??? [cf backend.py:52-53]
  419. actor.shared_inbox_url = activity_actor._data.get("endpoints", {}).get("sharedInbox")
  420. actor.inbox_url = activity_actor.inbox
  421. actor.outbox_url = activity_actor.outbot
  422. actor.public_key = activity_actor.get_key().pubkey_pem
  423. actor.summary = activity_actor.summary
  424. return actor
  425. def update_remote_actor(actor_id: int, activity_actor: ap.BaseActivity) -> None:
  426. """
  427. :param actor_id: an Actor db ID
  428. :param activity_actor: a Little Boxes Actor object
  429. :return: nothing
  430. """
  431. actor = Actor.query.filter(Actor.id == actor_id).first()
  432. current_app.logger.debug(f"asked to update Actor {actor_id}: {activity_actor!r}")
  433. actor.preferred_username = activity_actor.preferredUsername
  434. domain = urlparse(activity_actor.url)
  435. actor.domain = domain.netloc
  436. actor.name = activity_actor.name
  437. actor.manually_approves_followers = False
  438. actor.url = activity_actor.id # FIXME: or .id ??? [cf backend.py:52-53]
  439. actor.shared_inbox_url = activity_actor._data.get("endpoints", {}).get("sharedInbox")
  440. actor.inbox_url = activity_actor.inbox
  441. actor.outbox_url = activity_actor.outbot
  442. actor.public_key = activity_actor.get_key().pubkey_pem
  443. actor.summary = activity_actor.summary
  444. db.session.commit()