dsh-mikan 0.2.2 → 0.2.3

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.
Files changed (3) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/client.js +61 -10
  3. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # 更新日志
2
2
 
3
- ## 0.2.2
3
+ ## 0.2.3
4
4
 
5
5
  ### 新增
6
6
 
package/client.js CHANGED
@@ -107,6 +107,18 @@ window.__ModuleLoader__.load({
107
107
  ));
108
108
  }
109
109
 
110
+ /** Extract the port from a proxy string; the plugin only ever uses localhost. */
111
+ function portOfProxy(proxy) {
112
+ const raw = String(proxy || '').trim();
113
+ if (!raw) return '';
114
+ try {
115
+ return new URL(raw.includes('://') ? raw : `http://${raw}`).port || '';
116
+ } catch {
117
+ const digits = raw.replace(/\D/g, '');
118
+ return digits;
119
+ }
120
+ }
121
+
110
122
  function SchedulePage() {
111
123
  const [schedule, setSchedule] = useState(null);
112
124
  const [state, setState] = useState(null);
@@ -114,7 +126,7 @@ window.__ModuleLoader__.load({
114
126
  const [error, setError] = useState('');
115
127
  const [busy, setBusy] = useState('');
116
128
  const [notice, setNotice] = useState('');
117
- const [port, setPort] = useState('7890');
129
+ const [proxyInput, setProxyInput] = useState('');
118
130
  const [dialog, setDialog] = useState(null);
119
131
  const [browse, setBrowse] = useState(null);
120
132
  const [expanded, setExpanded] = useState({});
@@ -152,11 +164,27 @@ window.__ModuleLoader__.load({
152
164
  setBusy('bridge');
153
165
  setNotice('');
154
166
  try {
155
- const r = await postJson('/bridge', { input: port });
167
+ const r = await postJson('/bridge', { input: proxyInput });
156
168
  setNotice(r.ok ? `已桥接:${r.proxy}` : `失败:${r.reason}`);
157
169
  await load();
158
170
  } catch (e) { setNotice('桥接失败:' + e.message); } finally { setBusy(''); }
159
- }, [port, load]);
171
+ }, [proxyInput, load]);
172
+
173
+ const saveProxy = useCallback(async () => {
174
+ setBusy('proxy');
175
+ try {
176
+ const raw = proxyInput.trim();
177
+ const value = raw ? (/^\d+$/.test(raw) ? `http://127.0.0.1:${raw}` : raw) : '';
178
+ await postJson('/config', { proxy: value });
179
+ const r = await getJson('/state?refresh=1');
180
+ setState(r);
181
+ setNotice(r.mode === 'proxy' ? `代理已生效:端口 ${portOfProxy(r.proxy)}` : '代理不可用,仍为直连');
182
+ } catch (e) {
183
+ setNotice('保存失败:' + e.message);
184
+ } finally {
185
+ setBusy('');
186
+ }
187
+ }, [proxyInput]);
160
188
 
161
189
  const disconnect = useCallback(async () => {
162
190
  setBusy('disconnect');
@@ -634,7 +662,11 @@ window.__ModuleLoader__.load({
634
662
  h('button', { onClick: () => load(), disabled: Boolean(busy) }, '刷新')),
635
663
 
636
664
  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' ? '代理模式' : '直连模式'),
665
+ h(Pill, {
666
+ ok: state.mode === 'proxy',
667
+ warn: state.mode !== 'proxy',
668
+ onClick: () => { setProxyInput(portOfProxy(state?.proxy)); setDialog({ type: 'proxy' }); },
669
+ }, state.mode === 'proxy' ? '代理模式' : '直连模式'),
638
670
  h(Pill, {
639
671
  ok: state.mikanOk !== false,
640
672
  onClick: () => { setMikanBaseInput(state?.mikanCustom || ''); setDialog({ type: 'mikan' }); },
@@ -685,12 +717,7 @@ window.__ModuleLoader__.load({
685
717
  h('span', { style: { fontSize: 13, overflow: 'hidden', textOverflow: 'ellipsis' } }, text));
686
718
  })(),
687
719
 
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),
720
+ notice ? h('div', { style: { ...muted, marginBottom: 12 } }, notice) : null,
694
721
 
695
722
  h('div', { style: { display: 'grid', gridTemplateColumns: 'repeat(7, minmax(0, 1fr))', gap: 8 } },
696
723
  WEEK.map((label) => {
@@ -810,6 +837,30 @@ window.__ModuleLoader__.load({
810
837
  : h('div', { style: muted }, '加载作品中…'),
811
838
  h('div', { style: { ...muted, marginTop: 12 } }, '没有对应语言的作品会置灰。'))) : null,
812
839
 
840
+ dialog && dialog.type === 'proxy' ? h(Overlay, {
841
+ title: '代理连接', onClose: () => setDialog(null),
842
+ }, h('div', null,
843
+ h('div', { style: { marginBottom: 10, fontSize: 13 } },
844
+ state?.mode === 'proxy'
845
+ ? `当前:代理模式(端口 ${portOfProxy(state.proxy) || '?'})`
846
+ : '当前:直连模式'),
847
+ h('div', { style: { ...muted, marginBottom: 12, lineHeight: 1.7 } },
848
+ '代理用于访问墙外资源,只填端口即可(默认为本机)。留空则是直连模式。'),
849
+ h('div', { style: { display: 'flex', gap: 8, flexWrap: 'wrap', marginBottom: 10 } },
850
+ h('input', {
851
+ value: proxyInput,
852
+ onChange: (e) => setProxyInput(e.target.value),
853
+ placeholder: '7890',
854
+ style: { width: 120, padding: '6px 8px' },
855
+ }),
856
+ h('button', { onClick: saveProxy, disabled: Boolean(busy) }, busy === 'proxy' ? '保存中…' : '保存并检测'),
857
+ h('button', { onClick: bridge, disabled: busy === 'bridge' }, busy === 'bridge' ? '桥接中…' : '自动桥接')),
858
+ h('div', { style: { display: 'flex', gap: 8, flexWrap: 'wrap' } },
859
+ state?.mode === 'proxy' ? h('button', { onClick: disconnect, disabled: busy === 'disconnect' }, '断开代理') : null,
860
+ h('button', { onClick: refreshEnv, disabled: Boolean(busy) }, busy === 'env' ? '检测中…' : '重新检测')),
861
+ h('div', { style: { ...muted, marginTop: 10 } }, '自动桥接会扫描本地常见代理端口,找到即填上。'),
862
+ )) : null,
863
+
813
864
  dialog && dialog.type === 'nyaa' ? h(Overlay, {
814
865
  title: 'Nyaa 连接', onClose: () => setDialog(null),
815
866
  }, h('div', null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-mikan",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Mikan Project tracker for DeepSeek Harness: browse current and past seasons, follow subgroups, and send confirmed releases to BitComet or qBittorrent.",
5
5
  "type": "module",
6
6
  "license": "MIT",