@fish-under-sea/magpie-dragonapi 1.0.4 → 1.0.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/lib/service.mjs +39 -3
- package/lib/site.mjs +5 -1
- package/lib/usage.mjs +22 -6
- package/package.json +1 -1
- package/ui/app.js +105 -37
- package/ui/style.css +46 -26
package/lib/service.mjs
CHANGED
|
@@ -222,6 +222,10 @@ export async function startService({ port = 3517, dir = '.', site, catalog, stat
|
|
|
222
222
|
return { st, cat, cur, built, status: site_ }
|
|
223
223
|
}
|
|
224
224
|
|
|
225
|
+
// 页面「查看」列的记忆放在服务进程里:沙箱 iframe 没有 localStorage,
|
|
226
|
+
// 刷新页面后还能从同一个服务把选择拿回来。
|
|
227
|
+
const uiPrefs = { logCols: null, keysCols: null }
|
|
228
|
+
|
|
225
229
|
async function handler(req, res) {
|
|
226
230
|
const url = new URL(req.url || '/', 'http://127.0.0.1')
|
|
227
231
|
const path = url.pathname
|
|
@@ -276,6 +280,25 @@ export async function startService({ port = 3517, dir = '.', site, catalog, stat
|
|
|
276
280
|
return
|
|
277
281
|
}
|
|
278
282
|
|
|
283
|
+
if (path === '/api/prefs') {
|
|
284
|
+
if (req.method === 'GET') {
|
|
285
|
+
json(res, 200, { ok: true, ...uiPrefs })
|
|
286
|
+
return
|
|
287
|
+
}
|
|
288
|
+
if (req.method === 'PUT' || req.method === 'POST') {
|
|
289
|
+
let body = {}
|
|
290
|
+
try { body = (await readBody(req)) || {} } catch { throw new BadRequest('列偏好必须是 JSON') }
|
|
291
|
+
if (!body || typeof body !== 'object') throw new BadRequest('列偏好必须是 JSON 对象')
|
|
292
|
+
for (const field of ['logCols', 'keysCols']) {
|
|
293
|
+
if (Array.isArray(body[field])) {
|
|
294
|
+
uiPrefs[field] = body[field].map((v) => String(v)).filter(Boolean).slice(0, 32)
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
json(res, 200, { ok: true, ...uiPrefs })
|
|
298
|
+
return
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
279
302
|
if (path === '/api/state' && req.method === 'GET') {
|
|
280
303
|
const { st, cat, cur, built, status: site_ } = await stateOf()
|
|
281
304
|
const [accounts, userResult] = await Promise.all([
|
|
@@ -476,10 +499,20 @@ export async function startService({ port = 3517, dir = '.', site, catalog, stat
|
|
|
476
499
|
|
|
477
500
|
// 推荐奖励转入余额:原样转发站点的结论,不替它编「成功」。
|
|
478
501
|
if (path === '/api/aff/transfer' && req.method === 'POST') {
|
|
479
|
-
const { st } = await stateOf()
|
|
502
|
+
const { st, cur } = await stateOf()
|
|
480
503
|
if (!st.pat) { json(res, 400, { ok: false, error: '还没有设置访问令牌(PAT)' }); return }
|
|
504
|
+
let body = {}
|
|
505
|
+
try { body = (await readBody(req)) || {} } catch { throw new BadRequest('转入额度必须是 JSON') }
|
|
506
|
+
const per = Number(cur.per) > 0 ? Number(cur.per) : 500000
|
|
507
|
+
const quota = Math.floor(Number(body?.quota))
|
|
508
|
+
if (!Number.isFinite(quota) || quota <= 0) {
|
|
509
|
+
json(res, 400, { ok: false, error: '请填写要转入的额度' }); return
|
|
510
|
+
}
|
|
511
|
+
if (quota < per) {
|
|
512
|
+
json(res, 400, { ok: false, error: `站点最低一次转入 1 元(${cur.symbol || ''}1),请调高金额` }); return
|
|
513
|
+
}
|
|
481
514
|
try {
|
|
482
|
-
const r = await transferAff(site, st.pat)
|
|
515
|
+
const r = await transferAff(site, st.pat, { quota })
|
|
483
516
|
json(res, 200, { ok: r.ok, message: r.message || (r.ok ? '已转入余额' : '站点没有说明原因') })
|
|
484
517
|
} catch (e) {
|
|
485
518
|
json(res, 502, { ok: false, error: `转入失败:${e?.message || e}` })
|
|
@@ -488,7 +521,7 @@ export async function startService({ port = 3517, dir = '.', site, catalog, stat
|
|
|
488
521
|
}
|
|
489
522
|
// 推荐计划:合并邀请码与真实 self 指标,部分读取失败原话放 note。
|
|
490
523
|
if (path === '/api/aff' && req.method === 'GET') {
|
|
491
|
-
const { st } = await stateOf()
|
|
524
|
+
const { st, cur } = await stateOf()
|
|
492
525
|
if (!st.pat) { json(res, 400, { ok: false, error: '还没有设置访问令牌(PAT)' }); return }
|
|
493
526
|
const result = await readAff(site, st.pat)
|
|
494
527
|
const { code, note, ...aff } = result
|
|
@@ -497,6 +530,9 @@ export async function startService({ port = 3517, dir = '.', site, catalog, stat
|
|
|
497
530
|
aff: Object.keys(aff).length ? aff : null,
|
|
498
531
|
code,
|
|
499
532
|
link: code ? `${site}/sign-up?aff=${encodeURIComponent(code)}` : '',
|
|
533
|
+
// 页面换算金额与最低 1 元门槛用;quota 是站点内部单位。
|
|
534
|
+
per: Number(cur.per) > 0 ? Number(cur.per) : 500000,
|
|
535
|
+
symbol: cur.symbol || '$',
|
|
500
536
|
note,
|
|
501
537
|
at: Date.now(),
|
|
502
538
|
})
|
package/lib/site.mjs
CHANGED
|
@@ -454,10 +454,14 @@ export async function readSubscriptions(site, pat, cur, now = Date.now()) {
|
|
|
454
454
|
* 我们没有它的返回结构可依,所以原样把站点的 message 带回去——
|
|
455
455
|
* 成功失败都以站点为准,不在这里替它编一句「已转入」。
|
|
456
456
|
*/
|
|
457
|
-
export async function transferAff(site, pat) {
|
|
457
|
+
export async function transferAff(site, pat, { quota } = {}) {
|
|
458
|
+
const q = Number(quota)
|
|
458
459
|
const env = await siteCall(site, '/api/user/aff_transfer', {
|
|
459
460
|
method: 'POST',
|
|
460
461
|
auth: { kind: 'pat', token: pat },
|
|
462
|
+
// 站点要求 JSON body;不带 body 会直接 EOF。quota 单位是站点内部 quota,
|
|
463
|
+
// 页面按 1 元 = 500000 quota 换算。
|
|
464
|
+
body: Number.isFinite(q) && q > 0 ? { quota: Math.floor(q) } : {},
|
|
461
465
|
})
|
|
462
466
|
return { ok: env?.success !== false, message: String(env?.message || ''), data: env?.data ?? null }
|
|
463
467
|
}
|
package/lib/usage.mjs
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
// 也是 New API 部署,日志形状一致。
|
|
6
6
|
|
|
7
7
|
import { text } from './site.mjs'
|
|
8
|
+
import { chatCoeffs } from './pricing.mjs'
|
|
8
9
|
|
|
9
10
|
/** num 只接受真正的数字,字符串数字也认;其它一律 undefined。 */
|
|
10
11
|
function num(v) {
|
|
@@ -65,13 +66,28 @@ function firstToken(row) {
|
|
|
65
66
|
*/
|
|
66
67
|
function detailOf(other, quota) {
|
|
67
68
|
if (!other || typeof other !== 'object') return ''
|
|
68
|
-
const tier = pick(other?.
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
const tier = pick(other?.matched_tier, other?.tier, other?.billing_tier)
|
|
70
|
+
// 表达式计费(tiered_expr):价格在 expr_b64 里,model_ratio / completion_ratio
|
|
71
|
+
// 是 0 元占位,照它们拼只会得到「0 / 0」。解开表达式取 p / c 系数才是官网
|
|
72
|
+
// 详情列那串「$2 / $10/M」。
|
|
73
|
+
let input = num(other?.input_price) ?? num(other?.model_price_input)
|
|
74
|
+
let output = num(other?.output_price) ?? num(other?.model_price_output)
|
|
75
|
+
if ((input === undefined || output === undefined) && typeof other?.expr_b64 === 'string' && other.expr_b64) {
|
|
76
|
+
try {
|
|
77
|
+
const expr = Buffer.from(other.expr_b64, 'base64').toString('utf8')
|
|
78
|
+
const c = chatCoeffs(expr)
|
|
79
|
+
if (c) {
|
|
80
|
+
if (input === undefined) input = c.input
|
|
81
|
+
if (output === undefined) output = c.output
|
|
82
|
+
}
|
|
83
|
+
} catch { /* 表达式坏了就退到 tier */ }
|
|
84
|
+
}
|
|
71
85
|
const parts = []
|
|
72
|
-
if (tier) parts.push(tier)
|
|
73
|
-
if (
|
|
74
|
-
|
|
86
|
+
if (tier) parts.push(String(tier))
|
|
87
|
+
if (Number.isFinite(input) || Number.isFinite(output)) {
|
|
88
|
+
const inText = Number.isFinite(input) ? `$${input}` : '—'
|
|
89
|
+
const outText = Number.isFinite(output) ? `$${output}` : '—'
|
|
90
|
+
parts.push(`${inText} / ${outText}/M`)
|
|
75
91
|
}
|
|
76
92
|
if (!parts.length && quota !== undefined) return ''
|
|
77
93
|
return parts.join(' · ')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fish-under-sea/magpie-dragonapi",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "DragonAPI for magpie: a provider plugin whose models, groups and prices come from the site's public /api/pricing, with balance and per-call usage from an sk- key, plus a local page that lists the market (read-only), shows usage and can mint new keys for a group.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.mjs",
|
package/ui/app.js
CHANGED
|
@@ -259,13 +259,15 @@ const api = {
|
|
|
259
259
|
keys: () => request('/api/keys'),
|
|
260
260
|
aff: () => request('/api/aff'),
|
|
261
261
|
subscriptions: () => request('/api/subscriptions'),
|
|
262
|
-
transferAff: () => request('/api/aff/transfer', { method: 'POST' }),
|
|
262
|
+
transferAff: (body) => request('/api/aff/transfer', { method: 'POST', body }),
|
|
263
263
|
createKey: (body) => request('/api/keys', { method: 'POST', body }),
|
|
264
264
|
updateKey: (id, body) => request(`/api/keys/${encodeURIComponent(id)}`, { method: 'PUT', body }),
|
|
265
265
|
deleteKey: (id) => request(`/api/keys/${encodeURIComponent(id)}`, { method: 'DELETE' }),
|
|
266
266
|
revealKey: (id) => request(`/api/keys/${encodeURIComponent(id)}/reveal`, { method: 'POST' }),
|
|
267
267
|
bindInfo: () => request('/api/bind-info'),
|
|
268
268
|
health: () => request('/api/health'),
|
|
269
|
+
prefs: () => request('/api/prefs'),
|
|
270
|
+
savePrefs: (body) => request('/api/prefs', { method: 'PUT', body }),
|
|
269
271
|
};
|
|
270
272
|
|
|
271
273
|
// ── 提示条:所有失败都必须在界面上说话 ────────────────────
|
|
@@ -1468,9 +1470,6 @@ function subscriptionCard(s) {
|
|
|
1468
1470
|
// 站点 /api/user/aff 的字段名随部署而变(aff_count/aff_quota 是 New API 常见写法,
|
|
1469
1471
|
// 「待确认」没有公认键名),所以每列只在真拿到数字时才渲染。
|
|
1470
1472
|
|
|
1471
|
-
/** 转入余额需二次确认:第一下改成「确认转入」,5 秒内再点才真的发请求。 */
|
|
1472
|
-
let affTransferArmedUntil = 0;
|
|
1473
|
-
|
|
1474
1473
|
function renderAff() {
|
|
1475
1474
|
const box = $('#aff-body');
|
|
1476
1475
|
if (!box) return;
|
|
@@ -1483,12 +1482,12 @@ function renderAff() {
|
|
|
1483
1482
|
|
|
1484
1483
|
const link = d.link || '';
|
|
1485
1484
|
const a = d.aff || {};
|
|
1485
|
+
const per = Number(d.per) > 0 ? Number(d.per) : 500000;
|
|
1486
1486
|
// 三列:待确认(站点给才显示)/ 总收入 / 邀请。只认真实值,不拿 0 假装同步过。
|
|
1487
1487
|
const pending = Number.isFinite(a.pending) ? moneyRaw(a.pending) : null;
|
|
1488
1488
|
const total = Number.isFinite(a.historyQuota) ? moneyRaw(a.historyQuota) : null;
|
|
1489
1489
|
const invites = Number.isFinite(a.count) ? fmtInt(a.count) : null;
|
|
1490
1490
|
const canTransfer = Number.isFinite(a.quota) && a.quota > 0;
|
|
1491
|
-
const armed = Date.now() < affTransferArmedUntil;
|
|
1492
1491
|
|
|
1493
1492
|
// replaceChildren 收 null 会把它印成字符串「null」——先过滤再加。
|
|
1494
1493
|
box.replaceChildren(...[
|
|
@@ -1510,16 +1509,17 @@ function renderAff() {
|
|
|
1510
1509
|
link
|
|
1511
1510
|
? h('button', {
|
|
1512
1511
|
class: 'rf-copy', type: 'button', title: '复制推荐链接', 'aria-label': '复制推荐链接',
|
|
1513
|
-
|
|
1512
|
+
// 按钮只有 30px 宽;「已复制」会竖排溢出,用对勾表示成功。
|
|
1513
|
+
onclick: (ev) => copyText(link, ev.currentTarget, '✓'),
|
|
1514
1514
|
}, copyIcon())
|
|
1515
1515
|
: null,
|
|
1516
1516
|
canTransfer
|
|
1517
1517
|
? h('button', {
|
|
1518
|
-
class:
|
|
1518
|
+
class: 'btn primary rf-transfer',
|
|
1519
1519
|
type: 'button',
|
|
1520
1520
|
title: '把累计奖励转到余额(站点上的真实资金操作)',
|
|
1521
|
-
onclick: (
|
|
1522
|
-
},
|
|
1521
|
+
onclick: () => openAffTransfer(a, per, d.symbol || '$'),
|
|
1522
|
+
}, '转移到余额')
|
|
1523
1523
|
: null),
|
|
1524
1524
|
].filter(Boolean));
|
|
1525
1525
|
}
|
|
@@ -1531,29 +1531,64 @@ function rfStat(k, v) {
|
|
|
1531
1531
|
h('div', { class: 'rf-v', text: v }));
|
|
1532
1532
|
}
|
|
1533
1533
|
|
|
1534
|
-
/**
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
banner('info', '再点一次「确认转入」,就会把累计奖励转进余额。', { key: 'aff-transfer', timeout: 5000 });
|
|
1540
|
-
return;
|
|
1541
|
-
}
|
|
1534
|
+
/** closeAffTransfer 关掉转入浮窗。 */
|
|
1535
|
+
function closeAffTransfer() {
|
|
1536
|
+
const m = document.querySelector('.aff-modal');
|
|
1537
|
+
if (m) m.remove();
|
|
1538
|
+
}
|
|
1542
1539
|
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
}
|
|
1540
|
+
/**
|
|
1541
|
+
* openAffTransfer:和上游一样的浮窗输入金额,最低 1 元。
|
|
1542
|
+
* 站点 /api/user/aff_transfer 要 JSON body(quota 内部单位),不带会 EOF。
|
|
1543
|
+
*/
|
|
1544
|
+
function openAffTransfer(a, per, symbol) {
|
|
1545
|
+
closeAffTransfer();
|
|
1546
|
+
const available = Number(a?.quota) > 0 ? Number(a.quota) / per : 0;
|
|
1547
|
+
const amount = h('input', {
|
|
1548
|
+
class: 'aff-amount', type: 'number', min: '1', step: '0.01', inputmode: 'decimal',
|
|
1549
|
+
value: available >= 1 ? String(Math.floor(available * 100) / 100) : '1',
|
|
1550
|
+
'aria-label': '转入金额',
|
|
1551
|
+
});
|
|
1552
|
+
const error = h('p', { class: 'aff-modal-error', role: 'alert' });
|
|
1553
|
+
const confirm = h('button', { class: 'btn primary', type: 'button' }, '确认转入');
|
|
1554
|
+
const overlay = h('div', { class: 'aff-modal', role: 'dialog', 'aria-modal': 'true', 'aria-label': '转入余额' },
|
|
1555
|
+
h('div', { class: 'aff-modal-panel' },
|
|
1556
|
+
h('h3', { text: '转入余额' }),
|
|
1557
|
+
h('p', {
|
|
1558
|
+
class: 'aff-modal-hint',
|
|
1559
|
+
text: `可转奖励 ${symbol}${available.toFixed(2)};单次最低 1 元,按站点规则换算成 quota。`,
|
|
1560
|
+
}),
|
|
1561
|
+
h('label', { class: 'aff-modal-field' }, '转入金额', amount),
|
|
1562
|
+
error,
|
|
1563
|
+
h('div', { class: 'aff-modal-actions' },
|
|
1564
|
+
h('button', { class: 'btn ghost', type: 'button', onclick: closeAffTransfer }, '取消'),
|
|
1565
|
+
confirm)));
|
|
1566
|
+
overlay.addEventListener('click', (ev) => { if (ev.target === overlay) closeAffTransfer(); });
|
|
1567
|
+
const onKey = (ev) => { if (ev.key === 'Escape') { closeAffTransfer(); document.removeEventListener('keydown', onKey); } };
|
|
1568
|
+
document.addEventListener('keydown', onKey);
|
|
1569
|
+
confirm.addEventListener('click', async () => {
|
|
1570
|
+
const yuan = Number(amount.value);
|
|
1571
|
+
if (!Number.isFinite(yuan) || yuan < 1) { error.textContent = '最低转入 1 元。'; return; }
|
|
1572
|
+
if (available > 0 && yuan > available + 1e-6) { error.textContent = `最多可转 ${symbol}${available.toFixed(2)}。`; return; }
|
|
1573
|
+
error.textContent = '';
|
|
1574
|
+
confirm.disabled = true;
|
|
1575
|
+
confirm.textContent = '转入中…';
|
|
1576
|
+
try {
|
|
1577
|
+
const r = await api.transferAff({ quota: Math.round(yuan * per) });
|
|
1578
|
+
closeAffTransfer();
|
|
1579
|
+
document.removeEventListener('keydown', onKey);
|
|
1580
|
+
banner(r.ok ? 'ok' : 'warn', r.message || (r.ok ? '已转入余额' : '站点没有说明原因'), { key: 'aff-transfer' });
|
|
1581
|
+
await Promise.all([loadAff(true), loadState(true)]);
|
|
1582
|
+
renderAccounts();
|
|
1583
|
+
} catch (err) {
|
|
1584
|
+
error.textContent = `转入失败:${describeError(err)}`;
|
|
1585
|
+
confirm.disabled = false;
|
|
1586
|
+
confirm.textContent = '确认转入';
|
|
1587
|
+
}
|
|
1588
|
+
});
|
|
1589
|
+
document.body.append(overlay);
|
|
1590
|
+
amount.focus();
|
|
1591
|
+
amount.select();
|
|
1557
1592
|
}
|
|
1558
1593
|
|
|
1559
1594
|
/** 分享图标:三个节点由连线相接(与原站同一图形语言),放在圆形底上。 */
|
|
@@ -1621,10 +1656,8 @@ function renderAccounts() {
|
|
|
1621
1656
|
|
|
1622
1657
|
const bound = Array.isArray(st.accounts) ? st.accounts : Object.values(st.accounts || {});
|
|
1623
1658
|
const user = st.user;
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
...bound,
|
|
1627
|
-
];
|
|
1659
|
+
// 钱包只显示主账户;绑定钥匙的额度不再各占一张卡(它们仍在上方计数与密钥页)。
|
|
1660
|
+
const accounts = user ? [{ ...user, wallet: true, label: user.displayName || user.username, models: undefined }] : [];
|
|
1628
1661
|
if (sub) sub.textContent = [user ? 'PAT 账户钱包' : '', bound.length ? `${bound.length} 把绑定钥匙` : ''].filter(Boolean).join(' · ');
|
|
1629
1662
|
// 空态时让说明在卡里居中,而不是顶在上面、下面留一大片空白
|
|
1630
1663
|
box.classList.toggle('is-empty', accounts.length === 0);
|
|
@@ -1865,7 +1898,7 @@ const LOG_COLS = [
|
|
|
1865
1898
|
const logFilter = { model: '', group: '', kind: '', tokenName: '', requestId: '', upRequestId: '' };
|
|
1866
1899
|
const logView = {
|
|
1867
1900
|
page: 1, pageSize: 20, more: false, private: false, colsOpen: false,
|
|
1868
|
-
cols: new Set(['time', 'key', 'model', 'flow', 'tokens', 'cost', 'duration'
|
|
1901
|
+
cols: new Set(['time', 'key', 'model', 'flow', 'tokens', 'cost', 'duration']),
|
|
1869
1902
|
};
|
|
1870
1903
|
|
|
1871
1904
|
/** secs 秒数带单位:4.5 → 4.5s。 */
|
|
@@ -2010,6 +2043,7 @@ function renderLogs() {
|
|
|
2010
2043
|
ev.stopPropagation();
|
|
2011
2044
|
if (logView.cols.has(c.id)) { if (logView.cols.size > 1) logView.cols.delete(c.id); }
|
|
2012
2045
|
else logView.cols.add(c.id);
|
|
2046
|
+
saveColPrefs();
|
|
2013
2047
|
renderLogs();
|
|
2014
2048
|
},
|
|
2015
2049
|
}, c.label))),
|
|
@@ -2943,6 +2977,33 @@ const KEY_COLS = [
|
|
|
2943
2977
|
];
|
|
2944
2978
|
const keysView = new Set(['name', 'status', 'key', 'group', 'time', 'expire']);
|
|
2945
2979
|
|
|
2980
|
+
// 「查看」列的偏好记在服务进程里:沙箱 iframe 没有 localStorage,
|
|
2981
|
+
// 只存浏览器刷新就丢;服务活着就能跨刷新恢复。
|
|
2982
|
+
const colPrefs = { loaded: false, timer: 0 };
|
|
2983
|
+
function applyColPrefs(p) {
|
|
2984
|
+
const logIds = new Set(LOG_COLS.map((c) => c.id));
|
|
2985
|
+
const keyIds = new Set(KEY_COLS.map((c) => c.id));
|
|
2986
|
+
if (Array.isArray(p?.logCols)) {
|
|
2987
|
+
const saved = p.logCols.filter((id) => logIds.has(id));
|
|
2988
|
+
if (saved.length) logView.cols = new Set(saved);
|
|
2989
|
+
}
|
|
2990
|
+
if (Array.isArray(p?.keysCols)) {
|
|
2991
|
+
const saved = p.keysCols.filter((id) => keyIds.has(id));
|
|
2992
|
+
if (saved.length) keysView.clear(), saved.forEach((id) => keysView.add(id));
|
|
2993
|
+
}
|
|
2994
|
+
}
|
|
2995
|
+
async function loadColPrefs() {
|
|
2996
|
+
if (colPrefs.loaded) return;
|
|
2997
|
+
try { applyColPrefs(await api.prefs()); } catch { /* 服务不支持就用默认列 */ }
|
|
2998
|
+
colPrefs.loaded = true;
|
|
2999
|
+
}
|
|
3000
|
+
function saveColPrefs() {
|
|
3001
|
+
clearTimeout(colPrefs.timer);
|
|
3002
|
+
colPrefs.timer = setTimeout(() => {
|
|
3003
|
+
api.savePrefs({ logCols: [...logView.cols], keysCols: [...keysView] }).catch(() => {});
|
|
3004
|
+
}, 150);
|
|
3005
|
+
}
|
|
3006
|
+
|
|
2946
3007
|
const keysFilter = { name: '', key: '', status: '' };
|
|
2947
3008
|
const keysSel = new Set();
|
|
2948
3009
|
|
|
@@ -3125,7 +3186,11 @@ function renderKeys() {
|
|
|
3125
3186
|
const cells = {
|
|
3126
3187
|
name: h('td', { class: 'keys-name', text: k.name || '未命名' }),
|
|
3127
3188
|
status: h('td', null, h('span', { class: `keys-status ${status.cls.includes('ok') ? 'on' : 'off'}`, text: status.label })),
|
|
3128
|
-
key: h('td', null, h('span', { class: 'keys-key' }, k.masked || '—',
|
|
3189
|
+
key: h('td', null, h('span', { class: 'keys-key' }, k.masked || '—',
|
|
3190
|
+
h('button', {
|
|
3191
|
+
class: 'btn ghost', type: 'button', title: '复制完整密钥',
|
|
3192
|
+
onclick: () => copyKeySecret(k),
|
|
3193
|
+
}, '⧉'))),
|
|
3129
3194
|
quota: h('td', { class: 'keys-quota', title: Number.isFinite(k.used) ? `已用 ${fmtInt(k.used)} quota` : null },
|
|
3130
3195
|
k.unlimited ? '无限制' : moneyRaw(k.remain)),
|
|
3131
3196
|
group: h('td', null, k.group
|
|
@@ -3175,6 +3240,7 @@ function renderKeys() {
|
|
|
3175
3240
|
ev.stopPropagation();
|
|
3176
3241
|
if (keysView.has(c.id)) { if (keysView.size > 1) keysView.delete(c.id); }
|
|
3177
3242
|
else keysView.add(c.id);
|
|
3243
|
+
saveColPrefs();
|
|
3178
3244
|
renderKeys();
|
|
3179
3245
|
},
|
|
3180
3246
|
}, h('span', { class: 'keys-check-mark', text: keysView.has(c.id) ? '✓' : '' }), c.label)));
|
|
@@ -4278,6 +4344,8 @@ async function boot() {
|
|
|
4278
4344
|
bindPatControls();
|
|
4279
4345
|
bindDrawer();
|
|
4280
4346
|
|
|
4347
|
+
await loadColPrefs();
|
|
4348
|
+
|
|
4281
4349
|
const params = new URLSearchParams(location.search);
|
|
4282
4350
|
const wanted = params.get('tab');
|
|
4283
4351
|
// 密钥已并入账户页;旧的 ?tab=keys 链接仍要能打开(映射到 wallet),
|
package/ui/style.css
CHANGED
|
@@ -115,7 +115,7 @@ a { color: var(--accent); }
|
|
|
115
115
|
.app {
|
|
116
116
|
max-width: 1400px;
|
|
117
117
|
margin: 0 auto;
|
|
118
|
-
padding: 18px 22px
|
|
118
|
+
padding: 18px 22px 8px;
|
|
119
119
|
/* 外壳定高不滚:顶部(页头/标签/提示)与页脚钉住,主内容区自己滚 */
|
|
120
120
|
height: 100%;
|
|
121
121
|
display: flex;
|
|
@@ -3114,7 +3114,7 @@ input.keys-input:focus-visible, select.keys-select:focus-visible {
|
|
|
3114
3114
|
.logs-tools .btn { border-radius: 999px; }
|
|
3115
3115
|
|
|
3116
3116
|
/* 钱包左栏的账户主体不再自己滚:内容已居中放下,滚动条只在密钥卡里 */
|
|
3117
|
-
#panel-wallet .wallet-balance #account-body { overflow: hidden; }
|
|
3117
|
+
#panel-wallet .wallet-balance #account-body { overflow: hidden; }
|
|
3118
3118
|
|
|
3119
3119
|
/* ── API 密钥:照官网表格重做 ─────────────────────────────── */
|
|
3120
3120
|
.keys-title-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
|
|
@@ -3160,7 +3160,7 @@ input.keys-input:focus-visible, select.keys-select:focus-visible {
|
|
|
3160
3160
|
border-radius: 999px; border: 1px solid transparent; background: transparent; color: var(--muted); cursor: pointer;
|
|
3161
3161
|
}
|
|
3162
3162
|
.keys-act:hover { background: var(--card-hover); color: var(--fg); }
|
|
3163
|
-
.keys-act.danger:hover { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
|
|
3163
|
+
.keys-act.danger:hover { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
|
|
3164
3164
|
|
|
3165
3165
|
/* ── 日志头部:直接照 NearToken in Magpie 的 .lg-* 设计(覆盖上面的胶囊尝试) ── */
|
|
3166
3166
|
.logs-toolbar { padding: 8px; gap: 8px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255,255,255,.02); }
|
|
@@ -3186,7 +3186,7 @@ input.keys-input:focus-visible, select.keys-select:focus-visible {
|
|
|
3186
3186
|
.logs-tools .btn { height: 34px; padding: 0 8px; border-color: transparent; background: transparent; color: var(--muted); border-radius: 8px; }
|
|
3187
3187
|
.logs-tools .btn:hover { background: rgba(255,255,255,.06); color: var(--fg); }
|
|
3188
3188
|
.logs-tools .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; padding: 0 14px; }
|
|
3189
|
-
.logs-tools a.btn { text-decoration: none; display: inline-flex; align-items: center; }
|
|
3189
|
+
.logs-tools a.btn { text-decoration: none; display: inline-flex; align-items: center; }
|
|
3190
3190
|
|
|
3191
3191
|
/* API 密钥:查看列菜单 + 更小的复制图标 */
|
|
3192
3192
|
.keys-view-menu { margin-left: auto; }
|
|
@@ -3196,11 +3196,11 @@ input.keys-input:focus-visible, select.keys-select:focus-visible {
|
|
|
3196
3196
|
.keys-key .btn {
|
|
3197
3197
|
width: 22px; height: 22px; min-height: 0; padding: 0; font-size: 12px;
|
|
3198
3198
|
line-height: 1; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center;
|
|
3199
|
-
}
|
|
3199
|
+
}
|
|
3200
3200
|
|
|
3201
3201
|
/* 密钥「查看」菜单:选中用勾选,不用整行高亮 */
|
|
3202
3202
|
#keys-view-pop [role="option"][aria-selected="true"] { color: var(--fg); background: transparent; }
|
|
3203
|
-
#keys-view-pop [role="option"]:hover { background: var(--card-hover); }
|
|
3203
|
+
#keys-view-pop [role="option"]:hover { background: var(--card-hover); }
|
|
3204
3204
|
|
|
3205
3205
|
/* 日志头部:胶囊化 + 排布(最新要求);表格不许左右滚 */
|
|
3206
3206
|
.logs-filters { display: flex; flex-wrap: wrap; gap: 8px; }
|
|
@@ -3219,7 +3219,7 @@ input.keys-input:focus-visible, select.keys-select:focus-visible {
|
|
|
3219
3219
|
.logs-body { overflow-x: hidden; }
|
|
3220
3220
|
.lg-table { min-width: 0; width: 100%; }
|
|
3221
3221
|
.lg-row { grid-template-columns: var(--lg-cols); gap: 0 10px; }
|
|
3222
|
-
.lg-row > * { min-width: 0; }
|
|
3222
|
+
.lg-row > * { min-width: 0; }
|
|
3223
3223
|
|
|
3224
3224
|
/* 半透明表头 / 弹层:加不透明底 + 背景模糊,避免滚动内容透出来 */
|
|
3225
3225
|
.lg-head,
|
|
@@ -3239,7 +3239,7 @@ input.keys-input:focus-visible, select.keys-select:focus-visible {
|
|
|
3239
3239
|
.keys-titlebar {
|
|
3240
3240
|
backdrop-filter: blur(8px);
|
|
3241
3241
|
-webkit-backdrop-filter: blur(8px);
|
|
3242
|
-
}
|
|
3242
|
+
}
|
|
3243
3243
|
|
|
3244
3244
|
/* 表头再压实一点:接近不透明 + 模糊,滚动行完全不透出 */
|
|
3245
3245
|
.lg-head,
|
|
@@ -3247,7 +3247,7 @@ input.keys-input:focus-visible, select.keys-select:focus-visible {
|
|
|
3247
3247
|
background: color-mix(in srgb, var(--bg) 98%, transparent);
|
|
3248
3248
|
backdrop-filter: blur(12px);
|
|
3249
3249
|
-webkit-backdrop-filter: blur(12px);
|
|
3250
|
-
}
|
|
3250
|
+
}
|
|
3251
3251
|
|
|
3252
3252
|
/* 日志顶部(照站点源码的 primaryFilters 结构):一行、扁平胶囊、32px */
|
|
3253
3253
|
.logs-toolbar {
|
|
@@ -3278,7 +3278,7 @@ input.keys-input:focus-visible, select.keys-select:focus-visible {
|
|
|
3278
3278
|
border: 1px solid transparent; background: transparent; color: var(--muted);
|
|
3279
3279
|
display: inline-flex; align-items: center; gap: 4px;
|
|
3280
3280
|
}
|
|
3281
|
-
.logs-expand:hover { background: rgba(255,255,255,.06); color: var(--fg); }
|
|
3281
|
+
.logs-expand:hover { background: rgba(255,255,255,.06); color: var(--fg); }
|
|
3282
3282
|
|
|
3283
3283
|
/* 收紧日志顶部上下留白 */
|
|
3284
3284
|
.logs-toolbar { margin-bottom: 0; }
|
|
@@ -3305,10 +3305,10 @@ input.keys-input:focus-visible, select.keys-select:focus-visible {
|
|
|
3305
3305
|
.keys-filterbar .btn,
|
|
3306
3306
|
.keys-filterbar .sel-trigger { background: var(--card); border: 1px solid var(--line); padding: 0 14px; }
|
|
3307
3307
|
#keys-api-addr { background: transparent; border: 1px solid var(--line); padding: 0 14px; }
|
|
3308
|
-
#key-create-open { padding: 0 16px; }
|
|
3308
|
+
#key-create-open { padding: 0 16px; }
|
|
3309
3309
|
|
|
3310
3310
|
.logs-card { gap: 0; }
|
|
3311
|
-
|
|
3311
|
+
|
|
3312
3312
|
|
|
3313
3313
|
/* 弹层:完全不透明并压住表格,避免内容透出 */
|
|
3314
3314
|
.menu-pop, .sel-pop {
|
|
@@ -3334,7 +3334,7 @@ input.keys-input:focus-visible, select.keys-select:focus-visible {
|
|
|
3334
3334
|
background: var(--accent) !important;
|
|
3335
3335
|
border-color: var(--accent) !important;
|
|
3336
3336
|
color: #fff;
|
|
3337
|
-
}
|
|
3337
|
+
}
|
|
3338
3338
|
|
|
3339
3339
|
/* 密钥复制按钮:只留图标,去掉框选 */
|
|
3340
3340
|
.keys-key .btn {
|
|
@@ -3342,7 +3342,7 @@ input.keys-input:focus-visible, select.keys-select:focus-visible {
|
|
|
3342
3342
|
border: 0 !important; background: transparent !important; box-shadow: none;
|
|
3343
3343
|
color: var(--muted); border-radius: 0;
|
|
3344
3344
|
}
|
|
3345
|
-
.keys-key .btn:hover { color: var(--fg); background: transparent !important; }
|
|
3345
|
+
.keys-key .btn:hover { color: var(--fg); background: transparent !important; }
|
|
3346
3346
|
|
|
3347
3347
|
/* 密钥行操作:禁用/编辑/更多 */
|
|
3348
3348
|
.keys-actions { display: inline-flex; align-items: center; gap: 2px; }
|
|
@@ -3358,10 +3358,10 @@ input.keys-input:focus-visible, select.keys-select:focus-visible {
|
|
|
3358
3358
|
}
|
|
3359
3359
|
.keys-more-pop [role="option"]:hover, .keys-more-del:hover { background: var(--card-hover); }
|
|
3360
3360
|
.kmi-ico { color: var(--muted); }
|
|
3361
|
-
.keys-more-del { color: var(--bad); }
|
|
3361
|
+
.keys-more-del { color: var(--bad); }
|
|
3362
3362
|
|
|
3363
3363
|
/* 密钥行「更多」菜单向上弹,避免被卡片底边裁掉 */
|
|
3364
|
-
.keys-more-pop { top: auto; bottom: calc(100% + 6px); }
|
|
3364
|
+
.keys-more-pop { top: auto; bottom: calc(100% + 6px); }
|
|
3365
3365
|
|
|
3366
3366
|
/* 展开按钮:胶囊;展开行三个输入也胶囊扁平 */
|
|
3367
3367
|
.logs-expand { background: rgba(255,255,255,.05); color: var(--fg); border: 1px solid transparent; }
|
|
@@ -3375,7 +3375,7 @@ input.keys-input:focus-visible, select.keys-select:focus-visible {
|
|
|
3375
3375
|
.logs-filters-adv .logs-input {
|
|
3376
3376
|
flex: 1 1 0; height: 32px; border-radius: 999px; border: 1px solid transparent;
|
|
3377
3377
|
background: rgba(255,255,255,.05); padding: 0 12px; font-size: 11.5px;
|
|
3378
|
-
}
|
|
3378
|
+
}
|
|
3379
3379
|
|
|
3380
3380
|
/* 钱包标题即入口:无框,只加箭头;金额放大填满左栏 */
|
|
3381
3381
|
.wallet-title { margin: 0; }
|
|
@@ -3391,12 +3391,12 @@ input.keys-input:focus-visible, select.keys-select:focus-visible {
|
|
|
3391
3391
|
.wallet-balance .acct-hero { align-items: center; }
|
|
3392
3392
|
.wallet-balance .acct-num { font-size: 46px; line-height: 1.02; }
|
|
3393
3393
|
.wallet-balance .acct-cur { font-size: 24px; }
|
|
3394
|
-
.wallet-jump { display: none; }
|
|
3394
|
+
.wallet-jump { display: none; }
|
|
3395
3395
|
|
|
3396
3396
|
/* 每页行数下拉向上弹,避免被卡片底边裁掉 */
|
|
3397
3397
|
.lg-pager .sel-pop { top: auto; bottom: calc(100% + 6px); }
|
|
3398
3398
|
/* 日志表头不跟随滚动(不再 sticky) */
|
|
3399
|
-
.lg-head { position: static; backdrop-filter: none; -webkit-backdrop-filter: none; }
|
|
3399
|
+
.lg-head { position: static; backdrop-filter: none; -webkit-backdrop-filter: none; }
|
|
3400
3400
|
|
|
3401
3401
|
/* 日志:筛选区(绿框)+ 表格区(红框)各自成块,和官网一致 */
|
|
3402
3402
|
.logs-head-box {
|
|
@@ -3414,7 +3414,7 @@ input.keys-input:focus-visible, select.keys-select:focus-visible {
|
|
|
3414
3414
|
.logs-body .lg-table { border: 0; border-radius: 0; }
|
|
3415
3415
|
.lg-head { background: color-mix(in srgb, var(--card) 75%, transparent); }
|
|
3416
3416
|
.lg-row { padding: 10px 12px; }
|
|
3417
|
-
.logs-pager { margin-top: 10px; }
|
|
3417
|
+
.logs-pager { margin-top: 10px; }
|
|
3418
3418
|
|
|
3419
3419
|
/* 钱包左栏:左对齐,内容从顶部排,sub-plus 贴底与右侧卡片齐 */
|
|
3420
3420
|
.wallet-balance #account-body {
|
|
@@ -3423,24 +3423,24 @@ input.keys-input:focus-visible, select.keys-select:focus-visible {
|
|
|
3423
3423
|
.wallet-balance .acct-card { height: 100%; justify-content: flex-start; align-items: stretch; gap: 12px; text-align: left; }
|
|
3424
3424
|
.wallet-balance .acct-hero { justify-content: flex-start; }
|
|
3425
3425
|
.wallet-balance .acct-money { justify-content: flex-start; }
|
|
3426
|
-
.wallet-balance .acct-foot { margin-top: auto; }
|
|
3426
|
+
.wallet-balance .acct-foot { margin-top: auto; }
|
|
3427
3427
|
|
|
3428
3428
|
/* 推荐计划:同步时间下移,与左侧副标题小字同一行 */
|
|
3429
|
-
.rf-sync { align-self: flex-end; padding-bottom: 1px; }
|
|
3429
|
+
.rf-sync { align-self: flex-end; padding-bottom: 1px; }
|
|
3430
3430
|
|
|
3431
3431
|
/* 钱包左栏留白:标题下留空隙,数字下移填掉底部空白 */
|
|
3432
3432
|
.wallet-balance #account-body { margin-top: 10px; }
|
|
3433
|
-
.wallet-balance .acct-hero { margin-top: 12px; }
|
|
3433
|
+
.wallet-balance .acct-hero { margin-top: 12px; }
|
|
3434
3434
|
|
|
3435
3435
|
/* 展开后三行之间留足空隙,不要挤在一起 */
|
|
3436
3436
|
.logs-head-box .logs-filters-adv { margin-top: 14px; }
|
|
3437
|
-
.logs-head-box .logs-chips-bar { margin-top: 16px; }
|
|
3437
|
+
.logs-head-box .logs-chips-bar { margin-top: 16px; }
|
|
3438
3438
|
|
|
3439
3439
|
/* 展开区用 flex 纵向排列,统一 12px 间距,避免行间重叠 */
|
|
3440
3440
|
.logs-head-box { display: flex; flex-direction: column; gap: 12px; }
|
|
3441
3441
|
.logs-head-box .logs-toolbar,
|
|
3442
3442
|
.logs-head-box .logs-filters-adv,
|
|
3443
|
-
.logs-head-box .logs-chips-bar { margin: 0; }
|
|
3443
|
+
.logs-head-box .logs-chips-bar { margin: 0; }
|
|
3444
3444
|
|
|
3445
3445
|
/* 访问令牌:顶部两卡完整显示,不在卡片内部滚 */
|
|
3446
3446
|
#panel-pat { overflow-y: auto; }
|
|
@@ -3458,4 +3458,24 @@ input.keys-input:focus-visible, select.keys-select:focus-visible {
|
|
|
3458
3458
|
.banners .banner {
|
|
3459
3459
|
pointer-events: auto; background: var(--card);
|
|
3460
3460
|
box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
|
|
3461
|
-
}
|
|
3461
|
+
}
|
|
3462
|
+
|
|
3463
|
+
/* 推荐计划:转入余额浮窗(沙箱里不能用 window.confirm) */
|
|
3464
|
+
.aff-modal {
|
|
3465
|
+
position: fixed; inset: 0; z-index: 500; display: grid; place-items: center;
|
|
3466
|
+
padding: 18px; background: rgba(0, 0, 0, .55);
|
|
3467
|
+
}
|
|
3468
|
+
.aff-modal-panel {
|
|
3469
|
+
width: min(380px, 100%); border: 1px solid var(--line-strong); border-radius: var(--radius);
|
|
3470
|
+
background: var(--card); padding: 16px; display: flex; flex-direction: column; gap: 10px;
|
|
3471
|
+
box-shadow: 0 18px 48px rgba(0, 0, 0, .5);
|
|
3472
|
+
}
|
|
3473
|
+
.aff-modal-panel h3 { margin: 0; font-size: 14px; }
|
|
3474
|
+
.aff-modal-hint { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
|
|
3475
|
+
.aff-modal-field { display: flex; flex-direction: column; gap: 6px; font-size: 11.5px; color: var(--muted); }
|
|
3476
|
+
.aff-amount {
|
|
3477
|
+
height: 34px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line-strong);
|
|
3478
|
+
background: var(--sunken); color: var(--fg); font: inherit;
|
|
3479
|
+
}
|
|
3480
|
+
.aff-modal-error { margin: 0; min-height: 16px; color: var(--bad); font-size: 11.5px; }
|
|
3481
|
+
.aff-modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 2px; }
|