@evanp/activitypub-bot 0.13.9 → 0.13.11

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.
@@ -50,6 +50,13 @@ export class ActivityDeliverer {
50
50
  }
51
51
 
52
52
  async deliverTo (activity, bot) {
53
+ if (await this.#actorStorage.isInCollection(bot.username, 'inbox', activity)) {
54
+ this.#logger.info(
55
+ { activity: activity.id, username: bot.username },
56
+ 'skipping redelivery for activity already in the inbox'
57
+ )
58
+ return
59
+ }
53
60
  try {
54
61
  await this.#activityHandler.handleActivity(bot, activity)
55
62
  } catch (err) {
package/lib/keystorage.js CHANGED
@@ -50,7 +50,8 @@ export class KeyStorage {
50
50
  'found key for bot in database')
51
51
  publicKey = result[0].public_key
52
52
  privateKey = result[0].private_key
53
- } else {
53
+ }
54
+ if (!publicKey || !privateKey) {
54
55
  this.#logger.debug(
55
56
  { username, method: 'KeyStorage.#getKeys' },
56
57
  'no key for bot, generating new key'
@@ -62,11 +63,13 @@ export class KeyStorage {
62
63
  )
63
64
  await this.#saveKeyPair(username, publicKey, privateKey)
64
65
  }
66
+ const publicKeyHash = publicKey ? this.#hasher.humanize(publicKey) : null
67
+ const privateKeyHash = privateKey ? this.#hasher.humanize(privateKey) : null
65
68
  this.#logger.debug({
66
69
  username,
67
70
  method: 'KeyStorage.#getKeys',
68
- publicKeyHash: this.#hasher.humanize(publicKey),
69
- privateKeyHash: this.#hasher.humanize(privateKey)
71
+ publicKeyHash,
72
+ privateKeyHash
70
73
  })
71
74
  return [publicKey, privateKey]
72
75
  }
@@ -91,7 +94,11 @@ export class KeyStorage {
91
94
 
92
95
  async #saveKeyPair (username, publicKey, privateKey) {
93
96
  await this.#connection.query(`
94
- INSERT INTO new_keys (username, public_key, private_key) VALUES (?, ?, ?)
97
+ INSERT INTO new_keys (username, public_key, private_key)
98
+ VALUES (?, ?, ?)
99
+ ON CONFLICT(username) DO UPDATE SET
100
+ public_key = excluded.public_key,
101
+ private_key = excluded.private_key
95
102
  `, { replacements: [username, publicKey, privateKey] })
96
103
  }
97
104
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evanp/activitypub-bot",
3
- "version": "0.13.9",
3
+ "version": "0.13.11",
4
4
  "description": "server-side ActivityPub bot framework",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",