dsh-cookie-cleaner 0.6.4 → 0.7.2
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/CHANGELOG.md +270 -242
- package/LICENSE +21 -21
- package/README.md +432 -432
- package/cordis.patch.yml +5 -5
- package/dsh.plugin.json +1 -1
- package/lib/client.js +336 -8
- package/lib/client.js.map +1 -1
- package/package.json +1 -1
- package/scripts/gen-locales.mjs +82 -82
- package/scripts/hosts.mjs +57 -57
- package/scripts/sync-hosts.mjs +80 -80
- package/src/api-routes.js +144 -138
- package/src/cli.js +281 -236
- package/src/client/card.tsx +315 -253
- package/src/client/index.ts +129 -129
- package/src/client/locales.ts +91 -84
- package/src/client/routes.ts +138 -118
- package/src/client/star-row-copy.ts +256 -0
- package/src/core.js +669 -531
- package/src/i18n.js +140 -140
- package/src/index.js +426 -394
- package/src/jar-live.js +365 -365
- package/src/legacy-injection.js +137 -0
- package/src/locales-advise-owner.js +39 -39
- package/src/locales-dict.js +220 -220
- package/src/locales-dict2.js +214 -214
- package/src/locales-patch.js +207 -207
- package/src/patch-guard.js +509 -416
- package/src/patch-model.js +271 -271
- package/src/patch-read.js +251 -199
- package/src/report.js +243 -243
- package/src/runtime-guard.js +14 -4
- package/src/settings-waist.js +37 -37
package/src/core.js
CHANGED
|
@@ -1,531 +1,669 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* dsh-cookie-cleaner — 核心逻辑(纯函数面,host 半与 CLI 共用)。
|
|
3
|
-
*
|
|
4
|
-
* 为什么清理动作不能在插件运行期做(2026-11-04 对本机 0.2.1-rc.5 客户端实测):
|
|
5
|
-
* - Host 是 Electron 的纯 Node 模式子进程(`ELECTRON_RUN_AS_NODE=1`),拿不到
|
|
6
|
-
* `session.cookies`,只能落到磁盘上的 Chromium cookie 库;
|
|
7
|
-
* - 客户端在跑时该库被 Chromium 周期性持有:Host runtime(Electron 44 / Node 24)
|
|
8
|
-
* 连 `readOnly` 打开都报 `unable to open database file`,`fs.copyFileSync` 同样被拒;
|
|
9
|
-
* 而系统 node 22 在相近时刻却能读。**能否打开随时间漂移,而且只报一个笼统错,
|
|
10
|
-
* 所以不能拿错误码分档(POSIX 权限不足也不给 EACCES),只能自己探文件。**
|
|
11
|
-
* 因此本模块把「独占写锁」当作唯一的安全闸:拿不到锁就一律拒绝,
|
|
12
|
-
* 拿到锁即意味着此刻没有其它写者,删除是原子的、不会留中间态。
|
|
13
|
-
*
|
|
14
|
-
* 删了会不会掉登录?不会(源码依据):
|
|
15
|
-
* - 主窗口 HTTP/WS 用的是内存态 `hostCookie`(desktop `main.ts` 换发后经
|
|
16
|
-
* `forwardWebRequest` / `onBeforeSendHeaders` 注入),不经 cookie jar;
|
|
17
|
-
* - `BrowserAuth.isAuthenticated` 按当前 authority 派生**唯一**名字取值
|
|
18
|
-
* (`dsh-auth-<base64url(sha256(host:port))>`),其余同名前缀条目本就永远读不到;
|
|
19
|
-
* - 每次启动都会用 launch token 重新换发(`authenticateWebHost`)。
|
|
20
|
-
* 账号凭据(`.credentials.yaml`)、会话、插件配置都不在这个库里。
|
|
21
|
-
*/
|
|
22
|
-
import fs from 'node:fs'
|
|
23
|
-
import os from 'node:os'
|
|
24
|
-
import path from 'node:path'
|
|
25
|
-
import { createRequire } from 'node:module'
|
|
26
|
-
import { exitFor, translator } from './i18n.js'
|
|
27
|
-
import { snapshotThroughHandle } from './jar-live.js'
|
|
28
|
-
import './locales-dict.js'
|
|
29
|
-
|
|
30
|
-
/** Cookie 名前缀:宿主 client-connection 生成(`COOKIE_PREFIX + sha256(authority)`)。 */
|
|
31
|
-
export const AUTH_COOKIE_PREFIX = 'dsh-auth-'
|
|
32
|
-
|
|
33
|
-
/** 本地回环 host_key:一个端口一条记录,历史端口会长期堆积。 */
|
|
34
|
-
export const LOOPBACK_HOST_KEYS = Object.freeze(['127.0.0.1', 'localhost', '[::1]'])
|
|
35
|
-
|
|
36
|
-
/** Chromium 的 `expires_utc` 是自 1601-01-01 起的微秒数。 */
|
|
37
|
-
const WINDOWS_EPOCH_OFFSET_MICROSECONDS = 11_644_473_600_000_000
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* 请求头占用折算:把「条数」翻成用户能直接判断的余量。
|
|
41
|
-
*
|
|
42
|
-
* 三个数各有出处,不是把上游报告的 228/229 当常数直接乘:
|
|
43
|
-
* - 上限 `16384` 是 Node `--max-http-header-size` 默认值(头顶过即 431,见上游 #11366 / #11410 / #11650);
|
|
44
|
-
* - `name` 列在 Chromium 库里是**明文**,所以 `SUM(LENGTH(name))` 是实测值;每条还多 `'='` 与 `'; '` 共 3 个分隔字节;
|
|
45
|
-
* - `value` 列存的是 OS 加密后的**密文**(比真正进请求头的明文长),拿它算体积会高估,
|
|
46
|
-
* 所以明文部分按上游三份报告一致的 173 B/条作估算,结果里带 `basis:'estimated'` 说清这不是精确值。
|
|
47
|
-
*/
|
|
48
|
-
export const MAX_HEADER_BYTES = 16384
|
|
49
|
-
// 每条在 Cookie 头里的格式是 `name=value; ` → '=' 一个字节 + '; ' 两个字节 = 3。
|
|
50
|
-
// 上游三份报告的实测均为 52 + 1 + 173 + 2 = 228 B/条(#11366: 71 条 = 16,188 B),这里按同一口径对齐。
|
|
51
|
-
const HEADER_SEPARATOR_BYTES = 3
|
|
52
|
-
const VALUE_BYTES_ESTIMATE = 173
|
|
53
|
-
const NAME_LENGTH_FALLBACK = 52 // 'dsh-auth-' + base64url(sha256) 实测长度,仅在拿不到 SUM 时兜底
|
|
54
|
-
|
|
55
|
-
/** @param {{count:number, nameBytes?:number}} input @returns {{bytes:number,pct:number,rawPct:number,maxHeaderBytes:number,basis:string,threshold:number,remaining:number,over:boolean}} */
|
|
56
|
-
export function headerOccupancy({ count = 0, nameBytes }) {
|
|
57
|
-
const safeCount = Number.isFinite(count) && count > 0 ? Math.floor(count) : 0
|
|
58
|
-
const names = Number.isFinite(nameBytes) && nameBytes >= 0
|
|
59
|
-
? nameBytes
|
|
60
|
-
: safeCount * NAME_LENGTH_FALLBACK
|
|
61
|
-
const bytes = names + (HEADER_SEPARATOR_BYTES + VALUE_BYTES_ESTIMATE) * safeCount
|
|
62
|
-
const rawPct = Math.round((bytes / MAX_HEADER_BYTES) * 1000) / 10
|
|
63
|
-
const average = safeCount > 0 ? bytes / safeCount : HEADER_SEPARATOR_BYTES + NAME_LENGTH_FALLBACK + VALUE_BYTES_ESTIMATE
|
|
64
|
-
const threshold = Math.floor(MAX_HEADER_BYTES / Math.max(1, average))
|
|
65
|
-
return {
|
|
66
|
-
bytes,
|
|
67
|
-
pct: Math.min(100, rawPct),
|
|
68
|
-
rawPct,
|
|
69
|
-
maxHeaderBytes: MAX_HEADER_BYTES,
|
|
70
|
-
basis: 'estimated',
|
|
71
|
-
threshold,
|
|
72
|
-
remaining: Math.max(0, threshold - safeCount),
|
|
73
|
-
over: bytes >= MAX_HEADER_BYTES,
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/** 打包的 desktop 应用名(Electron 由 package.json 的 name 派生 userData 目录)。 */
|
|
78
|
-
const PRODUCT_DIR_NAMES = Object.freeze(['@deepseek-ai/dsh-desktop', 'DSH Desktop', 'deepseek-harness'])
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Chromium 在 POSIX 平台上用 WAL 日志(Windows 上用 rollback journal):
|
|
82
|
-
* 备份只拷主文件会丢掉 `-wal` 里尚未 checkpoint 的行,恢复时反而把库写小。
|
|
83
|
-
*/
|
|
84
|
-
const SIDECAR_SUFFIXES = Object.freeze(['-wal', '-shm', '-journal'])
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* 退出客户端的人话指引(托盘只在 Windows 存在;macOS 叫 Quit)。
|
|
88
|
-
* `lang` 缺省走当前激活语言(由 setLang 设定),文本按 9 语字典出。'zh' 是无探测时的底。
|
|
89
|
-
*/
|
|
90
|
-
export function exitInstruction(platform = process.platform, lang = activeLang()) {
|
|
91
|
-
return exitFor(platform, translator(lang))
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* 当前输出语言。调用方(CLI / 宿主命令)负责先探测再 setLang;
|
|
96
|
-
* 没设过时默认 zh,保证行为与 0.1.0 一致(不因为探测把一个中文用户推到英文)。
|
|
97
|
-
*/
|
|
98
|
-
let lang = 'zh'
|
|
99
|
-
export function setLang(next) { if (typeof next === 'string' && next) lang = next; return lang }
|
|
100
|
-
export function activeLang() { return lang }
|
|
101
|
-
|
|
102
|
-
const require = createRequire(import.meta.url)
|
|
103
|
-
|
|
104
|
-
/** Windows epoch 下的「现在」,用于和 `expires_utc` 同量纲比较。 */
|
|
105
|
-
function windowsNowMicroseconds() {
|
|
106
|
-
return Date.now() * 1000 + WINDOWS_EPOCH_OFFSET_MICROSECONDS
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/** 微秒级时间戳超过 2^53,一律以 BigInt 进出(node:sqlite 的 readBigInts 语义)。 */
|
|
110
|
-
function toBigInt(value) {
|
|
111
|
-
return typeof value === 'bigint' ? value : BigInt(Math.round(Number(value) || 0))
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/** COUNT(*) 之类的小整数:BigInt → Number(超安全范围只可能出现在损坏库上)。 */
|
|
115
|
-
function toCount(value) {
|
|
116
|
-
return typeof value === 'bigint' ? Number(value) : Number(value) || 0
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/** 把 Chromium 的微秒时间戳换成可读 UTC 时间(0/非法值给出对应文案)。 */
|
|
120
|
-
export function formatChromiumTimestamp(value) {
|
|
121
|
-
const microseconds = toBigInt(value)
|
|
122
|
-
if (microseconds <= 0n) return 'session / never'
|
|
123
|
-
const milliseconds = Number((microseconds - BigInt(WINDOWS_EPOCH_OFFSET_MICROSECONDS)) / 1000n)
|
|
124
|
-
if (!Number.isSafeInteger(milliseconds) || milliseconds < 0) return 'unknown'
|
|
125
|
-
return new Date(milliseconds).toISOString().slice(0, 16).replace('T', ' ') + ' UTC'
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/** 候选 cookie 库路径(按平台惯例派生;桌面客户端与 Web 共用同一 userData 布局)。 */
|
|
129
|
-
export function candidateCookieDbs(userDataRoot = '', platform = process.platform, env = process.env) {
|
|
130
|
-
// 分隔符跟随目标平台而不宿主:跨平台单测/多实例部署才不会拿到一身反斜杠的 posix 路径。
|
|
131
|
-
const pathModule = platform === 'win32' ? path.win32 : path.posix
|
|
132
|
-
// 显式给根 = 只要这个根(单测/多实例隔离),不得再把平台默认目录掺进来。
|
|
133
|
-
const explicit = String(userDataRoot || '').trim()
|
|
134
|
-
if (explicit) {
|
|
135
|
-
const out = []
|
|
136
|
-
for (const leaf of [pathModule.join('Network', 'Cookies'), 'Cookies']) {
|
|
137
|
-
out.push(pathModule.join(explicit, leaf))
|
|
138
|
-
}
|
|
139
|
-
return out
|
|
140
|
-
}
|
|
141
|
-
const roots = []
|
|
142
|
-
if (env.DSH_USER_DATA) roots.push(String(env.DSH_USER_DATA).trim())
|
|
143
|
-
// home 从注入的 env 取(方便单测/多用户场景),真跑时才回退到 os.homedir()。
|
|
144
|
-
const home = env.HOME || env.USERPROFILE || os.homedir()
|
|
145
|
-
if (platform === 'win32') {
|
|
146
|
-
if (env.APPDATA) for (const name of PRODUCT_DIR_NAMES) roots.push(pathModule.join(env.APPDATA, name))
|
|
147
|
-
} else if (platform === 'darwin') {
|
|
148
|
-
for (const name of PRODUCT_DIR_NAMES) roots.push(pathModule.join(home, 'Library', 'Application Support', name))
|
|
149
|
-
} else {
|
|
150
|
-
for (const name of PRODUCT_DIR_NAMES) roots.push(pathModule.join(env.XDG_CONFIG_HOME || pathModule.join(home, '.config'), name))
|
|
151
|
-
}
|
|
152
|
-
const out = []
|
|
153
|
-
// DSH_COOKIE_DB 是库文件本身:直接当首选候选,不拆根重组(拆错了就永远命不中)。
|
|
154
|
-
if (env.DSH_COOKIE_DB) out.push(pathModule.resolve(env.DSH_COOKIE_DB))
|
|
155
|
-
for (const root of roots) {
|
|
156
|
-
if (!root) continue
|
|
157
|
-
// Chromium ≥88 把网络状态收敛到 <userData>/Network/,更早的版本直接放根下。
|
|
158
|
-
for (const leaf of [pathModule.join('Network', 'Cookies'), 'Cookies']) {
|
|
159
|
-
const file = pathModule.join(root, leaf)
|
|
160
|
-
if (!out.includes(file)) out.push(file)
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
return out
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
try {
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
const
|
|
395
|
-
if (
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
const
|
|
490
|
-
const
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
/**
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* dsh-cookie-cleaner — 核心逻辑(纯函数面,host 半与 CLI 共用)。
|
|
3
|
+
*
|
|
4
|
+
* 为什么清理动作不能在插件运行期做(2026-11-04 对本机 0.2.1-rc.5 客户端实测):
|
|
5
|
+
* - Host 是 Electron 的纯 Node 模式子进程(`ELECTRON_RUN_AS_NODE=1`),拿不到
|
|
6
|
+
* `session.cookies`,只能落到磁盘上的 Chromium cookie 库;
|
|
7
|
+
* - 客户端在跑时该库被 Chromium 周期性持有:Host runtime(Electron 44 / Node 24)
|
|
8
|
+
* 连 `readOnly` 打开都报 `unable to open database file`,`fs.copyFileSync` 同样被拒;
|
|
9
|
+
* 而系统 node 22 在相近时刻却能读。**能否打开随时间漂移,而且只报一个笼统错,
|
|
10
|
+
* 所以不能拿错误码分档(POSIX 权限不足也不给 EACCES),只能自己探文件。**
|
|
11
|
+
* 因此本模块把「独占写锁」当作唯一的安全闸:拿不到锁就一律拒绝,
|
|
12
|
+
* 拿到锁即意味着此刻没有其它写者,删除是原子的、不会留中间态。
|
|
13
|
+
*
|
|
14
|
+
* 删了会不会掉登录?不会(源码依据):
|
|
15
|
+
* - 主窗口 HTTP/WS 用的是内存态 `hostCookie`(desktop `main.ts` 换发后经
|
|
16
|
+
* `forwardWebRequest` / `onBeforeSendHeaders` 注入),不经 cookie jar;
|
|
17
|
+
* - `BrowserAuth.isAuthenticated` 按当前 authority 派生**唯一**名字取值
|
|
18
|
+
* (`dsh-auth-<base64url(sha256(host:port))>`),其余同名前缀条目本就永远读不到;
|
|
19
|
+
* - 每次启动都会用 launch token 重新换发(`authenticateWebHost`)。
|
|
20
|
+
* 账号凭据(`.credentials.yaml`)、会话、插件配置都不在这个库里。
|
|
21
|
+
*/
|
|
22
|
+
import fs from 'node:fs'
|
|
23
|
+
import os from 'node:os'
|
|
24
|
+
import path from 'node:path'
|
|
25
|
+
import { createRequire } from 'node:module'
|
|
26
|
+
import { exitFor, translator } from './i18n.js'
|
|
27
|
+
import { snapshotThroughHandle } from './jar-live.js'
|
|
28
|
+
import './locales-dict.js'
|
|
29
|
+
|
|
30
|
+
/** Cookie 名前缀:宿主 client-connection 生成(`COOKIE_PREFIX + sha256(authority)`)。 */
|
|
31
|
+
export const AUTH_COOKIE_PREFIX = 'dsh-auth-'
|
|
32
|
+
|
|
33
|
+
/** 本地回环 host_key:一个端口一条记录,历史端口会长期堆积。 */
|
|
34
|
+
export const LOOPBACK_HOST_KEYS = Object.freeze(['127.0.0.1', 'localhost', '[::1]'])
|
|
35
|
+
|
|
36
|
+
/** Chromium 的 `expires_utc` 是自 1601-01-01 起的微秒数。 */
|
|
37
|
+
const WINDOWS_EPOCH_OFFSET_MICROSECONDS = 11_644_473_600_000_000
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* 请求头占用折算:把「条数」翻成用户能直接判断的余量。
|
|
41
|
+
*
|
|
42
|
+
* 三个数各有出处,不是把上游报告的 228/229 当常数直接乘:
|
|
43
|
+
* - 上限 `16384` 是 Node `--max-http-header-size` 默认值(头顶过即 431,见上游 #11366 / #11410 / #11650);
|
|
44
|
+
* - `name` 列在 Chromium 库里是**明文**,所以 `SUM(LENGTH(name))` 是实测值;每条还多 `'='` 与 `'; '` 共 3 个分隔字节;
|
|
45
|
+
* - `value` 列存的是 OS 加密后的**密文**(比真正进请求头的明文长),拿它算体积会高估,
|
|
46
|
+
* 所以明文部分按上游三份报告一致的 173 B/条作估算,结果里带 `basis:'estimated'` 说清这不是精确值。
|
|
47
|
+
*/
|
|
48
|
+
export const MAX_HEADER_BYTES = 16384
|
|
49
|
+
// 每条在 Cookie 头里的格式是 `name=value; ` → '=' 一个字节 + '; ' 两个字节 = 3。
|
|
50
|
+
// 上游三份报告的实测均为 52 + 1 + 173 + 2 = 228 B/条(#11366: 71 条 = 16,188 B),这里按同一口径对齐。
|
|
51
|
+
const HEADER_SEPARATOR_BYTES = 3
|
|
52
|
+
const VALUE_BYTES_ESTIMATE = 173
|
|
53
|
+
const NAME_LENGTH_FALLBACK = 52 // 'dsh-auth-' + base64url(sha256) 实测长度,仅在拿不到 SUM 时兜底
|
|
54
|
+
|
|
55
|
+
/** @param {{count:number, nameBytes?:number}} input @returns {{bytes:number,pct:number,rawPct:number,maxHeaderBytes:number,basis:string,threshold:number,remaining:number,over:boolean}} */
|
|
56
|
+
export function headerOccupancy({ count = 0, nameBytes }) {
|
|
57
|
+
const safeCount = Number.isFinite(count) && count > 0 ? Math.floor(count) : 0
|
|
58
|
+
const names = Number.isFinite(nameBytes) && nameBytes >= 0
|
|
59
|
+
? nameBytes
|
|
60
|
+
: safeCount * NAME_LENGTH_FALLBACK
|
|
61
|
+
const bytes = names + (HEADER_SEPARATOR_BYTES + VALUE_BYTES_ESTIMATE) * safeCount
|
|
62
|
+
const rawPct = Math.round((bytes / MAX_HEADER_BYTES) * 1000) / 10
|
|
63
|
+
const average = safeCount > 0 ? bytes / safeCount : HEADER_SEPARATOR_BYTES + NAME_LENGTH_FALLBACK + VALUE_BYTES_ESTIMATE
|
|
64
|
+
const threshold = Math.floor(MAX_HEADER_BYTES / Math.max(1, average))
|
|
65
|
+
return {
|
|
66
|
+
bytes,
|
|
67
|
+
pct: Math.min(100, rawPct),
|
|
68
|
+
rawPct,
|
|
69
|
+
maxHeaderBytes: MAX_HEADER_BYTES,
|
|
70
|
+
basis: 'estimated',
|
|
71
|
+
threshold,
|
|
72
|
+
remaining: Math.max(0, threshold - safeCount),
|
|
73
|
+
over: bytes >= MAX_HEADER_BYTES,
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** 打包的 desktop 应用名(Electron 由 package.json 的 name 派生 userData 目录)。 */
|
|
78
|
+
const PRODUCT_DIR_NAMES = Object.freeze(['@deepseek-ai/dsh-desktop', 'DSH Desktop', 'deepseek-harness'])
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Chromium 在 POSIX 平台上用 WAL 日志(Windows 上用 rollback journal):
|
|
82
|
+
* 备份只拷主文件会丢掉 `-wal` 里尚未 checkpoint 的行,恢复时反而把库写小。
|
|
83
|
+
*/
|
|
84
|
+
const SIDECAR_SUFFIXES = Object.freeze(['-wal', '-shm', '-journal'])
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* 退出客户端的人话指引(托盘只在 Windows 存在;macOS 叫 Quit)。
|
|
88
|
+
* `lang` 缺省走当前激活语言(由 setLang 设定),文本按 9 语字典出。'zh' 是无探测时的底。
|
|
89
|
+
*/
|
|
90
|
+
export function exitInstruction(platform = process.platform, lang = activeLang()) {
|
|
91
|
+
return exitFor(platform, translator(lang))
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* 当前输出语言。调用方(CLI / 宿主命令)负责先探测再 setLang;
|
|
96
|
+
* 没设过时默认 zh,保证行为与 0.1.0 一致(不因为探测把一个中文用户推到英文)。
|
|
97
|
+
*/
|
|
98
|
+
let lang = 'zh'
|
|
99
|
+
export function setLang(next) { if (typeof next === 'string' && next) lang = next; return lang }
|
|
100
|
+
export function activeLang() { return lang }
|
|
101
|
+
|
|
102
|
+
const require = createRequire(import.meta.url)
|
|
103
|
+
|
|
104
|
+
/** Windows epoch 下的「现在」,用于和 `expires_utc` 同量纲比较。 */
|
|
105
|
+
function windowsNowMicroseconds() {
|
|
106
|
+
return Date.now() * 1000 + WINDOWS_EPOCH_OFFSET_MICROSECONDS
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** 微秒级时间戳超过 2^53,一律以 BigInt 进出(node:sqlite 的 readBigInts 语义)。 */
|
|
110
|
+
function toBigInt(value) {
|
|
111
|
+
return typeof value === 'bigint' ? value : BigInt(Math.round(Number(value) || 0))
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** COUNT(*) 之类的小整数:BigInt → Number(超安全范围只可能出现在损坏库上)。 */
|
|
115
|
+
function toCount(value) {
|
|
116
|
+
return typeof value === 'bigint' ? Number(value) : Number(value) || 0
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** 把 Chromium 的微秒时间戳换成可读 UTC 时间(0/非法值给出对应文案)。 */
|
|
120
|
+
export function formatChromiumTimestamp(value) {
|
|
121
|
+
const microseconds = toBigInt(value)
|
|
122
|
+
if (microseconds <= 0n) return 'session / never'
|
|
123
|
+
const milliseconds = Number((microseconds - BigInt(WINDOWS_EPOCH_OFFSET_MICROSECONDS)) / 1000n)
|
|
124
|
+
if (!Number.isSafeInteger(milliseconds) || milliseconds < 0) return 'unknown'
|
|
125
|
+
return new Date(milliseconds).toISOString().slice(0, 16).replace('T', ' ') + ' UTC'
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** 候选 cookie 库路径(按平台惯例派生;桌面客户端与 Web 共用同一 userData 布局)。 */
|
|
129
|
+
export function candidateCookieDbs(userDataRoot = '', platform = process.platform, env = process.env) {
|
|
130
|
+
// 分隔符跟随目标平台而不宿主:跨平台单测/多实例部署才不会拿到一身反斜杠的 posix 路径。
|
|
131
|
+
const pathModule = platform === 'win32' ? path.win32 : path.posix
|
|
132
|
+
// 显式给根 = 只要这个根(单测/多实例隔离),不得再把平台默认目录掺进来。
|
|
133
|
+
const explicit = String(userDataRoot || '').trim()
|
|
134
|
+
if (explicit) {
|
|
135
|
+
const out = []
|
|
136
|
+
for (const leaf of [pathModule.join('Network', 'Cookies'), 'Cookies']) {
|
|
137
|
+
out.push(pathModule.join(explicit, leaf))
|
|
138
|
+
}
|
|
139
|
+
return out
|
|
140
|
+
}
|
|
141
|
+
const roots = []
|
|
142
|
+
if (env.DSH_USER_DATA) roots.push(String(env.DSH_USER_DATA).trim())
|
|
143
|
+
// home 从注入的 env 取(方便单测/多用户场景),真跑时才回退到 os.homedir()。
|
|
144
|
+
const home = env.HOME || env.USERPROFILE || os.homedir()
|
|
145
|
+
if (platform === 'win32') {
|
|
146
|
+
if (env.APPDATA) for (const name of PRODUCT_DIR_NAMES) roots.push(pathModule.join(env.APPDATA, name))
|
|
147
|
+
} else if (platform === 'darwin') {
|
|
148
|
+
for (const name of PRODUCT_DIR_NAMES) roots.push(pathModule.join(home, 'Library', 'Application Support', name))
|
|
149
|
+
} else {
|
|
150
|
+
for (const name of PRODUCT_DIR_NAMES) roots.push(pathModule.join(env.XDG_CONFIG_HOME || pathModule.join(home, '.config'), name))
|
|
151
|
+
}
|
|
152
|
+
const out = []
|
|
153
|
+
// DSH_COOKIE_DB 是库文件本身:直接当首选候选,不拆根重组(拆错了就永远命不中)。
|
|
154
|
+
if (env.DSH_COOKIE_DB) out.push(pathModule.resolve(env.DSH_COOKIE_DB))
|
|
155
|
+
for (const root of roots) {
|
|
156
|
+
if (!root) continue
|
|
157
|
+
// Chromium ≥88 把网络状态收敛到 <userData>/Network/,更早的版本直接放根下。
|
|
158
|
+
for (const leaf of [pathModule.join('Network', 'Cookies'), 'Cookies']) {
|
|
159
|
+
const file = pathModule.join(root, leaf)
|
|
160
|
+
if (!out.includes(file)) out.push(file)
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return out
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** 官方清理实现的函数名(desktop 外壳主进程里的标记字符串)。 */
|
|
167
|
+
const NATIVE_CLEANUP_MARKER = 'removeLegacyHostCookies'
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* 在二进制文件里搜一个 ASCII 标记,命中返回标记本身,否则 null。
|
|
171
|
+
*
|
|
172
|
+
* 为什么要这个:asar 容器把 `lib/main.js` 等文件原文拼在数据段,只有 Electron 打过补丁的
|
|
173
|
+
* `fs` 才能按路径读;纯 Node 子进程读不到。分块扫描只认字节,不解析 header,
|
|
174
|
+
* 也不把 200MB 一次读进内存(命中即停)。
|
|
175
|
+
* @param {string} file
|
|
176
|
+
* @param {string} marker
|
|
177
|
+
* @param {{chunkBytes?:number, readSync?:(fd:number, buffer:Buffer, offset:number, length:number, position:number)=>number, openSync?:Function, closeSync?:Function}} [io]
|
|
178
|
+
* @returns {string|null}
|
|
179
|
+
*/
|
|
180
|
+
export function scanBinaryFor(file, marker, io = {}) {
|
|
181
|
+
const openSync = io.openSync ?? fs.openSync
|
|
182
|
+
const readSync = io.readSync ?? fs.readSync
|
|
183
|
+
const closeSync = io.closeSync ?? fs.closeSync
|
|
184
|
+
const chunkBytes = io.chunkBytes ?? 4 * 1024 * 1024
|
|
185
|
+
const needle = Buffer.from(marker, 'utf8')
|
|
186
|
+
let fd
|
|
187
|
+
try {
|
|
188
|
+
fd = openSync(file, 'r')
|
|
189
|
+
} catch {
|
|
190
|
+
return null
|
|
191
|
+
}
|
|
192
|
+
try {
|
|
193
|
+
const buffer = Buffer.alloc(chunkBytes + needle.length)
|
|
194
|
+
let position = 0
|
|
195
|
+
for (;;) {
|
|
196
|
+
let read
|
|
197
|
+
try {
|
|
198
|
+
read = readSync(fd, buffer, 0, buffer.length, position)
|
|
199
|
+
} catch {
|
|
200
|
+
return null
|
|
201
|
+
}
|
|
202
|
+
if (read === 0) return null
|
|
203
|
+
// 块尾可能截断标记:下一次从 position + read - (needle.length - 1) 续读
|
|
204
|
+
if (buffer.subarray(0, read).includes(needle)) return marker
|
|
205
|
+
if (read < buffer.length) return null
|
|
206
|
+
position += read - (needle.length - 1)
|
|
207
|
+
}
|
|
208
|
+
} finally {
|
|
209
|
+
try {
|
|
210
|
+
closeSync(fd)
|
|
211
|
+
} catch {
|
|
212
|
+
/* 关闭失败不影响结论 */
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* 探测宿主外壳是否**自带** cookie 清理(desktop `removeLegacyHostCookies`)。
|
|
219
|
+
*
|
|
220
|
+
* 为什么要有这个探测:官方在 desktop 0.2.2-rc.2 起自己会删 jar 里的 `dsh-auth-*`
|
|
221
|
+
* (走 Electron `session.cookies.remove`,比我们下发 Set-Cookie 更彻底、且能删掉
|
|
222
|
+
* 历史端口残留)。插件运行在 `ELECTRON_RUN_AS_NODE=1` 的纯 Node 子进程里,
|
|
223
|
+
* **拿不到** `session.cookies`,所以照抄不了官方手法,只能:
|
|
224
|
+
* - 官方有 → 让位(别再重复清理,两套一起跑只会让水位读数抖动);
|
|
225
|
+
* - 官方无(目标区间 0.2.1 ~ 0.2.2-rc.1)→ 用 HTTP Set-Cookie 兜底。
|
|
226
|
+
*
|
|
227
|
+
* 判定不靠版本号猜:直接读已安装外壳主进程代码里有没有那个函数名。
|
|
228
|
+
* 读不到(未打包 / 权限 / 非 Electron 布局)→ `present:false`,即**保持插件兜底**,
|
|
229
|
+
* 宁可多做一次幂等清理,也不要误判成“官方已经管了”而留下无人清理的 431 隐患。
|
|
230
|
+
*
|
|
231
|
+
* @param {{userDataRoot?:string, platform?:string, env?:object, readFile?:(file:string)=>string|null}} [input]
|
|
232
|
+
* @returns {{present:boolean, evidence:string, checked:string[]}}
|
|
233
|
+
*/
|
|
234
|
+
export function detectNativeCleanup(input = {}) {
|
|
235
|
+
const platform = input.platform ?? process.platform
|
|
236
|
+
const env = input.env ?? process.env
|
|
237
|
+
// asar 是打包容器:`readFileSync('app.asar/lib/main.js')` 只有 Electron 打过补丁的 fs
|
|
238
|
+
// 才读得到;插件跑在纯 Node 子进程(ELECTRON_RUN_AS_NODE=1)里没有那个补丁。
|
|
239
|
+
// 所以这里读不了就走**二进制分块扫描**——asar 数据段就是原文拼接,直接搜标记字符串即可,
|
|
240
|
+
// 不需要解析 header,也不受 200MB 体积拖累(分块 + 命中即停)。
|
|
241
|
+
const read = input.readFile ?? ((file) => {
|
|
242
|
+
try {
|
|
243
|
+
return fs.readFileSync(file, 'utf8')
|
|
244
|
+
} catch {
|
|
245
|
+
return scanBinaryFor(file, NATIVE_CLEANUP_MARKER)
|
|
246
|
+
}
|
|
247
|
+
})
|
|
248
|
+
const pathModule = platform === 'win32' ? path.win32 : path.posix
|
|
249
|
+
const roots = []
|
|
250
|
+
const explicit = String(input.userDataRoot || '').trim()
|
|
251
|
+
if (explicit) roots.push(explicit)
|
|
252
|
+
else {
|
|
253
|
+
const home = env.HOME || env.USERPROFILE || os.homedir()
|
|
254
|
+
if (platform === 'win32' && env.APPDATA) {
|
|
255
|
+
for (const name of PRODUCT_DIR_NAMES) roots.push(pathModule.join(env.APPDATA, name))
|
|
256
|
+
} else if (platform === 'darwin') {
|
|
257
|
+
for (const name of PRODUCT_DIR_NAMES) roots.push(pathModule.join(home, 'Library', 'Application Support', name))
|
|
258
|
+
} else {
|
|
259
|
+
for (const name of PRODUCT_DIR_NAMES) roots.push(pathModule.join(env.XDG_CONFIG_HOME || pathModule.join(home, '.config'), name))
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
const checked = []
|
|
263
|
+
// 外壳安装根不按 userData 推(userData 在 %APPDATA%\@deepseek-ai\dsh-desktop,
|
|
264
|
+
// 安装目录在 %LOCALAPPDATA%\Programs\DeepSeek Harness,两者不同源)。
|
|
265
|
+
// 只认显式给的安装根 + 少数平台惯例,读不到就保持兜底(fail-safe 到「插件来做」)。
|
|
266
|
+
// 显式给安装根 = **只查这一个**(单测/多实例隔离);不得再把平台默认目录掺进来,
|
|
267
|
+
// 否则「临时目录里没有标记」会被本机真实安装的存在掩盖成 present:true。
|
|
268
|
+
const explicitInstall = String(input.installRoot || '').trim()
|
|
269
|
+
const installRoots = []
|
|
270
|
+
if (explicitInstall !== '') {
|
|
271
|
+
installRoots.push(explicitInstall)
|
|
272
|
+
} else {
|
|
273
|
+
if (env.DSH_DESKTOP_HOME) installRoots.push(String(env.DSH_DESKTOP_HOME).trim())
|
|
274
|
+
const home = env.HOME || env.USERPROFILE || os.homedir()
|
|
275
|
+
if (platform === 'win32' && env.LOCALAPPDATA) {
|
|
276
|
+
installRoots.push(pathModule.join(env.LOCALAPPDATA, 'Programs', 'DeepSeek Harness'))
|
|
277
|
+
} else if (platform === 'darwin') {
|
|
278
|
+
installRoots.push('/Applications/DeepSeek Harness.app/Contents/Resources/app')
|
|
279
|
+
} else {
|
|
280
|
+
installRoots.push(pathModule.join(home, '.local', 'share', 'deepseek-harness'))
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
for (const root of explicitInstall !== '' ? installRoots : [...installRoots, ...roots]) {
|
|
284
|
+
if (!root) continue
|
|
285
|
+
// 打包布局:<app>/resources/app.asar/lib/main.js —— asar 是普通文件,能整读;
|
|
286
|
+
// 未打包(开发态):<app>/lib/main.js。两种都试,命中即判有。
|
|
287
|
+
for (const file of [
|
|
288
|
+
// asar 是**文件**不是目录:直接扫这个容器文件本身(数据段含 lib/main.js 原文)。
|
|
289
|
+
pathModule.join(root, 'resources', 'app.asar'),
|
|
290
|
+
pathModule.join(root, 'lib', 'main.js'),
|
|
291
|
+
]) {
|
|
292
|
+
if (checked.includes(file)) continue
|
|
293
|
+
checked.push(file)
|
|
294
|
+
const text = read(file)
|
|
295
|
+
if (text === null || text === undefined) continue
|
|
296
|
+
if (text.includes(NATIVE_CLEANUP_MARKER)) {
|
|
297
|
+
return { present: true, evidence: `宿主外壳自带 removeLegacyHostCookies(${pathModule.basename(file)})`, checked }
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
return { present: false, evidence: '未在已安装外壳里找到官方清理实现', checked }
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/** 存在性过滤:返回真实存在的候选库(带大小),一个都没有 → 空数组。 */
|
|
305
|
+
export function resolveCookieDbs({ userDataRoot = '', platform = process.platform, env = process.env } = {}) {
|
|
306
|
+
const found = []
|
|
307
|
+
for (const file of candidateCookieDbs(userDataRoot, platform, env)) {
|
|
308
|
+
const bytes = sizeOf(file)
|
|
309
|
+
if (bytes > 0) found.push({ path: file, bytes })
|
|
310
|
+
}
|
|
311
|
+
return found
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function sizeOf(file) {
|
|
315
|
+
try {
|
|
316
|
+
const stat = fs.statSync(file)
|
|
317
|
+
return stat.isFile() ? stat.size : 0
|
|
318
|
+
} catch { return 0 }
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/** sidecar 存在性(journal/wal 可能是 0 字节,但仍是恢复现场的一部分)。 */
|
|
322
|
+
function existsFile(file) {
|
|
323
|
+
try { return fs.statSync(file).isFile() } catch { return false }
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function loadSqlite(explicit) {
|
|
327
|
+
if (explicit) return explicit
|
|
328
|
+
try {
|
|
329
|
+
// Node ≥22.5 / Electron 44(Node 24)自带;缺失时上层降级为「只给处置文案」。
|
|
330
|
+
return require('node:sqlite')
|
|
331
|
+
} catch (e) {
|
|
332
|
+
throw new Error(`当前 Node 运行时无 node:sqlite(需要 Node ≥22.5):${e.message}`, { cause: e })
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* 打不开时的真实归因。
|
|
338
|
+
*
|
|
339
|
+
* 为什么不看错误码:实测(Linux / node:sqlite)chmod 000 与权限不足都只报
|
|
340
|
+
* `ERR_SQLITE_ERROR: unable to open database file`,根本不出 EACCES——按码分档会永远走不到
|
|
341
|
+
* 权限档,把人误报成“客户端在跑”。所以自己探:可读性 → 属主 → 才能回到“占用”。
|
|
342
|
+
* @returns {'busy'|'unreadable'|'not-owned'|'missing'}
|
|
343
|
+
*/
|
|
344
|
+
export function classifyOpenFailure(filePath) {
|
|
345
|
+
let stat
|
|
346
|
+
try {
|
|
347
|
+
const probed = fs.statSync(filePath)
|
|
348
|
+
stat = probed.isFile() ? probed : null
|
|
349
|
+
} catch {
|
|
350
|
+
stat = null
|
|
351
|
+
}
|
|
352
|
+
if (stat === null) return 'missing'
|
|
353
|
+
try {
|
|
354
|
+
fs.accessSync(filePath, fs.constants.R_OK)
|
|
355
|
+
} catch {
|
|
356
|
+
return 'unreadable'
|
|
357
|
+
}
|
|
358
|
+
if (process.platform !== 'win32' && typeof process.getuid === 'function' && stat && typeof stat.uid === 'number') {
|
|
359
|
+
if (stat.uid !== process.getuid()) return 'not-owned'
|
|
360
|
+
}
|
|
361
|
+
return 'busy'
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* 打不开 = 库被占用、路径不对或权限不够。文案带处置指引,避免用户回头找 AI 解析。
|
|
366
|
+
* 分档靠 {@link classifyOpenFailure}(不是错误码);EPERM 等 ambiguous 码仍走占用档。
|
|
367
|
+
*/
|
|
368
|
+
export class CookieBusyError extends Error {
|
|
369
|
+
constructor(filePath, cause, platform = process.platform, classify = classifyOpenFailure) {
|
|
370
|
+
const t = translator(lang)
|
|
371
|
+
const exit = exitFor(platform, t)
|
|
372
|
+
const kind = classify(filePath)
|
|
373
|
+
const key = kind === 'missing' ? 'adviseMissing' : kind === 'unreadable' ? 'advisePermission' : kind === 'not-owned' ? 'adviseOwner' : 'adviseBusy'
|
|
374
|
+
super(
|
|
375
|
+
t('openFailed', { path: filePath }) + '\n' + t('reason', { reason: cause && cause.message ? cause.message : String(cause) }) + '\n' + t(key, { exit }),
|
|
376
|
+
{ cause },
|
|
377
|
+
)
|
|
378
|
+
this.name = 'CookieBusyError'
|
|
379
|
+
// 只有真占用才是 busy;其余三档都是「找错地方/错用户」,处置不同
|
|
380
|
+
this.code = kind === 'busy' ? 'cookie-busy' : 'cookie-' + kind
|
|
381
|
+
this.kind = kind
|
|
382
|
+
this.path = filePath
|
|
383
|
+
this.cause = cause
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* 打开数据库。`write:true` 会立刻 `BEGIN IMMEDIATE`——拿不到保留写锁即抛
|
|
389
|
+
* {@link CookieBusyError},这就是「必须关闭客户端」的机械实现。
|
|
390
|
+
* 统一开 `readBigInts`:真实的 `expires_utc`(~1.34e16 微秒)超过 2^53,
|
|
391
|
+
* 默认按 Number 读会直接 `ERR_OUT_OF_RANGE`。
|
|
392
|
+
*/
|
|
393
|
+
export function openDatabase(filePath, { write = false, sqlite, timeoutMs = 150, platform = process.platform, classify } = {}) {
|
|
394
|
+
const { DatabaseSync } = loadSqlite(sqlite)
|
|
395
|
+
if (!sizeOf(filePath)) {
|
|
396
|
+
throw new CookieBusyError(filePath, new Error(translator(lang)('missingFile')), platform, classify)
|
|
397
|
+
}
|
|
398
|
+
const options = { timeout: timeoutMs, readBigInts: true }
|
|
399
|
+
let handle
|
|
400
|
+
try {
|
|
401
|
+
handle = write ? new DatabaseSync(filePath, options) : new DatabaseSync(filePath, { ...options, readOnly: true })
|
|
402
|
+
} catch (e) {
|
|
403
|
+
// 老运行时可能不认 readBigInts:降级重试一次,仍失败才算占用/权限。
|
|
404
|
+
if (!/readBigInts/.test(String(e && e.message))) throw new CookieBusyError(filePath, e, platform, classify)
|
|
405
|
+
try {
|
|
406
|
+
handle = write ? new DatabaseSync(filePath) : new DatabaseSync(filePath, { readOnly: true })
|
|
407
|
+
} catch (e2) {
|
|
408
|
+
throw new CookieBusyError(filePath, e2, platform, classify)
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
if (write) {
|
|
412
|
+
try {
|
|
413
|
+
handle.exec('BEGIN IMMEDIATE')
|
|
414
|
+
} catch (e) {
|
|
415
|
+
try { handle.close() } catch { /* 忽略二次错误 */ }
|
|
416
|
+
throw new CookieBusyError(filePath, e, platform, classify) }
|
|
417
|
+
}
|
|
418
|
+
return handle
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/** host_key 白名单 + name 前缀都过字符校验,杜绝把外部输入拼进语句。 */
|
|
422
|
+
function assertSafeIdentifiers(hostKeys, prefix) {
|
|
423
|
+
for (const key of hostKeys) {
|
|
424
|
+
if (!/^[A-Za-z0-9._:[\]-]{1,64}$/.test(key)) throw new Error(`非法 host_key:${key}`)
|
|
425
|
+
}
|
|
426
|
+
if (!/^[A-Za-z0-9._-]{1,64}$/.test(prefix)) throw new Error(`非法 cookie 名前缀:${prefix}`)
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* 删除语句 + 绑定参数。`expiredOnly` 走参数绑定(时间戳不拼字符串),
|
|
431
|
+
* 且以 BigInt 绑定——微秒时间戳超出 2^53。
|
|
432
|
+
*
|
|
433
|
+
* `olderThanHours`:只删 `creation_utc` 早于“现在 - N 小时”的条目(按**创建时间**清理,
|
|
434
|
+
* 不是按过期时间)。这条路径只有离线 CLI 能跑——它直连 SQLite 读得到 `creation_utc`;
|
|
435
|
+
* 运行期守护走 HTTP 读不到创建时间,所以守护侧没有这个开关。
|
|
436
|
+
* 可与 `expiredOnly` 叠加(AND,更保守)。
|
|
437
|
+
* @returns {{sql:string, values:Array<bigint|string>}}
|
|
438
|
+
*/
|
|
439
|
+
export function buildDeleteStatement({ expiredOnly = false, olderThanHours = 0, hostKeys = LOOPBACK_HOST_KEYS, prefix = AUTH_COOKIE_PREFIX } = {}) {
|
|
440
|
+
assertSafeIdentifiers(hostKeys, prefix)
|
|
441
|
+
const hosts = hostKeys.map((key) => `'${key}'`).join(', ')
|
|
442
|
+
const conds = [`host_key IN (${hosts})`, 'name LIKE ?']
|
|
443
|
+
const values = [`${prefix}%`]
|
|
444
|
+
if (expiredOnly) {
|
|
445
|
+
conds.push('expires_utc > 0', 'expires_utc <= ?')
|
|
446
|
+
values.push(BigInt(windowsNowMicroseconds()))
|
|
447
|
+
}
|
|
448
|
+
const hours = Number(olderThanHours)
|
|
449
|
+
if (Number.isFinite(hours) && hours > 0) {
|
|
450
|
+
// creation_utc 也是 Chromium 微秒时间戳;阈值 = 现在 - N 小时(Number 在 1e16 量级误差仅微秒级)
|
|
451
|
+
conds.push('creation_utc > 0', 'creation_utc <= ?')
|
|
452
|
+
values.push(BigInt(windowsNowMicroseconds() - Math.round(hours * 3_600_000_000)))
|
|
453
|
+
}
|
|
454
|
+
return { sql: `DELETE FROM cookies WHERE ${conds.join(' AND ')}`, values }
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
/** 表结构自检:不是 Chromium cookie 库就收手,绝不对未知库执行写语句。 */
|
|
458
|
+
function assertCookieSchema(handle) {
|
|
459
|
+
const table = handle.prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'cookies'").get()
|
|
460
|
+
if (table === undefined) throw new Error('目标库里没有 cookies 表,可能不是 Chromium cookie 库')
|
|
461
|
+
const columns = new Set(handle.prepare('PRAGMA table_info(cookies)').all().map((row) => String(row.name)))
|
|
462
|
+
for (const need of ['host_key', 'name', 'expires_utc']) {
|
|
463
|
+
if (!columns.has(need)) throw new Error(`cookies 表缺少 ${need} 列,拒绝执行`)
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
/** 只读统计。客户端在跑时可能抛 CookieBusyError → 降级成 verdict:'warn'/busy。 */
|
|
468
|
+
export function statCookies({ userDataRoot = '', explicitPath = '', env = process.env, sqlite, timeoutMs, platform = process.platform } = {}) {
|
|
469
|
+
const candidates = explicitPath ? [{ path: explicitPath, bytes: sizeOf(explicitPath) }] : resolveCookieDbs({ userDataRoot, platform, env })
|
|
470
|
+
if (candidates.length === 0) {
|
|
471
|
+
return { verdict: 'skipped', reason: 'not-found', candidates: candidateCookieDbs(userDataRoot, platform, env) }
|
|
472
|
+
}
|
|
473
|
+
const target = candidates[0]
|
|
474
|
+
let handle
|
|
475
|
+
try {
|
|
476
|
+
handle = openDatabase(target.path, { write: false, sqlite, timeoutMs, platform })
|
|
477
|
+
} catch (e) {
|
|
478
|
+
if (e instanceof CookieBusyError) {
|
|
479
|
+
const reason = e.kind === 'busy' ? 'busy' : e.kind === 'missing' ? 'missing' : 'permission'
|
|
480
|
+
return { verdict: 'warn', reason, ...target, candidates }
|
|
481
|
+
}
|
|
482
|
+
throw e
|
|
483
|
+
}
|
|
484
|
+
try {
|
|
485
|
+
assertCookieSchema(handle)
|
|
486
|
+
const total = toCount(handle.prepare('SELECT COUNT(*) AS c FROM cookies').get().c)
|
|
487
|
+
const byHost = handle.prepare('SELECT host_key, COUNT(*) AS c FROM cookies GROUP BY host_key ORDER BY c DESC').all()
|
|
488
|
+
// 名字长度是实测部分(明文),所以单独聚一次给占用折算用
|
|
489
|
+
const nameAgg = handle.prepare('SELECT COALESCE(SUM(LENGTH(name)), 0) AS n FROM cookies WHERE name LIKE ?').get(`${AUTH_COOKIE_PREFIX}%`)
|
|
490
|
+
const rows = handle.prepare('SELECT name, host_key, expires_utc FROM cookies WHERE name LIKE ? ORDER BY expires_utc DESC')
|
|
491
|
+
.all(`${AUTH_COOKIE_PREFIX}%`)
|
|
492
|
+
const now = BigInt(windowsNowMicroseconds())
|
|
493
|
+
let expired = 0
|
|
494
|
+
let live = 0
|
|
495
|
+
for (const row of rows) {
|
|
496
|
+
const microseconds = toBigInt(row.expires_utc)
|
|
497
|
+
if (microseconds > 0n && microseconds <= now) expired += 1
|
|
498
|
+
else live += 1
|
|
499
|
+
}
|
|
500
|
+
return {
|
|
501
|
+
verdict: rows.length === 0 ? 'ok' : 'warn',
|
|
502
|
+
reason: rows.length === 0 ? 'nothing-to-clean' : 'has-stale-entries',
|
|
503
|
+
...target,
|
|
504
|
+
candidates,
|
|
505
|
+
totalCookies: total,
|
|
506
|
+
authCookies: rows.length,
|
|
507
|
+
authExpired: expired,
|
|
508
|
+
authLive: live,
|
|
509
|
+
byHost: byHost.map((row) => ({ hostKey: String(row.host_key), count: toCount(row.c) })),
|
|
510
|
+
header: headerOccupancy({ count: rows.length, nameBytes: toCount(nameAgg.n) }),
|
|
511
|
+
newestExpiry: rows.length > 0 ? formatChromiumTimestamp(rows[0].expires_utc) : '',
|
|
512
|
+
oldestExpiry: rows.length > 0 ? formatChromiumTimestamp(rows[rows.length - 1].expires_utc) : '',
|
|
513
|
+
}
|
|
514
|
+
} finally {
|
|
515
|
+
handle.close()
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* 执行清理。默认档删掉回环域下**全部** `dsh-auth-*`(含未过期,安全性见文件头);
|
|
521
|
+
* `expiredOnly` 为保守档。写盘前先落 `.bak-<ts>`:主库副本失败即整单放弃(全有或全无),
|
|
522
|
+
* sidecar(-wal/-shm/journal)拷不上只记为跳过,不拦停。
|
|
523
|
+
* @param {{expiredOnly?:boolean,noBackup?:boolean,noVacuum?:boolean,dryRun?:boolean,explicitPath?:string,userDataRoot?:string,env?:object,sqlite?:object,timestamp?:() => string,platform?:string,copyFile?:(from:string,to:string)=>void}} options
|
|
524
|
+
*/
|
|
525
|
+
export function cleanCookies(options = {}) {
|
|
526
|
+
const {
|
|
527
|
+
expiredOnly = false, olderThanHours = 0, noBackup = false, noVacuum = false, dryRun = false,
|
|
528
|
+
explicitPath = '', userDataRoot = '', env = process.env, sqlite,
|
|
529
|
+
timestamp = () => defaultTimestamp(), platform = process.platform,
|
|
530
|
+
copyFile = (from, to) => fs.copyFileSync(from, to),
|
|
531
|
+
} = options
|
|
532
|
+
const found = explicitPath ? [{ path: explicitPath, bytes: sizeOf(explicitPath) }] : resolveCookieDbs({ userDataRoot, platform, env })
|
|
533
|
+
if (found.length === 0) {
|
|
534
|
+
return {
|
|
535
|
+
ok: false, code: 'not-found',
|
|
536
|
+
message: `没找到 cookie 库。候选路径:\n ${candidateCookieDbs(userDataRoot, platform, env).join('\n ')}\n可用 --db=<完整路径> 指定。`,
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
const target = found[0]
|
|
540
|
+
const { sql, values } = buildDeleteStatement({ expiredOnly, olderThanHours })
|
|
541
|
+
const selectSql = sql.replace('DELETE FROM', 'SELECT COUNT(*) AS c FROM')
|
|
542
|
+
const handle = openDatabase(target.path, { write: true, sqlite, platform })
|
|
543
|
+
try {
|
|
544
|
+
assertCookieSchema(handle)
|
|
545
|
+
const wouldDelete = Number(handle.prepare(selectSql).get(...values).c)
|
|
546
|
+
if (dryRun) {
|
|
547
|
+
handle.exec('ROLLBACK')
|
|
548
|
+
return { ok: true, dryRun: true, path: target.path, bytes: target.bytes, wouldDelete, sql, expiredOnly, olderThanHours }
|
|
549
|
+
}
|
|
550
|
+
let backup = ''
|
|
551
|
+
const backupSidecars = []
|
|
552
|
+
const skippedSidecars = []
|
|
553
|
+
if (!noBackup) {
|
|
554
|
+
const stamp = timestamp()
|
|
555
|
+
backup = `${target.path}.bak-${stamp}`
|
|
556
|
+
try {
|
|
557
|
+
copyFile(target.path, backup)
|
|
558
|
+
} catch (e) {
|
|
559
|
+
handle.exec('ROLLBACK')
|
|
560
|
+
throw new Error(`备份失败,已放弃写入(未做任何修改):${e.message}`, { cause: e })
|
|
561
|
+
}
|
|
562
|
+
// 连 WAL/journal 一起拷:POSIX 上未 checkpoint 的行在 -wal 里,只拷主文件是个残副本。
|
|
563
|
+
// 但 sidecar 失败不能反过来拦停清理:-shm 只是可再生的一致性索引,-wal 在拿到独占写锁后
|
|
564
|
+
// 已无并发写者,拷不上顶多丢失少量尚未落盘的会话 cookie,而主库副本是完整的。
|
|
565
|
+
for (const suffix of SIDECAR_SUFFIXES) {
|
|
566
|
+
const side = `${target.path}${suffix}`
|
|
567
|
+
if (!existsFile(side)) continue
|
|
568
|
+
try {
|
|
569
|
+
copyFile(side, `${backup}${suffix}`)
|
|
570
|
+
backupSidecars.push(suffix)
|
|
571
|
+
} catch {
|
|
572
|
+
skippedSidecars.push(suffix)
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
const deleted = Number(handle.prepare(sql).run(...values).changes)
|
|
577
|
+
handle.exec('COMMIT')
|
|
578
|
+
let afterBytes = sizeOf(target.path)
|
|
579
|
+
if (!noVacuum) {
|
|
580
|
+
try {
|
|
581
|
+
handle.exec('VACUUM')
|
|
582
|
+
afterBytes = sizeOf(target.path)
|
|
583
|
+
} catch { /* VACUUM 失败不影响已提交的结果 */ }
|
|
584
|
+
}
|
|
585
|
+
return {
|
|
586
|
+
ok: true, dryRun: false, path: target.path, beforeBytes: target.bytes, afterBytes,
|
|
587
|
+
deleted, backup, backupSidecars, skippedSidecars, sql, expiredOnly, olderThanHours,
|
|
588
|
+
}
|
|
589
|
+
} catch (e) {
|
|
590
|
+
try { handle.exec('ROLLBACK') } catch { /* 事务已结束,忽略 */ }
|
|
591
|
+
throw e
|
|
592
|
+
} finally {
|
|
593
|
+
handle.close()
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
function defaultTimestamp() {
|
|
598
|
+
return new Date().toISOString().replace(/[-:]/g, '').replace(/\..+/, '').replace('T', '-')
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
/** 借句柄快照的节流窗口(扫全机句柄表不免费)。 */
|
|
602
|
+
const LIVE_CACHE_MS = 60_000
|
|
603
|
+
const LIVE_MIN_GAP_MS = 5_000
|
|
604
|
+
/** 只缓存“哪个库的快照结果”,不缓存 cookie 内容本身。测试可传入自己的 store 隔离。 */
|
|
605
|
+
const liveCache = { at: Number.NEGATIVE_INFINITY, path: '', outcome: undefined }
|
|
606
|
+
|
|
607
|
+
/**
|
|
608
|
+
* 读数阶梯:先普通只读打开;只有因占用而读不到时,才去借目标进程已打开的句柄拿快照。
|
|
609
|
+
*
|
|
610
|
+
* 三条约束:
|
|
611
|
+
* - 快照结果必须带 `source:'borrowed-handle'` 与 `snapshot:true`,界面得说“不是实时”;
|
|
612
|
+
* - 借不到就原样返回 busy,**绝不把“没读到”洗成 0 条**;
|
|
613
|
+
* - 扫全机句柄表不免费:同一个库 60 秒内复用上一次结果,失败也至少隔 5 秒再试。
|
|
614
|
+
* @param {{read?:Function, snapshot?:Function, now?:()=>number, cacheMs?:number, minGapMs?:number, platform?:string, cache?:object}} [options] 余下选项透给读数函数
|
|
615
|
+
*/
|
|
616
|
+
export function statCookiesLive(options = {}) {
|
|
617
|
+
const {
|
|
618
|
+
read = statCookies, snapshot = snapshotThroughHandle, now = () => Date.now(),
|
|
619
|
+
cacheMs = LIVE_CACHE_MS, minGapMs = LIVE_MIN_GAP_MS, platform = process.platform,
|
|
620
|
+
cache = liveCache,
|
|
621
|
+
...stat
|
|
622
|
+
} = options
|
|
623
|
+
const plain = read(stat)
|
|
624
|
+
if (plain.reason !== 'busy' || typeof plain.path !== 'string' || platform !== 'win32') return plain
|
|
625
|
+
const stamp = now()
|
|
626
|
+
if (cache !== null && cache.path === plain.path && cache.outcome !== undefined) {
|
|
627
|
+
const fresh = stamp - cache.at < cacheMs && cache.outcome.snapshot === true
|
|
628
|
+
const cooling = stamp - cache.at < minGapMs
|
|
629
|
+
if (fresh || cooling) return { ...plain, ...cache.outcome }
|
|
630
|
+
}
|
|
631
|
+
let outcome
|
|
632
|
+
if (typeof snapshot !== 'function') {
|
|
633
|
+
outcome = { snapshot: false, liveUnavailable: true, liveReason: 'no-snapshotter' }
|
|
634
|
+
} else {
|
|
635
|
+
const borrowed = snapshot({ filePath: plain.path, now })
|
|
636
|
+
if (borrowed?.ok !== true) {
|
|
637
|
+
outcome = { snapshot: false, liveUnavailable: true, liveReason: borrowed?.reason ?? 'borrow-failed' }
|
|
638
|
+
} else {
|
|
639
|
+
try {
|
|
640
|
+
const snapStat = read({ ...stat, explicitPath: borrowed.snapshotPath })
|
|
641
|
+
outcome = snapStat.reason === 'busy' || snapStat.verdict === 'skipped'
|
|
642
|
+
? { snapshot: false, liveUnavailable: true, liveReason: 'snapshot-unreadable' }
|
|
643
|
+
: { ...snapStat, path: plain.path, source: 'borrowed-handle', snapshot: true, snapshotBytes: borrowed.bytes }
|
|
644
|
+
} catch (e) {
|
|
645
|
+
outcome = { snapshot: false, liveUnavailable: true, liveReason: `snapshot-error-${String(e && e.code ? e.code : e.message)}` }
|
|
646
|
+
} finally {
|
|
647
|
+
try { fs.rmSync(borrowed.snapshotPath, { force: true }) } catch { /* 临时快照残留不影响读数 */ }
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
cache.at = stamp
|
|
652
|
+
cache.path = plain.path
|
|
653
|
+
cache.outcome = outcome
|
|
654
|
+
return { ...plain, ...outcome }
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
/** 给 CLI / 命令共用的「现在是什么状况」一句话(把处置说全,避免二次求助)。 */
|
|
658
|
+
export function describeStat(stat) {
|
|
659
|
+
const t = translator(lang)
|
|
660
|
+
if (stat.verdict === 'skipped') return t('skipped')
|
|
661
|
+
if (stat.reason === 'busy') return t('statBusy', { path: stat.path })
|
|
662
|
+
if (stat.reason === 'permission') return t('statPermission', { path: stat.path })
|
|
663
|
+
if (stat.reason === 'missing') return t('statMissing', { path: stat.path })
|
|
664
|
+
if (stat.verdict === 'ok') return t('statClean', { path: stat.path, total: stat.totalCookies })
|
|
665
|
+
return t('statFound', {
|
|
666
|
+
count: stat.authCookies, expired: stat.authExpired, live: stat.authLive,
|
|
667
|
+
hosts: stat.byHost.length, bytes: stat.bytes, path: stat.path,
|
|
668
|
+
})
|
|
669
|
+
}
|