bnpanel 0.5.5 → 0.5.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/client.js +246 -97
- package/index.js +129 -24
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -112,6 +112,43 @@
|
|
|
112
112
|
.bn-chip.dim{background:var(--bn-line);color:var(--bn-muted)}
|
|
113
113
|
.bn-chip .pulse{width:5px;height:5px;border-radius:50%;background:currentColor}
|
|
114
114
|
.bn-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(min(100%,280px),1fr));gap:14px;width:100%;min-width:0}
|
|
115
|
+
.bn-seg{display:inline-flex;align-items:center;padding:2px;border-radius:999px;background:var(--bn-bg);border:1px solid var(--bn-line)}
|
|
116
|
+
.bn-seg button,.bn-seg span{border:0;background:transparent;color:var(--bn-muted);border-radius:999px;padding:4px 10px;font:inherit;font-size:12px;font-weight:650;line-height:1.4}
|
|
117
|
+
.bn-seg button{cursor:pointer}
|
|
118
|
+
.bn-seg button:hover{color:var(--bn-ink)}
|
|
119
|
+
.bn-seg .on{background:#111;color:#d4f07a}
|
|
120
|
+
.bn-player-bar .bn-btn.play,.bn-reel-meta .bn-btn.play{background:#d4f07a;color:#111;border-color:#d4f07a;font-weight:700}
|
|
121
|
+
.bn-reels{margin:0 0 16px}
|
|
122
|
+
.bn-reels-head{display:flex;align-items:baseline;gap:8px;margin:0 0 8px}
|
|
123
|
+
.bn-reels-head b{font-weight:700}
|
|
124
|
+
.bn-reels-head span{color:var(--bn-muted);font-size:12px}
|
|
125
|
+
.bn-reels-row{display:flex;gap:12px;overflow:auto;padding-bottom:4px}
|
|
126
|
+
.bn-reel{flex:none;width:clamp(150px,calc(240px * var(--ar,1.777)),440px)}
|
|
127
|
+
.bn-reel video{display:block;width:100%;height:240px;object-fit:contain;background:#111;border-radius:16px;cursor:pointer}
|
|
128
|
+
.bn-reel-meta{display:flex;align-items:center;gap:8px;margin-top:8px}
|
|
129
|
+
.bn-reel-meta strong{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-weight:650}
|
|
130
|
+
.bn-player-back{position:fixed;inset:0;z-index:80;background:rgba(10,10,10,.62);display:grid;place-items:center;padding:28px}
|
|
131
|
+
.bn-player{width:min(92vw,calc((90vh - 64px) * var(--ar,1.777)));max-height:90vh;background:#111;border-radius:16px;overflow:hidden;display:flex;flex-direction:column;box-shadow:var(--bn-shadow-hover)}
|
|
132
|
+
.bn-player video{display:block;width:100%;height:auto;max-height:calc(90vh - 64px);aspect-ratio:var(--ar,1.777);object-fit:contain;background:#000}
|
|
133
|
+
.bn-player-bar{display:flex;align-items:center;gap:10px;padding:10px 14px;color:#f4f1ea;background:#111;flex:none}
|
|
134
|
+
.bn-player-bar strong{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-weight:700}
|
|
135
|
+
.bn-player-count{flex:none;color:rgba(244,241,234,.55);font-size:12px;font-variant-numeric:tabular-nums}
|
|
136
|
+
.bn-player-bar .bn-btn{background:#1c1c1c;color:#f4f1ea;border-color:#333}
|
|
137
|
+
.bn-player-bar .bn-btn.ghost{background:transparent;color:#f4f1ea;border-color:transparent}
|
|
138
|
+
.bn-docs-back{position:fixed;inset:0;z-index:69;background:rgba(10,10,10,.28)}
|
|
139
|
+
.bn-docs{position:fixed;top:0;right:0;bottom:0;width:min(560px,100%);z-index:70;background:var(--bn-surface);color:var(--bn-ink);border-left:1px solid var(--bn-line);box-shadow:var(--bn-shadow-hover);display:flex;flex-direction:column}
|
|
140
|
+
.bn-docs-bar{display:flex;align-items:center;gap:8px;padding:12px 14px;border-bottom:1px solid var(--bn-line);flex:none}
|
|
141
|
+
.bn-docs-bar strong{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
142
|
+
.bn-docs-bar a.bn-btn{text-decoration:none}
|
|
143
|
+
.bn-docs-tabs{display:flex;gap:6px;overflow:auto;padding:8px 14px;border-bottom:1px solid var(--bn-line);flex:none}
|
|
144
|
+
.bn-docs-tabs button{border:1px solid var(--bn-line);background:transparent;color:var(--bn-ink);border-radius:99px;padding:4px 10px;font:inherit;font-size:12px;cursor:pointer;white-space:nowrap}
|
|
145
|
+
.bn-docs-tabs button.on{background:#111;color:#d4f07a;border-color:#111}
|
|
146
|
+
.bn-docs-frame{position:relative;flex:1;min-height:0;display:flex}
|
|
147
|
+
.bn-docs iframe{flex:1;width:100%;min-height:0;border:0;background:#fff}
|
|
148
|
+
.bn-docs-miss{position:absolute;inset:0;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:12px;padding:28px;text-align:center;color:var(--bn-muted);background:var(--bn-surface)}
|
|
149
|
+
.bn-docs-miss .bn-btn{text-decoration:none;background:#d4f07a;color:#111;border-color:#d4f07a;font-weight:700}
|
|
150
|
+
.bn-tutor-list{display:flex;flex-direction:column;gap:8px;margin-top:8px}
|
|
151
|
+
.bn-tutor-item{display:flex;justify-content:space-between;gap:10px;align-items:center;padding:10px 0;border-top:1px solid var(--bn-line)}
|
|
115
152
|
.bn-card{position:relative;min-width:0;max-width:100%;overflow:hidden;background:var(--bn-surface);border:1px solid var(--bn-line);border-radius:var(--bn-r);padding:16px;box-shadow:var(--bn-shadow);transition:box-shadow .16s,border-color .16s}
|
|
116
153
|
.bn-grid .bn-card{background:radial-gradient(480px 220px at 100% 0%,rgba(212,240,122,.48),rgba(212,240,122,0) 70%),var(--bn-surface)}
|
|
117
154
|
.bn-card:hover{box-shadow:var(--bn-shadow-hover);border-color:var(--bn-line-strong)}
|
|
@@ -244,6 +281,7 @@
|
|
|
244
281
|
external: 'M14 3h7v7M10 14 21 3M21 14v7H3V3h7',
|
|
245
282
|
key: 'M21 2l-2 2m-7.6 7.6a5 5 0 11-7 7 5 5 0 017-7zm0 0L15.5 7.5m0 0l3 3L22 7l-3-3-3.5 3.5z',
|
|
246
283
|
chat: 'M8 10h.01M12 10h.01M16 10h.01M9 16H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-5l-5 5v-5z',
|
|
284
|
+
book: 'M6 3h9l5 5v13H6zM15 3v5h5M9 13h6M9 17h6',
|
|
247
285
|
};
|
|
248
286
|
return { tag: 'svg', props: { width: s, height: s, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', strokeWidth: 1.7, strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': true }, children: [{ tag: 'path', props: { d: paths[name] || paths.grid }, children: [] }] };
|
|
249
287
|
}
|
|
@@ -259,6 +297,16 @@
|
|
|
259
297
|
}
|
|
260
298
|
}
|
|
261
299
|
|
|
300
|
+
function docOpenLabel(url) {
|
|
301
|
+
try {
|
|
302
|
+
const host = new URL(String(url || '')).hostname;
|
|
303
|
+
if (/feishu|larkoffice|larksuite/i.test(host)) return '在飞书打开';
|
|
304
|
+
} catch {
|
|
305
|
+
/* 非法地址走下面的文案 */
|
|
306
|
+
}
|
|
307
|
+
return '在新窗口打开';
|
|
308
|
+
}
|
|
309
|
+
|
|
262
310
|
function createPanel(React, ReactDOM, dshNav) {
|
|
263
311
|
const h = React.createElement;
|
|
264
312
|
const { useState, useEffect, useRef, useCallback } = React;
|
|
@@ -539,9 +587,17 @@
|
|
|
539
587
|
const [pendingPerm, setPendingPerm] = useState(null);
|
|
540
588
|
const [contactOpen, setContactOpen] = useState(false);
|
|
541
589
|
const [campIdx, setCampIdx] = useState(0);
|
|
590
|
+
const [reelIdx, setReelIdx] = useState(0);
|
|
591
|
+
const [player, setPlayer] = useState(null);
|
|
592
|
+
const [playerRatio, setPlayerRatio] = useState(16 / 9);
|
|
593
|
+
const [docsOpen, setDocsOpen] = useState(false);
|
|
594
|
+
const [docId, setDocId] = useState('');
|
|
595
|
+
const [docBlocked, setDocBlocked] = useState(false);
|
|
596
|
+
const [studioQuery, setStudioQuery] = useState('');
|
|
542
597
|
const [contact, setContact] = useState(null);
|
|
543
598
|
const [contactStatus, setContactStatus] = useState('');
|
|
544
599
|
const [contactError, setContactError] = useState('');
|
|
600
|
+
const [checkNote, setCheckNote] = useState('');
|
|
545
601
|
|
|
546
602
|
const refresh = useCallback(async () => {
|
|
547
603
|
try {
|
|
@@ -559,13 +615,19 @@
|
|
|
559
615
|
const timer = setInterval(() => setCampIdx((index) => index + 1), 5000);
|
|
560
616
|
return () => clearInterval(timer);
|
|
561
617
|
}, [campaignCount]);
|
|
562
|
-
useEffect(() => { if (!toast) return; const t = setTimeout(() => setToast(null), toast.bad ? 12000 : 3200); return () => clearTimeout(t); }, [toast]);
|
|
618
|
+
useEffect(() => { if (!toast) return undefined; const t = setTimeout(() => setToast(null), toast.bad ? 12000 : 3200); return () => clearTimeout(t); }, [toast]);
|
|
563
619
|
useEffect(() => {
|
|
564
620
|
if (!contactOpen) return;
|
|
565
621
|
const onKey = (ev) => { if (ev.key === 'Escape') setContactOpen(false); };
|
|
566
622
|
window.addEventListener('keydown', onKey);
|
|
567
623
|
return () => window.removeEventListener('keydown', onKey);
|
|
568
624
|
}, [contactOpen]);
|
|
625
|
+
useEffect(() => {
|
|
626
|
+
if (!docsOpen) return undefined;
|
|
627
|
+
const onKey = (ev) => { if (ev.key === 'Escape') setDocsOpen(false); };
|
|
628
|
+
window.addEventListener('keydown', onKey);
|
|
629
|
+
return () => window.removeEventListener('keydown', onKey);
|
|
630
|
+
}, [docsOpen]);
|
|
569
631
|
|
|
570
632
|
const openContact = async () => {
|
|
571
633
|
setContactOpen(true);
|
|
@@ -649,8 +711,12 @@
|
|
|
649
711
|
|
|
650
712
|
const act = async (fn, okText) => {
|
|
651
713
|
setBusy(true);
|
|
652
|
-
try {
|
|
653
|
-
|
|
714
|
+
try {
|
|
715
|
+
const result = await fn();
|
|
716
|
+
await refresh();
|
|
717
|
+
const text = okText || (typeof result === 'string' ? result : '');
|
|
718
|
+
if (text) setToast({ text });
|
|
719
|
+
} catch (err) { setToast({ text: err.message, bad: true }); }
|
|
654
720
|
finally { setBusy(false); }
|
|
655
721
|
};
|
|
656
722
|
|
|
@@ -674,7 +740,58 @@
|
|
|
674
740
|
throw new Error('任务超时,请到「任务」查看');
|
|
675
741
|
};
|
|
676
742
|
|
|
677
|
-
const
|
|
743
|
+
const closePlayer = () => {
|
|
744
|
+
if (document.fullscreenElement && document.exitFullscreen) document.exitFullscreen().catch(() => {});
|
|
745
|
+
setPlayer(null);
|
|
746
|
+
};
|
|
747
|
+
|
|
748
|
+
const openPlayer = (item) => {
|
|
749
|
+
if (!item || !item.videoUrl) return;
|
|
750
|
+
setPlayerRatio(16 / 9);
|
|
751
|
+
setPlayer(item);
|
|
752
|
+
};
|
|
753
|
+
|
|
754
|
+
const playerRows = () => ((state && state.showcase && state.showcase.cases) || []);
|
|
755
|
+
|
|
756
|
+
const movePlayer = (delta) => {
|
|
757
|
+
const rows = playerRows();
|
|
758
|
+
if (!player || rows.length < 2) return;
|
|
759
|
+
const at = rows.findIndex((row) => row.id === player.id);
|
|
760
|
+
const nextAt = (((at < 0 ? 0 : at) + delta) % rows.length + rows.length) % rows.length;
|
|
761
|
+
setPlayerRatio(16 / 9);
|
|
762
|
+
setPlayer(rows[nextAt]);
|
|
763
|
+
setReelIdx(nextAt);
|
|
764
|
+
};
|
|
765
|
+
|
|
766
|
+
useEffect(() => {
|
|
767
|
+
if (!player) return undefined;
|
|
768
|
+
const onKey = (ev) => {
|
|
769
|
+
if (ev.key === 'Escape') closePlayer();
|
|
770
|
+
if (ev.key !== 'ArrowLeft' && ev.key !== 'ArrowRight') return;
|
|
771
|
+
if (ev.target && ev.target.tagName === 'VIDEO') return;
|
|
772
|
+
ev.preventDefault();
|
|
773
|
+
movePlayer(ev.key === 'ArrowLeft' ? -1 : 1);
|
|
774
|
+
};
|
|
775
|
+
window.addEventListener('keydown', onKey);
|
|
776
|
+
return () => window.removeEventListener('keydown', onKey);
|
|
777
|
+
}, [player, state]);
|
|
778
|
+
|
|
779
|
+
const shootLike = (item) => {
|
|
780
|
+
const slug = item && item.agent;
|
|
781
|
+
if (!slug) return;
|
|
782
|
+
const hit = (state.store || []).find((s) => s.slug === slug);
|
|
783
|
+
const installed = (state.agents || []).find((a) => a.id === slug || a.product === slug) || (hit && hit.agent);
|
|
784
|
+
if (!installed) {
|
|
785
|
+
setToast({ text: '请先安装对应 Agent,再使用同款开拍', bad: true });
|
|
786
|
+
return;
|
|
787
|
+
}
|
|
788
|
+
const query = item.style ? 'style=' + encodeURIComponent(item.style) : '';
|
|
789
|
+
closePlayer();
|
|
790
|
+
return openStudio(installed.id, query);
|
|
791
|
+
};
|
|
792
|
+
|
|
793
|
+
const openStudio = async (id, query) => {
|
|
794
|
+
setStudioQuery(query || '');
|
|
678
795
|
const agent = (state.agents || []).find((a) => a.id === id);
|
|
679
796
|
if (agent && agent.needsPermissionAck && !agent.permissionsAck) {
|
|
680
797
|
setPendingPerm(agent);
|
|
@@ -793,6 +910,31 @@
|
|
|
793
910
|
const hit = (state.store || []).find((item) => item.slug === studioAgent.product || item.slug === studioAgent.id);
|
|
794
911
|
return hit && hit.description ? String(hit.description).trim() : '';
|
|
795
912
|
})();
|
|
913
|
+
const docs = state.docs || [];
|
|
914
|
+
const doc = docs.find((item) => item.id === docId) || docs[0] || null;
|
|
915
|
+
const openDocs = () => { setDocBlocked(false); setDocsOpen(true); };
|
|
916
|
+
const licenseOn = !!(state.license && (state.license.state === 'active' || state.license.state === 'grace'));
|
|
917
|
+
const openManual = () => {
|
|
918
|
+
if (!docs.length) {
|
|
919
|
+
setToast({ text: '还没有手册', bad: true });
|
|
920
|
+
return;
|
|
921
|
+
}
|
|
922
|
+
openDocs();
|
|
923
|
+
};
|
|
924
|
+
const openCases = () => {
|
|
925
|
+
const cases = (state.showcase && state.showcase.cases) || [];
|
|
926
|
+
if (!cases.length) {
|
|
927
|
+
setToast({ text: '还没有案例', bad: true });
|
|
928
|
+
return;
|
|
929
|
+
}
|
|
930
|
+
const at = ((reelIdx % cases.length) + cases.length) % cases.length;
|
|
931
|
+
openPlayer(cases[at]);
|
|
932
|
+
};
|
|
933
|
+
const topSeg = h('div', { className: 'bn-seg' },
|
|
934
|
+
h('span', { className: 'on', title: (state.license && state.license.reason) || '' }, licenseOn ? '已授权' : '未授权'),
|
|
935
|
+
h('button', { type: 'button', onClick: openManual }, '手册'),
|
|
936
|
+
h('button', { type: 'button', onClick: openCases }, '案例'),
|
|
937
|
+
);
|
|
796
938
|
const campaigns = state.campaigns || [];
|
|
797
939
|
const camp = campaigns.length ? campaigns[((campIdx % campaigns.length) + campaigns.length) % campaigns.length] : null;
|
|
798
940
|
const campIcons = { spark: '✨', gift: '🎁', rocket: '🚀', crown: '👑', star: '⭐', bolt: '⚡', box: '📦', heart: '💛', fire: '🔥', gem: '💎', party: '🎉', tag: '🏷️' };
|
|
@@ -841,12 +983,10 @@
|
|
|
841
983
|
h('main', { className: 'bn-main' },
|
|
842
984
|
tab !== 'studio' ? h('div', { className: 'bn-head' },
|
|
843
985
|
h('div', null,
|
|
844
|
-
h('h1', { className: 'bn-h1' }, tab === 'agents' ? '
|
|
845
|
-
h('div', { className: 'bn-sub' }, tab === 'agents' ? '
|
|
846
|
-
),
|
|
847
|
-
h('div', { className: 'bn-head-actions' },
|
|
848
|
-
h(LicenseChip, { license: state.license }),
|
|
986
|
+
h('h1', { className: 'bn-h1' }, tab === 'agents' ? '今天就出片' : tab === 'tasks' ? '任务' : tab === 'account' ? '我的授权' : '设置'),
|
|
987
|
+
h('div', { className: 'bn-sub' }, tab === 'agents' ? '看一条成片,选一个 Agent。模板里已经写好提示词,改一句就能开拍。' : tab === 'tasks' ? '安装与创作进度' : tab === 'account' ? '激活码与购买' : '偏好设置'),
|
|
849
988
|
),
|
|
989
|
+
h('div', { className: 'bn-head-actions' }, topSeg),
|
|
850
990
|
) : null,
|
|
851
991
|
|
|
852
992
|
state.panel && state.panel.updateAvailable && tab !== 'studio' ? h('div', { className: 'bn-banner' },
|
|
@@ -886,7 +1026,8 @@
|
|
|
886
1026
|
: null,
|
|
887
1027
|
|
|
888
1028
|
tab === 'agents' ? (
|
|
889
|
-
|
|
1029
|
+
h('div', null,
|
|
1030
|
+
store.length
|
|
890
1031
|
? h('div', { className: 'bn-grid' }, store.map((item) => {
|
|
891
1032
|
const task = tasks.find((t) =>
|
|
892
1033
|
(t.agentId === item.slug || t.agentId === (item.agent && item.agent.id))
|
|
@@ -897,7 +1038,8 @@
|
|
|
897
1038
|
h('div', { className: 'art' }, h(Icon, { name: 'grid', size: 30 })),
|
|
898
1039
|
h('h3', null, '商店暂无 Agent'),
|
|
899
1040
|
h('p', null, state.storeError || '暂时没有可安装的内容,请检查网络后再打开。'),
|
|
900
|
-
)
|
|
1041
|
+
),
|
|
1042
|
+
)
|
|
901
1043
|
) : null,
|
|
902
1044
|
|
|
903
1045
|
tab === 'studio' ? (
|
|
@@ -909,8 +1051,9 @@
|
|
|
909
1051
|
h('div', { className: 'title' }, studioAgent.name + ' Studio'),
|
|
910
1052
|
studioBlurb ? h('div', { className: 'meta', title: studioBlurb }, studioBlurb) : null,
|
|
911
1053
|
),
|
|
912
|
-
h('div', { style: { marginLeft: 'auto', display: 'flex', gap: 8 } },
|
|
913
|
-
|
|
1054
|
+
h('div', { style: { marginLeft: 'auto', display: 'flex', gap: 8, alignItems: 'center' } },
|
|
1055
|
+
topSeg,
|
|
1056
|
+
h('button', { className: 'bn-btn', onClick: () => openStudio(studioAgent.id, studioQuery) }, h(Icon, { name: 'refresh' }), '刷新'),
|
|
914
1057
|
(() => {
|
|
915
1058
|
const studioBusy = (state.tasks || []).some(
|
|
916
1059
|
(t) => t.agentId === studioAgent.id && (t.status === 'running' || t.status === 'queued'),
|
|
@@ -924,7 +1067,12 @@
|
|
|
924
1067
|
})(),
|
|
925
1068
|
),
|
|
926
1069
|
),
|
|
927
|
-
h('iframe', {
|
|
1070
|
+
h('iframe', {
|
|
1071
|
+
key: studioAgent.id + (studioQuery ? '?' + studioQuery : ''),
|
|
1072
|
+
title: studioAgent.name,
|
|
1073
|
+
src: studioAgent.studioUrl + (studioQuery ? (String(studioAgent.studioUrl).indexOf('?') >= 0 ? '&' : '?') + studioQuery : ''),
|
|
1074
|
+
allow: 'clipboard-read; clipboard-write; fullscreen',
|
|
1075
|
+
}),
|
|
928
1076
|
)
|
|
929
1077
|
: h('div', { className: 'bn-empty' },
|
|
930
1078
|
h('h3', null, '尚未打开 Studio'),
|
|
@@ -1044,81 +1192,6 @@
|
|
|
1044
1192
|
) : null,
|
|
1045
1193
|
|
|
1046
1194
|
tab === 'settings' ? h('div', null,
|
|
1047
|
-
h('section', { className: 'bn-panel' },
|
|
1048
|
-
h('h2', null, '面板版本'),
|
|
1049
|
-
h('p', { className: 'bn-sub', style: { marginBottom: 8 } },
|
|
1050
|
-
'当前 bnpanel v' + ((state.panel && state.panel.version) || '?')
|
|
1051
|
-
+ (state.panel && state.panel.latest
|
|
1052
|
-
? (state.panel.updateAvailable
|
|
1053
|
-
? ' · 可更新至 v' + state.panel.latest
|
|
1054
|
-
: ' · 已是最新 v' + state.panel.latest + ')')
|
|
1055
|
-
: '')
|
|
1056
|
-
+ (state.panel && state.panel.error ? ' · 检查失败:' + state.panel.error : ''),
|
|
1057
|
-
),
|
|
1058
|
-
h('div', { className: 'bn-form' },
|
|
1059
|
-
h('input', {
|
|
1060
|
-
className: 'bn-input',
|
|
1061
|
-
style: { flex: 1, minWidth: 220 },
|
|
1062
|
-
placeholder: 'https://registry.npmmirror.com',
|
|
1063
|
-
defaultValue: (state.settings && state.settings.panelNpmRegistry) || 'https://registry.npmmirror.com',
|
|
1064
|
-
key: 'panel-reg-' + ((state.settings && state.settings.panelNpmRegistry) || ''),
|
|
1065
|
-
id: 'bn-panel-registry',
|
|
1066
|
-
}),
|
|
1067
|
-
h('button', {
|
|
1068
|
-
className: 'bn-btn',
|
|
1069
|
-
disabled: busy,
|
|
1070
|
-
onClick: () => act(async () => {
|
|
1071
|
-
const el = document.getElementById('bn-panel-registry');
|
|
1072
|
-
const url = String((el && el.value) || '').trim().replace(/\/$/, '');
|
|
1073
|
-
if (!url) throw new Error('请填写检查地址');
|
|
1074
|
-
if (!/^https?:\/\//i.test(url)) throw new Error('地址需以 http:// 或 https:// 开头');
|
|
1075
|
-
await api('/settings', { method: 'POST', body: { patch: { panelNpmRegistry: url } } });
|
|
1076
|
-
}, '检查源已保存'),
|
|
1077
|
-
}, '保存源'),
|
|
1078
|
-
h('button', {
|
|
1079
|
-
className: 'bn-btn primary',
|
|
1080
|
-
disabled: busy,
|
|
1081
|
-
onClick: () => act(async () => {
|
|
1082
|
-
const res = await api('/panel/check-update', { method: 'POST' });
|
|
1083
|
-
const p = res && res.panel;
|
|
1084
|
-
if (!p) return '已检查';
|
|
1085
|
-
if (p.error) throw new Error(p.error);
|
|
1086
|
-
if (p.updateAvailable) return '发现面板 v' + p.latest + ',请到 DSH 更新 bnpanel 后重启';
|
|
1087
|
-
return '面板已是最新 v' + (p.latest || p.current);
|
|
1088
|
-
}),
|
|
1089
|
-
}, h(Icon, { name: 'refresh' }), '检查面板更新'),
|
|
1090
|
-
),
|
|
1091
|
-
h('p', { className: 'bn-sub', style: { marginTop: 8 } },
|
|
1092
|
-
(state.panel && state.panel.installHint)
|
|
1093
|
-
|| '安装或更新面板:在 DSH 的插件列表里操作,然后重启',
|
|
1094
|
-
),
|
|
1095
|
-
),
|
|
1096
|
-
h('section', { className: 'bn-panel' },
|
|
1097
|
-
h('h2', null, '授权服务'),
|
|
1098
|
-
h('div', { className: 'bn-sub', style: { marginBottom: 8 } }, '商店与激活都连这个地址。线上请填 https://dsh.biunow.cn'),
|
|
1099
|
-
h('div', { className: 'bn-form' },
|
|
1100
|
-
h('input', {
|
|
1101
|
-
className: 'bn-input',
|
|
1102
|
-
style: { flex: 1, minWidth: 220 },
|
|
1103
|
-
placeholder: 'https://dsh.biunow.cn',
|
|
1104
|
-
defaultValue: state.licenseBaseUrl || '',
|
|
1105
|
-
key: 'lic-url-' + (state.licenseBaseUrl || ''),
|
|
1106
|
-
id: 'bn-license-url',
|
|
1107
|
-
}),
|
|
1108
|
-
h('button', {
|
|
1109
|
-
className: 'bn-btn primary',
|
|
1110
|
-
disabled: busy,
|
|
1111
|
-
onClick: () => act(async () => {
|
|
1112
|
-
const el = document.getElementById('bn-license-url');
|
|
1113
|
-
const url = String((el && el.value) || '').trim().replace(/\/$/, '');
|
|
1114
|
-
if (!url) throw new Error('请填写授权服务地址');
|
|
1115
|
-
if (!/^https?:\/\//i.test(url)) throw new Error('地址需以 http:// 或 https:// 开头');
|
|
1116
|
-
await api('/settings', { method: 'POST', body: { patch: { licenseBaseUrl: url } } });
|
|
1117
|
-
}, '授权服务已保存'),
|
|
1118
|
-
}, '保存'),
|
|
1119
|
-
),
|
|
1120
|
-
h('p', { className: 'bn-sub', style: { marginTop: 8 } }, '当前:' + (state.licenseBaseUrl || '未设置')),
|
|
1121
|
-
),
|
|
1122
1195
|
h('section', { className: 'bn-panel' },
|
|
1123
1196
|
h('h2', null, '偏好'),
|
|
1124
1197
|
h('label', { style: { display: 'flex', gap: 6, alignItems: 'center', marginTop: 4, fontSize: 13, color: 'var(--bn-muted)' } },
|
|
@@ -1129,16 +1202,15 @@
|
|
|
1129
1202
|
h('input', { type: 'checkbox', checked: !(state.settings && state.settings.autoKickoffInDsh === false), onChange: (e) => act(async () => { await api('/settings', { method: 'POST', body: { patch: { autoKickoffInDsh: e.target.checked } } }); }, '已保存') }),
|
|
1130
1203
|
'Studio 立项后自动进入创作(接通 DSH 对话,等同导入 Agent 丢需求)',
|
|
1131
1204
|
),
|
|
1132
|
-
h('label', { style: { display: 'flex', gap: 6, alignItems: 'center', marginTop: 10, fontSize: 13, color: 'var(--bn-muted)' } },
|
|
1133
|
-
h('input', { type: 'checkbox', checked: !!(state.settings && state.settings.telemetry), onChange: (e) => act(async () => { await api('/settings', { method: 'POST', body: { patch: { telemetry: e.target.checked } } }); }, '已保存') }),
|
|
1134
|
-
'匿名安装统计(仅上报已装 Agent 与版本,不含文件内容)',
|
|
1135
|
-
),
|
|
1136
1205
|
state.dsh ? h('p', { className: 'bn-sub', style: { marginTop: 8 } },
|
|
1137
1206
|
'DSH 接通:skill ' + (state.dsh.skills ? '已就绪' : '未注入') + ' · 会话 ' + (state.dsh.chat ? '已就绪' : '未注入') +
|
|
1138
1207
|
((state.dsh.recentKickoffs && state.dsh.recentKickoffs[0])
|
|
1139
1208
|
? ' · 最近 ' + (state.dsh.recentKickoffs[0].ok ? '已开拍' : '开拍失败')
|
|
1140
1209
|
: ''),
|
|
1141
1210
|
) : null,
|
|
1211
|
+
h('p', { className: 'bn-sub', style: { marginTop: 8 } }, '面板更新提示:手动卸载旧面板,再次通过 bnpanel 安装最新版本即可'),
|
|
1212
|
+
h('p', { className: 'bn-sub', style: { marginTop: 18 } }, '安装免费;每个 Agent 首次安装赠送 1 次试用生成。正式授权请到「我的授权」。'),
|
|
1213
|
+
checkNote ? h('p', { className: 'bn-sub', style: { marginTop: 8 } }, checkNote) : null,
|
|
1142
1214
|
h('div', { style: { marginTop: 16, display: 'flex', gap: 8, flexWrap: 'wrap' } },
|
|
1143
1215
|
h('button', {
|
|
1144
1216
|
className: 'bn-btn',
|
|
@@ -1146,13 +1218,18 @@
|
|
|
1146
1218
|
onClick: () => act(async () => {
|
|
1147
1219
|
const res = await api('/updates/check', { method: 'POST' });
|
|
1148
1220
|
const p = res && res.panel;
|
|
1149
|
-
if (p && p.
|
|
1150
|
-
|
|
1151
|
-
|
|
1221
|
+
if (p && p.error) {
|
|
1222
|
+
setCheckNote(String(p.error));
|
|
1223
|
+
throw new Error(p.error);
|
|
1224
|
+
}
|
|
1225
|
+
const text = p && p.updateAvailable
|
|
1226
|
+
? '发现面板 v' + p.latest + ',请手动卸载旧面板,再通过 bnpanel 安装'
|
|
1227
|
+
: '已检查,面板已是最新';
|
|
1228
|
+
setCheckNote(text);
|
|
1229
|
+
return text;
|
|
1152
1230
|
}),
|
|
1153
1231
|
}, h(Icon, { name: 'refresh' }), '检查更新'),
|
|
1154
1232
|
),
|
|
1155
|
-
h('p', { className: 'bn-sub', style: { marginTop: 18 } }, '安装免费;每个 Agent 首次安装赠送 1 次试用生成。正式授权请到「我的授权」。'),
|
|
1156
1233
|
),
|
|
1157
1234
|
) : null,
|
|
1158
1235
|
),
|
|
@@ -1233,6 +1310,78 @@
|
|
|
1233
1310
|
),
|
|
1234
1311
|
) : null,
|
|
1235
1312
|
|
|
1313
|
+
docsOpen && doc ? h('div', { className: 'bn-docs-back', onClick: () => setDocsOpen(false) },
|
|
1314
|
+
h('aside', { className: 'bn-docs', onClick: (event) => event.stopPropagation() },
|
|
1315
|
+
h('div', { className: 'bn-docs-bar' },
|
|
1316
|
+
h('strong', null, doc.title),
|
|
1317
|
+
h('a', { className: 'bn-btn', href: doc.url, target: '_blank', rel: 'noreferrer' }, docOpenLabel(doc.url)),
|
|
1318
|
+
h('button', { type: 'button', className: 'bn-btn ghost', onClick: () => setDocsOpen(false) }, '关闭'),
|
|
1319
|
+
),
|
|
1320
|
+
docs.length > 1 ? h('div', { className: 'bn-docs-tabs' },
|
|
1321
|
+
docs.map((item) => h('button', {
|
|
1322
|
+
key: item.id,
|
|
1323
|
+
type: 'button',
|
|
1324
|
+
className: item.id === doc.id ? 'on' : '',
|
|
1325
|
+
onClick: () => { setDocId(item.id); setDocBlocked(false); },
|
|
1326
|
+
}, item.title)),
|
|
1327
|
+
) : null,
|
|
1328
|
+
h('div', { className: 'bn-docs-frame' },
|
|
1329
|
+
h('iframe', {
|
|
1330
|
+
key: doc.id,
|
|
1331
|
+
title: doc.title,
|
|
1332
|
+
src: doc.url,
|
|
1333
|
+
onLoad: (event) => {
|
|
1334
|
+
const frame = event.target;
|
|
1335
|
+
window.setTimeout(() => {
|
|
1336
|
+
if (!frame.isConnected) return;
|
|
1337
|
+
try {
|
|
1338
|
+
const href = frame.contentWindow && frame.contentWindow.location && frame.contentWindow.location.href;
|
|
1339
|
+
setDocBlocked(!href || href === 'about:blank');
|
|
1340
|
+
} catch {
|
|
1341
|
+
setDocBlocked(false);
|
|
1342
|
+
}
|
|
1343
|
+
}, 700);
|
|
1344
|
+
},
|
|
1345
|
+
}),
|
|
1346
|
+
docBlocked ? h('div', { className: 'bn-docs-miss' },
|
|
1347
|
+
h('p', null, '这篇文档不允许嵌在面板里。'),
|
|
1348
|
+
h('a', { className: 'bn-btn', href: doc.url, target: '_blank', rel: 'noreferrer' }, docOpenLabel(doc.url)),
|
|
1349
|
+
) : null,
|
|
1350
|
+
),
|
|
1351
|
+
),
|
|
1352
|
+
) : null,
|
|
1353
|
+
|
|
1354
|
+
player ? (() => {
|
|
1355
|
+
const rows = playerRows();
|
|
1356
|
+
const at = Math.max(0, rows.findIndex((row) => row.id === player.id));
|
|
1357
|
+
const many = rows.length > 1;
|
|
1358
|
+
return h('div', { className: 'bn-player-back', onClick: (event) => { if (event.target === event.currentTarget) closePlayer(); } },
|
|
1359
|
+
h('div', { id: 'bn-player', className: 'bn-player', style: { '--ar': String(playerRatio) }, role: 'dialog' },
|
|
1360
|
+
h('video', {
|
|
1361
|
+
key: player.id,
|
|
1362
|
+
id: 'bn-player-video',
|
|
1363
|
+
src: player.videoUrl,
|
|
1364
|
+
poster: player.coverUrl || undefined,
|
|
1365
|
+
controls: true,
|
|
1366
|
+
autoPlay: true,
|
|
1367
|
+
playsInline: true,
|
|
1368
|
+
onLoadedMetadata: (event) => {
|
|
1369
|
+
const node = event.target;
|
|
1370
|
+
if (node.videoWidth && node.videoHeight) setPlayerRatio(node.videoWidth / node.videoHeight);
|
|
1371
|
+
},
|
|
1372
|
+
}),
|
|
1373
|
+
h('div', { className: 'bn-player-bar' },
|
|
1374
|
+
many ? h('button', { type: 'button', className: 'bn-btn', onClick: () => movePlayer(-1) }, '上一条') : null,
|
|
1375
|
+
h('span', { className: 'bn-player-count' }, '案例' + (many ? ' ' + (at + 1) + ' / ' + rows.length : '')),
|
|
1376
|
+
h('strong', null, player.title),
|
|
1377
|
+
player.agent ? h('button', { type: 'button', className: 'bn-btn play', onClick: () => shootLike(player) }, '用同款开拍') : null,
|
|
1378
|
+
many ? h('button', { type: 'button', className: 'bn-btn', onClick: () => movePlayer(1) }, '下一条') : null,
|
|
1379
|
+
h('button', { type: 'button', className: 'bn-btn ghost', onClick: closePlayer }, '关闭'),
|
|
1380
|
+
),
|
|
1381
|
+
),
|
|
1382
|
+
);
|
|
1383
|
+
})() : null,
|
|
1384
|
+
|
|
1236
1385
|
toast ? h('div', { className: 'bn-toast' + (toast.bad ? ' bad' : '') }, toast.text) : null,
|
|
1237
1386
|
);
|
|
1238
1387
|
}
|
package/index.js
CHANGED
|
@@ -8011,7 +8011,8 @@ var DEFAULT_SETTINGS = {
|
|
|
8011
8011
|
maxAgents: 8,
|
|
8012
8012
|
autoUpdate: true,
|
|
8013
8013
|
autoInstallUpdates: false,
|
|
8014
|
-
|
|
8014
|
+
/** Kept for old settings files. The panel always reports installs; users cannot turn this off. */
|
|
8015
|
+
telemetry: true,
|
|
8015
8016
|
mirror: null,
|
|
8016
8017
|
engineRoots: {},
|
|
8017
8018
|
permissionsAck: {},
|
|
@@ -8668,6 +8669,10 @@ function createPanelApp(options = {}) {
|
|
|
8668
8669
|
const getPanelPublicUrl = typeof options.getPanelPublicUrl === "function" ? options.getPanelPublicUrl : () => options.panelPublicUrl ?? null;
|
|
8669
8670
|
const dsh = options.dsh ?? null;
|
|
8670
8671
|
let settings = readSettings(paths);
|
|
8672
|
+
const pinnedLicense = String(options.licenseBaseUrl || DEFAULT_SETTINGS.licenseBaseUrl).replace(/\/$/, "");
|
|
8673
|
+
if (String(settings.licenseBaseUrl || "").replace(/\/$/, "") !== pinnedLicense) {
|
|
8674
|
+
settings = writeSettings(paths, { licenseBaseUrl: pinnedLicense });
|
|
8675
|
+
}
|
|
8671
8676
|
const accountId = options.accountId ?? settings.accountId ?? "local-dev";
|
|
8672
8677
|
const packageName = panelPackageName(options.packageName);
|
|
8673
8678
|
const resellerCode = panelResellerCode(options.resellerCode);
|
|
@@ -8717,9 +8722,26 @@ function createPanelApp(options = {}) {
|
|
|
8717
8722
|
registry: null,
|
|
8718
8723
|
error: null
|
|
8719
8724
|
};
|
|
8725
|
+
const fallbackRegistry = "https://registry.npmmirror.com";
|
|
8726
|
+
let remoteRegistry = "";
|
|
8727
|
+
let registryFetchedAt = 0;
|
|
8720
8728
|
function panelRegistryBase() {
|
|
8721
|
-
const raw = String(
|
|
8722
|
-
return raw ||
|
|
8729
|
+
const raw = String(remoteRegistry || fallbackRegistry).replace(/\/$/, "");
|
|
8730
|
+
return raw || fallbackRegistry;
|
|
8731
|
+
}
|
|
8732
|
+
async function refreshPanelRegistry() {
|
|
8733
|
+
if (remoteRegistry && Date.now() - registryFetchedAt < 10 * 60 * 1e3) return;
|
|
8734
|
+
registryFetchedAt = Date.now();
|
|
8735
|
+
const base = String(settings.licenseBaseUrl || "").replace(/\/$/, "");
|
|
8736
|
+
if (!base) return;
|
|
8737
|
+
try {
|
|
8738
|
+
const res = await fetch(`${base}/v1/commerce/site`, { cache: "no-store" });
|
|
8739
|
+
if (!res.ok) return;
|
|
8740
|
+
const body = await res.json();
|
|
8741
|
+
const url = String(body?.site?.panelRegistry || "").trim().replace(/\/$/, "");
|
|
8742
|
+
if (/^https?:\/\//i.test(url)) remoteRegistry = url;
|
|
8743
|
+
} catch {
|
|
8744
|
+
}
|
|
8723
8745
|
}
|
|
8724
8746
|
async function fetchPanelLatestFromRegistry(registry) {
|
|
8725
8747
|
const url = `${registry.replace(/\/$/, "")}/${encodeURIComponent(packageName)}`;
|
|
@@ -8738,6 +8760,7 @@ function createPanelApp(options = {}) {
|
|
|
8738
8760
|
return String(latest);
|
|
8739
8761
|
}
|
|
8740
8762
|
async function checkPanelSelfUpdate({ force = false } = {}) {
|
|
8763
|
+
await refreshPanelRegistry();
|
|
8741
8764
|
const registry = panelRegistryBase();
|
|
8742
8765
|
const official = "https://registry.npmjs.org";
|
|
8743
8766
|
const now = Date.now();
|
|
@@ -9009,6 +9032,7 @@ function createPanelApp(options = {}) {
|
|
|
9009
9032
|
} catch {
|
|
9010
9033
|
}
|
|
9011
9034
|
ctx.setProgress(100, "\u5B8C\u6210");
|
|
9035
|
+
void reportInstalls(true);
|
|
9012
9036
|
return { artifact: result.dir };
|
|
9013
9037
|
}
|
|
9014
9038
|
});
|
|
@@ -9165,6 +9189,7 @@ function createPanelApp(options = {}) {
|
|
|
9165
9189
|
return imported;
|
|
9166
9190
|
}
|
|
9167
9191
|
async function installPublishedAgent(product, version, sha, distribution) {
|
|
9192
|
+
await refreshPanelRegistry();
|
|
9168
9193
|
const npmName = agentNpmPackage(product);
|
|
9169
9194
|
if (npmName && version) {
|
|
9170
9195
|
try {
|
|
@@ -9211,30 +9236,48 @@ function createPanelApp(options = {}) {
|
|
|
9211
9236
|
} catch {
|
|
9212
9237
|
}
|
|
9213
9238
|
ctx.setProgress(90, "\u5B8C\u6210");
|
|
9239
|
+
void reportInstalls(true);
|
|
9214
9240
|
return { artifact: result.dir };
|
|
9215
9241
|
}
|
|
9216
9242
|
});
|
|
9217
9243
|
}
|
|
9218
9244
|
let lastReport = 0;
|
|
9219
9245
|
async function reportInstalls(force = false) {
|
|
9220
|
-
if (!settings.telemetry) return;
|
|
9221
9246
|
if (!force && Date.now() - lastReport < 6 * 36e5) return;
|
|
9222
|
-
const
|
|
9223
|
-
if (!
|
|
9224
|
-
const
|
|
9225
|
-
const
|
|
9226
|
-
|
|
9227
|
-
|
|
9228
|
-
|
|
9229
|
-
|
|
9230
|
-
|
|
9231
|
-
|
|
9232
|
-
|
|
9233
|
-
|
|
9234
|
-
}
|
|
9247
|
+
const installed = listInstalled(paths);
|
|
9248
|
+
if (!installed.length) return;
|
|
9249
|
+
const groups = /* @__PURE__ */ new Map();
|
|
9250
|
+
for (const agent of installed) {
|
|
9251
|
+
const product = productOf(agent) || agent.id;
|
|
9252
|
+
if (!groups.has(product)) groups.set(product, []);
|
|
9253
|
+
groups.get(product).push({ id: agent.id, version: agent.version });
|
|
9254
|
+
}
|
|
9255
|
+
const tokenFor = /* @__PURE__ */ new Map();
|
|
9256
|
+
for (const row of license.listProducts()) {
|
|
9257
|
+
const token = row?.product ? license.tokenFor(row.product) : null;
|
|
9258
|
+
if (token) tokenFor.set(row.product, token);
|
|
9259
|
+
}
|
|
9260
|
+
const deviceHash = license.deviceHash();
|
|
9261
|
+
let reported = false;
|
|
9262
|
+
for (const [product, installs] of groups) {
|
|
9263
|
+
const token = tokenFor.get(product) || null;
|
|
9264
|
+
try {
|
|
9265
|
+
const res = await fetch(`${settings.licenseBaseUrl}/v1/installs`, {
|
|
9266
|
+
method: "POST",
|
|
9267
|
+
headers: {
|
|
9268
|
+
"content-type": "application/json",
|
|
9269
|
+
...token ? { authorization: `Bearer ${token}` } : {}
|
|
9270
|
+
},
|
|
9271
|
+
body: JSON.stringify({ product, os: process.platform, installs, deviceHash })
|
|
9272
|
+
});
|
|
9273
|
+
if (res.ok) reported = true;
|
|
9274
|
+
} catch {
|
|
9275
|
+
}
|
|
9235
9276
|
}
|
|
9277
|
+
if (reported) lastReport = Date.now();
|
|
9236
9278
|
}
|
|
9237
9279
|
async function autoUpdateTick() {
|
|
9280
|
+
void reportInstalls();
|
|
9238
9281
|
if (!settings.autoUpdate) return;
|
|
9239
9282
|
for (const agent of listInstalled(paths)) {
|
|
9240
9283
|
await loadReleases(true, productOf(agent));
|
|
@@ -9420,14 +9463,14 @@ function createPanelApp(options = {}) {
|
|
|
9420
9463
|
buyUrl: buyPageUrl(),
|
|
9421
9464
|
licenseBaseUrl: settings.licenseBaseUrl,
|
|
9422
9465
|
campaigns: await loadPublicCampaigns(),
|
|
9466
|
+
showcase: await loadPublicShowcase(),
|
|
9467
|
+
docs: await loadPublicDocs(),
|
|
9423
9468
|
storeError,
|
|
9424
9469
|
tasks: queue.list(),
|
|
9425
9470
|
settings: {
|
|
9426
9471
|
autoInstallUpdates: !!settings.autoInstallUpdates,
|
|
9427
9472
|
autoUpdate: settings.autoUpdate !== false,
|
|
9428
|
-
autoKickoffInDsh: settings.autoKickoffInDsh !== false
|
|
9429
|
-
telemetry: !!settings.telemetry,
|
|
9430
|
-
panelNpmRegistry: panelRegistryBase()
|
|
9473
|
+
autoKickoffInDsh: settings.autoKickoffInDsh !== false
|
|
9431
9474
|
},
|
|
9432
9475
|
panel: {
|
|
9433
9476
|
name: packageName,
|
|
@@ -9435,7 +9478,6 @@ function createPanelApp(options = {}) {
|
|
|
9435
9478
|
latest: panelUpdateCache.latest,
|
|
9436
9479
|
updateAvailable: !!panelUpdateCache.updateAvailable,
|
|
9437
9480
|
checkedAt: panelUpdateCache.checkedAt || null,
|
|
9438
|
-
registry: panelUpdateCache.registry || panelRegistryBase(),
|
|
9439
9481
|
error: panelUpdateCache.error || null,
|
|
9440
9482
|
installHint: panelUpdateCache.installHint || panelInstallHint(false)
|
|
9441
9483
|
},
|
|
@@ -9459,12 +9501,13 @@ function createPanelApp(options = {}) {
|
|
|
9459
9501
|
buyUrl: buyPageUrl(),
|
|
9460
9502
|
licenseBaseUrl: settings.licenseBaseUrl,
|
|
9461
9503
|
campaigns: [],
|
|
9504
|
+
showcase: { cases: [], tutorials: [] },
|
|
9505
|
+
docs: [],
|
|
9462
9506
|
storeError: null,
|
|
9463
9507
|
tasks: queue.list(),
|
|
9464
9508
|
settings: {
|
|
9465
9509
|
autoInstallUpdates: !!settings.autoInstallUpdates,
|
|
9466
|
-
autoKickoffInDsh: settings.autoKickoffInDsh !== false
|
|
9467
|
-
telemetry: !!settings.telemetry
|
|
9510
|
+
autoKickoffInDsh: settings.autoKickoffInDsh !== false
|
|
9468
9511
|
},
|
|
9469
9512
|
dsh: {
|
|
9470
9513
|
skills: !!dsh?.skills?.available?.(),
|
|
@@ -9506,6 +9549,62 @@ function createPanelApp(options = {}) {
|
|
|
9506
9549
|
return campaignCache.items;
|
|
9507
9550
|
}
|
|
9508
9551
|
}
|
|
9552
|
+
let showcaseCache = { at: 0, cases: [], tutorials: [] };
|
|
9553
|
+
let docsCache = { at: 0, items: [] };
|
|
9554
|
+
async function loadPublicDocs() {
|
|
9555
|
+
const now = Date.now();
|
|
9556
|
+
if (now - docsCache.at < 6e4) return docsCache.items;
|
|
9557
|
+
const base = String(settings.licenseBaseUrl || "").replace(/\/$/, "");
|
|
9558
|
+
if (!base) {
|
|
9559
|
+
docsCache = { at: now, items: [] };
|
|
9560
|
+
return docsCache.items;
|
|
9561
|
+
}
|
|
9562
|
+
try {
|
|
9563
|
+
const res = await fetch(`${base}/v1/docs`, { signal: AbortSignal.timeout(4e3) });
|
|
9564
|
+
const data = await res.json().catch(() => ({}));
|
|
9565
|
+
if (!res.ok) throw new Error("docs unavailable");
|
|
9566
|
+
const items = (Array.isArray(data.docs) ? data.docs : []).map((item) => ({
|
|
9567
|
+
id: String(item.id || ""),
|
|
9568
|
+
title: String(item.title || ""),
|
|
9569
|
+
url: String(item.url || "")
|
|
9570
|
+
})).filter((item) => item.id && /^https?:\/\//i.test(item.url));
|
|
9571
|
+
docsCache = { at: now, items };
|
|
9572
|
+
return items;
|
|
9573
|
+
} catch {
|
|
9574
|
+
docsCache = { at: now, items: docsCache.items };
|
|
9575
|
+
return docsCache.items;
|
|
9576
|
+
}
|
|
9577
|
+
}
|
|
9578
|
+
async function loadPublicShowcase() {
|
|
9579
|
+
const now = Date.now();
|
|
9580
|
+
if (now - showcaseCache.at < 6e4) return showcaseCache;
|
|
9581
|
+
const base = String(settings.licenseBaseUrl || "").replace(/\/$/, "");
|
|
9582
|
+
if (!base) {
|
|
9583
|
+
showcaseCache = { at: now, cases: [], tutorials: [] };
|
|
9584
|
+
return showcaseCache;
|
|
9585
|
+
}
|
|
9586
|
+
try {
|
|
9587
|
+
const res = await fetch(`${base}/v1/showcase`, { signal: AbortSignal.timeout(4e3) });
|
|
9588
|
+
const data = await res.json().catch(() => ({}));
|
|
9589
|
+
if (!res.ok) throw new Error("showcase unavailable");
|
|
9590
|
+
const mapItem = (item) => ({
|
|
9591
|
+
id: String(item.id || ""),
|
|
9592
|
+
title: String(item.title || ""),
|
|
9593
|
+
blurb: String(item.blurb || ""),
|
|
9594
|
+
agent: String(item.agent || ""),
|
|
9595
|
+
style: String(item.style || ""),
|
|
9596
|
+
coverUrl: String(item.coverUrl || ""),
|
|
9597
|
+
videoUrl: String(item.videoUrl || "")
|
|
9598
|
+
});
|
|
9599
|
+
const cases = (Array.isArray(data.cases) ? data.cases : []).map(mapItem).filter((item) => item.id && item.videoUrl);
|
|
9600
|
+
const tutorials = (Array.isArray(data.tutorials) ? data.tutorials : []).map(mapItem).filter((item) => item.id && item.videoUrl);
|
|
9601
|
+
showcaseCache = { at: now, cases, tutorials };
|
|
9602
|
+
return showcaseCache;
|
|
9603
|
+
} catch {
|
|
9604
|
+
showcaseCache = { at: now, cases: showcaseCache.cases, tutorials: showcaseCache.tutorials };
|
|
9605
|
+
return showcaseCache;
|
|
9606
|
+
}
|
|
9607
|
+
}
|
|
9509
9608
|
async function loadPublicContact() {
|
|
9510
9609
|
const base = String(settings.licenseBaseUrl || "").replace(/\/$/, "");
|
|
9511
9610
|
if (!base) return { wechatId: "", hasQr: false, configured: false };
|
|
@@ -9928,7 +10027,13 @@ function createPanelApp(options = {}) {
|
|
|
9928
10027
|
return send(res, 200, { settings });
|
|
9929
10028
|
case "POST /settings": {
|
|
9930
10029
|
const body = await readJson(req);
|
|
9931
|
-
|
|
10030
|
+
const patch = body.patch ?? body ?? {};
|
|
10031
|
+
const allowed = {};
|
|
10032
|
+
if (typeof patch.autoInstallUpdates === "boolean") allowed.autoInstallUpdates = patch.autoInstallUpdates;
|
|
10033
|
+
if (typeof patch.autoKickoffInDsh === "boolean") allowed.autoKickoffInDsh = patch.autoKickoffInDsh;
|
|
10034
|
+
if (typeof patch.autoUpdate === "boolean") allowed.autoUpdate = patch.autoUpdate;
|
|
10035
|
+
if (typeof patch.concurrency === "number" && Number.isFinite(patch.concurrency)) allowed.concurrency = patch.concurrency;
|
|
10036
|
+
settings = writeSettings(paths, allowed);
|
|
9932
10037
|
return send(res, 200, { settings });
|
|
9933
10038
|
}
|
|
9934
10039
|
case "POST /agents/upload":
|