@evanp/activitypub-bot 0.14.0 → 0.14.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -479,13 +479,17 @@ export class ActivityHandler {
479
479
  await this.#objectStorage.addToCollection(object.id, 'likers', actor)
480
480
  const recipients = this.#getRecipients(object)
481
481
  this.#addRecipient(recipients, actor, 'to')
482
+ const parts = this.#formatter.unformat(object.id)
483
+ const likesCollectionId = this.#formatter.format({
484
+ username: parts.username,
485
+ type: parts.type,
486
+ nanoid: parts.nanoid,
487
+ collection: 'likes'
488
+ })
482
489
  await this.#doActivity(bot, {
483
490
  type: 'Add',
484
491
  object: activity,
485
- target: this.#formatter.format({
486
- username: bot.username,
487
- collection: 'likes'
488
- }),
492
+ target: likesCollectionId,
489
493
  ...recipients
490
494
  })
491
495
  await bot.onLike(object, activity)
@@ -550,13 +554,17 @@ export class ActivityHandler {
550
554
  await this.#objectStorage.addToCollection(object.id, 'sharers', actor)
551
555
  const recipients = this.#getRecipients(object)
552
556
  this.#addRecipient(recipients, actor, 'to')
557
+ const parts = this.#formatter.unformat(object.id)
558
+ const sharesCollectionId = this.#formatter.format({
559
+ username: parts.username,
560
+ type: parts.type,
561
+ nanoid: parts.nanoid,
562
+ collection: 'shares'
563
+ })
553
564
  await this.#doActivity(bot, {
554
565
  type: 'Add',
555
566
  object: activity,
556
- target: this.#formatter.format({
557
- username: bot.username,
558
- collection: 'shares'
559
- }),
567
+ target: sharesCollectionId,
560
568
  ...recipients
561
569
  })
562
570
  try {
@@ -840,7 +848,11 @@ export class ActivityHandler {
840
848
  const activity = await as2.import({
841
849
  ...activityData,
842
850
  id: this.#formatActivityId(bot, activityData.type),
843
- actor: await this.#botActor(bot),
851
+ actor: {
852
+ id: this.#botId(bot),
853
+ name: bot.fullname,
854
+ type: 'Service'
855
+ },
844
856
  published: now,
845
857
  updated: now
846
858
  })
@@ -948,7 +960,9 @@ export class ActivityHandler {
948
960
 
949
961
  async #botActor (bot) {
950
962
  return await as2.import({
951
- id: this.#formatter.format({ username: bot.username })
963
+ id: this.#formatter.format({ username: bot.username }),
964
+ name: bot.fullname,
965
+ type: 'Service'
952
966
  })
953
967
  }
954
968
 
package/lib/authorizer.js CHANGED
@@ -92,11 +92,11 @@ export class Authorizer {
92
92
  }
93
93
 
94
94
  async #getOwner (object) {
95
- if (object.attributedTo) {
95
+ if (object.attributedTo && object.attributedTo.first) {
96
96
  return object.attributedTo.first
97
- } else if (object.actor) {
97
+ } else if (object.actor && object.actor.first) {
98
98
  return object.actor.first
99
- } else if (object.owner) {
99
+ } else if (object.owner && object.owner.first) {
100
100
  return object.owner.first
101
101
  } else if (this.#formatter.isLocal(object.id)) {
102
102
  const parts = this.#formatter.unformat(object.id)
@@ -85,7 +85,17 @@ function collectionPageHandler (collection) {
85
85
  return false
86
86
  }
87
87
  req.log.debug({ id, object }, 'loaded object')
88
- return await authorizer.canRead(remote, object)
88
+ let result = false
89
+ try {
90
+ result = await authorizer.canRead(remote, object)
91
+ } catch (err) {
92
+ req.log.debug(
93
+ { err, remote: remote.id, object: object.id },
94
+ `Error checking read access`
95
+ )
96
+ result = false
97
+ }
98
+ return result
89
99
  })
90
100
  }
91
101
  } catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evanp/activitypub-bot",
3
- "version": "0.14.0",
3
+ "version": "0.14.2",
4
4
  "description": "server-side ActivityPub bot framework",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",