1
0
mirror of https://git.sr.ht/~cadence/bibliogram synced 2024-11-22 16:17:29 +00:00

Add experimental update stream

This commit is contained in:
Cadence Ember 2020-05-22 03:44:52 +12:00
parent 49575dc8a1
commit f798bd158d
No known key found for this signature in database
GPG Key ID: 128B99B1B74A6412
3 changed files with 33 additions and 3 deletions

4
package-lock.json generated
View File

@ -2738,8 +2738,8 @@
"integrity": "sha512-q0M/9eZHzmr0AulXyPwNfZjtwZ/RBZlbN3K3CErVrk50T2ASYI7Bye0EvekFY3IP1Nt2DHu0re+V2ZHIpMkuWg==" "integrity": "sha512-q0M/9eZHzmr0AulXyPwNfZjtwZ/RBZlbN3K3CErVrk50T2ASYI7Bye0EvekFY3IP1Nt2DHu0re+V2ZHIpMkuWg=="
}, },
"pinski": { "pinski": {
"version": "github:cloudrac3r/pinski#64e588416e27da406711d853778dfcd729138397", "version": "github:cloudrac3r/pinski#0ac730907da8f3a644bc9d50063b6367b15b7944",
"from": "github:cloudrac3r/pinski#64e588416e27da406711d853778dfcd729138397", "from": "github:cloudrac3r/pinski#0ac730907da8f3a644bc9d50063b6367b15b7944",
"requires": { "requires": {
"mime": "^2.4.4", "mime": "^2.4.4",
"pug": "^2.0.3", "pug": "^2.0.3",

View File

@ -19,7 +19,7 @@
"mixin-deep": "^2.0.1", "mixin-deep": "^2.0.1",
"node-dir": "^0.1.17", "node-dir": "^0.1.17",
"node-fetch": "^2.6.0", "node-fetch": "^2.6.0",
"pinski": "github:cloudrac3r/pinski#64e588416e27da406711d853778dfcd729138397", "pinski": "github:cloudrac3r/pinski#0ac730907da8f3a644bc9d50063b6367b15b7944",
"pug": "^2.0.4", "pug": "^2.0.4",
"semver": "^7.2.1", "semver": "^7.2.1",
"sharp": "^0.25.2", "sharp": "^0.25.2",

View File

@ -0,0 +1,30 @@
const {Readable} = require("stream")
const streams = new Set()
setInterval((new (function() {
const payload = `:keepalive ${Date.now()}\n\n`
for (const stream of streams.values()) {
stream.push(payload)
}
})).constructor, 50000)
module.exports = [
{
route: "/api/update_stream", methods: ["GET"], code: async () => {
const stream = new Readable({
read: function() {},
destroy: function() {
streams.delete(stream)
}
})
streams.add(stream)
return {
statusCode: 200,
contentType: "text/event-stream",
stream
}
}
}
]