@ssamurias/dsh-fish 1.0.0 → 1.0.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/AGENTS.md +6 -3
- package/CHANGELOG.md +572 -368
- package/README.md +148 -14
- package/RELEASE-NOTES-1.0.0.md +62 -3
- package/RELEASE-NOTES-1.0.1.md +363 -0
- package/RELEASE-NOTES-1.0.2.md +114 -0
- package/THIRD-PARTY-NOTICES.md +13 -3
- package/docs/troubleshooting.md +119 -0
- package/docs//346/217/222/344/273/266/347/272/246/345/256/232.md +167 -0
- package/docs//347/264/240/346/235/220/345/245/221/347/272/246.md +96 -0
- package/lib/ask.js +3 -3
- package/lib/at.js +4 -2
- package/lib/autobackup.js +414 -0
- package/lib/backup.js +75 -5
- package/lib/bili.js +132 -21
- package/lib/browse.js +33 -16
- package/lib/capture.js +27 -1
- package/lib/client.js +1329 -349
- package/lib/cloudbackup.js +352 -0
- package/lib/cloudcrypto.js +161 -0
- package/lib/clouddrive.js +693 -0
- package/lib/cloudsmtp.js +331 -0
- package/lib/cloudtargets.js +228 -0
- package/lib/comment.js +23 -5
- package/lib/contract.js +7 -2
- package/lib/deliver.js +4 -1
- package/lib/doing.js +316 -0
- package/lib/events.js +22 -4
- package/lib/firstwake.js +74 -0
- package/lib/freewake.js +5 -0
- package/lib/generator.js +35 -4
- package/lib/handoff.js +166 -0
- package/lib/hear.js +102 -7
- package/lib/home.js +169 -204
- package/lib/identity.js +498 -28
- package/lib/index.js +14 -2
- package/lib/look.js +37 -3
- package/lib/material.js +12 -1
- package/lib/note.js +100 -9
- package/lib/observe.js +365 -36
- package/lib/persona.js +61 -41
- package/lib/proactive.js +12 -5
- package/lib/recall.js +159 -10
- package/lib/report.js +14 -7
- package/lib/say.js +10 -2
- package/lib/scheduler.js +238 -26
- package/lib/schema.js +8 -1
- package/lib/scrub.js +105 -4
- package/lib/selfcheck.js +13 -1
- package/lib/selfdoc.js +170 -12
- package/lib/selfpronoun.js +112 -0
- package/lib/selfrules.js +50 -0
- package/lib/sessionnote.js +7 -3
- package/lib/settings.js +163 -13
- package/lib/status.js +16 -8
- package/lib/sub.js +42 -5
- package/lib/turnexport.js +123 -0
- package/lib/turns.js +102 -10
- package/lib/video.js +1 -1
- package/lib/voices.js +24 -1
- package/media/principle-drive.svg +131 -0
- package/media/principle-loop.svg +3 -3
- package/media/principle-memory.svg +1 -1
- package/package.json +2 -1
package/lib/cloudsmtp.js
ADDED
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
// 一个够用的 SMTP 客户端(2026-11-14,用户 m01090)
|
|
2
|
+
//
|
|
3
|
+
// 为什么自己写:插件是零依赖的(package.json 里三个 dependencies 全空),
|
|
4
|
+
// 装 nodemailer 违反那条铁律;而发一封带一个附件的信,用 node:net / node:tls 写两百行就够。
|
|
5
|
+
//
|
|
6
|
+
// 只做三件必要的事:
|
|
7
|
+
// 1. 465 直连 TLS,587/25 先明文再 STARTTLS(大多数邮箱走这两条之一)。
|
|
8
|
+
// 2. AUTH LOGIN(QQ/163/Gmail/Outlook 都支持;AUTH PLAIN 也顺手支持)。
|
|
9
|
+
// 3. 一封 multipart/mixed、一个 base64 附件。
|
|
10
|
+
// 不做:HTML 正文、多收件人分开发、DKIM、投递回执。用不上,也不该在这里长出来。
|
|
11
|
+
|
|
12
|
+
import { connect as tlsConnect } from 'node:tls'
|
|
13
|
+
import { connect as netConnect } from 'node:net'
|
|
14
|
+
import { hostname } from 'node:os'
|
|
15
|
+
|
|
16
|
+
const CRLF = '\r\n'
|
|
17
|
+
|
|
18
|
+
/** 一句话的错误:界面会原样显示。 */
|
|
19
|
+
class SMTPError extends Error {}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 把「服务器说了什么」翻译成人话。
|
|
23
|
+
* SMTP 的错误码对普通用户没有意义,但把它附在后面能让人拿去搜索。
|
|
24
|
+
*/
|
|
25
|
+
function explain(code, text) {
|
|
26
|
+
const t = String(text ?? '').trim()
|
|
27
|
+
const low = t.toLowerCase()
|
|
28
|
+
if (code === 535 || low.includes('auth') && low.includes('fail')) {
|
|
29
|
+
return `登录被拒了(${code})。多半是用了登录密码——这里要的是邮箱设置里那个「授权码 / 应用专用密码」。`
|
|
30
|
+
}
|
|
31
|
+
if (code === 534 || low.includes('application-specific')) {
|
|
32
|
+
return `邮箱要求用「授权码 / 应用专用密码」(${code}),不能用登录密码。`
|
|
33
|
+
}
|
|
34
|
+
if (code === 550 || code === 553) return `收件地址被拒了(${code}):${t}`
|
|
35
|
+
if (code === 552) return `附件太大了,这家邮箱收不下(${code})。`
|
|
36
|
+
if (code === 421 || code === 450 || code === 451) return `服务器暂时不收(${code}),过一会儿再试。`
|
|
37
|
+
return `${code} ${t}`
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** 一条连接:负责把字节写进去、把服务器的话按行读回来。 */
|
|
41
|
+
class Conn {
|
|
42
|
+
constructor(socket) {
|
|
43
|
+
this.socket = socket
|
|
44
|
+
this.buf = ''
|
|
45
|
+
this.waiters = []
|
|
46
|
+
this.err = null
|
|
47
|
+
socket.setEncoding('utf8')
|
|
48
|
+
socket.on('data', (chunk) => {
|
|
49
|
+
this.buf += chunk
|
|
50
|
+
this.pump()
|
|
51
|
+
})
|
|
52
|
+
socket.on('error', (e) => {
|
|
53
|
+
this.err = e
|
|
54
|
+
this.pump()
|
|
55
|
+
})
|
|
56
|
+
socket.on('close', () => {
|
|
57
|
+
this.err = this.err ?? new Error('连接被对方关掉了')
|
|
58
|
+
this.pump()
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
pump() {
|
|
63
|
+
while (this.waiters.length) {
|
|
64
|
+
const w = this.waiters[0]
|
|
65
|
+
const r = this.takeReply()
|
|
66
|
+
if (r) {
|
|
67
|
+
this.waiters.shift()
|
|
68
|
+
w.resolve(r)
|
|
69
|
+
} else if (this.err) {
|
|
70
|
+
this.waiters.shift()
|
|
71
|
+
w.reject(this.err)
|
|
72
|
+
} else return
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** 读一条完整回复(多行回复以「码-」续行,最后一行是「码 空格」)。 */
|
|
77
|
+
takeReply() {
|
|
78
|
+
const lines = this.buf.split(CRLF)
|
|
79
|
+
let code = null
|
|
80
|
+
let text = ''
|
|
81
|
+
let consumed = 0
|
|
82
|
+
for (let i = 0; i < lines.length; i++) {
|
|
83
|
+
const line = lines[i]
|
|
84
|
+
if (line.length < 3) break
|
|
85
|
+
const m = /^(\d{3})([ -])(.*)$/.exec(line)
|
|
86
|
+
if (!m) break
|
|
87
|
+
code = Number(m[1])
|
|
88
|
+
text += `${m[3]}${CRLF}`
|
|
89
|
+
consumed += line.length + CRLF.length
|
|
90
|
+
if (m[2] === ' ') {
|
|
91
|
+
this.buf = this.buf.slice(consumed)
|
|
92
|
+
return { code, text: text.trim() }
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return null
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
reply(timeoutMs = 30_000) {
|
|
99
|
+
return new Promise((resolve, reject) => {
|
|
100
|
+
const w = { resolve, reject }
|
|
101
|
+
this.waiters.push(w)
|
|
102
|
+
const t = setTimeout(() => {
|
|
103
|
+
const i = this.waiters.indexOf(w)
|
|
104
|
+
if (i >= 0) this.waiters.splice(i, 1)
|
|
105
|
+
reject(new SMTPError('服务器太久没回话(30 秒)。网络、代理、或者端口不对。'))
|
|
106
|
+
}, timeoutMs)
|
|
107
|
+
const done = (fn) => (v) => { clearTimeout(t); fn(v) }
|
|
108
|
+
w.resolve = done(resolve)
|
|
109
|
+
w.reject = done(reject)
|
|
110
|
+
this.pump()
|
|
111
|
+
})
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
write(s) {
|
|
115
|
+
this.socket.write(s)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
end() {
|
|
119
|
+
try { this.socket.end() } catch {}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function base64(s) {
|
|
124
|
+
return Buffer.from(String(s), 'utf8').toString('base64')
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** 点号转义:正文里以 . 开头的行要变成 ..,否则会被当成提前结束。 */
|
|
128
|
+
function dotStuff(s) {
|
|
129
|
+
return String(s).replace(/\r?\n/g, CRLF).replace(/^\./gm, '..')
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function encWord(s) {
|
|
133
|
+
// 中文主题要按 RFC 2047 编码,不然 Outlook 会显示成乱码。
|
|
134
|
+
const text = String(s ?? '')
|
|
135
|
+
if (/^[\x20-\x7e]*$/.test(text)) return text
|
|
136
|
+
return `=?UTF-8?B?${Buffer.from(text, 'utf8').toString('base64')}?=`
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function wrap76(b64) {
|
|
140
|
+
const out = []
|
|
141
|
+
for (let i = 0; i < b64.length; i += 76) out.push(b64.slice(i, i + 76))
|
|
142
|
+
return out.join(CRLF)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* 拼一封信。attachments: [{name, data: Buffer}]。
|
|
147
|
+
* Content-Type 里带 name 时要做编码,但大多数客户端靠 filename* 也能认。
|
|
148
|
+
*/
|
|
149
|
+
export function buildMessage({ from, to, subject, text, attachments = [] }) {
|
|
150
|
+
const boundary = `dshfish-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`
|
|
151
|
+
const head = [
|
|
152
|
+
`From: <${from}>`,
|
|
153
|
+
`To: ${to.map((x) => `<${x}>`).join(', ')}`,
|
|
154
|
+
`Subject: ${encWord(subject)}`,
|
|
155
|
+
`Date: ${new Date().toUTCString().replace('GMT', '+0000')}`,
|
|
156
|
+
`Message-ID: <${Date.now().toString(36)}.${Math.random().toString(36).slice(2, 8)}@dsh-fish>`,
|
|
157
|
+
'MIME-Version: 1.0',
|
|
158
|
+
`Content-Type: multipart/mixed; boundary="${boundary}"`,
|
|
159
|
+
'',
|
|
160
|
+
'这一封是自动发出的备份。',
|
|
161
|
+
'',
|
|
162
|
+
`--${boundary}`,
|
|
163
|
+
'Content-Type: text/plain; charset=utf-8',
|
|
164
|
+
'Content-Transfer-Encoding: base64',
|
|
165
|
+
'',
|
|
166
|
+
wrap76(Buffer.from(String(text ?? ''), 'utf8').toString('base64')),
|
|
167
|
+
]
|
|
168
|
+
for (const a of attachments) {
|
|
169
|
+
const name = String(a.name ?? 'backup.json')
|
|
170
|
+
head.push(
|
|
171
|
+
`--${boundary}`,
|
|
172
|
+
`Content-Type: application/octet-stream; name="${encWord(name)}"`,
|
|
173
|
+
'Content-Transfer-Encoding: base64',
|
|
174
|
+
`Content-Disposition: attachment; filename="${encWord(name)}"`,
|
|
175
|
+
'',
|
|
176
|
+
wrap76(Buffer.from(a.data ?? Buffer.alloc(0)).toString('base64')),
|
|
177
|
+
)
|
|
178
|
+
}
|
|
179
|
+
head.push(`--${boundary}--`, '')
|
|
180
|
+
return head.join(CRLF)
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export class SMTPSender {
|
|
184
|
+
constructor({ host, port = 465, user = '', pass = '', timeoutMs = 60_000, log = () => {} } = {}) {
|
|
185
|
+
this.host = String(host ?? '').trim()
|
|
186
|
+
this.port = Number(port) || 465
|
|
187
|
+
this.user = String(user ?? '').trim()
|
|
188
|
+
this.pass = String(pass ?? '')
|
|
189
|
+
this.timeoutMs = timeoutMs
|
|
190
|
+
this.log = log
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
connect() {
|
|
194
|
+
return new Promise((resolve, reject) => {
|
|
195
|
+
const sock = this.port === 465
|
|
196
|
+
? tlsConnect({ host: this.host, port: this.port, servername: this.host, timeout: this.timeoutMs })
|
|
197
|
+
: netConnect({ host: this.host, port: this.port, timeout: this.timeoutMs })
|
|
198
|
+
let settled = false
|
|
199
|
+
const fail = (e) => {
|
|
200
|
+
if (settled) return
|
|
201
|
+
settled = true
|
|
202
|
+
try { sock.destroy() } catch {}
|
|
203
|
+
reject(new SMTPError(this.friendly(e)))
|
|
204
|
+
}
|
|
205
|
+
sock.once('error', fail)
|
|
206
|
+
sock.once('timeout', () => fail(new Error('连不上')))
|
|
207
|
+
sock.once('connect', () => {
|
|
208
|
+
if (settled) return
|
|
209
|
+
// 465 上还要等 TLS 握手完;587 连上就能说话。
|
|
210
|
+
if (this.port === 465) {
|
|
211
|
+
sock.once('secureConnect', () => {
|
|
212
|
+
if (settled) return
|
|
213
|
+
settled = true
|
|
214
|
+
sock.removeListener('error', fail)
|
|
215
|
+
resolve(new Conn(sock))
|
|
216
|
+
})
|
|
217
|
+
} else {
|
|
218
|
+
settled = true
|
|
219
|
+
sock.removeListener('error', fail)
|
|
220
|
+
resolve(new Conn(sock))
|
|
221
|
+
}
|
|
222
|
+
})
|
|
223
|
+
})
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
friendly(e) {
|
|
227
|
+
const code = e?.code ?? ''
|
|
228
|
+
if (code === 'ENOTFOUND' || code === 'EAI_AGAIN') return `找不到服务器「${this.host}」,检查一下拼写。`
|
|
229
|
+
if (code === 'ECONNREFUSED') return `「${this.host}:${this.port}」不肯连——端口填错了,或者这家邮箱不支持这个端口。`
|
|
230
|
+
if (code === 'ETIMEDOUT') return '连接超时。检查网络,或者这家邮箱在本机网络下要开代理。'
|
|
231
|
+
if (code === 'CERT_HAS_EXPIRED' || String(e?.message ?? '').includes('certificate')) return 'TLS 证书有问题,可能是被中间人拦了。'
|
|
232
|
+
return `连不上:${e?.message ?? e}`
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/** 登录一次就断。给「测一下」按钮用。 */
|
|
236
|
+
async verify() {
|
|
237
|
+
const c = await this.connect()
|
|
238
|
+
try {
|
|
239
|
+
await this.hello(c)
|
|
240
|
+
await this.auth(c)
|
|
241
|
+
return 'ok'
|
|
242
|
+
} finally {
|
|
243
|
+
try { c.write('QUIT' + CRLF) } catch {}
|
|
244
|
+
setTimeout(() => c.end(), 200).unref?.()
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
async hello(c) {
|
|
249
|
+
const greet = await c.reply()
|
|
250
|
+
if (greet.code !== 220) throw new SMTPError(explain(greet.code, greet.text))
|
|
251
|
+
const name = hostname().replace(/[^\w.-]/g, '') || 'localhost'
|
|
252
|
+
c.write(`EHLO ${name}${CRLF}`)
|
|
253
|
+
let ehlo = await c.reply()
|
|
254
|
+
if (ehlo.code >= 400 || ehlo.code < 200) {
|
|
255
|
+
// 有的老服务器只认 HELO。
|
|
256
|
+
c.write(`HELO ${name}${CRLF}`)
|
|
257
|
+
ehlo = await c.reply()
|
|
258
|
+
}
|
|
259
|
+
if (ehlo.code !== 250) throw new SMTPError(explain(ehlo.code, ehlo.text))
|
|
260
|
+
// 587/25 上如果没有 STARTTLS 就明文发,等于把授权码和备份裸奔在网上——宁可不发。
|
|
261
|
+
if (this.port !== 465) {
|
|
262
|
+
if (!/\bSTARTTLS\b/i.test(ehlo.text)) {
|
|
263
|
+
throw new SMTPError(`这家服务器不同意加密(没有 STARTTLS)。为了不让授权码和备份明文上路,这里不发。换成 465 端口试试。`)
|
|
264
|
+
}
|
|
265
|
+
c.write('STARTTLS' + CRLF)
|
|
266
|
+
const st = await c.reply()
|
|
267
|
+
if (st.code !== 220) throw new SMTPError(explain(st.code, st.text))
|
|
268
|
+
await new Promise((resolve, reject) => {
|
|
269
|
+
const sock = c.socket
|
|
270
|
+
// net.Socket 换不了加密层,只能拿 TLS 包一层上去;包好之后这条连接的读写都走它。
|
|
271
|
+
const tls = tlsConnect({ socket: sock, servername: this.host, timeout: this.timeoutMs }, () => resolve())
|
|
272
|
+
tls.once('error', reject)
|
|
273
|
+
c.socket = tls
|
|
274
|
+
c.buf = ''
|
|
275
|
+
c.waiters = []
|
|
276
|
+
tls.setEncoding('utf8')
|
|
277
|
+
tls.on('data', (chunk) => { c.buf += chunk; c.pump() })
|
|
278
|
+
tls.on('error', (e) => { c.err = e; c.pump() })
|
|
279
|
+
tls.on('close', () => { c.err = c.err ?? new Error('连接被对方关掉了'); c.pump() })
|
|
280
|
+
})
|
|
281
|
+
const name2 = hostname().replace(/[^\w.-]/g, '') || 'localhost'
|
|
282
|
+
c.write(`EHLO ${name2}${CRLF}`)
|
|
283
|
+
const again = await c.reply()
|
|
284
|
+
if (again.code !== 250) throw new SMTPError(explain(again.code, again.text))
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
async auth(c) {
|
|
289
|
+
if (!this.user) return
|
|
290
|
+
c.write('AUTH LOGIN' + CRLF)
|
|
291
|
+
const a1 = await c.reply()
|
|
292
|
+
if (a1.code !== 334) throw new SMTPError(explain(a1.code, a1.text))
|
|
293
|
+
c.write(base64(this.user) + CRLF)
|
|
294
|
+
const a2 = await c.reply()
|
|
295
|
+
if (a2.code !== 334) throw new SMTPError(explain(a2.code, a2.text))
|
|
296
|
+
c.write(base64(this.pass) + CRLF)
|
|
297
|
+
const a3 = await c.reply()
|
|
298
|
+
if (a3.code !== 235) throw new SMTPError(explain(a3.code, a3.text))
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
async send({ from, to, subject, text, attachments = [] }) {
|
|
302
|
+
const c = await this.connect()
|
|
303
|
+
try {
|
|
304
|
+
await this.hello(c)
|
|
305
|
+
await this.auth(c)
|
|
306
|
+
c.write(`MAIL FROM:<${from}>${CRLF}`)
|
|
307
|
+
const m = await c.reply()
|
|
308
|
+
if (m.code !== 250) throw new SMTPError(explain(m.code, m.text))
|
|
309
|
+
for (const r of to) {
|
|
310
|
+
c.write(`RCPT TO:<${r}>${CRLF}`)
|
|
311
|
+
const rr = await c.reply()
|
|
312
|
+
if (rr.code !== 250 && rr.code !== 251) throw new SMTPError(explain(rr.code, rr.text))
|
|
313
|
+
}
|
|
314
|
+
c.write('DATA' + CRLF)
|
|
315
|
+
const d = await c.reply()
|
|
316
|
+
if (d.code !== 354) throw new SMTPError(explain(d.code, d.text))
|
|
317
|
+
const msg = buildMessage({ from, to, subject, text, attachments })
|
|
318
|
+
c.write(dotStuff(msg))
|
|
319
|
+
if (!msg.endsWith(CRLF)) c.write(CRLF)
|
|
320
|
+
c.write('.' + CRLF)
|
|
321
|
+
const done = await c.reply(180_000)
|
|
322
|
+
if (done.code !== 250) throw new SMTPError(explain(done.code, done.text))
|
|
323
|
+
return { ok: true, id: done.text }
|
|
324
|
+
} finally {
|
|
325
|
+
try { c.write('QUIT' + CRLF) } catch {}
|
|
326
|
+
setTimeout(() => c.end(), 200).unref?.()
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
export { SMTPError }
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
// 云端备份的目标形状(2026-11-14,用户 m01090)
|
|
2
|
+
//
|
|
3
|
+
// 这一份是**唯一的真源**:设置页的表单、后端的校验、配置的默认值,全都从下面这张表来。
|
|
4
|
+
// 以前吃过「界面加了字段、后端白名单没登记」的亏(backup 组那次),
|
|
5
|
+
// 所以这里刻意做成「加一个字段只改一处」的形状。
|
|
6
|
+
//
|
|
7
|
+
// 设计上只有两件事要守住:
|
|
8
|
+
// 1. 目标是一张列表,用户可以加任意多个、任意组合。不是「选一个渠道」。
|
|
9
|
+
// 2. 每个目标自己带 enabled。挂掉一个不影响别的,这就是「降级」的最小单位。
|
|
10
|
+
|
|
11
|
+
/** 字段类型:text 单行、pass 密码、num 数字、bool 开关、area 多行。 */
|
|
12
|
+
const F = (key, label, type, extra = {}) => ({ key, label, type, ...extra })
|
|
13
|
+
|
|
14
|
+
export const KINDS = {
|
|
15
|
+
folder: {
|
|
16
|
+
label: '一个文件夹',
|
|
17
|
+
short: '文件夹',
|
|
18
|
+
steps: '选一个文件夹。如果它正好是你网盘客户端的同步目录(坚果云、OneDrive、iCloud、123、夸克都能设),那这一份就自动跟着同步上去了——不需要任何账号或接口。',
|
|
19
|
+
fields: [
|
|
20
|
+
F('dir', '哪个文件夹', 'text', { required: true, placeholder: 'D:\\我的网盘\\大肥鱼备份', hint: '绝对路径。目录不存在会自动建。' }),
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
git: {
|
|
24
|
+
label: '一个 Git 仓库',
|
|
25
|
+
short: '仓库',
|
|
26
|
+
steps: '在 GitHub / Gitee / GitLab / Gitea 上建一个**私有**仓库(不要公开,包里是她的身份和登录凭据),然后生成一个有写权限的令牌粘进来。',
|
|
27
|
+
fields: [
|
|
28
|
+
F('repo', '仓库', 'text', { required: true, placeholder: '你的名字/dafish-backup', hint: '写成「用户名/仓库名」,或者直接粘仓库网页地址。' }),
|
|
29
|
+
F('token', '访问令牌', 'pass', { required: true, hint: '只勾仓库读写权限就够,别给全权限。令牌只存在本机。' }),
|
|
30
|
+
F('api', '接口地址', 'text', { placeholder: '留空按仓库地址自动判断', hint: 'GitHub 是 https://api.github.com,Gitee 是 https://gitee.com/api/v5。自建 Gitea 填自己的。' }),
|
|
31
|
+
F('releaseAssets', '用 GitHub Release 附件保存', 'bool', { dflt: false, hint: '仅限 GitHub 私有仓库。带日期的加密备份放在同一个 Release,按现有份数轮换。分支仅用于首次创建标签,仓库目录不适用。' }),
|
|
32
|
+
F('branch', '分支', 'text', { placeholder: 'main', hint: '留空用 main;Gitee 默认分支常叫 master。' }),
|
|
33
|
+
F('dir', '仓库里的目录', 'text', { placeholder: 'backups', hint: '留空就放仓库根目录。' }),
|
|
34
|
+
],
|
|
35
|
+
},
|
|
36
|
+
webdav: {
|
|
37
|
+
label: '一个 WebDAV 目录',
|
|
38
|
+
short: 'WebDAV',
|
|
39
|
+
steps: '坚果云、123 云盘、InfiniCLOUD、Nextcloud、群晖、Alist 都支持 WebDAV。用「应用密码」而不是登录密码——网页密码改了应用密码还在,泄露了也能单独吊销。',
|
|
40
|
+
fields: [
|
|
41
|
+
F('url', 'WebDAV 地址', 'text', { required: true, placeholder: 'https://dav.jianguoyun.com/dav/', hint: '填到你要用的那一层目录。' }),
|
|
42
|
+
F('user', '用户名', 'text', { required: true, hint: '坚果云是登录邮箱。' }),
|
|
43
|
+
F('pass', '应用密码', 'pass', { required: true, hint: '在各家的「安全设置 / 应用密码」里生成,不是登录密码。' }),
|
|
44
|
+
F('dir', '目录', 'text', { placeholder: 'dafish', hint: '在 WebDAV 地址下面再建一层。留空直接放上去。' }),
|
|
45
|
+
],
|
|
46
|
+
},
|
|
47
|
+
smtp: {
|
|
48
|
+
label: '发到邮箱',
|
|
49
|
+
short: '邮箱',
|
|
50
|
+
steps: '不用注册任何新东西:你自己的邮箱就能收。要去邮箱设置里开 SMTP 并生成一个「授权码」(不是登录密码)。附件上限一般是 50MB,我们的包 8MB 左右够用。',
|
|
51
|
+
fields: [
|
|
52
|
+
F('host', 'SMTP 服务器', 'text', { required: true, placeholder: 'smtp.qq.com', hint: 'QQ 邮箱 smtp.qq.com、163 是 smtp.163.com、Gmail 是 smtp.gmail.com。' }),
|
|
53
|
+
F('port', '端口', 'num', { dflt: 465, lo: 1, hi: 65535, hint: '465 是加密直连,587 是 STARTTLS。' }),
|
|
54
|
+
F('user', '账号', 'text', { required: true, placeholder: 'you@qq.com' }),
|
|
55
|
+
F('pass', '授权码', 'pass', { required: true, hint: '邮箱设置里生成的授权码,不是登录密码。' }),
|
|
56
|
+
F('to', '发到哪个邮箱', 'text', { required: true, hint: '留空就发给自己。可以填多个,用逗号分开。' }),
|
|
57
|
+
F('from', '发件人', 'text', { placeholder: '留空用上面的账号' }),
|
|
58
|
+
],
|
|
59
|
+
},
|
|
60
|
+
http: {
|
|
61
|
+
label: '自定义 HTTP 接口',
|
|
62
|
+
short: 'HTTP',
|
|
63
|
+
steps: '万能出口:任何能收一个 PUT/POST 的地址都行(你自己的对象存储、别人给的上传链接、内网服务)。请求体里的占位符会被替换成真实内容。',
|
|
64
|
+
fields: [
|
|
65
|
+
F('url', '地址', 'text', { required: true, placeholder: 'https://example.com/upload/{{name}}', hint: '可以用占位符:{{name}} {{file}} {{sha256}} {{size}}。' }),
|
|
66
|
+
F('method', '方法', 'text', { dflt: 'PUT', placeholder: 'PUT', hint: 'PUT 或 POST。' }),
|
|
67
|
+
F('headers', '请求头', 'area', { placeholder: 'Authorization: Bearer xxx\nContent-Type: application/octet-stream', hint: '一行一个,冒号分隔。' }),
|
|
68
|
+
F('bodyFile', '把文件放进请求体', 'bool', { dflt: true, hint: '关掉的话就发下面的文本模板,不发文件本身。' }),
|
|
69
|
+
F('body', '文本模板', 'area', { placeholder: '{"name":"{{name}}","sha256":"{{sha256}}"}', hint: 'bodyFile 关掉时才用。' }),
|
|
70
|
+
],
|
|
71
|
+
},
|
|
72
|
+
command: {
|
|
73
|
+
label: '跑一条命令',
|
|
74
|
+
short: '命令',
|
|
75
|
+
steps: '最强也最危险的出口:本机有 rclone / ossutil / 自己写的脚本,就让它去传。装 rclone 之后一行命令就能接上它支持的七十多种网盘。命令里的占位符会被替换。',
|
|
76
|
+
fields: [
|
|
77
|
+
F('cmd', '命令', 'area', { required: true, placeholder: 'rclone copy "{{file}}" myremote:dafish-backups/', hint: '占位符:{{file}} {{name}} {{sha256}} {{size}}。文件路径会自动加引号之外,其余要自己写对引号。' }),
|
|
78
|
+
F('shell', '用哪个 shell', 'text', { dflt: 'auto', placeholder: 'auto', hint: 'auto / cmd / bash。Windows 上默认 cmd。' }),
|
|
79
|
+
],
|
|
80
|
+
},
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export const KIND_ORDER = ['folder', 'git', 'webdav', 'smtp', 'http', 'command']
|
|
84
|
+
|
|
85
|
+
export function kindInfo(kind) {
|
|
86
|
+
return KINDS[String(kind ?? '')] ?? null
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function kindLabel(kind) {
|
|
90
|
+
return kindInfo(kind)?.short ?? String(kind ?? '')
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** 给界面用的一份完整说明书(字段表直接从上面这张表投影出去)。 */
|
|
94
|
+
export function kindsDoc() {
|
|
95
|
+
return KIND_ORDER.map((k) => ({ kind: k, ...KINDS[k] }))
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function clampNum(v, lo, hi, dflt) {
|
|
99
|
+
const n = Number(v)
|
|
100
|
+
if (!Number.isFinite(n)) return dflt
|
|
101
|
+
return Math.max(lo, Math.min(hi, Math.round(n)))
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function cleanId(s) {
|
|
105
|
+
return String(s ?? '').trim().replace(/[^\w-]/g, '').slice(0, 24)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* 把一个目标规整成规范形状。
|
|
110
|
+
* 认不出的 kind 返回 null(整条丢掉,不让它占着列表让人以为能用);
|
|
111
|
+
* 必填项为空的**保留**,只是 `ready:false`——用户正在填的时候不该被吞掉。
|
|
112
|
+
*/
|
|
113
|
+
export function normTarget(raw, index = 0) {
|
|
114
|
+
if (!raw || typeof raw !== 'object') return null
|
|
115
|
+
const kind = String(raw.kind ?? '').trim()
|
|
116
|
+
const info = KINDS[kind]
|
|
117
|
+
if (!info) return null
|
|
118
|
+
const out = {
|
|
119
|
+
id: cleanId(raw.id) || `t${index + 1}`,
|
|
120
|
+
kind,
|
|
121
|
+
name: String(raw.name ?? '').trim().slice(0, 40) || info.short,
|
|
122
|
+
enabled: raw.enabled !== false,
|
|
123
|
+
}
|
|
124
|
+
for (const f of info.fields) {
|
|
125
|
+
const v = raw[f.key]
|
|
126
|
+
if (f.type === 'bool') out[f.key] = v === undefined || v === null ? Boolean(f.dflt) : Boolean(v)
|
|
127
|
+
else if (f.type === 'num') out[f.key] = clampNum(v, f.lo ?? 0, f.hi ?? 1e9, f.dflt ?? 0)
|
|
128
|
+
else out[f.key] = String(v ?? f.dflt ?? '').replace(/^\uFEFF/, '').trim()
|
|
129
|
+
}
|
|
130
|
+
out.ready = info.fields.every((f) => !f.required || String(out[f.key] ?? '').trim() !== '')
|
|
131
|
+
out.missing = info.fields.filter((f) => f.required && String(out[f.key] ?? '').trim() === '').map((f) => f.label)
|
|
132
|
+
return out
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function normTargets(raw) {
|
|
136
|
+
const list = Array.isArray(raw) ? raw : []
|
|
137
|
+
const out = []
|
|
138
|
+
const seen = new Set()
|
|
139
|
+
for (let i = 0; i < list.length && out.length < 12; i++) {
|
|
140
|
+
const t = normTarget(list[i], i)
|
|
141
|
+
if (!t) continue
|
|
142
|
+
// id 撞了就改一个:界面上靠它定位,重复会让「删第二个」删到第一个。
|
|
143
|
+
let id = t.id
|
|
144
|
+
let n = 2
|
|
145
|
+
while (seen.has(id)) id = `${t.id}${n++}`
|
|
146
|
+
t.id = id
|
|
147
|
+
seen.add(id)
|
|
148
|
+
out.push(t)
|
|
149
|
+
}
|
|
150
|
+
return out
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** 一个目标缺什么、为什么不能用——一句话,给人看。 */
|
|
154
|
+
export function targetProblem(t) {
|
|
155
|
+
if (!t) return '这个目标不完整。'
|
|
156
|
+
const info = KINDS[t.kind]
|
|
157
|
+
if (!info) return '不认识这种目标。'
|
|
158
|
+
const miss = missingOf(t)
|
|
159
|
+
if (miss.length) return `还差:${miss.join('、')}`
|
|
160
|
+
return ''
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* 缺哪些必填项。
|
|
165
|
+
*
|
|
166
|
+
* 优先用 normTarget 算好的 t.missing;**没算过就现算**。
|
|
167
|
+
* 为什么不能只看 t.missing:从 config.json 里直接读出来的那一份、或者调用方手搓的
|
|
168
|
+
* 一个目标,都没有这个字段,`t.missing === undefined` 会让「缺必填」被当成「齐全」,
|
|
169
|
+
* 于是一个空仓库也被判成能用,一路推到 404 才报错。这里现算一遍,判据只有一处。
|
|
170
|
+
*/
|
|
171
|
+
function missingOf(t) {
|
|
172
|
+
if (Array.isArray(t.missing)) return t.missing
|
|
173
|
+
const info = KINDS[t?.kind]
|
|
174
|
+
if (!info) return []
|
|
175
|
+
const out = []
|
|
176
|
+
for (const f of info.fields) {
|
|
177
|
+
if (!f.required || f.type === 'bool') continue
|
|
178
|
+
const v = t[f.key]
|
|
179
|
+
if (v === undefined || v === null || String(v).trim() === '') out.push(f.label)
|
|
180
|
+
}
|
|
181
|
+
return out
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** 设置页上那句话:这个目标大概会怎么用。 */
|
|
185
|
+
export function targetBlurb(t) {
|
|
186
|
+
const info = KINDS[t?.kind]
|
|
187
|
+
return info?.steps ?? ''
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* 发给界面的那一份:**密码类字段不回显**,只回一个「填过了没有」。
|
|
192
|
+
*
|
|
193
|
+
* 为什么不让界面拿回原文:令牌、应用密码、授权码都是能直接把账号交出去的东西。
|
|
194
|
+
* 它们已经在 config.json 里躺着(本机文件,绕不开),但没有必要再多流进一次页面 DOM 和
|
|
195
|
+
* 浏览器内存——那一层还多一个「被别的脚本读到」的面。
|
|
196
|
+
* 编辑时密码框留空=不改(由 observe 的 /cloud/target 做合并)。
|
|
197
|
+
*/
|
|
198
|
+
export function publicTarget(t) {
|
|
199
|
+
if (!t) return null
|
|
200
|
+
const info = KINDS[t.kind]
|
|
201
|
+
const out = { id: t.id, kind: t.kind, name: t.name, enabled: t.enabled !== false, ready: Boolean(t.ready), problem: targetProblem(t) }
|
|
202
|
+
const filled = {}
|
|
203
|
+
for (const f of info?.fields ?? []) {
|
|
204
|
+
if (f.type === 'pass') {
|
|
205
|
+
out[f.key] = ''
|
|
206
|
+
filled[f.key] = String(t[f.key] ?? '') !== ''
|
|
207
|
+
} else {
|
|
208
|
+
out[f.key] = t[f.key]
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
out.filled = filled
|
|
212
|
+
return out
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* 保存一条目标时把「留空的密码」补回原值。
|
|
217
|
+
* 界面不回显密码,所以它交上来的那一项一定是空串——这时候空串的意思是「不改」,
|
|
218
|
+
* 不是「清掉」。真要清,用户得把它换成一个新值。
|
|
219
|
+
*/
|
|
220
|
+
export function mergeTargetSecrets(next, old) {
|
|
221
|
+
if (!next || !old || next.kind !== old.kind) return next
|
|
222
|
+
const info = KINDS[next.kind]
|
|
223
|
+
for (const f of info?.fields ?? []) {
|
|
224
|
+
if (f.type !== 'pass') continue
|
|
225
|
+
if (String(next[f.key] ?? '') === '' && String(old[f.key] ?? '') !== '') next[f.key] = old[f.key]
|
|
226
|
+
}
|
|
227
|
+
return next
|
|
228
|
+
}
|
package/lib/comment.js
CHANGED
|
@@ -28,6 +28,7 @@ import { recordGuard } from './guardlog.js'
|
|
|
28
28
|
import { deriveSelf } from './derive.js'
|
|
29
29
|
import { redactOwner } from './redact.js'
|
|
30
30
|
import { fillOwner } from './pronoun.js'
|
|
31
|
+
import { clipText } from './clip.js'
|
|
31
32
|
|
|
32
33
|
/** 出口脱敏用的名字:派生失败就当没有名字,绝不让一次发布因为派生失败而中断。 */
|
|
33
34
|
function safeOwnerName(events, override) {
|
|
@@ -332,24 +333,41 @@ export async function readMyReplies(o = {}) {
|
|
|
332
333
|
const client = o.client ?? createClient({})
|
|
333
334
|
const events = o.events ?? (await readEvents(root)).events
|
|
334
335
|
const { config } = await loadConfig(root)
|
|
336
|
+
// 2026-11-13(issue #136 B):调用方(bili_look)要能分清「没人回」「没发过评论」
|
|
337
|
+
// 「B 站没让查」——以前这些全被吞成空数组,上头只能一律说成 -412。
|
|
338
|
+
// diag 是可选的输出口:不传就什么也不多算,老调用方行为不变。
|
|
339
|
+
const diag = o.diag ?? null
|
|
340
|
+
const clear = () => { if (diag) { diag.off = false; diag.roots = 0; diag.failed = []; diag.unresolved = 0 } }
|
|
341
|
+
clear()
|
|
335
342
|
// issue #62:断网时也不翻自己的旧评论。
|
|
336
|
-
if (!biliOn(config))
|
|
343
|
+
if (!biliOn(config)) {
|
|
344
|
+
if (diag) diag.off = true
|
|
345
|
+
return []
|
|
346
|
+
}
|
|
337
347
|
const mine = await loginMid(root)
|
|
338
348
|
const owners = await ownerMids(root)
|
|
339
349
|
const wantBvid = String(o.bvid ?? '').trim()
|
|
340
350
|
const out = []
|
|
341
351
|
|
|
342
352
|
const days = Math.max(1, Math.min(REPLY_LOOKBACK_DAYS, Number(o.days ?? REPLY_LOOKBACK_DAYS)))
|
|
353
|
+
if (diag) diag.days = days
|
|
343
354
|
const roots = herCommentsRecent(events, days)
|
|
344
355
|
.filter((c) => !wantBvid || c.bvid === wantBvid)
|
|
345
356
|
.slice(0, MAX_SCAN_ROOTS)
|
|
357
|
+
if (diag) diag.roots = roots.length
|
|
346
358
|
|
|
347
359
|
for (const c of roots) {
|
|
348
360
|
const v = await client.view(c.bvid).catch(() => null)
|
|
349
361
|
const aid = Number(v?.data?.aid) || 0
|
|
350
|
-
if (!aid)
|
|
362
|
+
if (!aid) {
|
|
363
|
+
if (diag) diag.unresolved += 1
|
|
364
|
+
continue
|
|
365
|
+
}
|
|
351
366
|
const r = await client.subReplies(aid, c.rpid, { ps: 20 })
|
|
352
|
-
if (!r
|
|
367
|
+
if (!r?.ok) {
|
|
368
|
+
if (diag) diag.failed.push({ code: r?.code ?? 'FAIL', message: String(r?.message ?? '') })
|
|
369
|
+
continue
|
|
370
|
+
}
|
|
353
371
|
const self = selfIn(mine, r, c.rpid) // 和 scanReplies 同一个判断
|
|
354
372
|
for (const s of r.data ?? []) {
|
|
355
373
|
if (!s.rpid || !s.text) continue
|
|
@@ -468,8 +486,8 @@ export async function markRepliesSeen(root, list, { dateKey: dk = dateKey() } =
|
|
|
468
486
|
}
|
|
469
487
|
|
|
470
488
|
function oneLine(s, max) {
|
|
471
|
-
|
|
472
|
-
return
|
|
489
|
+
// issue #141:与 at.js 同因——外部正文按码元切会劈开代理对。
|
|
490
|
+
return clipText(String(s ?? '').replace(/\s+/g, ' ').trim(), max)
|
|
473
491
|
}
|
|
474
492
|
|
|
475
493
|
/**
|
package/lib/contract.js
CHANGED
|
@@ -156,14 +156,19 @@ export function coerceMaterial(raw, o = {}) {
|
|
|
156
156
|
}
|
|
157
157
|
const by = flat(q.by, LIMITS.by) || source
|
|
158
158
|
const qkind = flat(q.kind, LIMITS.kind) || 'body'
|
|
159
|
-
|
|
159
|
+
// 0 赞和「没有赞数这个概念」要分开(issue #140):弹幕根本不带 like,
|
|
160
|
+
// 评论/置顶/不同意见带的是数字,可能是 0。若把 0 也省掉,渲染层就分不清
|
|
161
|
+
// 「确实是 0 赞」和「不适用」,会把 undefined 当赞数递给她。
|
|
162
|
+
const likeRaw = q.like
|
|
163
|
+
const like = Number(likeRaw)
|
|
164
|
+
const hasLike = likeRaw !== undefined && likeRaw !== null && likeRaw !== '' && Number.isFinite(like)
|
|
160
165
|
quotes.push({
|
|
161
166
|
by,
|
|
162
167
|
kind: qkind,
|
|
163
168
|
grade,
|
|
164
169
|
text,
|
|
165
170
|
...(url ? { url } : {}),
|
|
166
|
-
...(
|
|
171
|
+
...(hasLike ? { like: Math.max(0, like) } : {}),
|
|
167
172
|
})
|
|
168
173
|
}
|
|
169
174
|
|
package/lib/deliver.js
CHANGED
|
@@ -53,6 +53,7 @@ import { randomUUID } from 'node:crypto'
|
|
|
53
53
|
import { sessionRow } from './home.js'
|
|
54
54
|
import { recheckToolRestrict } from './restrict.js'
|
|
55
55
|
import { fillOwner } from './pronoun.js'
|
|
56
|
+
import { cleanText } from './clip.js'
|
|
56
57
|
|
|
57
58
|
/**
|
|
58
59
|
* 我们自己起的来源名。
|
|
@@ -115,7 +116,9 @@ export function fishMessage(text = WAKE_PING, { rpcId = '', kind = FISH_SOURCE_K
|
|
|
115
116
|
role: 'user',
|
|
116
117
|
// 正文里指主人的位置写成 `{T}`(见 lib/pronoun.js 文件头);投递前填一次。
|
|
117
118
|
// 这条消息也可能带她的原话(回执、便条),那些文本里没有 `{T}`,不会被碰。
|
|
118
|
-
|
|
119
|
+
// 2026-11-15(issue #141):这是最后一道出口。正文里只要混进一个孤立代理项,
|
|
120
|
+
// 之后每次请求都会因非法 JSON 被整份拒绝——出口再兜一层,别处漏了也不至于锁死会话。
|
|
121
|
+
content: [{ type: 'text', text: cleanText(fillOwner(String(text ?? WAKE_PING))) }],
|
|
119
122
|
source,
|
|
120
123
|
}
|
|
121
124
|
}
|