@goodandready/dsh-subscriptions 0.4.10 → 0.4.12
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/client.js +16 -7
- package/lib/index.js +10 -1
- package/lib/usage.js +4 -3
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -667,19 +667,28 @@ function PluginCard(props) {
|
|
|
667
667
|
const id = setInterval(pull, 60 * 1000)
|
|
668
668
|
return () => clearInterval(id)
|
|
669
669
|
}, [])
|
|
670
|
-
// #69: если есть активная подписка — показываем её (провайдер +
|
|
670
|
+
// #69/#72: если есть активная подписка — показываем её (провайдер + индекс + windows с процентами).
|
|
671
671
|
if (state.active) {
|
|
672
672
|
const a = state.active
|
|
673
|
-
const
|
|
673
|
+
const wins = Array.isArray(a.windows) ? a.windows : []
|
|
674
|
+
// макс-процент среди окон для цвета полоски
|
|
675
|
+
let maxPct = -1
|
|
676
|
+
for (const w of wins) {
|
|
677
|
+
if (w && typeof w.usedPercent === 'number' && w.usedPercent > maxPct) maxPct = w.usedPercent
|
|
678
|
+
}
|
|
679
|
+
if (maxPct < 0 && typeof a.usagePercent === 'number') maxPct = a.usagePercent
|
|
680
|
+
const u = maxPct >= 0 ? maxPct : null
|
|
674
681
|
let acls = 'dsub-chipActive'
|
|
675
682
|
if (u != null) acls += u >= 100 ? ' dsub-chipActiveDanger' : (u >= 80 ? ' dsub-chipActiveDanger' : (u >= 50 ? ' dsub-chipActiveWarn' : ' dsub-chipActiveOk'))
|
|
676
683
|
const prov = t('provider' + a.provider.charAt(0).toUpperCase() + a.provider.slice(1)) || a.provider
|
|
677
|
-
const
|
|
678
|
-
const
|
|
679
|
-
const
|
|
684
|
+
const idx = a.index != null ? (' #' + a.index) : ''
|
|
685
|
+
const plan = a.plan ? (' ' + a.plan) : ''
|
|
686
|
+
const label = prov + idx + plan
|
|
687
|
+
// windows: "5h 12% 7d 8%"
|
|
688
|
+
const winLabels = wins.map((w) => (w.label || w.id) + ' ' + Math.round(w.usedPercent) + '%').join(' ')
|
|
680
689
|
return React.createElement('span', {
|
|
681
690
|
className: acls,
|
|
682
|
-
title: a.model ? (prov + ' · ' + a.model) : prov,
|
|
691
|
+
title: a.model ? (prov + idx + ' · ' + a.model) : (prov + idx),
|
|
683
692
|
},
|
|
684
693
|
React.createElement('span', { className: 'dsub-chipDot' }),
|
|
685
694
|
label,
|
|
@@ -687,7 +696,7 @@ function PluginCard(props) {
|
|
|
687
696
|
? React.createElement('span', { className: 'dsub-chipActiveBar' },
|
|
688
697
|
React.createElement('span', { className: 'dsub-chipActiveFill', style: { width: Math.min(100, Math.max(0, u)) + '%' } }))
|
|
689
698
|
: null,
|
|
690
|
-
|
|
699
|
+
winLabels || null,
|
|
691
700
|
)
|
|
692
701
|
}
|
|
693
702
|
const on = state.count > 0
|
package/lib/index.js
CHANGED
|
@@ -535,7 +535,7 @@ export function apply(ctx, config) {
|
|
|
535
535
|
}
|
|
536
536
|
} catch {}
|
|
537
537
|
}
|
|
538
|
-
// #69: активная подписка = последний успешный запрос (новые сверху).
|
|
538
|
+
// #69/#72: активная подписка = последний успешный запрос (новые сверху).
|
|
539
539
|
let active = null
|
|
540
540
|
const last = history.recent(1)
|
|
541
541
|
if (last.length) {
|
|
@@ -543,18 +543,27 @@ export function apply(ctx, config) {
|
|
|
543
543
|
const accts = await store.listAccounts(lastRow.provider)
|
|
544
544
|
const acct = accts.find((a) => a.ref === lastRow.ref) || accts[0]
|
|
545
545
|
let plan = ''
|
|
546
|
+
let index = acct && acct.ref ? Number(String(acct.ref).split('_').pop()) || null : null
|
|
546
547
|
let status = 'ok'
|
|
548
|
+
let windows = []
|
|
547
549
|
try {
|
|
548
550
|
const info = await store.describeRef(lastRow.ref)
|
|
549
551
|
plan = info.paidTierName || ''
|
|
550
552
|
if (info.validationUrl) status = 'verify'
|
|
551
553
|
else if (info.cooldownUntil && info.cooldownUntil > Date.now()) status = 'cooldown'
|
|
554
|
+
if (Array.isArray(info.usage)) {
|
|
555
|
+
windows = info.usage
|
|
556
|
+
.filter((w) => w && typeof w.usedPercent === 'number')
|
|
557
|
+
.map((w) => ({ id: w.id || w.en || w.ru, label: w.en || w.ru || w.id, usedPercent: w.usedPercent }))
|
|
558
|
+
}
|
|
552
559
|
} catch {}
|
|
553
560
|
active = {
|
|
554
561
|
provider: lastRow.provider,
|
|
562
|
+
index,
|
|
555
563
|
model: lastRow.model || null,
|
|
556
564
|
path: lastRow.path || null,
|
|
557
565
|
plan,
|
|
566
|
+
windows,
|
|
558
567
|
usagePercent: usage[lastRow.provider] != null ? usage[lastRow.provider] : null,
|
|
559
568
|
status,
|
|
560
569
|
at: lastRow.ts,
|
package/lib/usage.js
CHANGED
|
@@ -58,13 +58,14 @@ const WINDOW_LABELS = {
|
|
|
58
58
|
weekly_limit_7_days: { ru: "7д", en: "7d" },
|
|
59
59
|
primary: { ru: "осн.", en: "primary" },
|
|
60
60
|
secondary: { ru: "втор.", en: "secondary" },
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
// codex: vendor API отдаёт primary_window/secondary_window — для UI читаем как 5h/7d
|
|
62
|
+
primary_window: { ru: "5ч", en: "5h" },
|
|
63
|
+
secondary_window: { ru: "7д", en: "7d" },
|
|
63
64
|
monthly: { ru: "месяц", en: "month" },
|
|
64
65
|
credits: { ru: "кредиты", en: "credits" },
|
|
65
66
|
}
|
|
66
67
|
|
|
67
|
-
function windowLabel(id) {
|
|
68
|
+
export function windowLabel(id) {
|
|
68
69
|
const known = WINDOW_LABELS[id]
|
|
69
70
|
return known || { ru: id, en: id }
|
|
70
71
|
}
|
package/package.json
CHANGED