dsh-unlag 1.9.46 → 1.9.48
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/index.js +36 -4
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from 'node:async_hooks'
|
|
2
2
|
import { createHash } from 'node:crypto'
|
|
3
|
-
import { appendFileSync, existsSync, readFileSync, readdirSync, statSync, watch, writeFileSync } from 'node:fs'
|
|
3
|
+
import { appendFileSync, existsSync, mkdirSync, readFileSync, readdirSync, statSync, watch, writeFileSync } from 'node:fs'
|
|
4
4
|
import { homedir } from 'node:os'
|
|
5
5
|
import { join, resolve } from 'node:path'
|
|
6
6
|
import { Script } from 'node:vm'
|
|
@@ -222,6 +222,23 @@ export function oneLine(value, limit = 2000) {
|
|
|
222
222
|
return text.length > limit ? `${text.slice(0, limit)}\u2026` : text
|
|
223
223
|
}
|
|
224
224
|
|
|
225
|
+
/** Whether the directory holding the log has already been made, so one attempt per process. */
|
|
226
|
+
let logDirTried = false
|
|
227
|
+
/**
|
|
228
|
+
* The log is the only evidence a failed update leaves behind, and a home directory that never ran
|
|
229
|
+
* this app yet has no directory for it: one attempt per process to make that directory, then the
|
|
230
|
+
* write is retried. Every failure stays silent, because logging must never take a press down.
|
|
231
|
+
*/
|
|
232
|
+
function ensureLogDir(target) {
|
|
233
|
+
if (logDirTried) return
|
|
234
|
+
logDirTried = true
|
|
235
|
+
const cut = target.lastIndexOf('/')
|
|
236
|
+
if (cut <= 0) return
|
|
237
|
+
try {
|
|
238
|
+
mkdirSync(target.slice(0, cut), { recursive: true })
|
|
239
|
+
} catch {}
|
|
240
|
+
}
|
|
241
|
+
|
|
225
242
|
function log(line) {
|
|
226
243
|
try {
|
|
227
244
|
const target = logTarget()
|
|
@@ -235,7 +252,15 @@ function log(line) {
|
|
|
235
252
|
/* a missing or unreadable log is created by the append below */
|
|
236
253
|
}
|
|
237
254
|
}
|
|
238
|
-
|
|
255
|
+
const text = `${new Date().toISOString()} ${oneLine(line)}\n`
|
|
256
|
+
try {
|
|
257
|
+
appendFileSync(target, text)
|
|
258
|
+
} catch {
|
|
259
|
+
ensureLogDir(target)
|
|
260
|
+
try {
|
|
261
|
+
appendFileSync(target, text)
|
|
262
|
+
} catch {}
|
|
263
|
+
}
|
|
239
264
|
} catch {}
|
|
240
265
|
}
|
|
241
266
|
|
|
@@ -1760,8 +1785,14 @@ function serveButton(ctx, controller, config) {
|
|
|
1760
1785
|
if (!settings.reloadPlugins) return sendJson(res, 200, { status: 'off' })
|
|
1761
1786
|
const limit = Number(process.env.DSH_UNLAG_ANSWER_MS ?? '') || RELOAD_ANSWER_MS
|
|
1762
1787
|
let timer = null
|
|
1788
|
+
let timedOut = false
|
|
1763
1789
|
const stillApplying = new Promise((resolve) => {
|
|
1764
|
-
timer = setTimeout(() =>
|
|
1790
|
+
timer = setTimeout(() => {
|
|
1791
|
+
// Only the timer's own answer means the update outlasted the page: an update that
|
|
1792
|
+
// says "applying" itself is a press that arrived during another one, not a slow one.
|
|
1793
|
+
timedOut = true
|
|
1794
|
+
resolve({ status: 'applying', warnings: [], pending: [], restartReason: null, failedEntries: [] })
|
|
1795
|
+
}, limit)
|
|
1765
1796
|
})
|
|
1766
1797
|
let answeredEarly = false
|
|
1767
1798
|
try {
|
|
@@ -1782,7 +1813,8 @@ function serveButton(ctx, controller, config) {
|
|
|
1782
1813
|
const outcome = await Promise.race([work, stillApplying])
|
|
1783
1814
|
if (outcome?.status === 'applying') {
|
|
1784
1815
|
answeredEarly = true
|
|
1785
|
-
log('the update outlasted the answer the page waits for: the press is told it is still applying')
|
|
1816
|
+
if (timedOut) log('the update outlasted the answer the page waits for: the press is told it is still applying')
|
|
1817
|
+
else log('a press arrived while an update is already applying: the press is told it is still applying')
|
|
1786
1818
|
}
|
|
1787
1819
|
sendJson(res, 200, outcome)
|
|
1788
1820
|
} finally {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-unlag",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.48",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A press applies plugin edits right away and brings a laggy interface back; automatic reloading stays off unless you turn it on, so the press is the only trigger, and nothing restarts.",
|
|
6
6
|
"license": "MIT",
|