@evanp/activitypub-bot 0.21.2 → 0.22.0
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.
- package/bin/activitypub-bot.js +3 -1
- package/lib/app.js +11 -3
- package/lib/jobreaper.js +2 -2
- package/lib/routes/server.js +27 -15
- package/package.json +1 -1
- package/web/index.html +17 -0
package/bin/activitypub-bot.js
CHANGED
|
@@ -53,7 +53,9 @@ const LOG_LEVEL =
|
|
|
53
53
|
|
|
54
54
|
const bots = (await import(BOTS_CONFIG_FILE)).default
|
|
55
55
|
|
|
56
|
-
const app = await makeApp(
|
|
56
|
+
const app = await makeApp({
|
|
57
|
+
databaseUrl: DATABASE_URL, origin: ORIGIN, bots, logLevel: LOG_LEVEL
|
|
58
|
+
})
|
|
57
59
|
|
|
58
60
|
const server = app.listen(parseInt(PORT), () => {
|
|
59
61
|
app.locals.logger.info(`Listening on port ${PORT}`)
|
package/lib/app.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
import http from 'node:http'
|
|
2
|
+
import { resolve, dirname } from 'node:path'
|
|
3
|
+
import { fileURLToPath } from 'node:url'
|
|
4
|
+
|
|
1
5
|
import { Sequelize } from 'sequelize'
|
|
2
6
|
import express from 'express'
|
|
3
7
|
import Logger from 'pino'
|
|
4
8
|
import HTTPLogger from 'pino-http'
|
|
5
|
-
|
|
9
|
+
|
|
6
10
|
import { ActivityDistributor } from './activitydistributor.js'
|
|
7
11
|
import { ActivityPubClient } from './activitypubclient.js'
|
|
8
12
|
import { ActorStorage } from './actorstorage.js'
|
|
@@ -34,7 +38,10 @@ import { JobReaper } from './jobreaper.js'
|
|
|
34
38
|
import { DeliveryWorker } from './deliveryworker.js'
|
|
35
39
|
import { DistributionWorker } from './distributionworker.js'
|
|
36
40
|
|
|
37
|
-
|
|
41
|
+
const currentDir = dirname(fileURLToPath(import.meta.url))
|
|
42
|
+
const DEFAULT_INDEX_FILENAME = resolve(currentDir, '..', 'web', 'index.html')
|
|
43
|
+
|
|
44
|
+
export async function makeApp ({ databaseUrl, origin, bots, logLevel = 'silent', deliveryWorkerCount = 2, distributionWorkerCount = 8, indexFileName = DEFAULT_INDEX_FILENAME }) {
|
|
38
45
|
const logger = Logger({
|
|
39
46
|
level: logLevel
|
|
40
47
|
})
|
|
@@ -159,7 +166,8 @@ export async function makeApp (databaseUrl, origin, bots, logLevel = 'silent', d
|
|
|
159
166
|
activityHandler,
|
|
160
167
|
origin,
|
|
161
168
|
deliverer,
|
|
162
|
-
deliveryWorkers
|
|
169
|
+
deliveryWorkers,
|
|
170
|
+
indexFileName
|
|
163
171
|
}
|
|
164
172
|
|
|
165
173
|
app.use(HTTPLogger({
|
package/lib/jobreaper.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { setTimeout as sleep } from 'node:timers/promises'
|
|
2
2
|
|
|
3
|
-
const DEFAULT_TIMEOUT = 5 * 60 * 1000
|
|
4
|
-
const DEFAULT_INTERVAL = 60 * 1000
|
|
3
|
+
const DEFAULT_TIMEOUT = 5 * 60 * 1000 // 5 minutes
|
|
4
|
+
const DEFAULT_INTERVAL = 60 * 1000 // 1 minute
|
|
5
5
|
|
|
6
6
|
export class JobReaper {
|
|
7
7
|
#jobQueue
|
package/lib/routes/server.js
CHANGED
|
@@ -4,22 +4,34 @@ import as2 from '../activitystreams.js'
|
|
|
4
4
|
const router = express.Router()
|
|
5
5
|
|
|
6
6
|
router.get('/', async (req, res) => {
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
7
|
+
const fullUrl = `${req.protocol}://${req.get('host')}${req.originalUrl}`
|
|
8
|
+
res.format({
|
|
9
|
+
html: async () => {
|
|
10
|
+
const { indexFileName } = req.app.locals
|
|
11
|
+
res.sendFile(indexFileName)
|
|
12
|
+
},
|
|
13
|
+
json: async () => {
|
|
14
|
+
const { formatter } = req.app.locals
|
|
15
|
+
const server = await as2.import({
|
|
16
|
+
'@context': [
|
|
17
|
+
'https://www.w3.org/ns/activitystreams',
|
|
18
|
+
'https://w3id.org/security/v1'
|
|
19
|
+
],
|
|
20
|
+
id: formatter.format({ server: true }),
|
|
21
|
+
type: 'Service',
|
|
22
|
+
publicKey: formatter.format({ server: true, type: 'publickey' }),
|
|
23
|
+
url: {
|
|
24
|
+
type: 'Link',
|
|
25
|
+
mediaType: 'text/html',
|
|
26
|
+
href: fullUrl
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
const body = await server.export({ useOriginalContext: true })
|
|
30
|
+
res.status(200)
|
|
31
|
+
res.type(as2.mediaType)
|
|
32
|
+
res.json(body)
|
|
33
|
+
}
|
|
16
34
|
})
|
|
17
|
-
res.status(200)
|
|
18
|
-
res.type(as2.mediaType)
|
|
19
|
-
const body = await server.prettyWrite(
|
|
20
|
-
{ additional_context: 'https://w3id.org/security/v1' }
|
|
21
|
-
)
|
|
22
|
-
res.end(body)
|
|
23
35
|
})
|
|
24
36
|
|
|
25
37
|
router.get('/publickey', async (req, res) => {
|
package/package.json
CHANGED
package/web/index.html
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>activitypub.bot</title>
|
|
7
|
+
</head>
|
|
8
|
+
<body>
|
|
9
|
+
<h1>activitypub.bot</h1>
|
|
10
|
+
<p>
|
|
11
|
+
This is an activitypub.bot server. It hosts automated "bot" accounts on the <a href="https://en.wikipedia.org/wiki/Fediverse">Fediverse</a>.
|
|
12
|
+
</p>
|
|
13
|
+
<p>
|
|
14
|
+
<a href="https://github.com/evanp/activitypub-bot">Source</a>
|
|
15
|
+
</p>
|
|
16
|
+
</body>
|
|
17
|
+
</html>
|