dsh-mikan 0.2.3 → 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
 
@@ -137,6 +152,17 @@ window.__ModuleLoader__.load({
137
152
  const [mikanBaseInput, setMikanBaseInput] = useState('');
138
153
  const [bgmBaseInput, setBgmBaseInput] = useState('');
139
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);
140
166
 
141
167
  const load = useCallback(async ({ autoCheck = false } = {}) => {
142
168
  try {
@@ -147,7 +173,7 @@ window.__ModuleLoader__.load({
147
173
  const age = up.checkedAt ? Date.now() - new Date(up.checkedAt).getTime() : Infinity;
148
174
  if (autoCheck && age > 5 * 60 * 1000 && (up.subscriptions || 0) > 0) {
149
175
  try {
150
- await postJson('/check');
176
+ await postJson(MIKAN + '/check');
151
177
  up = await getJson('/status');
152
178
  } catch { /* keep the previous digest */ }
153
179
  }
@@ -238,7 +264,7 @@ window.__ModuleLoader__.load({
238
264
  if (!browse) return;
239
265
  setBusy('batch');
240
266
  try {
241
- 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`);
242
268
  const list = r.items || [];
243
269
  const candidates = list.filter((w) => lang === 'all' || (w.subtitle || 'multi') === lang);
244
270
  if (candidates.length === 0) {
@@ -256,11 +282,67 @@ window.__ModuleLoader__.load({
256
282
  }
257
283
  }, [browse]);
258
284
 
259
- const checkUpdates = useCallback(async () => {
260
- 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');
261
343
  setNotice('');
262
344
  try {
263
- const r = await postJson('/check');
345
+ const r = await postJson(MIKAN + '/check');
264
346
  setDialog({ type: 'check', title: '更新检查', updates: r.updates || [] });
265
347
  window.dispatchEvent(new Event(CHANGED_EVENT));
266
348
  await load();
@@ -277,7 +359,7 @@ window.__ModuleLoader__.load({
277
359
  const setSilent = useCallback(async (item, silent) => {
278
360
  setBusy('silent');
279
361
  try {
280
- await postJson('/silent', { id: item.id, silent });
362
+ await postJson(MIKAN + '/silent', { id: item.id, silent });
281
363
  setNotice(silent ? `已静默:${item.title}` : `已恢复:${item.title}`);
282
364
  window.dispatchEvent(new Event(CHANGED_EVENT));
283
365
  await load();
@@ -287,7 +369,7 @@ window.__ModuleLoader__.load({
287
369
  const unsubscribe = useCallback(async (item) => {
288
370
  setBusy('unsub');
289
371
  try {
290
- await postJson('/unsubscribe', { id: item.id });
372
+ await postJson(MIKAN + '/unsubscribe', { id: item.id });
291
373
  setNotice(`已取消订阅:${item.title}`);
292
374
  window.dispatchEvent(new Event(CHANGED_EVENT));
293
375
  await load();
@@ -305,7 +387,7 @@ window.__ModuleLoader__.load({
305
387
  setDialog({ type: 'browse' });
306
388
  setBrowse({ level: 'season', year: y, season: s, loading: true, groups: [] });
307
389
  try {
308
- const r = await getJson(`/season-list?year=${y}&season=${encodeURIComponent(s)}`);
390
+ const r = await getJson(`${MIKAN}/season-list?year=${y}&season=${encodeURIComponent(s)}`);
309
391
  setBrowse({ level: 'season', year: y, season: s, loading: false, groups: r.groups || [] });
310
392
  } catch (e) {
311
393
  setBrowse({ level: 'season', year: y, season: s, loading: false, groups: [], error: e.message });
@@ -316,7 +398,7 @@ window.__ModuleLoader__.load({
316
398
  setDialog({ type: 'browse' });
317
399
  setBrowse({ level: 'bangumi', bangumiId: id, title, loading: true, subgroups: [], season: ctx?.season, year: ctx?.year, weekday: ctx?.weekday });
318
400
  try {
319
- 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 || '')}`);
320
402
  setBrowse({
321
403
  level: 'bangumi', bangumiId: id, title: r.title || title, season: ctx?.season, year: ctx?.year,
322
404
  weekday: r.weekday || ctx?.weekday || '', startDate: r.startDate || '', airDate: r.airDate || '',
@@ -334,7 +416,7 @@ window.__ModuleLoader__.load({
334
416
  subgroupId: subgroup.subgroupId, subgroupName: subgroup.name, loading: true, works: [],
335
417
  }));
336
418
  try {
337
- 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`);
338
420
  setBrowse((b) => ({ ...b, loading: false, works: r.items || [], total: r.total || 0, limit: 30, counts: r.counts || null }));
339
421
  } catch (e) {
340
422
  setBrowse((b) => ({ ...b, loading: false, works: [], error: e.message }));
@@ -345,7 +427,7 @@ window.__ModuleLoader__.load({
345
427
  if (!browse?.bangumiId || !subgroup) return;
346
428
  setBusy('subscribe');
347
429
  try {
348
- const r = await postJson('/subscribe-group', {
430
+ const r = await postJson(MIKAN + '/subscribe-group', {
349
431
  bangumiId: browse.bangumiId,
350
432
  title: browse.title,
351
433
  season: browse.season || '',
@@ -369,7 +451,7 @@ window.__ModuleLoader__.load({
369
451
  if (!browse) return;
370
452
  const next = Math.min((browse.limit || 30) + 30, browse.total || 0);
371
453
  try {
372
- 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}`);
373
455
  setBrowse((b) => ({ ...b, works: r.items || [], total: r.total || 0, limit: next }));
374
456
  } catch (e) {
375
457
  setNotice('加载更多失败:' + e.message);
@@ -379,7 +461,7 @@ window.__ModuleLoader__.load({
379
461
  const showAllWorks = useCallback(async () => {
380
462
  if (!browse) return;
381
463
  try {
382
- 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`);
383
465
  setBrowse((b) => ({ ...b, works: r.items || [], total: r.total || 0, limit: r.displayed || 500 }));
384
466
  } catch (e) {
385
467
  setNotice('加载失败:' + e.message);
@@ -398,7 +480,7 @@ window.__ModuleLoader__.load({
398
480
  setBatchStats(null);
399
481
  setDialog({ type: 'batch' });
400
482
  try {
401
- 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`);
402
484
  const list = r.items || [];
403
485
  setBatchStats({
404
486
  all: list.length,
@@ -653,11 +735,12 @@ window.__ModuleLoader__.load({
653
735
 
654
736
  return h('div', { style: { padding: '18px 22px', overflow: 'auto', height: '100%' } },
655
737
  h('div', { style: { display: 'flex', alignItems: 'baseline', gap: 12, marginBottom: 12, flexWrap: 'wrap' } },
656
- h('h2', { style: { margin: 0, fontSize: 20 } }, '追番周历'),
738
+ h('h2', { style: { margin: 0, fontSize: 20 } }, '追番助手'),
657
739
  h('span', { style: muted }, `${total} 部订阅`),
740
+ h('span', { style: { width: 60, flex: '0 0 auto' } }),
741
+ h('button', { onClick: () => setDialog({ type: 'manual' }) }, '用户手册'),
658
742
  h('span', { style: { flex: 1 } }),
659
- h('button', { onClick: () => openSeason(), disabled: Boolean(busy) }, '当季浏览'),
660
- 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' }); } }, '设置'),
661
744
  h('button', { onClick: checkUpdates, disabled: Boolean(busy) }, busy === 'check' ? '检查中…' : '检查更新'),
662
745
  h('button', { onClick: () => load(), disabled: Boolean(busy) }, '刷新')),
663
746
 
@@ -744,6 +827,43 @@ window.__ModuleLoader__.load({
744
827
  h('button', { style: { fontSize: 11, padding: '2px 7px' }, onClick: (e) => { e.stopPropagation(); unsubscribe(item); } }, '取消订阅')))));
745
828
  })),
746
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
+
747
867
  silentList.length > 0 ? h('div', { style: { marginTop: 18 } },
748
868
  h('div', { style: { ...muted, marginBottom: 6 } }, `静默关注(${silentList.length})— 已从周表下架,仍会收到更新`),
749
869
  silentList.map((item) => h('div', { key: item.id, style: row },
@@ -837,8 +957,181 @@ window.__ModuleLoader__.load({
837
957
  : h('div', { style: muted }, '加载作品中…'),
838
958
  h('div', { style: { ...muted, marginTop: 12 } }, '没有对应语言的作品会置灰。'))) : null,
839
959
 
840
- dialog && dialog.type === 'proxy' ? h(Overlay, {
841
- title: '代理连接', onClose: () => setDialog(null),
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),
842
1135
  }, h('div', null,
843
1136
  h('div', { style: { marginBottom: 10, fontSize: 13 } },
844
1137
  state?.mode === 'proxy'
@@ -1014,15 +1307,160 @@ window.__ModuleLoader__.load({
1014
1307
  );
1015
1308
  }
1016
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
+
1017
1444
  return {
1018
1445
  inject: ['slots'],
1019
1446
  apply(ctx) {
1020
1447
  ctx.slots.inject('sidebar.panellist', () => ctx.slots.register({
1021
- name: 'sidebar.panellist', id: 'mikan', order: 60, label: '追番',
1448
+ name: 'sidebar.panellist', id: 'mikan', order: 60, label: '追番助手',
1022
1449
  }, (owner = {}) => h(MikanIcon, { size: owner.size })));
1023
1450
  ctx.slots.inject('main', () => ctx.slots.register({
1024
1451
  name: 'main', key: 'mikan',
1025
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 || {})));
1026
1464
  },
1027
1465
  };
1028
1466
  },
package/docs/DETAIL.md CHANGED
@@ -1,6 +1,6 @@
1
- # 蜜柑追番(dsh-mikan)
1
+ # 追番助手(dsh-mikan)
2
2
 
3
- 把「蜜柑计划的番剧更新」和「下载器」连起来的半自动追番工具:**自动发现 → 你确认 → 自动下载**。
3
+ 把「番剧更新」「资源检索」和「下载器」连起来的半自动追番工具:**自动发现 → 你确认 → 自动下载 → 整理归档**。
4
4
 
5
5
  支持 BitComet 与 qBittorrent 两种下载器,可自动检测切换。
6
6
 
@@ -17,7 +17,13 @@
17
17
  | 更新跟进 | 定时检查,该组出新集时通知 |
18
18
  | 追番周历 | 周一~周日分列,看每部番的更新 |
19
19
  | 静默关注 | 不显示在周历,仍接收更新 |
20
- | 下载执行 | 单集或批量,确认后发送给下载器 |
20
+ | 蜜柑检索 | 按关键词找资源,自动纠正生僻译名 |
21
+ | nyaa 检索 | 按分类与字幕组检索,结果带做种数 |
22
+ | 名称转换 | 中 / 日 / 英 / 别名互查,跨源检索时使用 |
23
+ | 对话点单 | 资源先入点单,确认后才交给下载器 |
24
+ | 媒体库部署 | 创建「下载中转站」并接管下载路径 |
25
+ | 媒体库整理 | 按 `【YYYY.M】番名/Season N` 归类已完成下载 |
26
+ | 本地索引 | 季表与名称库离线可用,可随时重建 |
21
27
  | 源检测 | Mikan / Bangumi / Nyaa 三个源分别检测,可自定义镜像 |
22
28
 
23
29
  ## 环境自适应
@@ -32,7 +38,26 @@
32
38
 
33
39
  - 自动选择当前网络可用的来源
34
40
  - 探测失败会降级,不会让整个插件报错
35
- - Nyaa 目前只做连接检测,资源接入计划在 0.3.0
41
+ - 状态每 60 秒或请求失败时重新探测,切换会记录在状态里
42
+
43
+ ## 源模块
44
+
45
+ 页面下方按来源分块,只有该来源可用时才显示,蜜柑置顶:
46
+
47
+ | 模块 | 内容 |
48
+ |---|---|
49
+ | **蜜柑计划** | 当季浏览、往季浏览 |
50
+ | **Nyaa** | 搜索框、分类、字幕组筛选、检索 |
51
+
52
+ 「设置」「检查更新」「刷新」属于通用操作,保留在标题栏。
53
+
54
+ ## 本地数据
55
+
56
+ | 数据 | 位置 | 说明 |
57
+ |---|---|---|
58
+ | 季表索引 | `catalog.json` | 44 季约 4000 部番的 id |
59
+ | 离线名称库 | `bgm-names.json` | 约 2.4 万条名称映射与首播日期 |
60
+ | 订阅与点单 | `state.json` | 订阅水位、点单、活动会话 |
36
61
 
37
62
  ## 下载器配置要求
38
63