dashboard: guest accounts — no Matrix section, Become-a-member instead of buy
Gift accounts (portal flag on /broker/usage) get a different dashboard: the Matrix card is hidden in the markup and only revealed for members (a guest never sees it, even before the usage fetch returns), the credit-pack buy button becomes 'Become a member' pointing at the OC contribution page, and the meta line names the gift. Everything else (spend, models, keys, docs links) unchanged.
This commit is contained in:
1 parent
3453131c73
commit
67c10bae25
1 file changed
+24
-3
+24
-3
@@ -40,6 +40,12 @@ BROKER_SECRET = os.environ.get("BROKER_SECRET", "")
|
|||||||
DEFAULT_CREDIT_PACK_URL = "https://opencollective.com/inference-cooperative/contribute"
|
DEFAULT_CREDIT_PACK_URL = "https://opencollective.com/inference-cooperative/contribute"
|
||||||
CREDIT_PACK_URL = (os.environ.get("CREDIT_PACK_URL") or "").strip() or DEFAULT_CREDIT_PACK_URL
|
CREDIT_PACK_URL = (os.environ.get("CREDIT_PACK_URL") or "").strip() or DEFAULT_CREDIT_PACK_URL
|
||||||
|
|
||||||
|
# Where a GUEST account's "Become a member" button points (the contribution
|
||||||
|
# page — what actually starts a membership). Deliberately independent of
|
||||||
|
# CREDIT_PACK_URL: a guest needs a membership, not a credit pack, even if the
|
||||||
|
# credit-pack link is ever repointed at a pack page.
|
||||||
|
BECOME_MEMBER_URL = "https://opencollective.com/inference-cooperative/contribute"
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
|
|
||||||
@@ -311,6 +317,7 @@ def render_page(identity: str) -> str:
|
|||||||
return (
|
return (
|
||||||
PAGE_HTML.replace("@@IDENTITY@@", _esc(identity))
|
PAGE_HTML.replace("@@IDENTITY@@", _esc(identity))
|
||||||
.replace("@@CREDIT_PACK_URL@@", _esc(CREDIT_PACK_URL))
|
.replace("@@CREDIT_PACK_URL@@", _esc(CREDIT_PACK_URL))
|
||||||
|
.replace("@@BECOME_MEMBER_URL@@", _esc(BECOME_MEMBER_URL))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -590,7 +597,7 @@ PAGE_HTML = """<!DOCTYPE html>
|
|||||||
<div class="bar"><div class="fill" id="fill" style="width:0%"></div></div>
|
<div class="bar"><div class="fill" id="fill" style="width:0%"></div></div>
|
||||||
<div class="meta" id="meta">Shared across chat and API.</div>
|
<div class="meta" id="meta">Shared across chat and API.</div>
|
||||||
<div class="buy-row">
|
<div class="buy-row">
|
||||||
<a class="buy-btn" href="@@CREDIT_PACK_URL@@" target="_blank" rel="noopener">Buy a credit pack</a>
|
<a class="buy-btn" id="buy-btn" href="@@CREDIT_PACK_URL@@" target="_blank" rel="noopener">Buy a credit pack</a>
|
||||||
<span class="buy-hint"><span id="buy-credits">Credit packs never expire · used after your monthly allowance</span>
|
<span class="buy-hint"><span id="buy-credits">Credit packs never expire · used after your monthly allowance</span>
|
||||||
<a class="buy-docs" href="https://docs.inference.coop/getting-started/#need-more-than-the-allowance" target="_blank" rel="noopener">More about allowance & credits →</a>
|
<a class="buy-docs" href="https://docs.inference.coop/getting-started/#need-more-than-the-allowance" target="_blank" rel="noopener">More about allowance & credits →</a>
|
||||||
</span>
|
</span>
|
||||||
@@ -656,7 +663,7 @@ PAGE_HTML = """<!DOCTYPE html>
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="card">
|
<div class="card" id="matrix-card" style="display:none">
|
||||||
<h2>Matrix chat</h2>
|
<h2>Matrix chat</h2>
|
||||||
<p class="hint">We use the Matrix chat protocol to collaborate. You can access our space with an inference.coop account or an account hosted elsewhere.</p>
|
<p class="hint">We use the Matrix chat protocol to collaborate. You can access our space with an inference.coop account or an account hosted elsewhere.</p>
|
||||||
<p class="hint" style="margin-bottom:6px;"><strong>Current Matrix ID:</strong></p>
|
<p class="hint" style="margin-bottom:6px;"><strong>Current Matrix ID:</strong></p>
|
||||||
@@ -701,6 +708,20 @@ async function load() {
|
|||||||
if (r.status === 401) { location.reload(); return; }
|
if (r.status === 401) { location.reload(); return; }
|
||||||
const d = await r.json();
|
const d = await r.json();
|
||||||
if (d.error) { flash(d.error, false); return; }
|
if (d.error) { flash(d.error, false); return; }
|
||||||
|
|
||||||
|
// Gift accounts (portal flag): no Matrix section — the card is hidden in
|
||||||
|
// the markup and only shown to members — and a Become-a-member button in
|
||||||
|
// place of the credit-pack buy path. Everything else stays.
|
||||||
|
const isGuest = !!d.guest;
|
||||||
|
$('matrix-card').style.display = isGuest ? 'none' : '';
|
||||||
|
if (isGuest) {
|
||||||
|
const b = $('buy-btn');
|
||||||
|
b.href = '@@BECOME_MEMBER_URL@@';
|
||||||
|
b.textContent = 'Become a member';
|
||||||
|
$('buy-credits').textContent = 'Your gift credit never expires · members get a monthly allowance';
|
||||||
|
$('meta').textContent = 'A gift from a member — $5 of AI usage across chat and the API.';
|
||||||
|
}
|
||||||
|
|
||||||
const balance = d.balance ?? 0;
|
const balance = d.balance ?? 0;
|
||||||
const spend = d.spend ?? 0;
|
const spend = d.spend ?? 0;
|
||||||
const remaining = d.remaining ?? Math.max(0, balance - spend);
|
const remaining = d.remaining ?? Math.max(0, balance - spend);
|
||||||
@@ -744,7 +765,7 @@ async function load() {
|
|||||||
renderModels(d.models || []);
|
renderModels(d.models || []);
|
||||||
renderBoard(d.coop_models || []);
|
renderBoard(d.coop_models || []);
|
||||||
renderKeys(d.keys || [], d.key_spend || []);
|
renderKeys(d.keys || [], d.key_spend || []);
|
||||||
loadMxid();
|
if (!isGuest) loadMxid();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
flash('Could not load usage: ' + e.message, false);
|
flash('Could not load usage: ' + e.message, false);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user