dsh-fishpal 0.9.0 → 0.9.5
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 +232 -0
- package/README.md +176 -16
- package/lib/bottle-ack.js +220 -0
- package/lib/bottle-crypto.js +179 -0
- package/lib/bottle-dedup.js +104 -0
- package/lib/bottle-gate.js +192 -0
- package/lib/bottle-pow.js +138 -0
- package/lib/bottle.js +358 -15
- package/lib/config.js +38 -1
- package/lib/guard.js +49 -0
- package/lib/index.js +838 -86
- package/lib/invite.js +134 -0
- package/lib/localserver.js +38 -2
- package/lib/loop.js +35 -2
- package/lib/peer.js +2 -2
- package/lib/pii.js +303 -0
- package/lib/protocol.js +65 -12
- package/lib/room.js +20 -1
- package/lib/ui.js +523 -14
- package/lib/visit.js +158 -0
- package/package.json +3 -2
- package/tests/run.mjs +176 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 漂流瓶工作量证明(PoW)
|
|
3
|
+
*
|
|
4
|
+
* ★ 2026-11-29 岸定的安全模型第三节第 3 条:
|
|
5
|
+
* 「每条漂流瓶独立 PoW,报文附带 nonce,接收节点验证哈希谜题。」
|
|
6
|
+
*
|
|
7
|
+
* 目的不是防某一个人,是**抬高批量刷屏的单价**:
|
|
8
|
+
* 发一只瓶子要花 0.5~2 秒 CPU,发一千只就是 500~2000 秒。
|
|
9
|
+
* 正常用户扔瓶子本来就慢(一天 5 只),这点开销感觉不到;
|
|
10
|
+
* 刷屏的人每多刷一只都要再算一次。
|
|
11
|
+
*
|
|
12
|
+
* ★ 难度按正文长度分级(规格第一条第 2 款):
|
|
13
|
+
* ≤16KB → 18 比特,期望约 26 万次哈希
|
|
14
|
+
* 16~64KB → 22 比特,期望约 420 万次哈希
|
|
15
|
+
* >64KB → 直接拒绝,不算 PoW
|
|
16
|
+
*
|
|
17
|
+
* ★ **耗时是随机变量,不是固定值 —— 这一点别写成死数字。**
|
|
18
|
+
* 2026-11-29 实测(同一台机器):
|
|
19
|
+
* 18 比特:376ms / 346,162 次
|
|
20
|
+
* 20 比特:1485ms / 1,385,879 次
|
|
21
|
+
* 22 比特:284ms / 282,898 次 ← 运气极好,28 万次就中了
|
|
22
|
+
* 22 比特的期望是 420 万次(约 4~5 秒),但方差极大:
|
|
23
|
+
* 可能 0.3 秒出结果,也可能十几秒。所以这里**不承诺任何固定耗时**,
|
|
24
|
+
* 只给预算上限(budgetMs),超了就说「没算完」,不假装成功。
|
|
25
|
+
* 长文多算,是因为长文占的带宽和别人的阅读时间都更多。
|
|
26
|
+
*
|
|
27
|
+
* ★ 校验端只算**一次**哈希 —— 生成才是慢的,验证是快的。
|
|
28
|
+
* 这一点很重要:收端不会因为别人发瓶子而卡。
|
|
29
|
+
*/
|
|
30
|
+
import { createHash } from 'node:crypto';
|
|
31
|
+
|
|
32
|
+
/** 正文大小分档(字节,UTF-8) */
|
|
33
|
+
export const SIZE_TIERS = [
|
|
34
|
+
{ maxBytes: 16 * 1024, difficulty: 18 },
|
|
35
|
+
{ maxBytes: 64 * 1024, difficulty: 22 },
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
/** 绝对上限:超过就不收了,也不给算 */
|
|
39
|
+
export const MAX_BOTTLE_BYTES = 64 * 1024;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 这段正文该用多少难度。
|
|
43
|
+
* @param {string} text
|
|
44
|
+
* @returns {{ok:true, difficulty:number, bytes:number} | {ok:false, reason:string, bytes:number}}
|
|
45
|
+
*/
|
|
46
|
+
export function difficultyFor(text) {
|
|
47
|
+
const s = String(text ?? '');
|
|
48
|
+
const bytes = Buffer.byteLength(s, 'utf8');
|
|
49
|
+
if (bytes > MAX_BOTTLE_BYTES) {
|
|
50
|
+
return { ok: false, bytes, reason: `正文 ${(bytes / 1024).toFixed(1)}KB,超过 64KB 硬上限` };
|
|
51
|
+
}
|
|
52
|
+
for (const t of SIZE_TIERS) {
|
|
53
|
+
if (bytes <= t.maxBytes) return { ok: true, difficulty: t.difficulty, bytes };
|
|
54
|
+
}
|
|
55
|
+
// 走不到这里(上面已经拦了 >MAX),兜底给最高档
|
|
56
|
+
return { ok: true, difficulty: SIZE_TIERS[SIZE_TIERS.length - 1].difficulty, bytes };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** 哈希里前导零比特数 */
|
|
60
|
+
export function leadingZeroBits(hex) {
|
|
61
|
+
const buf = Buffer.from(String(hex), 'hex');
|
|
62
|
+
let bits = 0;
|
|
63
|
+
for (const byte of buf) {
|
|
64
|
+
if (byte === 0) {
|
|
65
|
+
bits += 8;
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
// 找这个字节里最高位的 1 在第几位
|
|
69
|
+
bits += Math.clz32(byte) - 24;
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
return bits;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* PoW 的被签内容。★ 必须和验证端完全一致,差一个字符就通不过。
|
|
77
|
+
* 用 bottleId 做域隔离:同一段文字换个瓶子发,nonce 不能复用。
|
|
78
|
+
*/
|
|
79
|
+
export function powBase({ bottleId, text, anonPub }) {
|
|
80
|
+
return `fishpal-bottle-pow-v1|${String(bottleId || '')}|${String(anonPub || '')}|${String(text || '')}`;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** 单次校验:算一次哈希,看前导零够不够 */
|
|
84
|
+
export function verifyPow({ bottleId, text, anonPub, nonce, difficulty }) {
|
|
85
|
+
const d = Number(difficulty);
|
|
86
|
+
if (!Number.isFinite(d) || d <= 0) return { ok: false, reason: '难度不合法' };
|
|
87
|
+
if (!Number.isFinite(Number(nonce)) || Number(nonce) < 0) return { ok: false, reason: '没有 nonce' };
|
|
88
|
+
const base = powBase({ bottleId, text, anonPub });
|
|
89
|
+
const h = createHash('sha256').update(`${base}|${Number(nonce)}`).digest('hex');
|
|
90
|
+
const bits = leadingZeroBits(h);
|
|
91
|
+
if (bits < d) {
|
|
92
|
+
return { ok: false, reason: `PoW 不够(${bits} < ${d} 比特)`, bits, need: d };
|
|
93
|
+
}
|
|
94
|
+
return { ok: true, bits };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* 解题。★ 异步 —— 每算一批就让出事件循环,否则发送端界面会僵。
|
|
99
|
+
*
|
|
100
|
+
* @param {string} text
|
|
101
|
+
* @param {{bottleId:string, anonPub:string, difficulty?:number, budgetMs?:number}} opts
|
|
102
|
+
* @returns {Promise<{ok:true, nonce:number, difficulty:number, ms:number, tries:number}
|
|
103
|
+
* | {ok:false, reason:string, ms:number, tries:number}>}
|
|
104
|
+
*/
|
|
105
|
+
export async function solvePow(text, opts = {}) {
|
|
106
|
+
const t0 = Date.now();
|
|
107
|
+
const auto = difficultyFor(text);
|
|
108
|
+
if (!auto.ok) return { ok: false, reason: auto.reason, ms: 0, tries: 0 };
|
|
109
|
+
const difficulty = Number(opts.difficulty) || auto.difficulty;
|
|
110
|
+
const bottleId = String(opts.bottleId || '');
|
|
111
|
+
const anonPub = String(opts.anonPub || '');
|
|
112
|
+
const budgetMs = Number(opts.budgetMs) || 15_000; // 按 22 比特最坏情况留余量
|
|
113
|
+
const base = powBase({ bottleId, text, anonPub });
|
|
114
|
+
const prefix = Buffer.from(base, 'utf8');
|
|
115
|
+
|
|
116
|
+
let tries = 0;
|
|
117
|
+
let nonce = 0;
|
|
118
|
+
// 每批 4096 次哈希一次让出 —— 换得够勤,界面不卡;换得够少,开销不明显
|
|
119
|
+
for (;;) {
|
|
120
|
+
for (let i = 0; i < 4096; i++) {
|
|
121
|
+
const h = createHash('sha256')
|
|
122
|
+
.update(prefix)
|
|
123
|
+
.update('|')
|
|
124
|
+
.update(String(nonce + i))
|
|
125
|
+
.digest('hex');
|
|
126
|
+
if (leadingZeroBits(h) >= difficulty) {
|
|
127
|
+
return { ok: true, nonce: nonce + i, difficulty, ms: Date.now() - t0, tries: tries + i + 1 };
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
tries += 4096;
|
|
131
|
+
nonce += 4096;
|
|
132
|
+
if (Date.now() - t0 > budgetMs) {
|
|
133
|
+
return { ok: false, reason: `算了 ${budgetMs}ms 还没出结果(难度 ${difficulty})`, ms: Date.now() - t0, tries };
|
|
134
|
+
}
|
|
135
|
+
// 让出事件循环一次
|
|
136
|
+
await new Promise((r) => setImmediate(r));
|
|
137
|
+
}
|
|
138
|
+
}
|
package/lib/bottle.js
CHANGED
|
@@ -16,13 +16,35 @@
|
|
|
16
16
|
import fs from 'node:fs';
|
|
17
17
|
import path from 'node:path';
|
|
18
18
|
import crypto from 'node:crypto';
|
|
19
|
-
import { signPayload } from './crypto.js';
|
|
19
|
+
import { signPayload, verifyPayload } from './crypto.js';
|
|
20
|
+
import { newBottleKey, bottleKeyOf, sealReplyText, openReplyText } from './bottle-crypto.js';
|
|
21
|
+
import * as pow from './bottle-pow.js';
|
|
20
22
|
|
|
21
23
|
export const MAX_TEXT_CHARS = 500;
|
|
22
24
|
export const MAX_DRAFTS = 50;
|
|
23
25
|
/** 瓶子保质期(天)。过了就当它漂走了 —— 不占地方,也不让人看见一句陈年的话。 */
|
|
24
26
|
export const BOTTLE_TTL_DAYS = 7;
|
|
25
27
|
|
|
28
|
+
// ── 安全模型(2026-11-29 岸定的规格)──────────────────────────────────
|
|
29
|
+
// ★ 字段白名单(规格一.3):只认这些,别的字段**丢弃**(不是拒收报文)。
|
|
30
|
+
// 这样以后加新字段,老版本不认识也不至于把整只瓶子扔掉。
|
|
31
|
+
const BOTTLE_FIELDS = new Set([
|
|
32
|
+
'type',
|
|
33
|
+
'ver',
|
|
34
|
+
'bottle_id',
|
|
35
|
+
'text',
|
|
36
|
+
'enable_locate',
|
|
37
|
+
'qq_nick',
|
|
38
|
+
'anon_pub',
|
|
39
|
+
'anon_sign_pub',
|
|
40
|
+
'sent_at',
|
|
41
|
+
'expire_at',
|
|
42
|
+
'nonce', // PoW 的解
|
|
43
|
+
'signature',
|
|
44
|
+
]);
|
|
45
|
+
/** 时间戳窗口(规格一.4):±15 分钟,防重放 */
|
|
46
|
+
const CLOCK_SKEW_MS = 15 * 60_000;
|
|
47
|
+
|
|
26
48
|
function keyFile(dataDir) {
|
|
27
49
|
return path.join(dataDir, 'bottle-key.json');
|
|
28
50
|
}
|
|
@@ -69,6 +91,124 @@ export function ensureAnonIdentity(dataDir) {
|
|
|
69
91
|
return id;
|
|
70
92
|
}
|
|
71
93
|
|
|
94
|
+
/**
|
|
95
|
+
* 只读匿名身份:没建过就返回 null,**绝不顺手创建**。
|
|
96
|
+
*
|
|
97
|
+
* ★ 为什么要跟 ensureAnonIdentity 分开(2026-11-29):
|
|
98
|
+
* 收瓶子的时候要用它判断「这条是不是我自己发的」。
|
|
99
|
+
* 如果那里调 ensure 版,一台从没发过瓶子的机器只要收到一只别人的瓶子,
|
|
100
|
+
* 就会凭空生成一把匿名私钥 —— 那是没必要的副作用,也让「有没有发过」这件事失真。
|
|
101
|
+
*/
|
|
102
|
+
export function loadAnonIdentity(dataDir) {
|
|
103
|
+
try {
|
|
104
|
+
const parsed = JSON.parse(fs.readFileSync(keyFile(dataDir), 'utf8'));
|
|
105
|
+
if (parsed?.exchange?.public && parsed?.signing?.public) return parsed;
|
|
106
|
+
} catch {
|
|
107
|
+
/* 没有就是没有 */
|
|
108
|
+
}
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* 校验一只从公共池捡到的瓶子(纯函数,不落盘、不要 dataDir)。
|
|
114
|
+
*
|
|
115
|
+
* ★ 顺序不能换:
|
|
116
|
+
* ① 解析 → ② 结构 → ③ **验签** → ④ 排自己 → ⑤ 排过期。
|
|
117
|
+
* 为什么验签必须在「排自己」之前:不验签的话,谁都能把 anon_sign_pub 伪装成
|
|
118
|
+
* 我的公钥,让这条被当成「自己发的」悄悄丢掉 —— 那是拿丢弃当攻击面。
|
|
119
|
+
* 先验签,再谈内容。
|
|
120
|
+
*
|
|
121
|
+
* @param {string} raw MQTT 收到的原始字符串
|
|
122
|
+
* @param {string|null} mySignPub 本机的匿名签名公钥(没建过身份就传 null)
|
|
123
|
+
* @returns {{ok:true, packet:object} | {ok:false, reason:string}}
|
|
124
|
+
*/
|
|
125
|
+
export function verifyBottlePacket(raw, mySignPub, now = Date.now()) {
|
|
126
|
+
let pkt;
|
|
127
|
+
try {
|
|
128
|
+
pkt = JSON.parse(String(raw ?? ''));
|
|
129
|
+
} catch {
|
|
130
|
+
return { ok: false, reason: '不是 JSON' };
|
|
131
|
+
}
|
|
132
|
+
if (!pkt || typeof pkt !== 'object' || Array.isArray(pkt)) return { ok: false, reason: '不是对象' };
|
|
133
|
+
if (pkt.type !== 'bottle') return { ok: false, reason: `type 是 ${pkt.type}` };
|
|
134
|
+
if (pkt.ver !== 1) return { ok: false, reason: `ver 是 ${pkt.ver}` };
|
|
135
|
+
|
|
136
|
+
const { signature, ...rawBody } = pkt;
|
|
137
|
+
if (typeof rawBody.anon_sign_pub !== 'string' || !rawBody.anon_sign_pub) {
|
|
138
|
+
return { ok: false, reason: '没有签名公钥' };
|
|
139
|
+
}
|
|
140
|
+
if (typeof signature !== 'string' || !signature) {
|
|
141
|
+
return { ok: false, reason: '没有签名' };
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// ① 字段白名单(规格一.3):额外自定义字段**丢弃**,但不丢整条报文。
|
|
145
|
+
// ★ 注意这里是「从 body 里挑」,不是「拒绝报文」—— 以后加新字段,
|
|
146
|
+
// 老版本不认识、也不会因此拒收,兼容性是这么留的。
|
|
147
|
+
const body = {};
|
|
148
|
+
for (const k of BOTTLE_FIELDS) if (k in rawBody) body[k] = rawBody[k];
|
|
149
|
+
|
|
150
|
+
// ② 正文与大小分级(规格一.1 / 一.2):纯文本、64KB 硬上限
|
|
151
|
+
if (typeof body.text !== 'string' || !body.text.trim()) return { ok: false, reason: '没有正文' };
|
|
152
|
+
const size = pow.difficultyFor(body.text);
|
|
153
|
+
if (!size.ok) return { ok: false, reason: size.reason, bytes: size.bytes };
|
|
154
|
+
|
|
155
|
+
// ③ 验签 —— ★ 用**原始**对象验,不能用过滤后的 body。
|
|
156
|
+
// 签名签的是发送端发出去的那个对象,我这边丢掉扩展字段再验就一定对不上。
|
|
157
|
+
// (2026-11-29:这条顺序搞反过一次,删字段和验签谁先谁后是硬约束)
|
|
158
|
+
let sigOk = false;
|
|
159
|
+
try {
|
|
160
|
+
sigOk = verifyPayload(JSON.stringify(rawBody), signature, rawBody.anon_sign_pub);
|
|
161
|
+
} catch (e) {
|
|
162
|
+
// ★ 2026-11-29:这里原来是个空 catch —— 它把「verifyPayload 没 import」这种
|
|
163
|
+
// 程序错误也吞成「签名对不上」。实测代价:函数写完忘了 import,10 条断言里
|
|
164
|
+
// 4 条红,报的全是「签名对不上」,我查了三轮才查到 import 上。
|
|
165
|
+
// 现在把原因带出去:报文坏了和代码坏了,日志里必须分得开。
|
|
166
|
+
return { ok: false, reason: `验签出错:${e?.message ?? e}` };
|
|
167
|
+
}
|
|
168
|
+
if (!sigOk) return { ok: false, reason: '签名对不上' };
|
|
169
|
+
|
|
170
|
+
// 走到这里,这条确实是 anon_sign_pub 那把钥匙发的、中途没被改过
|
|
171
|
+
if (mySignPub && rawBody.anon_sign_pub === mySignPub) {
|
|
172
|
+
return { ok: false, reason: '这是我自己发的' };
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// ④ 时间戳窗口(规格一.4):±15 分钟,防重放。
|
|
176
|
+
// ★ 只对**带了** sent_at 的报文生效 —— 缺时间戳是「不知道」,
|
|
177
|
+
// 不等于「伪造」;那条交给过期检查。
|
|
178
|
+
const sentMs = Date.parse(body.sent_at || '');
|
|
179
|
+
if (Number.isFinite(sentMs)) {
|
|
180
|
+
const skew = Math.abs(now - sentMs);
|
|
181
|
+
if (skew > CLOCK_SKEW_MS) {
|
|
182
|
+
return {
|
|
183
|
+
ok: false,
|
|
184
|
+
reason: `发送时间偏了 ${Math.round(skew / 60_000)} 分钟(窗口 ±${CLOCK_SKEW_MS / 60_000} 分钟),拒收`,
|
|
185
|
+
skewMs: skew,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// ⑤ 过期(老字段,跟时间窗口不重复:这个管「瓶子本身过期了」)
|
|
191
|
+
const exp = body.expire_at ? Date.parse(body.expire_at) : 0;
|
|
192
|
+
if (Number.isFinite(exp) && exp > 0 && exp < now) {
|
|
193
|
+
return { ok: false, reason: '过期了' };
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// ⑥ PoW(规格三.3)—— ★ 难度由**接收端**按正文长度自己算,
|
|
197
|
+
// 绝不看报文里声明了什么:报文能写「难度 0」,那我这边就等于没设防。
|
|
198
|
+
const pw = pow.verifyPow({
|
|
199
|
+
bottleId: body.bottle_id,
|
|
200
|
+
text: body.text,
|
|
201
|
+
anonPub: body.anon_pub,
|
|
202
|
+
nonce: body.nonce,
|
|
203
|
+
difficulty: size.difficulty,
|
|
204
|
+
});
|
|
205
|
+
if (!pw.ok) {
|
|
206
|
+
return { ok: false, reason: `PoW 没过:${pw.reason}`, powBits: pw.bits, powNeed: size.difficulty };
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return { ok: true, packet: body, powBits: pw.bits, difficulty: size.difficulty };
|
|
210
|
+
}
|
|
211
|
+
|
|
72
212
|
export function loadDrafts(dataDir) {
|
|
73
213
|
try {
|
|
74
214
|
const parsed = JSON.parse(fs.readFileSync(draftFile(dataDir), 'utf8'));
|
|
@@ -164,6 +304,120 @@ export function unblockAnon(dataDir, anonSignPub) {
|
|
|
164
304
|
return { ok: true, count: next.length };
|
|
165
305
|
}
|
|
166
306
|
|
|
307
|
+
// ── 漂流档案(2026-11-29)──────────────────────────────────────────────
|
|
308
|
+
//
|
|
309
|
+
// 「档案」跟「收到的瓶子」是两件事,岸在规格里说得很清楚:
|
|
310
|
+
// · 收到的 = **被动的**:谁发过什么,按时间排,会被 expire / 进隔离区 / 被清掉
|
|
311
|
+
// · 档案 = **主动的**:我捡到一只好的,点了「存念」,它进一个**永不清理**的列表
|
|
312
|
+
//
|
|
313
|
+
// 所以这里刻意不跟 quarantine / drafts 走同一条路:
|
|
314
|
+
// ① 独立文件(favorites.json),谁的清理逻辑都碰不到它
|
|
315
|
+
// ② 没写任何 TTL / prune —— 存了就是存了,只有人自己点「不再存」才消失
|
|
316
|
+
// ③ 存的是**当时那份快照**(正文 + 昵称 + 时间),不是引用 ——
|
|
317
|
+
// 引用会随隔离区清理而指向空气,那就不是「档案」了。
|
|
318
|
+
function favoritesFile(dataDir) {
|
|
319
|
+
return path.join(dataDir, 'favorites.json');
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/** 读全部存念,新的在前。坏文件当空处理,别让界面打不开。 */
|
|
323
|
+
export function loadFavorites(dataDir) {
|
|
324
|
+
try {
|
|
325
|
+
const parsed = JSON.parse(fs.readFileSync(favoritesFile(dataDir), 'utf8'));
|
|
326
|
+
const list = Array.isArray(parsed && parsed.favorites) ? parsed.favorites : [];
|
|
327
|
+
return list
|
|
328
|
+
.filter((x) => x && typeof x.id === 'string' && x.id)
|
|
329
|
+
.map((x) => ({
|
|
330
|
+
id: String(x.id),
|
|
331
|
+
text: typeof x.text === 'string' ? x.text : '',
|
|
332
|
+
nick: typeof x.nick === 'string' ? x.nick : '',
|
|
333
|
+
savedAt: Number(x.savedAt) || 0,
|
|
334
|
+
fromBottleId: typeof x.fromBottleId === 'string' ? x.fromBottleId : '',
|
|
335
|
+
}))
|
|
336
|
+
.sort((a, b) => b.savedAt - a.savedAt);
|
|
337
|
+
} catch {
|
|
338
|
+
return [];
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
function saveFavorites(dataDir, favorites) {
|
|
343
|
+
try {
|
|
344
|
+
fs.mkdirSync(dataDir, { recursive: true });
|
|
345
|
+
const tmp = favoritesFile(dataDir) + '.tmp';
|
|
346
|
+
fs.writeFileSync(tmp, JSON.stringify({ schemaVersion: 1, favorites }, null, 2), {
|
|
347
|
+
encoding: 'utf8',
|
|
348
|
+
mode: 0o600,
|
|
349
|
+
});
|
|
350
|
+
fs.renameSync(tmp, favoritesFile(dataDir));
|
|
351
|
+
return true;
|
|
352
|
+
} catch {
|
|
353
|
+
return false;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* 存念一只瓶子。★ 同一只瓶子重复存不重复入档(id 一样就覆盖成最新的那份快照)。
|
|
359
|
+
* @returns {{ok:boolean, count?:number, error?:string}}
|
|
360
|
+
*/
|
|
361
|
+
export function addFavorite(dataDir, { text, nick = '', fromBottleId = '' } = {}) {
|
|
362
|
+
const body = String(text || '').trim();
|
|
363
|
+
if (!body) return { ok: false, error: '空的,存不下来' };
|
|
364
|
+
const all = loadFavorites(dataDir);
|
|
365
|
+
const id = String(fromBottleId || '').trim() || `fav_${Date.now().toString(36)}`;
|
|
366
|
+
const rest = all.filter((x) => x.id !== id);
|
|
367
|
+
rest.push({ id, text: body, nick: String(nick || '').slice(0, 40), savedAt: Date.now(), fromBottleId: String(fromBottleId || '') });
|
|
368
|
+
if (!saveFavorites(dataDir, rest)) return { ok: false, error: '存不下来' };
|
|
369
|
+
return { ok: true, count: rest.length };
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/** 从档案里拿掉一条(「不再存了」)。★ 这是唯一能让存念消失的方式。 */
|
|
373
|
+
export function removeFavorite(dataDir, id) {
|
|
374
|
+
const key = String(id || '').trim();
|
|
375
|
+
if (!key) return { ok: false, error: '要删哪条?' };
|
|
376
|
+
const all = loadFavorites(dataDir);
|
|
377
|
+
const next = all.filter((x) => x.id !== key);
|
|
378
|
+
if (next.length === all.length) return { ok: false, error: '档案里没有这一条' };
|
|
379
|
+
if (!saveFavorites(dataDir, next)) return { ok: false, error: '删不掉' };
|
|
380
|
+
return { ok: true, count: next.length };
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/** 给界面用:档案列表 + 哪几条已经在档案里(渲染那个「已存念」按钮状态) */
|
|
384
|
+
export function favoritesForUi(dataDir) {
|
|
385
|
+
const list = loadFavorites(dataDir);
|
|
386
|
+
return { count: list.length, items: list, ids: list.map((x) => x.id) };
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* 从隔离队列里按 id 取一只瓶子的正文(存念用)。
|
|
391
|
+
*
|
|
392
|
+
* ★ 为什么要有这个函数,而不是让界面把正文一起送上来(2026-11-29):
|
|
393
|
+
* 界面上那份正文是**解包出来给人看的**,界面能改 DOM 就能改它。
|
|
394
|
+
* 让「存念」信界面送来的正文,等于给了一个「把任意字符串塞进永久档案」的入口。
|
|
395
|
+
* 所以正文只从本机的隔离队列取 —— 那里是收消息时写下的原始快照。
|
|
396
|
+
*
|
|
397
|
+
* ★ 取不到就是取不到(瓶子被清理了 / 旧版本没 id),返回 {ok:false} 让人看见,
|
|
398
|
+
* 不许回退成「那用界面送来那份吧」—— 那正是上面要挡住的那条路。
|
|
399
|
+
*
|
|
400
|
+
* @param {Array} quarantine 隔离队列(每项 {id, text, ...},text 是收到的原始报文 JSON)
|
|
401
|
+
* @returns {{ok:true, text:string, nick:string} | {ok:false, error:string}}
|
|
402
|
+
*/
|
|
403
|
+
export function resolveBottleBody(quarantine, id) {
|
|
404
|
+
const want = String(id || '');
|
|
405
|
+
if (!want) return { ok: false, error: '没给瓶子 id' };
|
|
406
|
+
const list = Array.isArray(quarantine) ? quarantine : [];
|
|
407
|
+
const rec = list.find((q) => q && String(q.id) === want);
|
|
408
|
+
if (!rec) return { ok: false, error: '找不到这只瓶子(可能已经被清理了)' };
|
|
409
|
+
let pkt = null;
|
|
410
|
+
try {
|
|
411
|
+
pkt = JSON.parse(String(rec.text || '{}'));
|
|
412
|
+
} catch {
|
|
413
|
+
return { ok: false, error: '这只瓶子的正文读不出来(报文坏了)' };
|
|
414
|
+
}
|
|
415
|
+
const body = String((pkt && pkt.text) || '').trim();
|
|
416
|
+
if (!body) return { ok: false, error: '这只瓶子里没有正文' };
|
|
417
|
+
return { ok: true, text: body, nick: String((pkt && pkt.qq_nick) || '') };
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
|
|
167
421
|
/** 飘出去的瓶子只该留个记号,正文该丢 —— 但草稿阶段要留着给人看 */
|
|
168
422
|
const DONE_KEEP_DAYS = 7;
|
|
169
423
|
|
|
@@ -287,6 +541,27 @@ export function listRejectedDrafts(dataDir, { limit = 10 } = {}) {
|
|
|
287
541
|
.slice(0, limit);
|
|
288
542
|
}
|
|
289
543
|
|
|
544
|
+
/**
|
|
545
|
+
* 把「被主人打回的草稿」排成一段话,塞进鱼每次碰瓶子时的返回里。
|
|
546
|
+
*
|
|
547
|
+
* ★ 为什么不靠投递:DSH 的 tool context 不传 sessionId,插件认不出鱼是在哪个
|
|
548
|
+
* 会话里写的瓶子,所以「投给正在做的那边」做不到。改成「一碰就看见」——
|
|
549
|
+
* 鱼不管在哪个窗口动手,只要调 fishpal_bottle,这段就在它眼前。
|
|
550
|
+
* ★ 空数组返回空串:没被打回时整段不该出现,别留个没有内容的标题。
|
|
551
|
+
*/
|
|
552
|
+
export function formatRejectHint(rejected = []) {
|
|
553
|
+
if (!Array.isArray(rejected) || !rejected.length) return '';
|
|
554
|
+
const lines = [`⚠ 有 ${rejected.length} 只瓶子被主人打回了 —— 先看这个,再写新的:`];
|
|
555
|
+
rejected.forEach((d, i) => {
|
|
556
|
+
const said = d.note ? `他说的:${d.note}` : '(他没留意见,只说了不要这条)';
|
|
557
|
+
const full = String(d.text ?? '');
|
|
558
|
+
const body = full.slice(0, 60) + (full.length > 60 ? '…' : '');
|
|
559
|
+
lines.push(`${i + 1}. ${said}`, ` 被打回的是:「${body}」`);
|
|
560
|
+
});
|
|
561
|
+
lines.push('打回 ≠ 丢弃:正文归你,照这个意见重写一只,别去改他只是提意见的地方。');
|
|
562
|
+
return '\n\n' + lines.join('\n');
|
|
563
|
+
}
|
|
564
|
+
|
|
290
565
|
function decide(dataDir, id, status) {
|
|
291
566
|
const drafts = pruneDone(loadDrafts(dataDir));
|
|
292
567
|
const d = drafts.find((x) => x && x.id === id && x.status === 'draft');
|
|
@@ -307,12 +582,20 @@ export function dropDraft(dataDir, id) {
|
|
|
307
582
|
* ★ 这份报文里**没有** fp_xxx、没有 QQ 群号、没有 IP。
|
|
308
583
|
* 只有:正文、是否留位置、昵称(可选)、匿名公钥、签名。
|
|
309
584
|
*/
|
|
310
|
-
export function buildBottlePacket(dataDir, id, now = new Date().toISOString()) {
|
|
585
|
+
export async function buildBottlePacket(dataDir, id, now = new Date().toISOString()) {
|
|
311
586
|
const drafts = loadDrafts(dataDir);
|
|
312
587
|
const d = drafts.find((x) => x && x.id === id && x.status === 'draft');
|
|
313
588
|
if (!d) return { ok: false, error: '没有这条草稿' };
|
|
314
589
|
|
|
315
|
-
|
|
590
|
+
// ★ 2026-11-29(岸:「漂流瓶的密码是单独的,用一次换一次」):
|
|
591
|
+
// 每只瓶子一把新钥匙,私钥按 bottle_id 存本地。
|
|
592
|
+
// 原来这里用的是 ensureAnonIdentity 的**长期**密钥 —— 所有瓶子同一把,
|
|
593
|
+
// 别人能把「这些瓶子是同一个人扔的」串起来。
|
|
594
|
+
// 匿名只是「不知道你是谁」,不等于「不能把你干的事连起来」。
|
|
595
|
+
const made = newBottleKey(dataDir, d.id);
|
|
596
|
+
if (!made.ok) return { ok: false, error: made.error };
|
|
597
|
+
const mine = bottleKeyOf(dataDir, d.id);
|
|
598
|
+
if (!mine) return { ok: false, error: '瓶子的钥匙没存下来,这只先别发(存盘失败)' };
|
|
316
599
|
// ★ 过期时间也写进报文(手册 6.7 的风控):
|
|
317
600
|
// 收方不用回头问发送方就知道这只瓶子还值不值得看。
|
|
318
601
|
// 算不出来就别硬编一个 —— 没有 expire_at 的老报文按「不知道过期时间」处理,
|
|
@@ -327,20 +610,32 @@ export function buildBottlePacket(dataDir, id, now = new Date().toISOString()) {
|
|
|
327
610
|
text: d.text,
|
|
328
611
|
enable_locate: Boolean(d.enableLocate),
|
|
329
612
|
qq_nick: d.qqNick || null,
|
|
330
|
-
|
|
331
|
-
|
|
613
|
+
// ★ 这只瓶子自己的公钥 —— 不是长期身份那把。
|
|
614
|
+
// 别人拿到它才能加密回信,而且和其他瓶子不可关联。
|
|
615
|
+
anon_pub: mine.exchange.public,
|
|
616
|
+
anon_sign_pub: mine.signing.public,
|
|
332
617
|
sent_at: now,
|
|
333
618
|
expire_at: Number.isFinite(sentMs)
|
|
334
619
|
? new Date(sentMs + BOTTLE_TTL_DAYS * 86400_000).toISOString()
|
|
335
620
|
: null,
|
|
336
621
|
};
|
|
622
|
+
// ★ 2026-11-29(安全模型三.3):发之前先算 PoW。
|
|
623
|
+
// ★ 这步是 async 的 —— 算力证明要跑几百毫秒到几秒,同步算会把界面冻住。
|
|
624
|
+
// ★ nonce 必须在**签名之前**放进去:签名签的是整个 payload,
|
|
625
|
+
// 先签后补 nonce 就等于签名作废。
|
|
626
|
+
const solved = await pow.solvePow(d.text, { bottleId: d.id, anonPub: mine.exchange.public });
|
|
627
|
+
if (!solved.ok) {
|
|
628
|
+
return { ok: false, error: `算力证明没算出来:${solved.reason}。这只先别发。` };
|
|
629
|
+
}
|
|
630
|
+
payload.nonce = solved.nonce;
|
|
631
|
+
|
|
337
632
|
let signature;
|
|
338
633
|
try {
|
|
339
|
-
signature = signPayload(JSON.stringify(payload),
|
|
634
|
+
signature = signPayload(JSON.stringify(payload), mine.signing.private);
|
|
340
635
|
} catch (e) {
|
|
341
636
|
return { ok: false, error: '签名失败:' + (e?.message ?? e) };
|
|
342
637
|
}
|
|
343
|
-
return { ok: true, draft: d, packet: { ...payload, signature } };
|
|
638
|
+
return { ok: true, draft: d, packet: { ...payload, signature }, powMs: solved.ms, powTries: solved.tries };
|
|
344
639
|
}
|
|
345
640
|
|
|
346
641
|
// ── 发送限流(手册 6.7)────────────────────────────────────────────────
|
|
@@ -512,8 +807,8 @@ export function nickOf(dataDir, anonSignPub) {
|
|
|
512
807
|
}
|
|
513
808
|
|
|
514
809
|
/** 放行:标记 + 返回报文(真正发出去的是调用方) */
|
|
515
|
-
export function approveDraft(dataDir, id, now) {
|
|
516
|
-
const built = buildBottlePacket(dataDir, id, now);
|
|
810
|
+
export async function approveDraft(dataDir, id, now) {
|
|
811
|
+
const built = await buildBottlePacket(dataDir, id, now);
|
|
517
812
|
if (!built.ok) return built;
|
|
518
813
|
const r = decide(dataDir, id, 'approved');
|
|
519
814
|
if (!r.ok) return r;
|
|
@@ -680,21 +975,38 @@ export function checkReplyQuota(
|
|
|
680
975
|
* ★ 报文里带 is_temp_channel / has_replied —— 收方一眼看出「这条没有后续」,
|
|
681
976
|
* 不会把它当成聊天开头继续回。
|
|
682
977
|
*/
|
|
683
|
-
export function buildReplyPacket(dataDir, bottleId, now = new Date().toISOString()) {
|
|
978
|
+
export async function buildReplyPacket(dataDir, bottleId, now = new Date().toISOString()) {
|
|
684
979
|
const key = String(bottleId || '').trim();
|
|
685
980
|
const replies = loadReplies(dataDir);
|
|
686
981
|
const rec = replies.find((r) => r && r.bottleId === key && r.status === 'draft');
|
|
687
982
|
if (!rec) return { ok: false, error: '没有这条回信草稿(可能已经放过或丢掉了)' };
|
|
688
983
|
const anon = ensureAnonIdentity(dataDir);
|
|
984
|
+
// ★ 2026-11-29:正文加密。拿不到对方公钥就**发不出去**,绝不退化成明文 ——
|
|
985
|
+
// 发一条「看上去加密了其实没有」的回信,比不发更坏。
|
|
986
|
+
const peerPub = String(rec.toAnonPub || '');
|
|
987
|
+
if (!peerPub) {
|
|
988
|
+
return { ok: false, error: '这只瓶子没带对方的公钥,加密不了(旧版瓶子回不了)' };
|
|
989
|
+
}
|
|
990
|
+
const sealed = sealReplyText(
|
|
991
|
+
anon.exchange.private,
|
|
992
|
+
peerPub,
|
|
993
|
+
{ text: rec.text, sentAt: now },
|
|
994
|
+
key
|
|
995
|
+
);
|
|
996
|
+
if (!sealed) return { ok: false, error: '加密失败(对方的公钥可能不合法)' };
|
|
689
997
|
const sentMs = Date.parse(now);
|
|
690
998
|
const payload = {
|
|
691
999
|
type: 'bottle_reply',
|
|
692
|
-
|
|
1000
|
+
// ★ 2026-11-29(岸:「别人收到回信是要走私密的,不要让其他人看到」):
|
|
1001
|
+
// ver 2 = 正文加密。用【我的匿名私钥】+【瓶子里对方的公钥】做 ECDH,
|
|
1002
|
+
// 密文只有原丢瓶人拿他自己那只瓶子的私钥才解得开。
|
|
1003
|
+
// ★ 拿不到对方公钥就**发不出去**,绝不退化成明文 —— 那等于骗人。
|
|
1004
|
+
ver: 2,
|
|
693
1005
|
bottle_id: key,
|
|
694
1006
|
reply_to_bottle_id: key,
|
|
695
1007
|
is_temp_channel: true,
|
|
696
1008
|
has_replied: true,
|
|
697
|
-
|
|
1009
|
+
sealed, // 密文,代替 ver 1 的明文 text
|
|
698
1010
|
anon_pub: anon.exchange.public,
|
|
699
1011
|
anon_sign_pub: anon.signing.public,
|
|
700
1012
|
sent_at: now,
|
|
@@ -702,13 +1014,22 @@ export function buildReplyPacket(dataDir, bottleId, now = new Date().toISOString
|
|
|
702
1014
|
? new Date(sentMs + BOTTLE_TTL_DAYS * 86400_000).toISOString()
|
|
703
1015
|
: null,
|
|
704
1016
|
};
|
|
1017
|
+
// ★ 2026-11-29(安全模型四.2):回信也得算 PoW。
|
|
1018
|
+
// ★ base 用**密文** sealed —— 收方在解密之前手里只有密文,
|
|
1019
|
+
// 用明文当 base 的话他根本验不了(拿不到明文)。
|
|
1020
|
+
const solved = await pow.solvePow(sealed, { bottleId: key, anonPub: anon.exchange.public });
|
|
1021
|
+
if (!solved.ok) {
|
|
1022
|
+
return { ok: false, error: `回信的算力证明没算出来:${solved.reason}` };
|
|
1023
|
+
}
|
|
1024
|
+
payload.nonce = solved.nonce;
|
|
1025
|
+
|
|
705
1026
|
let signature;
|
|
706
1027
|
try {
|
|
707
1028
|
signature = signPayload(JSON.stringify(payload), anon.signing.private);
|
|
708
1029
|
} catch (e) {
|
|
709
1030
|
return { ok: false, error: '签名失败:' + (e?.message ?? e) };
|
|
710
1031
|
}
|
|
711
|
-
return { ok: true, reply: rec, packet: { ...payload, signature } };
|
|
1032
|
+
return { ok: true, reply: rec, packet: { ...payload, signature }, powMs: solved.ms };
|
|
712
1033
|
}
|
|
713
1034
|
|
|
714
1035
|
/**
|
|
@@ -736,6 +1057,28 @@ export function listRejectedReplies(dataDir, { limit = 10 } = {}) {
|
|
|
736
1057
|
.slice(0, limit);
|
|
737
1058
|
}
|
|
738
1059
|
|
|
1060
|
+
/**
|
|
1061
|
+
* 把「被主人打回的回信」排成一段话。
|
|
1062
|
+
*
|
|
1063
|
+
* ★ 跟 formatRejectHint 一个道理(插件不知道鱼在哪个会话,所以靠「一碰就看见」),
|
|
1064
|
+
* 但回信有一处不同:一只瓶子只说一句,通道发完就关 ——
|
|
1065
|
+
* 打回之后那条回信就作废了,鱼得照意见重写一条,而不是「改改原来那句」。
|
|
1066
|
+
* 这句差别必须写出来,不然鱼会以为还能回去编辑。
|
|
1067
|
+
* ★ 空数组返回空串:没被打回时整段不该出现。
|
|
1068
|
+
*/
|
|
1069
|
+
export function formatReplyRejectHint(replies = []) {
|
|
1070
|
+
if (!Array.isArray(replies) || !replies.length) return '';
|
|
1071
|
+
const lines = [`⚠ 有 ${replies.length} 条回信被主人打回了 —— 先看这个,再写新的:`];
|
|
1072
|
+
replies.forEach((r, i) => {
|
|
1073
|
+
const said = r.note ? `他说的:${r.note}` : '(他没留意见,只说了不要这条)';
|
|
1074
|
+
const full = String(r.text ?? '');
|
|
1075
|
+
const body = full.slice(0, 60) + (full.length > 60 ? '…' : '');
|
|
1076
|
+
lines.push(`${i + 1}. ${said}`, ` 被打回的是:「${body}」`);
|
|
1077
|
+
});
|
|
1078
|
+
lines.push('回信打回 ≠ 那只瓶子也没了:瓶子还在,但一只瓶子只说一句,照意见重写一条。');
|
|
1079
|
+
return '\n\n' + lines.join('\n');
|
|
1080
|
+
}
|
|
1081
|
+
|
|
739
1082
|
/** 把一条回信标成「已回」(通道从此关闭)。★ 发成功之后才调它。 */
|
|
740
1083
|
export function markReplyApproved(dataDir, bottleId, { now = Date.now() } = {}) {
|
|
741
1084
|
const key = String(bottleId || '');
|
|
@@ -750,8 +1093,8 @@ export function markReplyApproved(dataDir, bottleId, { now = Date.now() } = {})
|
|
|
750
1093
|
}
|
|
751
1094
|
|
|
752
1095
|
/** 放行:标记 approved + 返回报文(真正发出去的是调用方) */
|
|
753
|
-
export function approveReply(dataDir, bottleId, now = new Date().toISOString()) {
|
|
754
|
-
const built = buildReplyPacket(dataDir, bottleId, now);
|
|
1096
|
+
export async function approveReply(dataDir, bottleId, now = new Date().toISOString()) {
|
|
1097
|
+
const built = await buildReplyPacket(dataDir, bottleId, now);
|
|
755
1098
|
if (!built.ok) return built;
|
|
756
1099
|
const replies = loadReplies(dataDir);
|
|
757
1100
|
const rec = replies.find((r) => r && r.bottleId === String(bottleId) && r.status === 'draft');
|
package/lib/config.js
CHANGED
|
@@ -164,7 +164,20 @@ export function createConfig({ me, meFp }) {
|
|
|
164
164
|
// 放顶层而不是塞进 loop:loop 是出站闸门(一堆限流参数),
|
|
165
165
|
// 这一个是「收不收别人的瓶子」,语义不同,也不该跟着闸门一起被批量改。
|
|
166
166
|
bottle: {
|
|
167
|
+
// ★ 2026-11-30 按手册 §6.1 / §6.4 加的两个开关:
|
|
168
|
+
// enabled = 总开关,收和发一起停(管的是「玩不玩」)
|
|
169
|
+
// safeMode = 校验宽严三档(管的是「关到多死」)
|
|
170
|
+
// 跟 receive 的关系:receive 只管「收不收」,是 11-29 加的旧开关,
|
|
171
|
+
// 留着不动是为了兼容已经存了配置的机器 —— 但 enabled=false 时它是死的。
|
|
172
|
+
enabled: true,
|
|
173
|
+
safeMode: 'default', // default | conservative | off
|
|
167
174
|
receive: true, // 收:关掉后收到的瓶子在最前面就丢弃,不入隔离区
|
|
175
|
+
// ★ 循环广播(岸 2026-11-30):「隔 1 到 2 个小时去广播一次,就那种尝试的感觉」。
|
|
176
|
+
// loopMinutes 是**下限**,实际每跳在 [loopMinutes, +60] 分钟里随机取 ——
|
|
177
|
+
// 固定 60 分钟是定时器,随机才像「过一阵想起来了又扔一次」。
|
|
178
|
+
// loopTimes = 再循环几次(含首发共 loopTimes+1 次);2 → 共 3 次。
|
|
179
|
+
loopMinutes: 60,
|
|
180
|
+
loopTimes: 2,
|
|
168
181
|
},
|
|
169
182
|
proactive: {
|
|
170
183
|
enabled: false,
|
|
@@ -346,9 +359,33 @@ export function setProactive(patch = {}) {
|
|
|
346
359
|
export function setBottle(patch = {}) {
|
|
347
360
|
const cfg = loadConfig();
|
|
348
361
|
if (!cfg) throw new Error('还没有配置,先生成身份');
|
|
349
|
-
const base = {
|
|
362
|
+
const base = {
|
|
363
|
+
enabled: true,
|
|
364
|
+
safeMode: 'default',
|
|
365
|
+
receive: true,
|
|
366
|
+
loopMinutes: 60,
|
|
367
|
+
loopTimes: 2,
|
|
368
|
+
};
|
|
350
369
|
const next = { ...base, ...(cfg.bottle || {}) };
|
|
351
370
|
if ('receive' in patch) next.receive = patch.receive !== false;
|
|
371
|
+
if ('enabled' in patch) next.enabled = patch.enabled !== false;
|
|
372
|
+
if ('safeMode' in patch) {
|
|
373
|
+
const m = String(patch.safeMode || '').toLowerCase();
|
|
374
|
+
// ★ 认不出来的值不静默吞掉 —— 直接报错。静默变 default 会让人以为档位调了。
|
|
375
|
+
if (!['default', 'conservative', 'off'].includes(m)) {
|
|
376
|
+
throw new Error(`safeMode 只能是 default / conservative / off:${patch.safeMode}`);
|
|
377
|
+
}
|
|
378
|
+
next.safeMode = m;
|
|
379
|
+
}
|
|
380
|
+
for (const k of ['loopMinutes', 'loopTimes']) {
|
|
381
|
+
if (!(k in patch)) continue;
|
|
382
|
+
const n = Number(patch[k]);
|
|
383
|
+
// ★ loopTimes 允许 0(= 不循环,只发一次);loopMinutes 是间隔下限,0 没意义。
|
|
384
|
+
if (!Number.isFinite(n) || (k === 'loopTimes' ? n < 0 : n <= 0)) {
|
|
385
|
+
throw new Error(`${k} 要是一个${k === 'loopTimes' ? '非负' : '正'}数:${patch[k]}`);
|
|
386
|
+
}
|
|
387
|
+
next[k] = n;
|
|
388
|
+
}
|
|
352
389
|
cfg.bottle = next;
|
|
353
390
|
saveConfig(cfg);
|
|
354
391
|
return cfg;
|