owlservable 0.2.9 → 0.2.10
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/dashboard.html +20 -2
- package/index.cjs +8 -0
- package/index.js +8 -0
- package/package.json +1 -1
package/dashboard.html
CHANGED
|
@@ -257,9 +257,10 @@ function addRow(r,prepend){
|
|
|
257
257
|
|
|
258
258
|
function applyUpdate(id,patch){
|
|
259
259
|
var e=byId[id];if(!e)return;
|
|
260
|
+
var prevTok=(e.data.tokens&&e.data.tokens.total)||0;
|
|
260
261
|
Object.assign(e.data,patch);
|
|
261
262
|
if(patch.tokens){
|
|
262
|
-
totalTok+=patch.tokens.total||0;
|
|
263
|
+
totalTok+=(patch.tokens.total||0)-prevTok;
|
|
263
264
|
nTok.textContent=fn(totalTok);
|
|
264
265
|
e.tr.querySelector('.c-tok').innerHTML=tokHtml(e.data);
|
|
265
266
|
}else if('metaPending' in patch&&!patch.metaPending){
|
|
@@ -307,7 +308,7 @@ function handleMsg(msg){
|
|
|
307
308
|
msg.requests.slice().reverse().forEach(function(r){addRow(r,false);});
|
|
308
309
|
renderSave(msg.save);
|
|
309
310
|
}else if(msg.type==='request'){
|
|
310
|
-
addRow(msg.record,true);
|
|
311
|
+
if(!byId[msg.record.id])addRow(msg.record,true);
|
|
311
312
|
}else if(msg.type==='update'){
|
|
312
313
|
applyUpdate(msg.id,msg.patch);
|
|
313
314
|
}else if(msg.type==='saveConfig'){
|
|
@@ -352,6 +353,23 @@ function connect(){
|
|
|
352
353
|
try{handleMsg(msg);}catch(_){}
|
|
353
354
|
});
|
|
354
355
|
}
|
|
356
|
+
var pollGen=1;
|
|
357
|
+
function poll(){
|
|
358
|
+
fetch('/api/requests').then(function(r){return r.json();}).then(function(d){
|
|
359
|
+
var reqs=d.requests||[],gen=d.generation||1;
|
|
360
|
+
if(gen!==pollGen){
|
|
361
|
+
pollGen=gen;reset();
|
|
362
|
+
reqs.slice().reverse().forEach(function(r){addRow(r,false);});
|
|
363
|
+
renderSave(d.save);return;
|
|
364
|
+
}
|
|
365
|
+
reqs.forEach(function(r){
|
|
366
|
+
if(!byId[r.id]){addRow(r,true);}
|
|
367
|
+
else if(byId[r.id].data.metaPending&&!r.metaPending){applyUpdate(r.id,r);}
|
|
368
|
+
});
|
|
369
|
+
}).catch(function(){});
|
|
370
|
+
}
|
|
371
|
+
setInterval(poll,2000);
|
|
372
|
+
setTimeout(poll,500);
|
|
355
373
|
connect();
|
|
356
374
|
})();
|
|
357
375
|
</script>
|
package/index.cjs
CHANGED
|
@@ -17,6 +17,7 @@ emitter.setMaxListeners(100)
|
|
|
17
17
|
|
|
18
18
|
const requests = []
|
|
19
19
|
let nextId = 1
|
|
20
|
+
let generation = 1
|
|
20
21
|
|
|
21
22
|
function addRequest(entry) {
|
|
22
23
|
try {
|
|
@@ -43,6 +44,7 @@ function updateRequest(id, patch) {
|
|
|
43
44
|
function getRequests() { try { return requests.slice() } catch (_) { return [] } }
|
|
44
45
|
|
|
45
46
|
function clearRequests() {
|
|
47
|
+
generation++
|
|
46
48
|
requests.splice(0)
|
|
47
49
|
if (saveState.enabled) try { fs.writeFileSync(saveState.filePath, '') } catch (_) {}
|
|
48
50
|
emitter.emit('reload', { requests: [], save: getSaveInfo() })
|
|
@@ -383,6 +385,12 @@ function startDashboard(port) {
|
|
|
383
385
|
return
|
|
384
386
|
}
|
|
385
387
|
|
|
388
|
+
if (urlPath === '/api/requests' && req.method === 'GET') {
|
|
389
|
+
res.writeHead(200, { 'Content-Type': 'application/json', 'Cache-Control': 'no-cache' })
|
|
390
|
+
res.end(JSON.stringify({ requests: getRequests(), save: getSaveInfo(), generation }))
|
|
391
|
+
return
|
|
392
|
+
}
|
|
393
|
+
|
|
386
394
|
if (urlPath === '/owl.png') {
|
|
387
395
|
try {
|
|
388
396
|
const data = fs.readFileSync(path.join(__dir, 'owl.png'))
|
package/index.js
CHANGED
|
@@ -17,6 +17,7 @@ emitter.setMaxListeners(100)
|
|
|
17
17
|
|
|
18
18
|
const requests = []
|
|
19
19
|
let nextId = 1
|
|
20
|
+
let generation = 1
|
|
20
21
|
|
|
21
22
|
function addRequest(entry) {
|
|
22
23
|
try {
|
|
@@ -43,6 +44,7 @@ function updateRequest(id, patch) {
|
|
|
43
44
|
function getRequests() { try { return requests.slice() } catch (_) { return [] } }
|
|
44
45
|
|
|
45
46
|
function clearRequests() {
|
|
47
|
+
generation++
|
|
46
48
|
requests.splice(0)
|
|
47
49
|
if (saveState.enabled) try { fs.writeFileSync(saveState.filePath, '') } catch (_) {}
|
|
48
50
|
emitter.emit('reload', { requests: [], save: getSaveInfo() })
|
|
@@ -383,6 +385,12 @@ function startDashboard(port) {
|
|
|
383
385
|
return
|
|
384
386
|
}
|
|
385
387
|
|
|
388
|
+
if (urlPath === '/api/requests' && req.method === 'GET') {
|
|
389
|
+
res.writeHead(200, { 'Content-Type': 'application/json', 'Cache-Control': 'no-cache' })
|
|
390
|
+
res.end(JSON.stringify({ requests: getRequests(), save: getSaveInfo(), generation }))
|
|
391
|
+
return
|
|
392
|
+
}
|
|
393
|
+
|
|
386
394
|
if (urlPath === '/owl.png') {
|
|
387
395
|
try {
|
|
388
396
|
const data = fs.readFileSync(path.join(__dir, 'owl.png'))
|