Pre-launch — Gluecron is in final validation. Public signups and git hosting for non-owner users open after launch review.
CodeIssuesDiscussionsWikiPull RequestsProjectsCommitsActionsReleasesContributorsPulse● GatesSecuritySettingsDeploymentsPipelineInsightsAgents✨ Explain✨ Ask AI✨ Workspace✨ Spec✨ Tests▓ Debt Map✨ NL Search🏛 Archaeology
claude/adoring-hopper-5x74bqclaude/affectionate-feynman-ykrf1hclaude/architecture-audit-design-wxprenclaude/build-status-update-3MXsfclaude/charming-meitner-mllb5rclaude/compare-gate-gluecron-s4mFQclaude/confident-faraday-tikcwbclaude/continue-work-XMTlIclaude/crontech-gluecron-deploy-7MIECclaude/crontech-platform-setup-SeKfwclaude/design-2026claude/ecstatic-ptolemy-jMdigclaude/enhance-github-integration-QNHdGclaude/fix-aa-loop-issue-PonMQclaude/fix-actions-and-processclaude/fix-desktop-errors-XqoW8claude/fix-red-workflowsclaude/fix-website-access-6FKJNclaude/gatetest-integration-hardeningclaude/github-audit-improvements-bDFr9claude/gluecron-launch-status-FoMRlclaude/hopeful-lamport-olfCTclaude/issue-to-pr-and-protectionsclaude/jolly-heisenberg-2sg1Qclaude/launch-preparation-QmTb6claude/new-session-xk1l7claude/plan-platform-architecture-kkN4yclaude/platform-analysis-roadmap-1nUGLclaude/platform-launch-assessment-8dWV8claude/polish-platform-release-AeDrUclaude/resume-previous-work-KzyLwclaude/review-crontech-handoff-qYEVqclaude/review-project-completeness-lHhS2claude/review-readme-docs-ulqPKclaude/serene-edison-rj87weclaude/setup-multi-repo-dev-BCwNQclaude/ship-fixes-and-tests-Jvz1cclaude/site-audit-competitive-pctlwgclaude/site-migration-vercel-XstpKclaude/standalone-product-repos-XHFTDcopilot/feat-smart-empty-states-keyboard-first-enhancementcopilot/feat-smart-morning-digest-review-context-restorecopilot/fix-and-process-workflowscopilot/update-ai-powered-code-reviewfeat/debt-mapfeat/push-policy-codeowners-hardeningfeat/smart-digest-contextfeat/stage-impactfeat/t1-secret-migrationfeat/u-polishfeat/w-self-hostfeat/w2-claude-configfix/agent-journey-orphan-sweepgatetest/auto-fix-1776586424172gatetest/auto-fix-1776586534814gatetest/auto-fix-1776590685143gatetest/auto-fix-1776590808199mainops/redeploy-retriggerstyle/dxt-cta-themeworktree-agent-a3377aad30d55da26worktree-agent-a7ef607b7ee1d6c74
sponsors.tsx13.0 KB · 432 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
/**
 * Block I6 — Sponsors.
 *
 *   GET  /sponsors/:username                  — public sponsor page
 *   GET  /settings/sponsors                   — maintain your own tiers + activity
 *   POST /settings/sponsors/tiers/new         — publish a tier
 *   POST /settings/sponsors/tiers/:id/delete  — retire a tier
 *   POST /sponsors/:username                  — record a sponsorship
 *
 * Payment rails are out of scope — this captures intent + thank-you notes.
 */

import { Hono } from "hono";
import { and, desc, eq, isNull, sql } from "drizzle-orm";
import { db } from "../db";
import {
  sponsorships,
  sponsorshipTiers,
  users,
} from "../db/schema";
import { Layout } from "../views/layout";
import { softAuth, requireAuth } from "../middleware/auth";
import type { AuthEnv } from "../middleware/auth";

const sponsors = new Hono<AuthEnv>();
sponsors.use("*", softAuth);

