dsh-mikan 0.2.2 → 0.3.0

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/client.js CHANGED
@@ -6,7 +6,22 @@ window.__ModuleLoader__.load({
6
6
  const { useState, useEffect, useCallback } = React;
7
7
 
8
8
  const API = '/dsh-mikan';
9
+ /** Per-source namespace for the Mikan module (`getJson` prepends API). */
10
+ const MIKAN = '/source/mikan';
9
11
  const WEEK = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'];
12
+ /** nyaa categories, named in Chinese; only the Anime branch is relevant. */
13
+ const NYAA_CATEGORIES = [
14
+ ['1_0', '全部'],
15
+ ['1_1', '音乐视频'],
16
+ ['1_2', '英译'],
17
+ ['1_3', '非英译(中字为主)'],
18
+ ['1_4', '生肉'],
19
+ ];
20
+ /** Active Chinese fansub groups used to filter nyaa results locally. */
21
+ const NYAA_GROUPS = [
22
+ 'ANi', 'LoliHouse', '喵萌奶茶屋', '桜都字幕组', '诸神字幕组',
23
+ 'SweetSub', '北宇治字幕组', 'Prejudice-Studio', '幻樱字幕组', '凉风字幕组',
24
+ ];
10
25
  /** Fired after any action that can change the update digest. */
11
26
  const CHANGED_EVENT = 'dsh-mikan:changed';
12
27
 
@@ -107,6 +122,18 @@ window.__ModuleLoader__.load({
107
122
  ));
108
123
  }
109
124
 
125
+ /** Extract the port from a proxy string; the plugin only ever uses localhost. */
126
+ function portOfProxy(proxy) {
127
+ const raw = String(proxy || '').trim();
128
+ if (!raw) return '';
129
+ try {
130
+ return new URL(raw.includes('://') ? raw : `http://${raw}`).port || '';
131
+ } catch {
132
+ const digits = raw.replace(/\D/g, '');
133
+ return digits;
134
+ }
135
+ }
136
+
110
137
  function SchedulePage() {
111
138
  const [schedule, setSchedule] = useState(null);
112
139
  const [state, setState] = useState(null);
@@ -114,7 +141,7 @@ window.__ModuleLoader__.load({
114
141
  const [error, setError] = useState('');
115
142
  const [busy, setBusy] = useState('');
116
143
  const [notice, setNotice] = useState('');
117
- const [port, setPort] = useState('7890');
144
+ const [proxyInput, setProxyInput] = useState('');
118
145
  const [dialog, setDialog] = useState(null);
119
146
  const [browse, setBrowse] = useState(null);
120
147
  const [expanded, setExpanded] = useState({});
@@ -125,6 +152,17 @@ window.__ModuleLoader__.load({
125
152
  const [mikanBaseInput, setMikanBaseInput] = useState('');
126
153
  const [bgmBaseInput, setBgmBaseInput] = useState('');
127
154
  const [nyaaBaseInput, setNyaaBaseInput] = useState('');
155
+ // Settings dialog state.
156
+ const [savePathInput, setSavePathInput] = useState('');
157
+ // Nyaa search state.
158
+ const [nyaaQuery, setNyaaQuery] = useState('');
159
+ const [nyaaCategory, setNyaaCategory] = useState('1_0');
160
+ const [nyaaGroup, setNyaaGroup] = useState('');
161
+ const [nyaaResults, setNyaaResults] = useState(null);
162
+ const [nyaaShowing, setNyaaShowing] = useState(30);
163
+ const [intervalInput, setIntervalInput] = useState('');
164
+ const [namePrefInput, setNamePrefInput] = useState('cn');
165
+ const [indexInfo, setIndexInfo] = useState(null);
128
166
 
129
167
  const load = useCallback(async ({ autoCheck = false } = {}) => {
130
168
  try {
@@ -135,7 +173,7 @@ window.__ModuleLoader__.load({
135
173
  const age = up.checkedAt ? Date.now() - new Date(up.checkedAt).getTime() : Infinity;
136
174
  if (autoCheck && age > 5 * 60 * 1000 && (up.subscriptions || 0) > 0) {
137
175
  try {
138
- await postJson('/check');
176
+ await postJson(MIKAN + '/check');
139
177
  up = await getJson('/status');
140
178
  } catch { /* keep the previous digest */ }
141
179
  }
@@ -152,11 +190,27 @@ window.__ModuleLoader__.load({
152
190
  setBusy('bridge');
153
191
  setNotice('');
154
192
  try {
155
- const r = await postJson('/bridge', { input: port });
193
+ const r = await postJson('/bridge', { input: proxyInput });
156
194
  setNotice(r.ok ? `已桥接:${r.proxy}` : `失败:${r.reason}`);
157
195
  await load();
158
196
  } catch (e) { setNotice('桥接失败:' + e.message); } finally { setBusy(''); }
159
- }, [port, load]);
197
+ }, [proxyInput, load]);
198
+
199
+ const saveProxy = useCallback(async () => {
200
+ setBusy('proxy');
201
+ try {
202
+ const raw = proxyInput.trim();
203
+ const value = raw ? (/^\d+$/.test(raw) ? `http://127.0.0.1:${raw}` : raw) : '';
204
+ await postJson('/config', { proxy: value });
205
+ const r = await getJson('/state?refresh=1');
206
+ setState(r);
207
+ setNotice(r.mode === 'proxy' ? `代理已生效:端口 ${portOfProxy(r.proxy)}` : '代理不可用,仍为直连');
208
+ } catch (e) {
209
+ setNotice('保存失败:' + e.message);
210
+ } finally {
211
+ setBusy('');
212
+ }
213
+ }, [proxyInput]);
160
214
 
161
215
  const disconnect = useCallback(async () => {
162
216
  setBusy('disconnect');
@@ -210,7 +264,7 @@ window.__ModuleLoader__.load({
210
264
  if (!browse) return;
211
265
  setBusy('batch');
212
266
  try {
213
- const r = await getJson(`/works?bangumiId=${encodeURIComponent(browse.bangumiId)}&subgroupId=${encodeURIComponent(browse.subgroupId || '')}&subgroupName=${encodeURIComponent(browse.subgroupName || '')}&limit=500`);
267
+ const r = await getJson(`${MIKAN}/works?bangumiId=${encodeURIComponent(browse.bangumiId)}&subgroupId=${encodeURIComponent(browse.subgroupId || '')}&subgroupName=${encodeURIComponent(browse.subgroupName || '')}&limit=500`);
214
268
  const list = r.items || [];
215
269
  const candidates = list.filter((w) => lang === 'all' || (w.subtitle || 'multi') === lang);
216
270
  if (candidates.length === 0) {
@@ -228,11 +282,67 @@ window.__ModuleLoader__.load({
228
282
  }
229
283
  }, [browse]);
230
284
 
231
- const checkUpdates = useCallback(async () => {
232
- setBusy('check');
285
+ const runNyaaSearch = useCallback(async () => {
286
+ const q = nyaaQuery.trim();
287
+ if (!q) {
288
+ setNotice('请输入关键词');
289
+ return;
290
+ }
291
+ setBusy('nyaa');
292
+ try {
293
+ // nyaa indexes Japanese titles, so translate the Chinese input first.
294
+ let term = q;
295
+ try {
296
+ const resolved = await getJson(`/resolve-names?q=${encodeURIComponent(q)}`);
297
+ const jp = resolved.ok ? (resolved.matches?.[0]?.jp || '') : '';
298
+ if (jp) term = jp;
299
+ } catch { /* fall back to the raw keyword */ }
300
+ const r = await getJson(`/nyaa-search?q=${encodeURIComponent(term)}&c=${nyaaCategory}`);
301
+ if (!r.ok) {
302
+ setNotice(r.reason || '检索失败');
303
+ return;
304
+ }
305
+ let items = r.items || [];
306
+ if (nyaaGroup) items = items.filter((it) => String(it.title || '').includes(nyaaGroup));
307
+ setNyaaResults({ items, total: items.length, keyword: q, usedTerm: term });
308
+ setNyaaShowing(30);
309
+ setDialog({ type: 'nyaa-results' });
310
+ } catch (e) {
311
+ setNotice('检索失败:' + e.message);
312
+ } finally {
313
+ setBusy('');
314
+ }
315
+ }, [nyaaQuery, nyaaCategory, nyaaGroup]);
316
+
317
+ /** Fetch the info hash for one nyaa result, then queue it in the order. */
318
+ const addNyaaToOrder = useCallback(async (item) => {
319
+ if (!item.id) {
320
+ setNotice('这条结果没有 id,无法取 hash');
321
+ return;
322
+ }
323
+ setBusy('nyaa-add');
324
+ try {
325
+ const detail = await getJson(`/nyaa-hash?id=${encodeURIComponent(item.id)}`);
326
+ if (!detail.ok || !detail.hash) {
327
+ setNotice(`取 hash 失败:${detail.reason || '未知'}`);
328
+ return;
329
+ }
330
+ await postJson('/order/add', {
331
+ items: [{ hash: detail.hash, title: item.title, size: item.size || '', episode: '' }],
332
+ });
333
+ setNotice(`已加入点单:${String(item.title || '').slice(0, 40)}`);
334
+ window.dispatchEvent(new Event(CHANGED_EVENT));
335
+ } catch (e) {
336
+ setNotice('加入点单失败:' + e.message);
337
+ } finally {
338
+ setBusy('');
339
+ }
340
+ }, []);
341
+
342
+ const checkUpdates = useCallback(async () => { setBusy('check');
233
343
  setNotice('');
234
344
  try {
235
- const r = await postJson('/check');
345
+ const r = await postJson(MIKAN + '/check');
236
346
  setDialog({ type: 'check', title: '更新检查', updates: r.updates || [] });
237
347
  window.dispatchEvent(new Event(CHANGED_EVENT));
238
348
  await load();
@@ -249,7 +359,7 @@ window.__ModuleLoader__.load({
249
359
  const setSilent = useCallback(async (item, silent) => {
250
360
  setBusy('silent');
251
361
  try {
252
- await postJson('/silent', { id: item.id, silent });
362
+ await postJson(MIKAN + '/silent', { id: item.id, silent });
253
363
  setNotice(silent ? `已静默:${item.title}` : `已恢复:${item.title}`);
254
364
  window.dispatchEvent(new Event(CHANGED_EVENT));
255
365
  await load();
@@ -259,7 +369,7 @@ window.__ModuleLoader__.load({
259
369
  const unsubscribe = useCallback(async (item) => {
260
370
  setBusy('unsub');
261
371
  try {
262
- await postJson('/unsubscribe', { id: item.id });
372
+ await postJson(MIKAN + '/unsubscribe', { id: item.id });
263
373
  setNotice(`已取消订阅:${item.title}`);
264
374
  window.dispatchEvent(new Event(CHANGED_EVENT));
265
375
  await load();
@@ -277,7 +387,7 @@ window.__ModuleLoader__.load({
277
387
  setDialog({ type: 'browse' });
278
388
  setBrowse({ level: 'season', year: y, season: s, loading: true, groups: [] });
279
389
  try {
280
- const r = await getJson(`/season-list?year=${y}&season=${encodeURIComponent(s)}`);
390
+ const r = await getJson(`${MIKAN}/season-list?year=${y}&season=${encodeURIComponent(s)}`);
281
391
  setBrowse({ level: 'season', year: y, season: s, loading: false, groups: r.groups || [] });
282
392
  } catch (e) {
283
393
  setBrowse({ level: 'season', year: y, season: s, loading: false, groups: [], error: e.message });
@@ -288,7 +398,7 @@ window.__ModuleLoader__.load({
288
398
  setDialog({ type: 'browse' });
289
399
  setBrowse({ level: 'bangumi', bangumiId: id, title, loading: true, subgroups: [], season: ctx?.season, year: ctx?.year, weekday: ctx?.weekday });
290
400
  try {
291
- const r = await getJson(`/bangumi-info?bangumiId=${encodeURIComponent(id)}&title=${encodeURIComponent(title || '')}`);
401
+ const r = await getJson(`${MIKAN}/bangumi-info?bangumiId=${encodeURIComponent(id)}&title=${encodeURIComponent(title || '')}`);
292
402
  setBrowse({
293
403
  level: 'bangumi', bangumiId: id, title: r.title || title, season: ctx?.season, year: ctx?.year,
294
404
  weekday: r.weekday || ctx?.weekday || '', startDate: r.startDate || '', airDate: r.airDate || '',
@@ -306,7 +416,7 @@ window.__ModuleLoader__.load({
306
416
  subgroupId: subgroup.subgroupId, subgroupName: subgroup.name, loading: true, works: [],
307
417
  }));
308
418
  try {
309
- const r = await getJson(`/works?bangumiId=${encodeURIComponent(id)}&subgroupId=${encodeURIComponent(subgroup.subgroupId || '')}&subgroupName=${encodeURIComponent(subgroup.name || '')}&limit=30`);
419
+ const r = await getJson(`${MIKAN}/works?bangumiId=${encodeURIComponent(id)}&subgroupId=${encodeURIComponent(subgroup.subgroupId || '')}&subgroupName=${encodeURIComponent(subgroup.name || '')}&limit=30`);
310
420
  setBrowse((b) => ({ ...b, loading: false, works: r.items || [], total: r.total || 0, limit: 30, counts: r.counts || null }));
311
421
  } catch (e) {
312
422
  setBrowse((b) => ({ ...b, loading: false, works: [], error: e.message }));
@@ -317,7 +427,7 @@ window.__ModuleLoader__.load({
317
427
  if (!browse?.bangumiId || !subgroup) return;
318
428
  setBusy('subscribe');
319
429
  try {
320
- const r = await postJson('/subscribe-group', {
430
+ const r = await postJson(MIKAN + '/subscribe-group', {
321
431
  bangumiId: browse.bangumiId,
322
432
  title: browse.title,
323
433
  season: browse.season || '',
@@ -341,7 +451,7 @@ window.__ModuleLoader__.load({
341
451
  if (!browse) return;
342
452
  const next = Math.min((browse.limit || 30) + 30, browse.total || 0);
343
453
  try {
344
- const r = await getJson(`/works?bangumiId=${encodeURIComponent(browse.bangumiId)}&subgroupId=${encodeURIComponent(browse.subgroupId || '')}&subgroupName=${encodeURIComponent(browse.subgroupName || '')}&limit=${next}`);
454
+ const r = await getJson(`${MIKAN}/works?bangumiId=${encodeURIComponent(browse.bangumiId)}&subgroupId=${encodeURIComponent(browse.subgroupId || '')}&subgroupName=${encodeURIComponent(browse.subgroupName || '')}&limit=${next}`);
345
455
  setBrowse((b) => ({ ...b, works: r.items || [], total: r.total || 0, limit: next }));
346
456
  } catch (e) {
347
457
  setNotice('加载更多失败:' + e.message);
@@ -351,7 +461,7 @@ window.__ModuleLoader__.load({
351
461
  const showAllWorks = useCallback(async () => {
352
462
  if (!browse) return;
353
463
  try {
354
- const r = await getJson(`/works?bangumiId=${encodeURIComponent(browse.bangumiId)}&subgroupId=${encodeURIComponent(browse.subgroupId || '')}&subgroupName=${encodeURIComponent(browse.subgroupName || '')}&limit=500`);
464
+ const r = await getJson(`${MIKAN}/works?bangumiId=${encodeURIComponent(browse.bangumiId)}&subgroupId=${encodeURIComponent(browse.subgroupId || '')}&subgroupName=${encodeURIComponent(browse.subgroupName || '')}&limit=500`);
355
465
  setBrowse((b) => ({ ...b, works: r.items || [], total: r.total || 0, limit: r.displayed || 500 }));
356
466
  } catch (e) {
357
467
  setNotice('加载失败:' + e.message);
@@ -370,7 +480,7 @@ window.__ModuleLoader__.load({
370
480
  setBatchStats(null);
371
481
  setDialog({ type: 'batch' });
372
482
  try {
373
- const r = await getJson(`/works?bangumiId=${encodeURIComponent(bangumiId)}&subgroupId=${encodeURIComponent(subgroup.subgroupId || '')}&subgroupName=${encodeURIComponent(subgroup.name || '')}&limit=500`);
483
+ const r = await getJson(`${MIKAN}/works?bangumiId=${encodeURIComponent(bangumiId)}&subgroupId=${encodeURIComponent(subgroup.subgroupId || '')}&subgroupName=${encodeURIComponent(subgroup.name || '')}&limit=500`);
374
484
  const list = r.items || [];
375
485
  setBatchStats({
376
486
  all: list.length,
@@ -625,16 +735,21 @@ window.__ModuleLoader__.load({
625
735
 
626
736
  return h('div', { style: { padding: '18px 22px', overflow: 'auto', height: '100%' } },
627
737
  h('div', { style: { display: 'flex', alignItems: 'baseline', gap: 12, marginBottom: 12, flexWrap: 'wrap' } },
628
- h('h2', { style: { margin: 0, fontSize: 20 } }, '追番周历'),
738
+ h('h2', { style: { margin: 0, fontSize: 20 } }, '追番助手'),
629
739
  h('span', { style: muted }, `${total} 部订阅`),
740
+ h('span', { style: { width: 60, flex: '0 0 auto' } }),
741
+ h('button', { onClick: () => setDialog({ type: 'manual' }) }, '用户手册'),
630
742
  h('span', { style: { flex: 1 } }),
631
- h('button', { onClick: () => openSeason(), disabled: Boolean(busy) }, '当季浏览'),
632
- h('button', { onClick: () => setDialog({ type: 'season-picker' }), disabled: Boolean(busy) }, '往季浏览'),
743
+ h('button', { onClick: () => { setSavePathInput(state?.savePath || ''); setIntervalInput(String(state?.checkIntervalMinutes ?? 30)); setNamePrefInput(state?.namePreference || 'cn'); setIndexInfo(null); setDialog({ type: 'settings' }); } }, '设置'),
633
744
  h('button', { onClick: checkUpdates, disabled: Boolean(busy) }, busy === 'check' ? '检查中…' : '检查更新'),
634
745
  h('button', { onClick: () => load(), disabled: Boolean(busy) }, '刷新')),
635
746
 
636
747
  state && h('div', { style: { ...panel, display: 'flex', flexWrap: 'wrap', gap: 10, alignItems: 'center', padding: '10px 12px', marginBottom: 12 } },
637
- h(Pill, { ok: state.mode === 'proxy', warn: state.mode !== 'proxy' }, state.mode === 'proxy' ? '代理模式' : '直连模式'),
748
+ h(Pill, {
749
+ ok: state.mode === 'proxy',
750
+ warn: state.mode !== 'proxy',
751
+ onClick: () => { setProxyInput(portOfProxy(state?.proxy)); setDialog({ type: 'proxy' }); },
752
+ }, state.mode === 'proxy' ? '代理模式' : '直连模式'),
638
753
  h(Pill, {
639
754
  ok: state.mikanOk !== false,
640
755
  onClick: () => { setMikanBaseInput(state?.mikanCustom || ''); setDialog({ type: 'mikan' }); },
@@ -685,12 +800,7 @@ window.__ModuleLoader__.load({
685
800
  h('span', { style: { fontSize: 13, overflow: 'hidden', textOverflow: 'ellipsis' } }, text));
686
801
  })(),
687
802
 
688
- h('div', { style: { ...panel, display: 'flex', flexWrap: 'wrap', gap: 8, alignItems: 'center', padding: '10px 12px', marginBottom: 16 } },
689
- h('label', { style: { fontSize: 13 } }, '代理桥接'),
690
- h('input', { value: port, onChange: (e) => setPort(e.target.value), placeholder: '7890 或 http://127.0.0.1:7890', style: { width: 220, padding: '6px 8px' } }),
691
- h('button', { onClick: bridge, disabled: busy === 'bridge' }, busy === 'bridge' ? '桥接中…' : '自动桥接'),
692
- state?.mode === 'proxy' ? h('button', { onClick: disconnect, disabled: busy === 'disconnect' }, '断开桥接') : null,
693
- notice ? h('span', { style: muted }, notice) : null),
803
+ notice ? h('div', { style: { ...muted, marginBottom: 12 } }, notice) : null,
694
804
 
695
805
  h('div', { style: { display: 'grid', gridTemplateColumns: 'repeat(7, minmax(0, 1fr))', gap: 8 } },
696
806
  WEEK.map((label) => {
@@ -717,6 +827,43 @@ window.__ModuleLoader__.load({
717
827
  h('button', { style: { fontSize: 11, padding: '2px 7px' }, onClick: (e) => { e.stopPropagation(); unsubscribe(item); } }, '取消订阅')))));
718
828
  })),
719
829
 
830
+ // ---------- source modules ----------
831
+ h('div', { style: { display: 'flex', flexDirection: 'column', gap: 10, marginTop: 18 } },
832
+ state?.mikanOk !== false ? h('div', { style: { ...panel, padding: '12px 14px' } },
833
+ h('div', { style: { display: 'flex', alignItems: 'center', gap: 8, marginBottom: 10 } },
834
+ h('img', { src: API + '/assets/mikan.png', width: 20, height: 20, alt: '', style: { borderRadius: 4 } }),
835
+ h('span', { style: { fontWeight: 600, fontSize: 13 } }, '蜜柑计划')),
836
+ h('div', { style: { display: 'flex', gap: 8, flexWrap: 'wrap' } },
837
+ h('button', { onClick: () => openSeason(), disabled: Boolean(busy) }, '当季浏览'),
838
+ h('button', { onClick: () => setDialog({ type: 'season-picker' }), disabled: Boolean(busy) }, '往季浏览')))
839
+ : null,
840
+ state?.nyaa ? h('div', { style: { ...panel, padding: '12px 14px' } },
841
+ h('div', { style: { display: 'flex', alignItems: 'center', gap: 8, marginBottom: 10 } },
842
+ h('img', { src: API + '/assets/nyaa.png', width: 20, height: 20, alt: '', style: { borderRadius: 4 } }),
843
+ h('span', { style: { fontWeight: 600, fontSize: 13 } }, 'Nyaa')),
844
+ h('div', { style: { display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap' } },
845
+ h('input', {
846
+ value: nyaaQuery,
847
+ onChange: (e) => setNyaaQuery(e.target.value),
848
+ onKeyDown: (e) => { if (e.key === 'Enter') runNyaaSearch(); },
849
+ placeholder: '番剧中文名',
850
+ style: { flex: 1, minWidth: 180, padding: '6px 8px' },
851
+ }),
852
+ h('select', {
853
+ value: nyaaCategory,
854
+ onChange: (e) => setNyaaCategory(e.target.value),
855
+ style: { padding: '6px 8px' },
856
+ }, NYAA_CATEGORIES.map(([value, label]) => h('option', { key: value, value }, label))),
857
+ h('select', {
858
+ value: nyaaGroup,
859
+ onChange: (e) => setNyaaGroup(e.target.value),
860
+ style: { padding: '6px 8px' },
861
+ },
862
+ h('option', { value: '' }, '全部字幕组'),
863
+ NYAA_GROUPS.map((g) => h('option', { key: g, value: g }, g))),
864
+ h('button', { onClick: runNyaaSearch, disabled: busy === 'nyaa' }, busy === 'nyaa' ? '检索中…' : '检索')))
865
+ : null),
866
+
720
867
  silentList.length > 0 ? h('div', { style: { marginTop: 18 } },
721
868
  h('div', { style: { ...muted, marginBottom: 6 } }, `静默关注(${silentList.length})— 已从周表下架,仍会收到更新`),
722
869
  silentList.map((item) => h('div', { key: item.id, style: row },
@@ -810,6 +957,203 @@ window.__ModuleLoader__.load({
810
957
  : h('div', { style: muted }, '加载作品中…'),
811
958
  h('div', { style: { ...muted, marginTop: 12 } }, '没有对应语言的作品会置灰。'))) : null,
812
959
 
960
+ dialog && dialog.type === 'nyaa-results' && nyaaResults ? h(Overlay, {
961
+ title: `Nyaa 检索 · ${nyaaResults.keyword}${nyaaResults.usedTerm && nyaaResults.usedTerm !== nyaaResults.keyword ? ` → ${nyaaResults.usedTerm}` : ''}`,
962
+ onClose: () => { setDialog(null); setNyaaResults(null); },
963
+ }, h('div', null,
964
+ h('div', { style: { ...muted, marginBottom: 10 } },
965
+ `共 ${nyaaResults.total} 条${nyaaGroup ? `(已过滤字幕组:${nyaaGroup})` : ''}`),
966
+ nyaaResults.items.length === 0
967
+ ? h('div', { style: muted }, '没有结果。nyaa 只认日文名,换个关键词试试。')
968
+ : h('div', null,
969
+ nyaaResults.items.slice(0, nyaaShowing).map((it) => h('div', { key: it.id || it.title, style: row },
970
+ h('div', { style: { flex: 1 } },
971
+ h('div', { style: { fontSize: 13, lineHeight: 1.35 } }, it.title),
972
+ h('div', { style: muted },
973
+ `${it.size || '—'} · 做种 ${it.seeders ?? '—'} · ${it.category || ''}`)),
974
+ h('button', { disabled: Boolean(busy), onClick: () => addNyaaToOrder(it) },
975
+ busy === 'nyaa-add' ? '查询中…' : '加入点单'))),
976
+ nyaaResults.items.length > nyaaShowing
977
+ ? h('div', { style: { display: 'flex', gap: 8, justifyContent: 'center', marginTop: 14 } },
978
+ h('button', { onClick: () => setNyaaShowing((n) => n + 30) },
979
+ `显示更多(已显示 ${Math.min(nyaaShowing, nyaaResults.items.length)} / ${nyaaResults.total})`),
980
+ h('button', { onClick: () => setNyaaShowing(nyaaResults.items.length) },
981
+ `显示全部(${nyaaResults.total})`))
982
+ : null))) : null,
983
+
984
+ dialog && dialog.type === 'manual' ? h(Overlay, {
985
+ title: '追番助手 · 用户手册', onClose: () => setDialog(null),
986
+ }, h('div', { style: { lineHeight: 1.85, fontSize: 13 } },
987
+ [
988
+ ['快速开始', [
989
+ '在对话里说「部署媒体库」:可以指定一个专门目录(如 D:\\Anime),不指定则用当前会话的工作区。',
990
+ 'DSH 的默认工作区或配置目录不能当媒体库。',
991
+ '部署会创建「下载中转站」,并把下载器的默认路径改到那里。',
992
+ '这个文件夹不要删除或重命名,整理功能依赖它。',
993
+ ]],
994
+ ['订阅番剧', [
995
+ '点「当季浏览」或「往季浏览」,选番 → 选字幕组 → 订阅。',
996
+ '订阅从该组的最新一集开始,之后的新集会提示。',
997
+ '「检查更新」可以手动查一次。',
998
+ ]],
999
+ ['点单下载', [
1000
+ '搜到资源后加入点单,在会话顶部的「番剧下载点单」里确认。',
1001
+ '确认后才会真正交给下载器,不会自动下载。',
1002
+ ]],
1003
+ ['搜索资源', [
1004
+ '蜜柑用中文名,nyaa 用日文名,两边结果可以对照着看。',
1005
+ 'nyaa 搜不到时,先用名称转换查一下日文名。',
1006
+ 'nyaa 的结果带做种数,能判断资源是否还活着。',
1007
+ ]],
1008
+ ['整理媒体库', [
1009
+ '下载完成后说「整理」,会按【YYYY.M】番名/Season N 归类。',
1010
+ '【YYYY.M】取第一季播出季度;没有分季的电影取上映年月。',
1011
+ '多季放 Season 2、Season 3;OVA、Movie、特典各自单独目录。',
1012
+ '默认只演练不移动,确认后才真正搬运。',
1013
+ ]],
1014
+ ['设置', [
1015
+ '保存路径、检查间隔、番剧文件夹命名方式(中文/日文/英文)。',
1016
+ '连接:代理、Mikan、Bangumi、Nyaa、下载器。',
1017
+ '本地索引:季表与名称库,可查看状态或重建。',
1018
+ ]],
1019
+ ['本地索引', [
1020
+ '季表记录每部番的 Mikan id,名称库记录中/日/英文名与首播日期。',
1021
+ '名称库离线可用,整理时不用每次联网。',
1022
+ '重建名称库需要联网一次(约 7 MB)。',
1023
+ ]],
1024
+ ['找不到番?', [
1025
+ '换个名字试试,也可以先用名称转换查别名。',
1026
+ 'nyaa 只认日文名,中文名直接搜通常没有结果。',
1027
+ ]],
1028
+ ].map(([title, items]) => h('div', { key: title, style: { marginBottom: 18 } },
1029
+ h('div', { style: { fontWeight: 600, marginBottom: 6 } }, title),
1030
+ items.map((t, i) => h('div', { key: i, style: { ...muted, marginBottom: 4 } }, '· ' + t)))))) : null,
1031
+
1032
+ dialog && dialog.type === 'settings' ? h(Overlay, {
1033
+ title: '设置', onClose: () => setDialog(null),
1034
+ }, h('div', null,
1035
+ h('div', { style: { fontWeight: 600, fontSize: 13, marginBottom: 8 } }, '下载'),
1036
+ h('div', { style: row },
1037
+ h('span', { style: { width: 96, fontSize: 13 } }, '保存路径'),
1038
+ h('input', {
1039
+ value: savePathInput,
1040
+ onChange: (e) => setSavePathInput(e.target.value),
1041
+ placeholder: 'E:\\中转',
1042
+ style: { flex: 1, minWidth: 220, padding: '6px 8px' },
1043
+ }),
1044
+ h('button', {
1045
+ onClick: async () => {
1046
+ try {
1047
+ await postJson('/config', { savePath: savePathInput.trim() });
1048
+ await load();
1049
+ setNotice('保存路径已更新');
1050
+ } catch (e) { setNotice('保存失败:' + e.message); }
1051
+ },
1052
+ }, '保存')),
1053
+ h('div', { style: { ...muted, margin: '6px 0 16px' } },
1054
+ '下载器把任务存到这里;整理工具从「下载中转站」搬运。'),
1055
+
1056
+ h('div', { style: { fontWeight: 600, fontSize: 13, marginBottom: 8 } }, '插件行为'),
1057
+ h('div', { style: row },
1058
+ h('span', { style: { width: 96, fontSize: 13 } }, '检查间隔'),
1059
+ h('input', {
1060
+ value: intervalInput,
1061
+ onChange: (e) => setIntervalInput(e.target.value),
1062
+ style: { width: 80, padding: '6px 8px' },
1063
+ }),
1064
+ h('span', { style: muted }, '分钟'),
1065
+ h('button', {
1066
+ onClick: async () => {
1067
+ try {
1068
+ await postJson('/config', { checkIntervalMinutes: Number(intervalInput) || 30 });
1069
+ await load();
1070
+ setNotice('检查间隔已更新');
1071
+ } catch (e) { setNotice('保存失败:' + e.message); }
1072
+ },
1073
+ }, '保存')),
1074
+ h('div', { style: row },
1075
+ h('span', { style: { width: 96, fontSize: 13 } }, '命名方式'),
1076
+ h('select', {
1077
+ value: namePrefInput,
1078
+ onChange: (e) => setNamePrefInput(e.target.value),
1079
+ style: { padding: '6px 8px' },
1080
+ },
1081
+ h('option', { value: 'cn' }, '中文名'),
1082
+ h('option', { value: 'jp' }, '日文名'),
1083
+ h('option', { value: 'en' }, '英文名'),
1084
+ h('option', { value: 'romaji' }, '罗马音')),
1085
+ h('button', {
1086
+ onClick: async () => {
1087
+ try {
1088
+ await postJson('/config', { namePreference: namePrefInput });
1089
+ await load();
1090
+ setNotice('命名方式已更新');
1091
+ } catch (e) { setNotice('保存失败:' + e.message); }
1092
+ },
1093
+ }, '保存')),
1094
+ h('div', { style: { ...muted, margin: '6px 0 16px' } },
1095
+ '整理时番剧文件夹才用的命名方式。'),
1096
+
1097
+ h('div', { style: { fontWeight: 600, fontSize: 13, margin: '16px 0 8px' } }, '连接'),
1098
+ h('div', { style: { display: 'flex', gap: 8, flexWrap: 'wrap' } },
1099
+ h('button', { onClick: () => { setProxyInput(portOfProxy(state?.proxy)); setDialog({ type: 'proxy' }); } }, '代理'),
1100
+ h('button', { onClick: () => { setMikanBaseInput(state?.mikanCustom || ''); setDialog({ type: 'mikan' }); } }, 'Mikan'),
1101
+ h('button', { onClick: () => { setBgmBaseInput(state?.bgmCustom || ''); setDialog({ type: 'bgm' }); } }, 'Bangumi'),
1102
+ h('button', { onClick: () => { setNyaaBaseInput(state?.nyaaCustom || ''); setDialog({ type: 'nyaa' }); } }, 'Nyaa'),
1103
+ h('button', { onClick: () => setDialog({ type: 'downloader' }) }, '下载器')),
1104
+
1105
+ h('div', { style: { fontWeight: 600, fontSize: 13, margin: '16px 0 8px' } }, '本地索引'),
1106
+ h('div', { style: { display: 'flex', gap: 8, flexWrap: 'wrap' } },
1107
+ h('button', {
1108
+ onClick: async () => {
1109
+ setBusy('settings');
1110
+ try {
1111
+ const [cat, names] = await Promise.all([getJson('/catalog-status'), getJson('/names-status')]);
1112
+ setIndexInfo({ cat, names });
1113
+ } catch (e) { setNotice('读取索引状态失败:' + e.message); } finally { setBusy(''); }
1114
+ },
1115
+ }, busy === 'settings' ? '读取中…' : '查看状态'),
1116
+ h('button', {
1117
+ onClick: async () => {
1118
+ setBusy('settings');
1119
+ try {
1120
+ const r = await postJson('/names-build');
1121
+ setNotice(r.ok ? `名称库已更新:${r.entries} 条` : `更新失败:${r.reason}`);
1122
+ } catch (e) { setNotice('更新失败:' + e.message); } finally { setBusy(''); }
1123
+ },
1124
+ }, '重建名称库')),
1125
+ indexInfo ? h('div', { style: { ...muted, marginTop: 8, lineHeight: 1.7 } },
1126
+ `季表:${indexInfo.cat.series || 0} 部 / ${indexInfo.cat.seasons || 0} 季`,
1127
+ h('br'),
1128
+ `名称库:${indexInfo.names.entries || 0} 条${indexInfo.names.updatedAt ? `(更新于 ${String(indexInfo.names.updatedAt).slice(0, 10)})` : '(未构建)'}`) : null,
1129
+
1130
+ h('div', { style: { display: 'flex', justifyContent: 'flex-end', marginTop: 18 } },
1131
+ h('button', { onClick: () => setDialog({ type: 'manual' }) }, '用户手册')),
1132
+ )) : null,
1133
+
1134
+ dialog && dialog.type === 'proxy' ? h(Overlay, { title: '代理连接', onClose: () => setDialog(null),
1135
+ }, h('div', null,
1136
+ h('div', { style: { marginBottom: 10, fontSize: 13 } },
1137
+ state?.mode === 'proxy'
1138
+ ? `当前:代理模式(端口 ${portOfProxy(state.proxy) || '?'})`
1139
+ : '当前:直连模式'),
1140
+ h('div', { style: { ...muted, marginBottom: 12, lineHeight: 1.7 } },
1141
+ '代理用于访问墙外资源,只填端口即可(默认为本机)。留空则是直连模式。'),
1142
+ h('div', { style: { display: 'flex', gap: 8, flexWrap: 'wrap', marginBottom: 10 } },
1143
+ h('input', {
1144
+ value: proxyInput,
1145
+ onChange: (e) => setProxyInput(e.target.value),
1146
+ placeholder: '7890',
1147
+ style: { width: 120, padding: '6px 8px' },
1148
+ }),
1149
+ h('button', { onClick: saveProxy, disabled: Boolean(busy) }, busy === 'proxy' ? '保存中…' : '保存并检测'),
1150
+ h('button', { onClick: bridge, disabled: busy === 'bridge' }, busy === 'bridge' ? '桥接中…' : '自动桥接')),
1151
+ h('div', { style: { display: 'flex', gap: 8, flexWrap: 'wrap' } },
1152
+ state?.mode === 'proxy' ? h('button', { onClick: disconnect, disabled: busy === 'disconnect' }, '断开代理') : null,
1153
+ h('button', { onClick: refreshEnv, disabled: Boolean(busy) }, busy === 'env' ? '检测中…' : '重新检测')),
1154
+ h('div', { style: { ...muted, marginTop: 10 } }, '自动桥接会扫描本地常见代理端口,找到即填上。'),
1155
+ )) : null,
1156
+
813
1157
  dialog && dialog.type === 'nyaa' ? h(Overlay, {
814
1158
  title: 'Nyaa 连接', onClose: () => setDialog(null),
815
1159
  }, h('div', null,
@@ -963,15 +1307,160 @@ window.__ModuleLoader__.load({
963
1307
  );
964
1308
  }
965
1309
 
1310
+ /* ---------------- conversation order (点单) ---------------- */
1311
+
1312
+ function OrderEntry({ sessionId }) {
1313
+ const [count, setCount] = useState(0);
1314
+ useEffect(() => {
1315
+ let stopped = false;
1316
+ // Without a sessionId the server falls back to the active session, so
1317
+ // the badge still works when this slot provides no props.
1318
+ const url = sessionId ? '/order?sessionId=' + encodeURIComponent(sessionId) : '/order';
1319
+ const load = () => getJson(url)
1320
+ .then((r) => { if (!stopped) setCount((r.items || []).length); })
1321
+ .catch(() => {});
1322
+ load();
1323
+ const timer = setInterval(load, 8000);
1324
+ return () => { stopped = true; clearInterval(timer); };
1325
+ }, [sessionId]);
1326
+ if (!count) return null;
1327
+ return h('span', {
1328
+ title: '当前会话的番剧点单',
1329
+ style: { fontSize: 12, opacity: 0.75, padding: '0 6px', whiteSpace: 'nowrap' },
1330
+ }, `点单 ${count}`);
1331
+ }
1332
+
1333
+ function OrderView({ sessionId }) {
1334
+ const [items, setItems] = useState([]);
1335
+ const [checked, setChecked] = useState({});
1336
+ const [busy, setBusy] = useState('');
1337
+ const [notice, setNotice] = useState('');
1338
+
1339
+ const load = useCallback(async () => {
1340
+ if (!sessionId) return;
1341
+ try {
1342
+ const r = await getJson('/order?sessionId=' + encodeURIComponent(sessionId));
1343
+ setItems(r.items || []);
1344
+ setChecked({});
1345
+ } catch (e) {
1346
+ setNotice('加载失败:' + e.message);
1347
+ }
1348
+ }, [sessionId]);
1349
+
1350
+ useEffect(() => { load(); }, [load]);
1351
+
1352
+ const remove = async (hash) => {
1353
+ setBusy(hash);
1354
+ try {
1355
+ await postJson('/order/remove', { sessionId, hash });
1356
+ await load();
1357
+ } catch (e) {
1358
+ setNotice('移除失败:' + e.message);
1359
+ } finally {
1360
+ setBusy('');
1361
+ }
1362
+ };
1363
+
1364
+ const toggle = (hash) => setChecked((c) => ({ ...c, [hash]: !c[hash] }));
1365
+
1366
+ const confirm = async (onlyChecked) => {
1367
+ const hashes = onlyChecked ? Object.keys(checked).filter((k) => checked[k]) : [];
1368
+ if (onlyChecked && hashes.length === 0) {
1369
+ setNotice('没有勾选任何条目');
1370
+ return;
1371
+ }
1372
+ setBusy('confirm');
1373
+ try {
1374
+ const r = await postJson('/order/confirm', { sessionId, hashes });
1375
+ setNotice(r.ok
1376
+ ? `已提交 ${r.added} 个任务到下载器${r.removed ? `,点单移除 ${r.removed} 条` : ''}`
1377
+ : `提交失败:${r.reason || '下载器未就绪'}`);
1378
+ await load();
1379
+ } catch (e) {
1380
+ setNotice('提交失败:' + e.message);
1381
+ } finally {
1382
+ setBusy('');
1383
+ }
1384
+ };
1385
+
1386
+ const clear = async () => {
1387
+ setBusy('clear');
1388
+ try {
1389
+ await postJson('/order/clear', { sessionId });
1390
+ setNotice('点单已清空');
1391
+ await load();
1392
+ } catch (e) {
1393
+ setNotice('清空失败:' + e.message);
1394
+ } finally {
1395
+ setBusy('');
1396
+ }
1397
+ };
1398
+
1399
+ const checkedCount = Object.keys(checked).filter((k) => checked[k]).length;
1400
+
1401
+ return h('div', { style: { padding: '16px 20px', overflow: 'auto', height: '100%' } },
1402
+ h('div', { style: { display: 'flex', alignItems: 'baseline', gap: 10, marginBottom: 12 } },
1403
+ h('h3', { style: { margin: 0, fontSize: 16 } }, '番剧点单'),
1404
+ h('span', { style: muted }, `${items.length} 条`),
1405
+ h('span', { style: { flex: 1 } }),
1406
+ items.length > 0 ? h('button', { onClick: clear, disabled: Boolean(busy) }, '清空') : null,
1407
+ items.length > 0 ? h('button', {
1408
+ onClick: () => confirm(true),
1409
+ disabled: Boolean(busy) || checkedCount === 0,
1410
+ }, `确认选中(${checkedCount})`) : null,
1411
+ items.length > 0 ? h('button', {
1412
+ onClick: () => confirm(false),
1413
+ disabled: Boolean(busy),
1414
+ }, `全部下载(${items.length})`) : null),
1415
+
1416
+ notice ? h('div', { style: { ...muted, marginBottom: 10 } }, notice) : null,
1417
+
1418
+ items.length === 0
1419
+ ? h('div', { style: { ...muted, marginTop: 24 } },
1420
+ '这个对话还没有点单。在对话里让我把想下的集数加进点单,确认后在这里下载。')
1421
+ : items.map((it) => h('div', {
1422
+ key: it.hash,
1423
+ style: { ...row, gap: 10 },
1424
+ },
1425
+ h('input', {
1426
+ type: 'checkbox',
1427
+ checked: Boolean(checked[it.hash]),
1428
+ onChange: () => toggle(it.hash),
1429
+ style: { flex: '0 0 auto' },
1430
+ }),
1431
+ h('div', { style: { flex: 1, minWidth: 0 } },
1432
+ h('div', { style: { fontSize: 13, lineHeight: 1.35 } },
1433
+ h('span', {
1434
+ style: {
1435
+ fontSize: 11, padding: '1px 5px', borderRadius: 4, marginRight: 6, border,
1436
+ color: SUB_COLOR[it.subtitle] || SUB_COLOR.multi,
1437
+ },
1438
+ }, SUB_LABEL[it.subtitle] || '多'),
1439
+ it.title || it.hash.slice(0, 12)),
1440
+ h('div', { style: muted }, [it.episode ? `第 ${it.episode} 集` : '', it.size || ''].filter(Boolean).join(' · ') || it.hash.slice(0, 8))),
1441
+ h('button', { onClick: () => remove(it.hash), disabled: Boolean(busy) }, '移除'))));
1442
+ }
1443
+
966
1444
  return {
967
1445
  inject: ['slots'],
968
1446
  apply(ctx) {
969
1447
  ctx.slots.inject('sidebar.panellist', () => ctx.slots.register({
970
- name: 'sidebar.panellist', id: 'mikan', order: 60, label: '追番',
1448
+ name: 'sidebar.panellist', id: 'mikan', order: 60, label: '追番助手',
971
1449
  }, (owner = {}) => h(MikanIcon, { size: owner.size })));
972
1450
  ctx.slots.inject('main', () => ctx.slots.register({
973
1451
  name: 'main', key: 'mikan',
974
1452
  }, () => h(SchedulePage)));
1453
+ ctx.slots.inject('conversation.view', () => ctx.slots.register({
1454
+ name: 'conversation.view',
1455
+ id: 'mikan-order',
1456
+ order: 30,
1457
+ label: '番剧下载点单',
1458
+ }, (props) => h(OrderView, props || {})));
1459
+ ctx.slots.inject('conversation.session.header.utilities', () => ctx.slots.register({
1460
+ name: 'conversation.session.header.utilities',
1461
+ id: 'mikan-order-entry',
1462
+ order: 30,
1463
+ }, (props) => h(OrderEntry, props || {})));
975
1464
  },
976
1465
  };
977
1466
  },