dsh-folia 4.26.0-pre.12 → 4.26.0-pre.13

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/lib/client.js CHANGED
@@ -20713,10 +20713,32 @@ window.__ModuleLoader__.load({
20713
20713
  },
20714
20714
  postChat: async (text, onState) => {
20715
20715
  petBubble.setState('answer');
20716
- const res = await apiFetch('/pet-chat/chat', {
20717
- method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ text }),
20718
- });
20719
- const reader = res.body.getReader();
20716
+ // ⚠️ apiFetch 的返回值里**已经带上了原始 Response**(字段 `response`)。
20717
+ // 上一版误写成 `res.body.getReader()`:res 是 { ok, status, data, response },
20718
+ // res.body 恒为 undefined ⇒ 抛 TypeError ⇒ 读流代码一行都跑不到
20719
+ // (真机症状:输入后气泡停在 answer 状态、一个字都不出)。
20720
+ // 也不要用裸 fetch —— 守卫 verify-api-client 要求客户端零裸 fetch。
20721
+ let res;
20722
+ try {
20723
+ res = await apiFetch('/pet-chat/chat', {
20724
+ method: 'POST',
20725
+ headers: { 'content-type': 'application/json' },
20726
+ body: JSON.stringify({ text }),
20727
+ });
20728
+ } catch {
20729
+ petBubble.show('连不上宿主,稍后再试');
20730
+ petBubble.hide(3000);
20731
+ if (typeof onState === 'function') onState({ state: 'idle' });
20732
+ return;
20733
+ }
20734
+ const stream = res && res.response;
20735
+ if (!res || !res.ok || !stream || !stream.body) {
20736
+ petBubble.show(res && res.status === 401 ? '模型 Key 无效,去设置里换一把' : '这次没答上来,再试一次');
20737
+ petBubble.hide(3000);
20738
+ if (typeof onState === 'function') onState({ state: 'idle' });
20739
+ return;
20740
+ }
20741
+ const reader = stream.body.getReader();
20720
20742
  const decoder = new TextDecoder();
20721
20743
  let buffer = '';
20722
20744
  for (;;) {
@@ -22,21 +22,43 @@ export const RECORD_DEFAULTS = Object.freeze({
22
22
  sampleRate: 16000,
23
23
  });
24
24
 
25
- /** 从 ffmpeg `-list_devices` 的 stderr 里解析音频设备名(引号内那一段)。 */
25
+ /**
26
+ * 从 ffmpeg `-list_devices` 的 stderr 里解析音频设备名。
27
+ *
28
+ * 两种输出格式都要认(实测两代 ffmpeg 不一样):
29
+ * ① 老式分段:`DirectShow audio devices` … `"麦克风"` … `DirectShow video devices`
30
+ * ② 新式带类型:`[dshow @ …] "麦克风 (C-Media(R) Audio)" (audio)`
31
+ * —— 本仓自带的 ffmpeg 就是这种,**没有** "DirectShow audio devices" 字样,
32
+ * 只按 ① 解析会得到空列表 ⇒ /record 恒回 no-device(真机踩过)。
33
+ * `Alternative name` 行同样是引号包裹,但它不是设备名,必须排除。
34
+ */
26
35
  export function parseDevices(stderr) {
27
36
  const text = String(stderr || '');
37
+ const devices = [];
38
+ const seen = new Set();
39
+ const push = (name) => {
40
+ const clean = String(name || '').trim();
41
+ if (!clean || seen.has(clean)) return;
42
+ seen.add(clean);
43
+ devices.push(clean);
44
+ };
45
+
46
+ // ② 新式:`[dshow @ …] "设备名" (audio|video)` —— 只收 audio
47
+ const typed = /\[dshow[^\]]*\]\s+"([^"]+)"\s+\((audio|video)\)/gi;
48
+ let m;
49
+ while ((m = typed.exec(text)) !== null) {
50
+ if (m[2].toLowerCase() === 'audio') push(m[1]);
51
+ }
52
+ if (devices.length) return devices;
53
+
54
+ // ① 老式:先截出 audio 段,再取引号内容(排除 Alternative name)
28
55
  const audioStart = text.search(/DirectShow audio devices/i);
29
56
  if (audioStart < 0) return [];
30
57
  const section = text.slice(audioStart);
31
58
  const end = section.search(/DirectShow video devices/i);
32
59
  const body = end >= 0 ? section.slice(0, end) : section;
33
- const devices = [];
34
- const pattern = /"([^"]+)"/g;
35
- let match = pattern.exec(body);
36
- while (match) {
37
- devices.push(match[1]);
38
- match = pattern.exec(body);
39
- }
60
+ const pattern = /^\s*(?:\[[^\]]*\]\s*)?"([^"]+)"/gm;
61
+ while ((m = pattern.exec(body)) !== null) push(m[1]);
40
62
  return devices;
41
63
  }
42
64
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-folia",
3
- "version": "4.26.0-pre.12",
3
+ "version": "4.26.0-pre.13",
4
4
  "description": "DSH 壁纸引擎:本机 WE 壁纸实时渲染,视频/网页/开机动画/桌宠皮肤,一键拉取在线素材。",
5
5
  "type": "module",
6
6
  "engines": {