function formatCents(cents: number): string {
  if (cents === 0) return "Any amount";
  const dollars = (cents / 100).toFixed(2);
  return `$${dollars}`;
}

// ---------- Public sponsor page ----------

sponsors.get("/sponsors/:username", async (c) => {
  const user = c.get("user");
  const targetName = c.req.param("username");
  const [target] = await db
    .select()
    .from(users)
    .where(eq(users.username, targetName))
    .limit(1);
  if (!target) return c.notFound();

  const tiers = await db
    .select()
    .from(sponsorshipTiers)
    .where(
      and(
        eq(sponsorshipTiers.maintainerId, target.id),
        eq(sponsorshipTiers.isActive, true)
      )
    )
    .orderBy(sponsorshipTiers.monthlyCents);

  const recentPublic = await db
    .select({
      id: sponsorships.id,
      amountCents: sponsorships.amountCents,
      createdAt: sponsorships.createdAt,
      note: sponsorships.note,
      sponsorName: users.username,
    })
    .from(sponsorships)
    .innerJoin(users, eq(sponsorships.sponsorId, users.id))
    .where(
      and(
        eq(sponsorships.maintainerId, target.id),
        eq(sponsorships.isPublic, true),
        isNull(sponsorships.cancelledAt)
      )
    )
    .orderBy(desc(sponsorships.createdAt))
    .limit(20);

  return c.html(
    <Layout title={`Sponsor ${targetName}`} user={user}>
      <h2>Sponsor {targetName}</h2>
      <p
        style="font-size:14px;color:var(--text-muted);margin:8px 0 20px"
      >
        Support {targetName}'s open-source work on Gluecron.
      </p>

      {tiers.length === 0 ? (
        <div class="panel" style="padding:16px">
          <p style="margin-bottom:12px">
            {targetName} hasn't published any sponsorship tiers yet.
          </p>
          {user ? (
            <form method="post" action={`/sponsors/${targetName}`}>
              <input
                type="number"
                name="amount_cents"
                placeholder="Amount in cents (e.g. 500 = $5)"
                min="100"
                required
                style="width:60%"
              />{" "}
              <button type="submit" class="btn btn-primary">
                Sponsor (one-time)
              </button>
            </form>
          ) : (
            <a href={`/login?next=/sponsors/${targetName}`}>
              Sign in to sponsor
            </a>
          )}
        </div>
      ) : (
        <div
          style="display:grid;grid-template-columns:repeat(auto-fit,minmax(220px,1fr));gap:12px;margin-bottom:20px"
        >
          {tiers.map((t) => (
            <form
              method="post"
              action={`/sponsors/${targetName}`}
              class="panel"
              style="padding:16px;display:flex;flex-direction:column;gap:8px"
            >
              <input type="hidden" name="tier_id" value={t.id} />
              <div style="font-weight:700;font-size:16px">{t.name}</div>
              <div style="font-size:22px;color:var(--accent);font-weight:700">
                {formatCents(t.monthlyCents)}
                {t.monthlyCents > 0 && (
                  <span style="font-size:13px;color:var(--text-muted);font-weight:400">
                    /mo
                  </span>
                )}
              </div>
              <div
                style="font-size:13px;color:var(--text-muted);flex:1"
              >
                {t.description || "\u2014"}
              </div>
              {user ? (
                <>
                  <select name="kind" style="font-size:13px">
                    <option value="monthly">Monthly</option>
                    {t.oneTimeAllowed && (
                      <option value="one_time">One-time</option>
                    )}
                  </select>
                  <button type="submit" class="btn btn-primary">
                    Sponsor
                  </button>
                </>
              ) : (
                <a
                  href={`/login?next=/sponsors/${targetName}`}
                  class="btn"
                  style="text-align:center"
                >
                  Sign in to sponsor
                </a>
              )}
            </form>
          ))}
        </div>
      )}

      <h3>Recent sponsors</h3>
      <div class="panel">
        {recentPublic.length === 0 ? (
          <div class="panel-empty">Be the first to sponsor.</div>
        ) : (
          recentPublic.map((s) => (
            <div class="panel-item" style="justify-content:space-between">
              <div>
                <a href={`/${s.sponsorName}`}>
                  <strong>{s.sponsorName}</strong>
                </a>
                {s.note && (
                  <span
                    style="margin-left:8px;font-size:13px;color:var(--text-muted)"
                  >
                    "{s.note}"
                  </span>
                )}
              </div>
              <div
                style="font-size:12px;color:var(--text-muted);white-space:nowrap"
              >
                {formatCents(s.amountCents)} ·{" "}
                {new Date(s.createdAt).toLocaleDateString()}
              </div>
            </div>
          ))
        )}
      </div>
    </Layout>
  );
});

