feat: relay-key 共用模块(三桥 + homeagent)
Sha256 clamp relay_key 过 160 字节上限,避免服务端 400 被 worker 当暂时失败让位,导致邮件驱动会话无本地 UI 静默挂死。 新增 relay_key.go / relay-key.js + 15 个纯函数测试。
This commit is contained in:
20
plugins/dsh-mail-bridge/lib/relay-key.d.ts
vendored
Normal file
20
plugins/dsh-mail-bridge/lib/relay-key.d.ts
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
/** 服务端 relay_key 列宽(字节)。 */
|
||||
export const RELAY_KEY_MAX_BYTES: number;
|
||||
|
||||
/** UTF-8 字节数。 */
|
||||
export function byteLength(s: string | null | undefined): number;
|
||||
|
||||
/** 按字节截断,回退到最近的字符边界(不产生半个字符)。 */
|
||||
export function truncateToBytes(s: string | null | undefined, maxBytes: number): string;
|
||||
|
||||
/**
|
||||
* 把 relay_key 收敛到服务端能接受的长度。
|
||||
* 未超限时原样返回;超限时保留可读前缀 + `:sha256:<原始键的完整哈希>`。
|
||||
*/
|
||||
export function clampRelayKey(key: string | null | undefined, limit?: number): string;
|
||||
|
||||
/**
|
||||
* 这次失败是不是「永远不会成功」。
|
||||
* 4xx(除 408 / 429)= 永久;408 / 429 / 5xx / 无 status = 暂时。
|
||||
*/
|
||||
export function isPermanentFailure(err: { status?: number | string } | null | undefined): boolean;
|
||||
Reference in New Issue
Block a user