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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  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 = value
  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. fname, _ = os.path.splitext(self.filename)
  170. return os.path.join(self.user.slug, "{0}.png".format(fname))
  171. def path_sound(self, orig=False):
  172. if self.transcode_needed and self.transcode_state == self.TRANSCODE_DONE and not orig:
  173. return os.path.join(self.user.slug, self.filename_transcoded)
  174. else:
  175. return os.path.join(self.user.slug, self.filename)
  176. def licence_info(self):
  177. return licences[self.licence]
  178. def get_title(self):
  179. if not self.title:
  180. return self.filename
  181. return self.title
  182. def processing_done(self):
  183. return self.transcode_state == self.TRANSCODE_DONE
  184. def is_ready(self):
  185. infos = self.sound_infos.first()
  186. if not infos:
  187. return False
  188. return self.processing_done() and infos.done_basic
  189. class Album(db.Model):
  190. __tablename__ = "album"
  191. id = db.Column(db.Integer, primary_key=True)
  192. title = db.Column(db.String(255), nullable=True)
  193. created = db.Column(db.DateTime(timezone=False), default=datetime.datetime.utcnow)
  194. updated = db.Column(
  195. db.DateTime(timezone=False), default=datetime.datetime.utcnow, onupdate=datetime.datetime.utcnow
  196. )
  197. # TODO tags
  198. description = db.Column(db.UnicodeText(), nullable=True)
  199. private = db.Column(db.Boolean(), default=False, nullable=True)
  200. slug = db.Column(db.String(255), unique=True, nullable=True)
  201. user_id = db.Column(db.Integer(), db.ForeignKey("user.id"), nullable=False)
  202. sounds = db.relationship("Sound", backref="album", lazy="dynamic")
  203. timeline = db.relationship("Timeline", uselist=False, back_populates="album")
  204. __mapper_args__ = {"order_by": created.desc()}
  205. def elapsed(self):
  206. el = datetime.datetime.utcnow() - self.created
  207. return el.total_seconds()
  208. class Timeline(db.Model):
  209. __tablename__ = "timeline"
  210. id = db.Column(db.Integer, primary_key=True)
  211. timestamp = db.Column(db.DateTime(timezone=False), default=datetime.datetime.utcnow)
  212. private = db.Column(db.Boolean, default=False)
  213. sound_id = db.Column(db.Integer(), db.ForeignKey("user.id"), nullable=False)
  214. album_id = db.Column(db.Integer(), db.ForeignKey("album.id"), nullable=False)
  215. user_id = db.Column(db.Integer(), db.ForeignKey("sound.id"), nullable=False)
  216. album = db.relationship("Album", back_populates="timeline")
  217. sound = db.relationship("Sound", back_populates="timeline")
  218. __mapper_args__ = {"order_by": timestamp.desc()}
  219. licences = {
  220. 0: {"name": "Not Specified", "id": 0, "link": "", "icon": ""},
  221. 1: {
  222. "name": "CC Attribution",
  223. "id": 1,
  224. "link": "https://creativecommons.org/licenses/by/4.0/",
  225. "icon": "creative-commons",
  226. },
  227. 2: {
  228. "name": "CC Attribution Share Alike",
  229. "id": 2,
  230. "link": "https://creativecommons.org/licenses/by-sa/4.0",
  231. "icon": "creative-commons",
  232. },
  233. 3: {
  234. "name": "CC Attribution No Derivatives",
  235. "id": 3,
  236. "link": "https://creativecommons.org/licenses/by-nd/4.0",
  237. "icon": "creative-commons",
  238. },
  239. 4: {
  240. "name": "CC Attribution Non Commercial",
  241. "id": 4,
  242. "link": "https://creativecommons.org/licenses/by-nc/4.0",
  243. "icon": "creative-commons",
  244. },
  245. 5: {
  246. "name": "CC Attribution Non Commercial - Share Alike",
  247. "id": 5,
  248. "link": "https://creativecommons.org/licenses/by-nc-sa/4.0",
  249. "icon": "creative-commons",
  250. },
  251. 6: {
  252. "name": "CC Attribution Non Commercial - No Derivatives",
  253. "id": 6,
  254. "link": "https://creativecommons.org/licenses/by-nc-nd/4.0",
  255. "icon": "creative-commons",
  256. },
  257. 7: {"name": "Public Domain Dedication", "id": 7, "link": "", "icon": ""},
  258. }
  259. @event.listens_for(Sound, "after_update")
  260. @event.listens_for(Sound, "after_insert")
  261. def make_sound_slug(mapper, connection, target):
  262. if not target.title or target.title == "":
  263. title = "{0} {1}".format(target.id, target.filename_orig)
  264. else:
  265. if slugify(target.title) == "":
  266. title = "{0} {1}".format(target.id, target.filename_orig)
  267. else:
  268. title = "{0} {1}".format(target.id, target.title)
  269. slug = slugify(title[:255])
  270. connection.execute(Sound.__table__.update().where(Sound.__table__.c.id == target.id).values(slug=slug))
  271. @event.listens_for(Album, "after_update")
  272. @event.listens_for(Album, "after_insert")
  273. def make_album_slug(mapper, connection, target):
  274. title = "{0} {1}".format(target.id, target.title)
  275. slug = slugify(title[:255])
  276. connection.execute(Album.__table__.update().where(Album.__table__.c.id == target.id).values(slug=slug))
  277. @event.listens_for(User, "after_update")
  278. def update_user_actor(mapper, connection, target):
  279. connection.execute(
  280. Actor.__table__.update().where(Actor.__table__.c.user_id == target.id).values(name=target.display_name)
  281. )
  282. # #### Federation ####
  283. ACTOR_TYPE_CHOICES = [
  284. ("Person", "Person"),
  285. ("Application", "Application"),
  286. ("Group", "Group"),
  287. ("Organization", "Organization"),
  288. ("Service", "Service"),
  289. ]
  290. # This table keeps followings in every way
  291. # (remote to local, local to local, to remote...)
  292. # Query this table directly to get list for a specific actor or target
  293. class Follower(db.Model):
  294. __tablename__ = "followers"
  295. id = db.Column(db.Integer, primary_key=True)
  296. uuid = db.Column(UUID(as_uuid=True), server_default=sa_text("uuid_generate_v4()"), unique=True)
  297. actor_id = db.Column(db.Integer, db.ForeignKey("actor.id"))
  298. target_id = db.Column(db.Integer, db.ForeignKey("actor.id"))
  299. activity_url = db.Column(URLType(), unique=True, nullable=True)
  300. creation_date = db.Column(db.DateTime(timezone=False), default=datetime.datetime.utcnow)
  301. modification_date = db.Column(db.DateTime(timezone=False), onupdate=datetime.datetime.now)
  302. actor = db.relationship("Actor", foreign_keys=[actor_id])
  303. target = db.relationship("Actor", foreign_keys=[target_id])
  304. __table_args__ = (UniqueConstraint("actor_id", "target_id", name="unique_following"),)
  305. def __repr__(self):
  306. return f"<Follower(id='{self.id}', actor_id='{self.actor_id}', target_id='{self.target_id}')>"
  307. class Actor(db.Model):
  308. __tablename__ = "actor"
  309. ap_type = "Actor"
  310. id = db.Column(db.Integer, primary_key=True)
  311. url = db.Column(URLType(), unique=True, index=True)
  312. outbox_url = db.Column(URLType())
  313. inbox_url = db.Column(URLType())
  314. following_url = db.Column(URLType(), nullable=True)
  315. followers_url = db.Column(URLType(), nullable=True)
  316. shared_inbox_url = db.Column(URLType(), nullable=True)
  317. type = db.Column(ChoiceType(ACTOR_TYPE_CHOICES), server_default="Person")
  318. name = db.Column(db.String(200), nullable=True)
  319. domain = db.Column(db.String(1000), nullable=False)
  320. summary = db.Column(db.String(500), nullable=True)
  321. preferred_username = db.Column(db.String(200), nullable=True)
  322. public_key = db.Column(db.String(5000), nullable=True)
  323. private_key = db.Column(db.String(5000), nullable=True)
  324. creation_date = db.Column(db.DateTime(timezone=False), default=datetime.datetime.utcnow)
  325. last_fetch_date = db.Column(db.DateTime(timezone=False), default=datetime.datetime.utcnow)
  326. manually_approves_followers = db.Column(db.Boolean, nullable=True, server_default=None)
  327. # Who follows self
  328. followers = db.relationship("Follower", backref="followers", primaryjoin=id == Follower.target_id)
  329. # Who self follows
  330. followings = db.relationship("Follower", backref="followings", primaryjoin=id == Follower.actor_id)
  331. # Relation on itself, intermediary with actor and target
  332. # By using an Association Object, which isn't possible except by using
  333. # two relations. This may be better than only one, and some hackish things
  334. # by querying directly the old db.Table definition
  335. user_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=True)
  336. user = db.relationship("User", backref=db.backref("actor"))
  337. __table_args__ = (UniqueConstraint("domain", "preferred_username", name="_domain_pref_username_uc"),)
  338. def __repr__(self):
  339. return f"<Actor(id='{self.id}', user_id='{self.user_id}', preferredUsername='{self.preferred_username}', domain='{self.domain}')>"
  340. def webfinger_subject(self):
  341. return f"{self.preferred_username}@{self.domain}"
  342. def private_key_id(self):
  343. return f"{self.url}#main-key"
  344. def mention_username(self):
  345. return f"@{self.preferred_username}@{self.domain}"
  346. def is_local(self):
  347. return self.domain == current_app.config["AP_DOMAIN"]
  348. def follow(self, activity_url, target):
  349. current_app.logger.debug(f"saving: {self.id} following {target.id}")
  350. rel = Follower.query.filter(Follower.actor_id == self.id, Follower.target_id == target.id).first()
  351. if not rel:
  352. rel = Follower()
  353. rel.actor_id = self.id
  354. rel.target_id = target.id
  355. rel.activity_url = activity_url
  356. db.session.add(rel)
  357. db.session.commit()
  358. def unfollow(self, target):
  359. current_app.logger.debug(f"saving: {self.id} unfollowing {target.id}")
  360. rel = Follower.query.filter(Follower.actor_id == self.id, Follower.target_id == target.id).first()
  361. if rel:
  362. db.session.delete(rel)
  363. db.session.commit()
  364. def to_dict(self):
  365. return {
  366. "@context": ["https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1"],
  367. "id": self.url,
  368. "type": self.type.code,
  369. "preferredUsername": self.preferred_username,
  370. "name": self.name,
  371. "inbox": self.inbox_url,
  372. "outbox": self.outbox_url,
  373. "manuallyApprovesFollowers": self.manually_approves_followers,
  374. "publicKey": {"id": self.private_key_id(), "owner": self.url, "publicKeyPem": self.public_key},
  375. "endpoints": {"sharedInbox": self.shared_inbox_url},
  376. }
  377. class Activity(db.Model):
  378. __tablename__ = "activity"
  379. id = db.Column(db.Integer, primary_key=True)
  380. actor = db.Column(db.Integer, db.ForeignKey("actor.id"))
  381. uuid = db.Column(UUID(as_uuid=True), server_default=sa_text("uuid_generate_v4()"), unique=True)
  382. url = db.Column(URLType(), unique=True, nullable=True)
  383. type = db.Column(db.String(100), index=True)
  384. box = db.Column(db.String(100))
  385. payload = db.Column(JSONType())
  386. creation_date = db.Column(db.DateTime(timezone=False), default=datetime.datetime.utcnow)
  387. delivered = db.Column(db.Boolean, default=None, nullable=True)
  388. delivered_date = db.Column(db.DateTime(timezone=False), nullable=True)
  389. local = db.Column(db.Boolean, default=True)
  390. def create_actor(user):
  391. """
  392. :param user: an User object
  393. :return: an Actor object
  394. """
  395. actor = Actor()
  396. # Init a new Keypair for this user
  397. key = LittleBoxesKey(owner=user.name)
  398. key.new()
  399. actor.preferred_username = user.name
  400. actor.domain = current_app.config["AP_DOMAIN"]
  401. actor.type = "Person"
  402. actor.name = user.display_name
  403. actor.manually_approves_followers = False
  404. actor.url = ap_url("url", user.name)
  405. actor.shared_inbox_url = ap_url("shared_inbox", user.name)
  406. actor.inbox_url = ap_url("inbox", user.name)
  407. actor.outbox_url = ap_url("outbox", user.name)
  408. actor.private_key = key.privkey_pem
  409. actor.public_key = key.pubkey_pem
  410. return actor
  411. def create_remote_actor(activity_actor: ap.BaseActivity):
  412. """
  413. :param activity_actor: a Little Boxes Actor object
  414. :return: an Actor object
  415. """
  416. actor = Actor()
  417. actor.preferred_username = activity_actor.preferredUsername
  418. domain = urlparse(activity_actor.url)
  419. actor.domain = domain.netloc
  420. actor.type = "Person"
  421. # FIXME: test for .name, it won't exist if not set (at least for mastodon)
  422. actor.name = activity_actor.preferredUsername # mastodon don't have .name
  423. actor.manually_approves_followers = False
  424. actor.url = activity_actor.id # FIXME: or .id ??? [cf backend.py:52-53]
  425. actor.shared_inbox_url = activity_actor._data.get("endpoints", {}).get("sharedInbox")
  426. actor.inbox_url = activity_actor.inbox
  427. actor.outbox_url = activity_actor.outbot
  428. actor.public_key = activity_actor.get_key().pubkey_pem
  429. actor.summary = activity_actor.summary
  430. return actor
  431. def update_remote_actor(actor_id: int, activity_actor: ap.BaseActivity) -> None:
  432. """
  433. :param actor_id: an Actor db ID
  434. :param activity_actor: a Little Boxes Actor object
  435. :return: nothing
  436. """
  437. actor = Actor.query.filter(Actor.id == actor_id).first()
  438. current_app.logger.debug(f"asked to update Actor {actor_id}: {activity_actor!r}")
  439. actor.preferred_username = activity_actor.preferredUsername
  440. domain = urlparse(activity_actor.url)
  441. actor.domain = domain.netloc
  442. actor.name = activity_actor.name
  443. actor.manually_approves_followers = False
  444. actor.url = activity_actor.id # FIXME: or .id ??? [cf backend.py:52-53]
  445. actor.shared_inbox_url = activity_actor._data.get("endpoints", {}).get("sharedInbox")
  446. actor.inbox_url = activity_actor.inbox
  447. actor.outbox_url = activity_actor.outbot
  448. actor.public_key = activity_actor.get_key().pubkey_pem
  449. actor.summary = activity_actor.summary
  450. db.session.commit()