// Record a sponsorship
sponsors.post("/sponsors/:username", requireAuth, async (c) => {
  const user = c.get("user")!;
  const targetName = c.req.param("username");
  const [target] = await db
    .select()
    .from(users)
    .where(eq(users.username, targetName))
    .limit(1);
  if (!target) return c.notFound();
  if (target.id === user.id) {
    return c.redirect(`/sponsors/${targetName}`);
  }
  const body = await c.req.parseBody();
  const tierId = body.tier_id ? String(body.tier_id) : null;
  let amountCents = 0;
  let kind = String(body.kind || "one_time");
  if (kind !== "monthly" && kind !== "one_time") kind = "one_time";

  if (tierId) {
    const [tier] = await db
      .select()
      .from(sponsorshipTiers)
      .where(eq(sponsorshipTiers.id, tierId))
      .limit(1);
    if (!tier || tier.maintainerId !== target.id) {
      return c.redirect(`/sponsors/${targetName}`);
    }
    amountCents = tier.monthlyCents;
  } else {
    amountCents = Math.max(0, parseInt(String(body.amount_cents || "0"), 10));
  }
  if (amountCents <= 0 && !tierId) {
    return c.redirect(`/sponsors/${targetName}`);
  }

  await db.insert(sponsorships).values({
    sponsorId: user.id,
    maintainerId: target.id,
    tierId: tierId || null,
    amountCents,
    kind,
    note: body.note ? String(body.note).slice(0, 200) : null,
    isPublic: body.is_public !== "0",
  });
  return c.redirect(`/sponsors/${targetName}?thanks=1`);
});

// ---------- Maintainer settings ----------

