fix(browser): 源 Cookie 的 expires_utc 换算移入 SQL,避开 int64 越界

This commit is contained in:
Rick Ye
2026-09-13 01:07:29 +08:00
parent 5cf13f4396
commit d8c20022d8
@@ -306,8 +306,15 @@ async function readSourceCookies(root: string, staging: string): Promise<SourceC
const db = new DatabaseSync(dbFile, { readOnly: true })
try {
// expires_utc 是 1601 纪元的微秒 int64(超过 Number.MAX_SAFE_INTEGER,
// node:sqlite 裸读直接抛 ERR_OUT_OF_RANGE)——纪元换算放在 SQL 里做:
// int64 除法精确,结果秒值 ~4e8 在安全整数范围内
const rows = db
.prepare('SELECT host_key, name, value, encrypted_value, path, is_secure, is_httponly, expires_utc, samesite FROM cookies')
.prepare(
'SELECT host_key, name, value, encrypted_value, path, is_secure, is_httponly, ' +
'CASE WHEN expires_utc > 0 THEN expires_utc / 1000000 - 11644473600 ELSE 0 END AS expires_sec, ' +
'samesite FROM cookies'
)
.all()
const cookies: BrowserCookieSeed[] = []
let skipped = 0
@@ -321,7 +328,7 @@ async function readSourceCookies(root: string, staging: string): Promise<SourceC
path: string
is_secure: number
is_httponly: number
expires_utc: number
expires_sec: number
samesite: number | null
}
let value = r.value
@@ -340,7 +347,7 @@ async function readSourceCookies(root: string, staging: string): Promise<SourceC
path: r.path || '/',
secure: r.is_secure === 1,
httpOnly: r.is_httponly === 1,
...(r.expires_utc > 0 ? { expirationDate: r.expires_utc / 1_000_000 - 11_644_473_600 } : {}),
...(r.expires_sec > 0 ? { expirationDate: r.expires_sec } : {}),
...(mapSameSite(r.samesite) ? { sameSite: mapSameSite(r.samesite) } : {})
})
} catch {