aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/instances-index/mock-instances-index.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-09-04 11:18:33 +0200
committerChocobozzz <chocobozzz@cpy.re>2019-09-04 16:24:58 +0200
commit6f1b4fa417786c2015f16b435e872aa65378efd7 (patch)
treebcf97760b4819d3204f42592a9e6f052674b1f01 /shared/extra-utils/instances-index/mock-instances-index.ts
parent8424c4026afd7304880a4ce8138a04ffb3d8c938 (diff)
downloadPeerTube-6f1b4fa417786c2015f16b435e872aa65378efd7.tar.gz
PeerTube-6f1b4fa417786c2015f16b435e872aa65378efd7.tar.zst
PeerTube-6f1b4fa417786c2015f16b435e872aa65378efd7.zip
Add auto follow instances index support
Diffstat (limited to 'shared/extra-utils/instances-index/mock-instances-index.ts')
-rw-r--r--shared/extra-utils/instances-index/mock-instances-index.ts38
1 files changed, 38 insertions, 0 deletions
diff --git a/shared/extra-utils/instances-index/mock-instances-index.ts b/shared/extra-utils/instances-index/mock-instances-index.ts
new file mode 100644
index 000000000..cfa4523c1
--- /dev/null
+++ b/shared/extra-utils/instances-index/mock-instances-index.ts
@@ -0,0 +1,38 @@
1import * as express from 'express'
2
3export class MockInstancesIndex {
4 private indexInstances: { host: string, createdAt: string }[] = []
5
6 initialize () {
7 return new Promise(res => {
8 const app = express()
9
10 app.use('/', (req: express.Request, res: express.Response, next: express.NextFunction) => {
11 if (process.env.DEBUG) console.log('Receiving request on mocked server %s.', req.url)
12
13 return next()
14 })
15
16 app.get('/api/v1/instances/hosts', (req: express.Request, res: express.Response) => {
17 const since = req.query.since
18
19 const filtered = this.indexInstances.filter(i => {
20 if (!since) return true
21
22 return i.createdAt > since
23 })
24
25 return res.json({
26 total: filtered.length,
27 data: filtered
28 })
29 })
30
31 app.listen(42100, () => res())
32 })
33 }
34
35 addInstance (host: string) {
36 this.indexInstances.push({ host, createdAt: new Date().toISOString() })
37 }
38}