sponsors.get("/settings/sponsors", requireAuth, async (c) => {
  const user = c.get("user")!;
  const [tiers, activity] = await Promise.all([
    db
      .select()
      .from(sponsorshipTiers)
      .where(eq(sponsorshipTiers.maintainerId, user.id))
      .orderBy(sponsorshipTiers.monthlyCents),
    db
      .select({
        id: sponsorships.id,
        amountCents: sponsorships.amountCents,
        kind: sponsorships.kind,
        createdAt: sponsorships.createdAt,
        sponsorName: users.username,
      })
      .from(sponsorships)
      .innerJoin(users, eq(sponsorships.sponsorId, users.id))
      .where(eq(sponsorships.maintainerId, user.id))
      .orderBy(desc(sponsorships.createdAt))
      .limit(50),
  ]);
  const total = activity.reduce((sum, s) => sum + s.amountCents, 0);
  return c.html(
    <Layout title="Sponsorship settings" user={user}>
      <h2>Sponsorship</h2>
      <p style="color:var(--text-muted);margin-bottom:16px">
        Your public sponsor page is at{" "}
        <a href={`/sponsors/${user.username}`}>/sponsors/{user.username}</a>.
      </p>

      <div class="panel" style="padding:16px;margin-bottom:20px">
        <div style="font-size:12px;color:var(--text-muted)">
          Total received
        </div>
        <div style="font-size:24px;font-weight:700">
          {formatCents(total)}
        </div>
      </div>

      <h3>Tiers</h3>
      <div class="panel" style="margin-bottom:20px">
        {tiers.length === 0 ? (
          <div class="panel-empty">
            No tiers yet. Add one below to start accepting support.
          </div>
        ) : (
          tiers.map((t) => (
            <div class="panel-item" style="justify-content:space-between">
              <div>
                <div style="font-weight:600">{t.name}</div>
                <div
                  style="font-size:12px;color:var(--text-muted);margin-top:2px"
                >
                  {formatCents(t.monthlyCents)}/mo ·{" "}
                  {t.description || "no description"}
                </div>
              </div>
              <form
                method="post"
                action={`/settings/sponsors/tiers/${t.id}/delete`}
                onsubmit="return confirm('Retire this tier?')"
              >
                <button type="submit" class="btn btn-sm btn-danger">
                  Retire
                </button>
              </form>
            </div>
          ))
        )}
      </div>

      <h3>Add a tier</h3>
      <form
        method="post"
        action="/settings/sponsors/tiers/new"
        class="panel"
        style="padding:16px"
      >
        <div class="form-group">
          <label>Name</label>
          <input type="text" name="name" required style="width:100%" />
        </div>
        <div class="form-group">
          <label>Description</label>
          <textarea name="description" rows={2} style="width:100%" />
        </div>
        <div class="form-group">
          <label>Monthly amount (cents)</label>
          <input
            type="number"
            name="monthly_cents"
            min="0"
            placeholder="500 = $5/mo"
            required
          />
        </div>
        <button type="submit" class="btn btn-primary">
          Add tier
        </button>
      </form>

      <h3 style="margin-top:24px">Recent activity</h3>
      <div class="panel">
        {activity.length === 0 ? (
          <div class="panel-empty">No sponsors yet.</div>
        ) : (
          activity.map((a) => (
            <div class="panel-item" style="justify-content:space-between">
              <div>
                <a href={`/${a.sponsorName}`}>{a.sponsorName}</a>
                <span
                  style="margin-left:8px;font-size:12px;color:var(--text-muted)"
                >
                  {a.kind}
                </span>
              </div>
              <div
                style="font-size:12px;color:var(--text-muted);white-space:nowrap"
              >
                {formatCents(a.amountCents)} ·{" "}
                {new Date(a.createdAt).toLocaleDateString()}
              </div>
            </div>
          ))
        )}
      </div>
    </Layout>
  );
});

sponsors.post("/settings/sponsors/tiers/new", requireAuth, async (c) => {
  const user = c.get("user")!;
  const body = await c.req.parseBody();
  const name = String(body.name || "").trim();
  if (!name) return c.redirect("/settings/sponsors");
  const monthlyCents = Math.max(
    0,
    parseInt(String(body.monthly_cents || "0"), 10)
  );
  await db.insert(sponsorshipTiers).values({
    maintainerId: user.id,
    name,
    description: String(body.description || ""),
    monthlyCents,
  });
  return c.redirect("/settings/sponsors");
});

sponsors.post(
  "/settings/sponsors/tiers/:id/delete",
  requireAuth,
  async (c) => {
    const user = c.get("user")!;
    const id = c.req.param("id");
    await db
      .update(sponsorshipTiers)
      .set({ isActive: false })
      .where(
        and(
          eq(sponsorshipTiers.id, id),
          eq(sponsorshipTiers.maintainerId, user.id)
        )
      );
    return c.redirect("/settings/sponsors");
  }
);

// Handy stat helper for other pages
export async function sponsorshipTotalForUser(
  userId: string
): Promise<number> {
  try {
    const [r] = await db
      .select({ n: sql<number>`coalesce(sum(${sponsorships.amountCents}), 0)::int` })
      .from(sponsorships)
      .where(eq(sponsorships.maintainerId, userId));
    return Number(r?.n || 0);
  } catch {
    return 0;
  }
}

/** Test-only hook. */
export const __internal = { formatCents };

export default sponsors;