mirror of
https://git.sr.ht/~cadence/bibliogram
synced 2024-11-26 01:37:28 +00:00
Add experimental update stream
This commit is contained in:
parent
49575dc8a1
commit
f798bd158d
4
package-lock.json
generated
4
package-lock.json
generated
@ -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",
|
||||||
|
@ -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",
|
||||||
|
30
src/site/api/update_stream.js
Normal file
30
src/site/api/update_stream.js
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
Loading…
Reference in New Issue
Block a user