dsh-fish-soul 0.18.4 → 0.18.6
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/README.md +1 -1
- package/lib/channels/vendor/douyin-bridge/douyin-api.mjs +34 -15
- package/lib/channels/vendor/douyin-bridge/douyin-dm.mjs +6 -5
- package/lib/client.js +33 -4
- package/lib/douyin-browse.js +3 -1
- package/lib/gateway.js +3 -3
- package/lib/routes-v07.js +4 -14
- package/lib/routes.js +26 -0
- package/lib/workspace-guard.js +31 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -597,6 +597,33 @@ function decodeMessageNode(c, selfSecUid = '', secByUid = null) {
|
|
|
597
597
|
}
|
|
598
598
|
}
|
|
599
599
|
|
|
600
|
+
/**
|
|
601
|
+
* 这条解出来的消息算不算「一条真消息」。
|
|
602
|
+
*
|
|
603
|
+
* 🔴 **全仓唯一的判据** —— 以前这个判据有 3 份副本(本文件的 `countUseful`
|
|
604
|
+
* 和 `pickMessages` 各一份内联、`douyin-dm.mjs` 的 `filterUseful` 一份),
|
|
605
|
+
* 修一处漏两处:#129 给 `filterUseful` 挡了协议控制帧,但这两处内联副本没挡,
|
|
606
|
+
* 于是控制帧(kind=50001、text 空、带 convId/seq/senderId)照样通过
|
|
607
|
+
* `pickMessages` 的「唯一会话」判定 → 它的 convId 被当成这一轮读到的会话,
|
|
608
|
+
* 多个会话拿到同一个 convId(#128 的串会话)。
|
|
609
|
+
* ⇒ 判据只留这一份,`douyin-dm.mjs` 从这里 import。
|
|
610
|
+
*
|
|
611
|
+
* 判据要点(都是踩出来的,别动):
|
|
612
|
+
* · 不能放 `kind`:空壳消息的 kind 也非 0(实测 58),放进来会让
|
|
613
|
+
* 「解出一堆空壳」的结构赢过「解出真消息」的结构。
|
|
614
|
+
* · 协议控制帧必须挡:`kind === 50001` 或带 `raw.command_type` 的帧
|
|
615
|
+
* (登录态同步、会话标记等)也有 convId/seq/senderId,但它不是用户消息,
|
|
616
|
+
* 拿来定会话归属会把别人的消息记到这个会话头上。
|
|
617
|
+
*
|
|
618
|
+
* @param {object} m parseMessages 解出来的消息
|
|
619
|
+
* @returns {boolean}
|
|
620
|
+
*/
|
|
621
|
+
export function isUsefulMessage(m) {
|
|
622
|
+
if (!m) return false
|
|
623
|
+
if (m.kind === 50001 || (m.raw && m.raw.command_type != null)) return false
|
|
624
|
+
return Boolean(m.text || m.tips || m.shareAweme || m.convId || m.seq || m.senderId)
|
|
625
|
+
}
|
|
626
|
+
|
|
600
627
|
/**
|
|
601
628
|
* 把 hook 抓到的一条 protobuf 响应解成消息数组。
|
|
602
629
|
*
|
|
@@ -642,15 +669,9 @@ export function parseMessages(raw, opts = {}) {
|
|
|
642
669
|
|
|
643
670
|
const selfSecUid = String(opts.selfSecUid || '')
|
|
644
671
|
|
|
645
|
-
//
|
|
646
|
-
//
|
|
647
|
-
|
|
648
|
-
// ⚠️ 判据里**不能放 kind**:空壳消息的 kind 也是非 0(实测 58),放进去会让「解出一堆空壳」
|
|
649
|
-
// 的结构赢过「解出真消息」的结构 —— 直接挑错。只有 convId / seq / senderId 才是
|
|
650
|
-
// 「这条真的是一条带身份的消息」的证据。
|
|
651
|
-
const countUseful = (list) => list.filter(
|
|
652
|
-
(m) => m.text || m.tips || m.shareAweme || m.convId || m.seq || m.senderId,
|
|
653
|
-
).length
|
|
672
|
+
// 「解出来了」的判据走全仓唯一那份(`isUsefulMessage`)—— 详见它的注释:
|
|
673
|
+
// 内联副本会漏掉后来加的判据(协议控制帧),#128 的串会话就是这么来的。
|
|
674
|
+
const countUseful = (list) => list.filter(isUsefulMessage).length
|
|
654
675
|
|
|
655
676
|
// ① 旧结构:消息在 `#6.#301.#1[]`。解每个 item 时重新走一遍原始字段,
|
|
656
677
|
// 否则 36 字节的会话 ID 会被 parseTree 误判成子树(见 fieldsToNodes 注释)。
|
|
@@ -861,12 +882,10 @@ export function pickMessages(captured, opts = {}) {
|
|
|
861
882
|
try {
|
|
862
883
|
const raw = Buffer.from(h.b64, 'base64')
|
|
863
884
|
const parsed = parseMessages(raw, opts)
|
|
864
|
-
//
|
|
865
|
-
//
|
|
866
|
-
//
|
|
867
|
-
const useful = parsed.messages.filter(
|
|
868
|
-
(m) => m.text || m.tips || m.shareAweme || m.convId || m.seq || m.senderId,
|
|
869
|
-
)
|
|
885
|
+
// 判据走全仓唯一那份(`isUsefulMessage`):媒体消息(无 text/tips)也算解出来了,
|
|
886
|
+
// 否则「对方只发图片」的响应会被整条跳过 → 推送/轮询都拿不到 convId;
|
|
887
|
+
// 同时又挡掉协议控制帧(它带 convId,会被当成「这一轮读到的会话」)。
|
|
888
|
+
const useful = parsed.messages.filter(isUsefulMessage)
|
|
870
889
|
if (!useful.length) continue
|
|
871
890
|
const ids = new Set(useful.map((m) => String(m.convId ?? '').trim()).filter((x) => x !== ''))
|
|
872
891
|
// 指定了会话:只要它,别的会话直接跳过
|
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
drain as apiDrain,
|
|
22
22
|
peek as apiPeek,
|
|
23
23
|
pickMessages as apiPickMessages,
|
|
24
|
+
isUsefulMessage,
|
|
24
25
|
parseMessages as apiParseMessages,
|
|
25
26
|
selfInfo as apiSelfInfo,
|
|
26
27
|
triggerFetch as apiTriggerFetch,
|
|
@@ -401,13 +402,13 @@ function shapeResult(rawMessages, limit, via, convId = '') {
|
|
|
401
402
|
*
|
|
402
403
|
* ⚠️ 缓存也要用这个过滤 —— 否则缓存里塞一堆 kind=8 的空壳,
|
|
403
404
|
* `shapeResult` 过滤完就空了,表现为「缓存命中了但 0 条」。
|
|
405
|
+
*
|
|
406
|
+
* 🔴 判据本体在 `douyin-api.mjs` 的 `isUsefulMessage`(全仓唯一一份)。
|
|
407
|
+
* 以前这里是第 3 份副本,于是 #129 只修到这一份、漏了 api 里那两份,
|
|
408
|
+
* 控制帧照样从 `pickMessages` 穿过去(#128 的串会话)。别再复制判据过来。
|
|
404
409
|
*/
|
|
405
410
|
function filterUseful(rawMessages) {
|
|
406
|
-
return (rawMessages || []).filter(
|
|
407
|
-
// ⚠️ 判据里**不能放 kind**:空壳消息的 kind 也是非 0(实测 58),放进来会把
|
|
408
|
-
// 「解出一堆空壳」当成「解出消息」。只有 text/tips/shareAweme 或
|
|
409
|
-
// convId/seq/senderId 才算真的解出了一条带身份的消息。
|
|
410
|
-
m.text || m.tips || m.shareAweme || m.convId || m.seq || m.senderId)
|
|
411
|
+
return (rawMessages || []).filter(isUsefulMessage)
|
|
411
412
|
}
|
|
412
413
|
|
|
413
414
|
/** 内部函数给测试用(不参与对外契约)。 */
|
package/lib/client.js
CHANGED
|
@@ -635,6 +635,8 @@ window.__ModuleLoader__.load({
|
|
|
635
635
|
const [acTime, setAcTime] = react.useState("");
|
|
636
636
|
const [showCookie, setShowCookie] = react.useState(false);
|
|
637
637
|
const [busy, setBusy] = react.useState(false);
|
|
638
|
+
const [olderSeen, setOlderSeen] = react.useState({ items: [], next: null, started: false, busy: false });
|
|
639
|
+
const [olderLog, setOlderLog] = react.useState({ items: [], next: null, started: false, busy: false });
|
|
638
640
|
const [form, setForm, patch] = useForm(data, () => ({
|
|
639
641
|
masterUid: b.masterUid ?? "", allowList: (b.allowList ?? []).join("\n"), links: (b.links ?? []).join("\n"), replyWindowMinutes: b.replyWindowMinutes ?? 120,
|
|
640
642
|
perDay: br.perDay ?? 3, videosPerSession: br.videosPerSession ?? 3, favoritePerDay: br.favoritePerDay ?? 2, searchKeywords: (br.searchKeywords ?? []).join(","), searchPerDay: br.searchPerDay ?? 2, frames: br.frames === true, framesPerDay: br.framesPerDay ?? 1, framesPerDayChat: br.framesPerDayChat ?? 10,
|
|
@@ -696,6 +698,30 @@ window.__ModuleLoader__.load({
|
|
|
696
698
|
...(so.comments?.recent ?? []).map((x, i) => ({ key: `c${i}${x.at}`, tag: Tag(x.status === "replied" ? "回了" : x.status === "failed" ? "没发出" : "没回", x.status === "failed" ? "danger" : undefined),
|
|
697
699
|
text: `${x.name}:${x.content}${x.reply ? ` → ${x.reply}` : ""}`, at: x.at }))
|
|
698
700
|
].sort((x, y) => y.at - x.at).slice(0, 10);
|
|
701
|
+
// #132:加载更多的旧记录合并进面板给的最近几条后面
|
|
702
|
+
const socialLogAll = [...socialLog, ...olderLog.items.map((x) => ({
|
|
703
|
+
key: x.key,
|
|
704
|
+
tag: x.kind === "post" ? Tag("动态", "outline")
|
|
705
|
+
: Tag(x.status === "replied" ? "回了" : x.status === "failed" ? "没发出" : "没回", x.status === "failed" ? "danger" : undefined),
|
|
706
|
+
text: x.text, at: x.at
|
|
707
|
+
}))].sort((x, y) => y.at - x.at);
|
|
708
|
+
const recentAll = [...recent, ...olderSeen.items];
|
|
709
|
+
const seenNext = olderSeen.started ? olderSeen.next : (recent.length > 0 ? recent[recent.length - 1].seenAt : null);
|
|
710
|
+
const logNext = olderLog.started ? olderLog.next : (socialLog.length > 0 ? socialLog[socialLog.length - 1].at : null);
|
|
711
|
+
const loadMoreSeen = async () => {
|
|
712
|
+
if (seenNext === null || olderSeen.busy) return;
|
|
713
|
+
setOlderSeen((s) => ({ ...s, busy: true }));
|
|
714
|
+
const r = await api("GET", `/bili/seen?before=${seenNext}&limit=20`);
|
|
715
|
+
if (r?.ok) setOlderSeen((s) => ({ items: [...s.items, ...r.items], next: r.next, started: true, busy: false }));
|
|
716
|
+
else { setOlderSeen((s) => ({ ...s, busy: false })); notify(r?.error ?? "加载失败"); }
|
|
717
|
+
};
|
|
718
|
+
const loadMoreLog = async () => {
|
|
719
|
+
if (logNext === null || olderLog.busy) return;
|
|
720
|
+
setOlderLog((s) => ({ ...s, busy: true }));
|
|
721
|
+
const r = await api("GET", `/bili/social-log?before=${logNext}&limit=20`);
|
|
722
|
+
if (r?.ok) setOlderLog((s) => ({ items: [...s.items, ...r.items], next: r.next, started: true, busy: false }));
|
|
723
|
+
else { setOlderLog((s) => ({ ...s, busy: false })); notify(r?.error ?? "加载失败"); }
|
|
724
|
+
};
|
|
699
725
|
|
|
700
726
|
return h(react.Fragment, null,
|
|
701
727
|
Group({ title: "账号" },
|
|
@@ -792,13 +818,16 @@ window.__ModuleLoader__.load({
|
|
|
792
818
|
cm.enabled ? Row({ title: "回一句大概多长", desc: "给模型的上限提示,不是硬截断;评论区默认 40 字比较像真人" },
|
|
793
819
|
Num({ min: 10, max: 300, step: 10, value: form.commentsReplyChars, "aria-label": "回评论字数", onChange: (e) => patch({ commentsReplyChars: e.target.value }), onBlur: () => save() }), Muted("字")) : null,
|
|
794
820
|
so.lastError ? Row({ title: "上次出错" }, State("error", so.lastError)) : null,
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
821
|
+
socialLogAll.length === 0 ? null : h(react.Fragment, null,
|
|
822
|
+
h("div", { className: "fs-list" }, socialLogAll.map((x) => Item({ key: x.key, lead: x.tag, text: x.text, title: x.text, meta: [h("span", { key: "t" }, relTime(x.at, Date.now()))] }))),
|
|
823
|
+
logNext !== null ? h("div", { style: { padding: "4px 12px 8px" } }, Button({ variant: "ghost", disabled: olderLog.busy, onClick: loadMoreLog }, olderLog.busy ? "加载中…" : "加载更多")) : null)),
|
|
824
|
+
recentAll.length === 0 ? null : Group({ title: "最近看过" },
|
|
825
|
+
h("div", { className: "fs-list" }, recentAll.map((v) => Item({
|
|
798
826
|
key: v.bvid, lead: Tag(v.favorited ? "藏" : v.liked ? "赞" : v.skipped ? "划走" : v.source === "following" ? "关注" : v.source === "search" ? "搜索" : "推荐", v.liked ? "danger" : undefined),
|
|
799
827
|
text: `${v.title}${v.impression ? ` — ${v.impression}` : ""}`, title: `${v.title}${v.owner ? ` · ${v.owner}` : ""}${v.impression ? `\n${v.impression}` : ""}`,
|
|
800
828
|
meta: [h("a", { key: "a", href: `https://www.bilibili.com/video/${v.bvid}`, target: "_blank", rel: "noreferrer" }, v.owner || v.bvid), h("span", { key: "t" }, relTime(v.seenAt, Date.now()))]
|
|
801
|
-
})))
|
|
829
|
+
}))),
|
|
830
|
+
seenNext !== null ? h("div", { style: { padding: "4px 12px 8px" } }, Button({ variant: "ghost", disabled: olderSeen.busy, onClick: loadMoreSeen }, olderSeen.busy ? "加载中…" : "加载更多")) : null))
|
|
802
831
|
}
|
|
803
832
|
|
|
804
833
|
// ── 按需加载的分块:抖音页(client.douyin.js)、记忆检视 / 动态(client.soul.js)、模型(client.models.js)、人格(client.persona.js);控件通过 props.ui 传过去 ──
|
package/lib/douyin-browse.js
CHANGED
|
@@ -231,7 +231,9 @@ export class DouyinBrowser {
|
|
|
231
231
|
const timeout = () => Math.max(1, Math.min(this.tm.evalTimeoutMs, left()));
|
|
232
232
|
// 预算耗尽后**不能再发起** eval / send / 睡眠:max(1,…) 只防 0,不是通行证。
|
|
233
233
|
// 否则点「下一条」失败后,键盘 / 滚轮分支会各在预算之外再等一次超时,照样霸锁。
|
|
234
|
-
|
|
234
|
+
// 🔴 剩余预算只剩几毫秒时也别发起:timeout() 的 max(1,…) 会把 1ms 当成可用预算,
|
|
235
|
+
// 于是 send 在 left()=1ms 时被放行、1ms 后超时——断言「预算耗尽后不再发起」会红。
|
|
236
|
+
const expired = () => left() <= 10;
|
|
235
237
|
const changed = async () => {
|
|
236
238
|
for (let i = 0; i < 8; i++) {
|
|
237
239
|
if (expired()) return false;
|
package/lib/gateway.js
CHANGED
|
@@ -384,11 +384,11 @@ export class ChatGateway {
|
|
|
384
384
|
* 昵称可以随便改,只拿昵称当身份 ⇒ 任何人改名就能读/写别人的私聊会话
|
|
385
385
|
* (真机验证过,PR #96 原版确实能并进去)。
|
|
386
386
|
*
|
|
387
|
-
* 但主人习惯在设置页写「昵称 = QQ
|
|
387
|
+
* 但主人习惯在设置页写「昵称 = QQ 号」(比如填 `某个昵称=12345678` 这种)。
|
|
388
388
|
* 所以这里做成**两级**:
|
|
389
389
|
*
|
|
390
|
-
* ① **数字 uid 对应表**(`
|
|
391
|
-
* ②
|
|
390
|
+
* ① **数字 uid 对应表**(`1234567890123456=12345678`)—— 直接认,最硬;
|
|
391
|
+
* ② **昵称对应表**(`某个昵称=12345678`)—— 只用来**定位候选**,
|
|
392
392
|
* 还必须拿到这个会话的**真实 uid**,且该 uid 已在**绑定表**里被确认过
|
|
393
393
|
* (`douyin.uin.<uid>` → QQ 号)。
|
|
394
394
|
*
|
package/lib/routes-v07.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* - 首次引导:检查清单 + 不再显示。
|
|
8
8
|
*/
|
|
9
9
|
import { existsSync, readFileSync, createWriteStream, unlinkSync, mkdirSync } from 'node:fs';
|
|
10
|
-
import { join, basename
|
|
10
|
+
import { join, basename } from 'node:path';
|
|
11
11
|
import { pipeline } from 'node:stream/promises';
|
|
12
12
|
import { Transform } from 'node:stream';
|
|
13
13
|
import { randomUUID } from 'node:crypto';
|
|
@@ -21,6 +21,7 @@ import { WEB_PROVIDERS, webSearchConfig, ownSearchReady } from './websearch.js';
|
|
|
21
21
|
import { listChatSessions } from './db.js';
|
|
22
22
|
import { previewMaiBotExtras, importMaiBotExtras, sniffImage } from './maibot-extras.js';
|
|
23
23
|
import { maskKey } from './routes.js';
|
|
24
|
+
import { sameWorkspace, knownWorkspace as _knownWorkspace } from './workspace-guard.js';
|
|
24
25
|
|
|
25
26
|
const BODY_MAX = 256 * 1024;
|
|
26
27
|
const IMPORT_BODY_MAX = 6 * 1024 * 1024; // 旧路(JSON + base64)的 body 上限
|
|
@@ -103,19 +104,8 @@ export async function handleV07Route({ method, path, url, req, res, send, readBo
|
|
|
103
104
|
const renamed = stickers?.autoRename?.(r.file, tags, args.workspacePath) ?? { ok: false };
|
|
104
105
|
return { ...r, ...(renamed.ok ? { file: renamed.file } : {}), tags };
|
|
105
106
|
};
|
|
106
|
-
|
|
107
|
-
const
|
|
108
|
-
const x = String(a ?? ''); const y = String(b ?? '');
|
|
109
|
-
if (x === '' || y === '') return false;
|
|
110
|
-
try { return resolve(x) === resolve(y); } catch { return x === y; }
|
|
111
|
-
};
|
|
112
|
-
/** ws 得是认得的工作区(当前工作区 / 收藏记录里出现过的),不能随便指个目录来读、改、删文件。 */
|
|
113
|
-
const knownWorkspace = (p) => {
|
|
114
|
-
const ws = String(p ?? '');
|
|
115
|
-
if (ws === '') return false;
|
|
116
|
-
if (sameWorkspace(ws, gateway?.workspacePath?.() ?? '')) return true;
|
|
117
|
-
return (stickers?.collected() ?? []).some((x) => sameWorkspace(x.workspacePath, ws));
|
|
118
|
-
};
|
|
107
|
+
// 工作区校验从 workspace-guard.js 来(设计消除:不 import 就没有)
|
|
108
|
+
const knownWorkspace = (p) => _knownWorkspace(p, gateway, stickers);
|
|
119
109
|
const webState = () => {
|
|
120
110
|
const w = webConfig?.() ?? webSearchConfig({});
|
|
121
111
|
return {
|
package/lib/routes.js
CHANGED
|
@@ -567,6 +567,7 @@ export function registerRoutes(ctx, deps) {
|
|
|
567
567
|
followUpCount: q.followUpCount ?? 3,
|
|
568
568
|
followUpSeconds: q.followUpSeconds ?? 120,
|
|
569
569
|
followUpSmart: q.followUpSmart === true,
|
|
570
|
+
mentionOnly: q.mentionOnly === true,
|
|
570
571
|
// 回显:设置页的数字框要能读回来,否则改完刷新又弹回去(写进去读不出来)
|
|
571
572
|
replyWindowMinutes: clampReplyWindow(q.replyWindowMinutes),
|
|
572
573
|
batchMs: q.batchMs ?? 3000,
|
|
@@ -857,6 +858,31 @@ export function registerRoutes(ctx, deps) {
|
|
|
857
858
|
return send(200, { ok: true, started: true });
|
|
858
859
|
}
|
|
859
860
|
|
|
861
|
+
// ── #132:设置页「最近看过 / 动态和评论」分页(只读,时间戳游标)──
|
|
862
|
+
// 游标是「at < before」严格小于:同一毫秒的多条若恰好跨页,下一页会把同毫秒剩余的跳过(不重复不死循环,只是丢几条;串行写入基本撞不上)。
|
|
863
|
+
if (method === 'GET' && path === '/bili/seen') {
|
|
864
|
+
const before = Number(url.searchParams.get('before')) || Number.MAX_SAFE_INTEGER;
|
|
865
|
+
const limit = Math.min(50, Math.max(1, Math.floor(Number(url.searchParams.get('limit')) || 20)));
|
|
866
|
+
const rows = db.prepare(`SELECT bvid, title, owner_name AS owner, impression, skipped, liked, favorited, source, seen_real_at AS seenAt
|
|
867
|
+
FROM bili_seen WHERE seen_real_at < ? ORDER BY seen_real_at DESC LIMIT ?`).all(before, limit + 1)
|
|
868
|
+
.map((r) => ({ ...r, skipped: r.skipped === 1, liked: r.liked === 1, favorited: r.favorited === 1 }));
|
|
869
|
+
const items = rows.slice(0, limit);
|
|
870
|
+
return send(200, { ok: true, items, next: rows.length > limit ? items[items.length - 1].seenAt : null });
|
|
871
|
+
}
|
|
872
|
+
if (method === 'GET' && path === '/bili/social-log') {
|
|
873
|
+
const before = Number(url.searchParams.get('before')) || Number.MAX_SAFE_INTEGER;
|
|
874
|
+
const limit = Math.min(50, Math.max(1, Math.floor(Number(url.searchParams.get('limit')) || 20)));
|
|
875
|
+
const posts = db.prepare(`SELECT id, post_id, content, created_real_at FROM social_post
|
|
876
|
+
WHERE platform = 'bili' AND created_real_at < ? ORDER BY created_real_at DESC LIMIT ?`).all(before, limit + 1)
|
|
877
|
+
.map((r) => ({ key: `mp${r.id}`, kind: 'post', text: r.content, at: r.created_real_at }));
|
|
878
|
+
const replies = db.prepare(`SELECT rowid, from_name, subject, content, reply, status, created_real_at FROM social_reply
|
|
879
|
+
WHERE platform = 'bili' AND status != 'backlog' AND created_real_at < ? ORDER BY created_real_at DESC LIMIT ?`).all(before, limit + 1)
|
|
880
|
+
.map((r) => ({ key: `mc${r.rowid}`, kind: 'reply', status: r.status, text: `${r.from_name}:${r.content}${r.reply ? ` → ${r.reply}` : ''}`, at: r.created_real_at }));
|
|
881
|
+
const merged = [...posts, ...replies].sort((a, b) => b.at - a.at).slice(0, limit + 1);
|
|
882
|
+
const items = merged.slice(0, limit);
|
|
883
|
+
return send(200, { ok: true, items, next: merged.length > limit ? items[items.length - 1].at : null });
|
|
884
|
+
}
|
|
885
|
+
|
|
860
886
|
// ── v0.10:现在发一条动态 / 现在看一眼评论 ──
|
|
861
887
|
if (method === 'POST' && (path === '/bili/post-now' || path === '/bili/comments-now')) {
|
|
862
888
|
if (!sameOrigin(req)) return send(403, { ok: false, error: 'forbidden' });
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 工作区路径守卫:sameWorkspace / knownWorkspace。
|
|
3
|
+
*
|
|
4
|
+
* 为什么抽出来:
|
|
5
|
+
* routes-v07.js 的 _stickers 路由靠这两个函数挡「随便指个目录来读改删文件」。
|
|
6
|
+
* 抽成独立模块让其他需要校验工作区路径的路由直接 import,
|
|
7
|
+
* 让「不校验」变成「import 不到」——设计消除,不靠记得调。
|
|
8
|
+
*
|
|
9
|
+
* 参照:D40(/stickers 写路由加 knownWorkspace 白名单)。
|
|
10
|
+
*/
|
|
11
|
+
import { resolve } from 'node:path';
|
|
12
|
+
|
|
13
|
+
/** 同一个工作区?路径写法可能不一样(相对 / 绝对),比绝对路径。 */
|
|
14
|
+
export function sameWorkspace(a, b) {
|
|
15
|
+
const x = String(a ?? ''); const y = String(b ?? '');
|
|
16
|
+
if (x === '' || y === '') return false;
|
|
17
|
+
try { return resolve(x) === resolve(y); } catch { return x === y; }
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* ws 得是认得的工作区(当前工作区 / 收藏记录里出现过的),不能随便指个目录来读、改、删文件。
|
|
22
|
+
* @param {string} p 待校验的工作区路径
|
|
23
|
+
* @param {{ workspacePath?: () => string }} gateway 网关(拿当前工作区)
|
|
24
|
+
* @param {{ collected?: () => Array<{workspacePath: string}> }} stickers 表情包(拿历史工作区)
|
|
25
|
+
*/
|
|
26
|
+
export function knownWorkspace(p, gateway, stickers) {
|
|
27
|
+
const ws = String(p ?? '');
|
|
28
|
+
if (ws === '') return false;
|
|
29
|
+
if (sameWorkspace(ws, gateway?.workspacePath?.() ?? '')) return true;
|
|
30
|
+
return (stickers?.collected() ?? []).some((x) => sameWorkspace(x.workspacePath, ws));
|
|
31
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-fish-soul",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.6",
|
|
4
4
|
"description": "鱼 · 人格、按人记忆(可纠正、有印象、能导入旧聊天记录)、日程自走与主动开口,直连 SnowLuma 收发 QQ(群里会自己插话),B站 / 抖音小号私信与自己刷视频;按功能选模型并统计用量花费,能听会说 QQ 语音、收藏表情包、学群里的梗,可选上网查;心情影响说话、去 AI 味、每个群的设定、按聊天选模型、每晚写日记、每周记忆存档与可选周记(DSH 插件,单角色 feiyu ,v0.15.37)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -64,6 +64,6 @@
|
|
|
64
64
|
}
|
|
65
65
|
},
|
|
66
66
|
"scripts": {
|
|
67
|
-
"test": "node test/memory-bulk-move.mjs && node test/safe-download.mjs && node test/douyin-exact-id.mjs && node test/douyin-pb-init.mjs && node test/douyin-conversation.mjs && node test/douyin-inbox.mjs && node test/douyin-quarantine.mjs && node test/douyin-send-target.mjs && node test/douyin-send-exclusive.mjs && node test/douyin-gap-dedupe.mjs && node test/douyin-message-id-dedupe.mjs && node test/douyin-read-fail-retry.mjs && node test/douyin-read-cache.mjs && node test/douyin-dm-media-conv.mjs && node test/douyin-read-fail-retry-poll.mjs && node test/douyin-inbox-contract.mjs && node test/person-attribution.mjs && node test/memory-owner-reassign.mjs && node test/douyin-poll-and-timer-safety.mjs && node test/p2-limits.mjs && node test/resource-safety.mjs && node test/leftover-edge-cases.mjs && node test/douyin-master-person-merge.mjs && node test/douyin-master-uid.mjs && node test/douyin-identity-e2e.mjs && node test/douyin-post-jobs.mjs && node test/retrieval-filtered-vectors.mjs && node test/security-boundaries.mjs && node test/douyin-cdp-cursor.mjs && node test/douyin-nav-timeout.mjs && node test/persona-isolation.mjs && node test/smoke.mjs && node test/douyin-browser.mjs && node test/douyin-page-alive.mjs && node test/douyin-eval-timeout.mjs && node test/douyin-bridge-timeout.mjs && node test/douyin-goto-budget.mjs && node test/douyin-music.mjs && node test/startup-gate.mjs && node test/outbox.mjs && node test/import-coverage.mjs && node test/update-check.mjs && node test/issue-fixes.mjs && node test/import-resume.mjs && node test/maibot-extras.mjs && node test/worldinfo.mjs && node test/memory-bulk.mjs && node test/memory-tiers.mjs && node test/memory-weekly.mjs && node test/issue-98-self-archive.mjs && node test/issue-99-memory-order.mjs && node test/issue-115-memory-date.mjs && node test/issue-119-memory-page.mjs && node test/issue-125-memory-filter.mjs && node test/issue-78-diagnostic.mjs && node test/memory-storage.mjs && node test/memory-storage-restore.mjs && node test/backup-restore.mjs && node test/douyin-group.mjs && node test/review-fixes.mjs && node test/at-reads-video.mjs && node test/search-source.mjs && node test/followups.mjs && node test/detail-config.mjs && node test/qq-send-any-image.mjs && node test/qq-read-attachment.mjs && node test/qq-batch-window.mjs && node test/comment-video.mjs && node test/frames.mjs && node test/face-name.mjs && node test/comment-reply.mjs && node test/chat-comment.mjs && node test/at-target.mjs && node test/quota-caps.mjs && node test/client-lint.mjs && node test/client-panels.mjs && node test/dsh-desktop.mjs && node test/group-mention-only.mjs && node test/qq-private-allowlist.mjs && node test/issue-59-interject.mjs && node test/issue-59-diagnose.mjs && node test/sticker-backfill.mjs && node test/issue-118-sticker-diagnostics.mjs && node test/sticker-manage.mjs && node test/bili-emotes.mjs && node test/qq-outbound-sanitize.mjs && node test/person-delete.mjs && node test/qq-group-admin.mjs && node test/douyin-recovery.mjs && node test/session-preset.mjs && node test/qq-connect-error.mjs && node test/douyin-comment-bridge.mjs && node test/douyin-comment-write-unknown.mjs && node test/douyin-reply-verify-status.mjs && node test/bili-comment-emoji.mjs && node test/douyin-state-echo.mjs && node test/issue-75-proactive.mjs && node test/issue-76-capability.mjs && node test/douyin-http-browse.mjs && node test/douyin-verify-backoff.mjs && node test/douyin-digg-bridge.mjs && node test/memory-evidence-transcript.mjs && node test/chat-archive-default.mjs && node test/issue-113-desktop-archive.mjs && node test/dream-transcript-wire.mjs && node test/douyin-frames-collect.mjs && node test/master-qq-uin-rebind.mjs && node test/douyin-session-health.mjs && node test/douyin-delivered.mjs && node test/douyin-card-share.mjs && node test/douyin-push-drop.mjs && node test/douyin-stranger-dm.mjs && node test/douyin-uid-binding.mjs && node test/image-webp-fallback.mjs && node test/douyin-emoji-fallback.mjs && node test/relay-other-platform.mjs && node test/issue-101-voice-files.mjs && node test/voice-volcengine.mjs && node test/voice-minimax-dashscope.mjs && node test/bili-switch-persist.mjs && node test/cross-channel-context.mjs && node test/reply-target.mjs && node test/shared-session.mjs && node test/memory-source-label.mjs && node test/pending-delivery.mjs && node test/recall-window-78.mjs && node test/memory-recall-recent-78.mjs && node test/client-syntax.mjs && node test/diag-log.mjs && node test/check-rings.mjs && node test/release-workflow.mjs && node test/sticker-import-gif.mjs && node test/sticker-real-gif.mjs && node test/sticker-upload-binary.mjs && node test/sticker-vision-tags.mjs && node test/sticker-manual-tags.mjs && node test/sticker-auto-name.mjs && node test/self-update.mjs && node test/group-list.mjs && node test/douyin-inbox-noise.mjs && node test/douyin-inbox-diag.mjs && node test/douyin-inbox-stuck.mjs && node test/reply-window.mjs && node test/douyin-sticker-heuristic.mjs && node test/douyin-image-boundary.mjs && node test/media-image-boundary.mjs && node test/douyin-comment-identity-cid.mjs"
|
|
67
|
+
"test": "node test/memory-bulk-move.mjs && node test/safe-download.mjs && node test/douyin-exact-id.mjs && node test/douyin-pb-init.mjs && node test/douyin-conversation.mjs && node test/douyin-inbox.mjs && node test/douyin-quarantine.mjs && node test/douyin-send-target.mjs && node test/douyin-send-exclusive.mjs && node test/douyin-gap-dedupe.mjs && node test/douyin-message-id-dedupe.mjs && node test/douyin-read-fail-retry.mjs && node test/douyin-read-cache.mjs && node test/douyin-dm-media-conv.mjs && node test/douyin-read-fail-retry-poll.mjs && node test/douyin-inbox-contract.mjs && node test/person-attribution.mjs && node test/memory-owner-reassign.mjs && node test/douyin-poll-and-timer-safety.mjs && node test/p2-limits.mjs && node test/resource-safety.mjs && node test/leftover-edge-cases.mjs && node test/douyin-master-person-merge.mjs && node test/douyin-master-uid.mjs && node test/douyin-identity-e2e.mjs && node test/douyin-post-jobs.mjs && node test/retrieval-filtered-vectors.mjs && node test/security-boundaries.mjs && node test/douyin-cdp-cursor.mjs && node test/douyin-nav-timeout.mjs && node test/persona-isolation.mjs && node test/smoke.mjs && node test/douyin-browser.mjs && node test/douyin-page-alive.mjs && node test/douyin-eval-timeout.mjs && node test/douyin-bridge-timeout.mjs && node test/douyin-goto-budget.mjs && node test/douyin-music.mjs && node test/startup-gate.mjs && node test/outbox.mjs && node test/import-coverage.mjs && node test/update-check.mjs && node test/issue-fixes.mjs && node test/import-resume.mjs && node test/maibot-extras.mjs && node test/worldinfo.mjs && node test/memory-bulk.mjs && node test/memory-tiers.mjs && node test/memory-weekly.mjs && node test/issue-98-self-archive.mjs && node test/issue-99-memory-order.mjs && node test/issue-115-memory-date.mjs && node test/issue-119-memory-page.mjs && node test/issue-125-memory-filter.mjs && node test/issue-78-diagnostic.mjs && node test/memory-storage.mjs && node test/memory-storage-restore.mjs && node test/backup-restore.mjs && node test/douyin-group.mjs && node test/review-fixes.mjs && node test/at-reads-video.mjs && node test/search-source.mjs && node test/followups.mjs && node test/detail-config.mjs && node test/qq-send-any-image.mjs && node test/qq-read-attachment.mjs && node test/qq-batch-window.mjs && node test/comment-video.mjs && node test/frames.mjs && node test/face-name.mjs && node test/comment-reply.mjs && node test/chat-comment.mjs && node test/at-target.mjs && node test/quota-caps.mjs && node test/client-lint.mjs && node test/client-panels.mjs && node test/dsh-desktop.mjs && node test/group-mention-only.mjs && node test/qq-private-allowlist.mjs && node test/issue-59-interject.mjs && node test/issue-59-diagnose.mjs && node test/sticker-backfill.mjs && node test/issue-118-sticker-diagnostics.mjs && node test/sticker-manage.mjs && node test/bili-emotes.mjs && node test/qq-outbound-sanitize.mjs && node test/person-delete.mjs && node test/qq-group-admin.mjs && node test/douyin-recovery.mjs && node test/session-preset.mjs && node test/qq-connect-error.mjs && node test/douyin-comment-bridge.mjs && node test/douyin-comment-write-unknown.mjs && node test/douyin-reply-verify-status.mjs && node test/bili-comment-emoji.mjs && node test/douyin-state-echo.mjs && node test/issue-75-proactive.mjs && node test/issue-76-capability.mjs && node test/douyin-http-browse.mjs && node test/douyin-verify-backoff.mjs && node test/douyin-digg-bridge.mjs && node test/memory-evidence-transcript.mjs && node test/chat-archive-default.mjs && node test/issue-113-desktop-archive.mjs && node test/dream-transcript-wire.mjs && node test/douyin-frames-collect.mjs && node test/master-qq-uin-rebind.mjs && node test/douyin-session-health.mjs && node test/douyin-delivered.mjs && node test/douyin-card-share.mjs && node test/douyin-push-drop.mjs && node test/douyin-stranger-dm.mjs && node test/douyin-uid-binding.mjs && node test/image-webp-fallback.mjs && node test/douyin-emoji-fallback.mjs && node test/relay-other-platform.mjs && node test/issue-101-voice-files.mjs && node test/voice-volcengine.mjs && node test/voice-minimax-dashscope.mjs && node test/bili-switch-persist.mjs && node test/cross-channel-context.mjs && node test/reply-target.mjs && node test/shared-session.mjs && node test/memory-source-label.mjs && node test/pending-delivery.mjs && node test/recall-window-78.mjs && node test/memory-recall-recent-78.mjs && node test/client-syntax.mjs && node test/diag-log.mjs && node test/check-rings.mjs && node test/release-workflow.mjs && node test/sticker-import-gif.mjs && node test/sticker-real-gif.mjs && node test/sticker-upload-binary.mjs && node test/sticker-vision-tags.mjs && node test/sticker-manual-tags.mjs && node test/sticker-auto-name.mjs && node test/self-update.mjs && node test/group-list.mjs && node test/douyin-inbox-noise.mjs && node test/douyin-inbox-diag.mjs && node test/douyin-inbox-stuck.mjs && node test/reply-window.mjs && node test/douyin-sticker-heuristic.mjs && node test/douyin-image-boundary.mjs && node test/media-image-boundary.mjs && node test/douyin-comment-identity-cid.mjs && node test/qq-mention-only-echo.mjs && node test/bili-panel-pagination.mjs && node test/bili-allowlist.mjs && node test/douyin-master-uid-mismatch.mjs && node test/check-test-chain.mjs && node test/check-route-guard.mjs && node test/check-client-imports.mjs && node test/check-secrets.mjs"
|
|
68
68
|
}
|
|
69
69
|
}
|