Pre-launch — Gluecron is in final validation. Public signups and git hosting for non-owner users open after launch review.
CodeIssuesPull RequestsActionsSecurityInsightsSettings
✨ AI
More
Blame · Line-by-line history

web.tsx

Each line is annotated with the commit that last touched it. Click any SHA to jump to that commit and see the surrounding change.

web.tsxBlame914 lines · 1 contributor
fc1817aClaude1/**
2 * Web UI routes — browse repositories, code, commits, diffs.
06d5ffeClaude3 * Now auth-aware with user profiles, repo creation, stars, and syntax highlighting.
fc1817aClaude4 */
5
6import { Hono } from "hono";
79136bbClaude7import { html } from "hono/html";
06d5ffeClaude8import { eq, and, desc } from "drizzle-orm";
9import { db } from "../db";
10import { users, repositories, stars } from "../db/schema";
fc1817aClaude11import { Layout } from "../views/layout";
12import {
13 RepoHeader,
14 RepoNav,
15 Breadcrumb,
16 FileTable,
17 CommitList,
18 DiffView,
06d5ffeClaude19 RepoCard,
20 BranchSwitcher,
21 HighlightedCode,
22 PlainCode,
fc1817aClaude23} from "../views/components";
24import {
25 getTree,
26 getBlob,
27 listCommits,
28 getCommit,
29 getCommitFullMessage,
30 getDiff,
31 getReadme,
32 getDefaultBranch,
33 listBranches,
34 repoExists,
06d5ffeClaude35 initBareRepo,
79136bbClaude36 getBlame,
37 getRawBlob,
38 searchCode,
fc1817aClaude39} from "../git/repository";
79136bbClaude40import { renderMarkdown, markdownCss } from "../lib/markdown";
06d5ffeClaude41import { highlightCode } from "../lib/highlight";
42import { softAuth, requireAuth } from "../middleware/auth";
43import type { AuthEnv } from "../middleware/auth";
fc1817aClaude44
06d5ffeClaude45const web = new Hono<AuthEnv>();
46
47// Soft auth on all web routes — c.get("user") available but may be null
48web.use("*", softAuth);
fc1817aClaude49
50// Home page
06d5ffeClaude51web.get("/", async (c) => {
52 const user = c.get("user");
53
54 if (user) {
55 // Show user's repos
56 const repos = await db
57 .select()
58 .from(repositories)
59 .where(eq(repositories.ownerId, user.id))
60 .orderBy(desc(repositories.updatedAt));
61
62 return c.html(
63 <Layout title="Dashboard" user={user}>
64 <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px">
65 <h2>Your repositories</h2>
66 <a href="/new" class="btn btn-primary">
67 + New repository
68 </a>
69 </div>
70 {repos.length === 0 ? (
71 <div class="empty-state">
72 <h2>No repositories yet</h2>
73 <p>Create your first repository to get started.</p>
74 </div>
75 ) : (
76 <div class="card-grid">
77 {repos.map((repo) => (
78 <RepoCard repo={repo} ownerName={user.username} />
79 ))}
80 </div>
81 )}
82 </Layout>
83 );
84 }
85
fc1817aClaude86 return c.html(
06d5ffeClaude87 <Layout user={null}>
fc1817aClaude88 <div class="empty-state">
89 <h2>gluecron</h2>
90 <p>AI-native code intelligence platform</p>
06d5ffeClaude91 <div style="margin-top: 24px; display: flex; gap: 12px; justify-content: center">
92 <a href="/register" class="btn btn-primary">
93 Get started
94 </a>
95 <a href="/login" class="btn">
96 Sign in
97 </a>
98 </div>
99 <pre style="margin-top: 32px">{`# Quick start
fc1817aClaude100curl -X POST http://localhost:3000/api/setup \\
101 -H 'Content-Type: application/json' \\
102 -d '{"username":"you","email":"you@dev.com","repoName":"hello"}'
103
104git remote add gluecron http://localhost:3000/you/hello.git
105git push gluecron main`}</pre>
106 </div>
107 </Layout>
108 );
109});
110
06d5ffeClaude111// New repository form
112web.get("/new", requireAuth, (c) => {
113 const user = c.get("user")!;
114 const error = c.req.query("error");
115
116 return c.html(
117 <Layout title="New repository" user={user}>
118 <div class="new-repo-form">
119 <h2>Create a new repository</h2>
120 {error && <div class="auth-error">{decodeURIComponent(error)}</div>}
45e31d0Claude121 <form method="post" action="/new">
06d5ffeClaude122 <div class="form-group">
123 <label>Owner</label>
124 <input type="text" value={user.username} disabled class="input-disabled" />
125 </div>
126 <div class="form-group">
127 <label for="name">Repository name</label>
128 <input
129 type="text"
130 id="name"
131 name="name"
132 required
133 pattern="^[a-zA-Z0-9._-]+$"
134 placeholder="my-project"
135 autocomplete="off"
136 />
137 </div>
138 <div class="form-group">
139 <label for="description">Description (optional)</label>
140 <input
141 type="text"
142 id="description"
143 name="description"
144 placeholder="A short description of your repository"
145 />
146 </div>
147 <div class="visibility-options">
148 <label class="visibility-option">
149 <input type="radio" name="visibility" value="public" checked />
150 <div class="vis-label">Public</div>
151 <div class="vis-desc">Anyone can see this repository</div>
152 </label>
153 <label class="visibility-option">
154 <input type="radio" name="visibility" value="private" />
155 <div class="vis-label">Private</div>
156 <div class="vis-desc">Only you can see this repository</div>
157 </label>
158 </div>
159 <button type="submit" class="btn btn-primary">
160 Create repository
161 </button>
162 </form>
163 </div>
164 </Layout>
165 );
166});
167
168web.post("/new", requireAuth, async (c) => {
169 const user = c.get("user")!;
170 const body = await c.req.parseBody();
171 const name = String(body.name || "").trim();
172 const description = String(body.description || "").trim();
173 const isPrivate = body.visibility === "private";
174
175 if (!name) {
176 return c.redirect("/new?error=Repository+name+is+required");
177 }
178
179 if (!/^[a-zA-Z0-9._-]+$/.test(name)) {
180 return c.redirect("/new?error=Invalid+repository+name");
181 }
182
183 if (await repoExists(user.username, name)) {
184 return c.redirect("/new?error=Repository+already+exists");
185 }
186
187 const diskPath = await initBareRepo(user.username, name);
188
189 await db.insert(repositories).values({
190 name,
191 ownerId: user.id,
192 description: description || null,
193 isPrivate,
194 diskPath,
195 });
196
197 return c.redirect(`/${user.username}/${name}`);
198});
199
200// User profile
fc1817aClaude201web.get("/:owner", async (c) => {
06d5ffeClaude202 const { owner: ownerName } = c.req.param();
203 const user = c.get("user");
204
205 // Avoid clashing with fixed routes
206 if (
207 ["login", "register", "logout", "new", "settings", "api"].includes(
208 ownerName
209 )
210 ) {
211 return c.notFound();
212 }
213
214 let ownerUser;
215 try {
216 const [found] = await db
217 .select()
218 .from(users)
219 .where(eq(users.username, ownerName))
220 .limit(1);
221 ownerUser = found;
222 } catch {
223 // DB not available — check if repos exist on disk
224 ownerUser = null;
225 }
226
227 // Even without DB, show repos if they exist on disk
228 let repos: any[] = [];
229 if (ownerUser) {
230 const allRepos = await db
231 .select()
232 .from(repositories)
233 .where(eq(repositories.ownerId, ownerUser.id))
234 .orderBy(desc(repositories.updatedAt));
235
236 // Show public repos to everyone, private only to owner
237 repos =
238 user?.id === ownerUser.id
239 ? allRepos
240 : allRepos.filter((r) => !r.isPrivate);
241 }
242
fc1817aClaude243 return c.html(
06d5ffeClaude244 <Layout title={ownerName} user={user}>
245 <div class="user-profile">
246 <div class="user-avatar">
247 {(ownerUser?.displayName || ownerName)[0].toUpperCase()}
248 </div>
249 <div class="user-info">
250 <h2>{ownerUser?.displayName || ownerName}</h2>
251 <div class="username">@{ownerName}</div>
252 {ownerUser?.bio && <div class="bio">{ownerUser.bio}</div>}
253 </div>
254 </div>
255 <h3 style="margin-bottom: 16px">Repositories</h3>
256 {repos.length === 0 ? (
257 <p style="color: var(--text-muted)">No repositories yet.</p>
258 ) : (
259 <div class="card-grid">
260 {repos.map((repo) => (
261 <RepoCard repo={repo} ownerName={ownerName} />
262 ))}
263 </div>
264 )}
fc1817aClaude265 </Layout>
266 );
267});
268
06d5ffeClaude269// Star/unstar a repo
270web.post("/:owner/:repo/star", requireAuth, async (c) => {
271 const { owner: ownerName, repo: repoName } = c.req.param();
272 const user = c.get("user")!;
273
274 try {
275 const [ownerUser] = await db
276 .select()
277 .from(users)
278 .where(eq(users.username, ownerName))
279 .limit(1);
280 if (!ownerUser) return c.redirect(`/${ownerName}/${repoName}`);
281
282 const [repo] = await db
283 .select()
284 .from(repositories)
285 .where(
286 and(
287 eq(repositories.ownerId, ownerUser.id),
288 eq(repositories.name, repoName)
289 )
290 )
291 .limit(1);
292 if (!repo) return c.redirect(`/${ownerName}/${repoName}`);
293
294 // Toggle star
295 const [existing] = await db
296 .select()
297 .from(stars)
298 .where(
299 and(eq(stars.userId, user.id), eq(stars.repositoryId, repo.id))
300 )
301 .limit(1);
302
303 if (existing) {
304 await db.delete(stars).where(eq(stars.id, existing.id));
305 await db
306 .update(repositories)
307 .set({ starCount: Math.max(0, repo.starCount - 1) })
308 .where(eq(repositories.id, repo.id));
309 } else {
310 await db.insert(stars).values({
311 userId: user.id,
312 repositoryId: repo.id,
313 });
314 await db
315 .update(repositories)
316 .set({ starCount: repo.starCount + 1 })
317 .where(eq(repositories.id, repo.id));
318 }
319 } catch {
320 // DB error — ignore
321 }
322
323 return c.redirect(`/${ownerName}/${repoName}`);
324});
325
fc1817aClaude326// Repository overview — file tree at HEAD
327web.get("/:owner/:repo", async (c) => {
328 const { owner, repo } = c.req.param();
06d5ffeClaude329 const user = c.get("user");
fc1817aClaude330
331 if (!(await repoExists(owner, repo))) {
332 return c.html(
06d5ffeClaude333 <Layout title="Not Found" user={user}>
fc1817aClaude334 <div class="empty-state">
335 <h2>Repository not found</h2>
336 <p>
337 {owner}/{repo} does not exist.
338 </p>
339 </div>
340 </Layout>,
341 404
342 );
343 }
344
345 const defaultBranch = (await getDefaultBranch(owner, repo)) || "main";
06d5ffeClaude346 const branches = await listBranches(owner, repo);
fc1817aClaude347 const tree = await getTree(owner, repo, defaultBranch);
348
06d5ffeClaude349 // Get star info if user logged in
350 let starCount = 0;
351 let starred = false;
352 try {
353 const [ownerUser] = await db
354 .select()
355 .from(users)
356 .where(eq(users.username, owner))
357 .limit(1);
358 if (ownerUser) {
359 const [repoRow] = await db
360 .select()
361 .from(repositories)
362 .where(
363 and(
364 eq(repositories.ownerId, ownerUser.id),
365 eq(repositories.name, repo)
366 )
367 )
368 .limit(1);
369 if (repoRow) {
370 starCount = repoRow.starCount;
371 if (user) {
372 const [star] = await db
373 .select()
374 .from(stars)
375 .where(
376 and(
377 eq(stars.userId, user.id),
378 eq(stars.repositoryId, repoRow.id)
379 )
380 )
381 .limit(1);
382 starred = !!star;
383 }
384 }
385 }
386 } catch {
387 // DB not available
388 }
389
fc1817aClaude390 if (tree.length === 0) {
391 return c.html(
06d5ffeClaude392 <Layout title={`${owner}/${repo}`} user={user}>
393 <RepoHeader
394 owner={owner}
395 repo={repo}
396 starCount={starCount}
397 starred={starred}
398 currentUser={user?.username}
399 />
fc1817aClaude400 <RepoNav owner={owner} repo={repo} active="code" />
401 <div class="empty-state">
402 <h2>Empty repository</h2>
403 <p>Get started by pushing code:</p>
404 <pre>{`git remote add gluecron http://localhost:3000/${owner}/${repo}.git
405git push -u gluecron main`}</pre>
406 </div>
407 </Layout>
408 );
409 }
410
411 const readme = await getReadme(owner, repo, defaultBranch);
412
413 return c.html(
06d5ffeClaude414 <Layout title={`${owner}/${repo}`} user={user}>
415 <RepoHeader
416 owner={owner}
417 repo={repo}
418 starCount={starCount}
419 starred={starred}
420 currentUser={user?.username}
421 />
fc1817aClaude422 <RepoNav owner={owner} repo={repo} active="code" />
06d5ffeClaude423 <BranchSwitcher
424 owner={owner}
425 repo={repo}
426 currentRef={defaultBranch}
427 branches={branches}
428 pathType="tree"
429 />
fc1817aClaude430 <FileTable
431 entries={tree}
432 owner={owner}
433 repo={repo}
434 ref={defaultBranch}
435 path=""
436 />
79136bbClaude437 {readme && (() => {
438 const readmeHtml = renderMarkdown(readme);
439 return (
440 <div class="blob-view" style="margin-top: 20px">
441 <div class="blob-header">README.md</div>
442 <style>{markdownCss}</style>
443 <div class="markdown-body">
444 {html([readmeHtml] as unknown as TemplateStringsArray)}
445 </div>
fc1817aClaude446 </div>
79136bbClaude447 );
448 })()}
fc1817aClaude449 </Layout>
450 );
451});
452
453// Browse tree at ref/path
454web.get("/:owner/:repo/tree/:ref{.+$}", async (c) => {
455 const { owner, repo } = c.req.param();
06d5ffeClaude456 const user = c.get("user");
fc1817aClaude457 const refAndPath = c.req.param("ref");
458
459 const branches = await listBranches(owner, repo);
460 let ref = "";
461 let treePath = "";
462
463 for (const branch of branches) {
464 if (refAndPath === branch || refAndPath.startsWith(branch + "/")) {
465 ref = branch;
466 treePath = refAndPath.slice(branch.length + 1);
467 break;
468 }
469 }
470
471 if (!ref) {
472 const slashIdx = refAndPath.indexOf("/");
473 if (slashIdx === -1) {
474 ref = refAndPath;
475 } else {
476 ref = refAndPath.slice(0, slashIdx);
477 treePath = refAndPath.slice(slashIdx + 1);
478 }
479 }
480
481 const tree = await getTree(owner, repo, ref, treePath);
482
483 return c.html(
06d5ffeClaude484 <Layout title={`${treePath || "/"} — ${owner}/${repo}`} user={user}>
fc1817aClaude485 <RepoHeader owner={owner} repo={repo} />
486 <RepoNav owner={owner} repo={repo} active="code" />
06d5ffeClaude487 <BranchSwitcher
488 owner={owner}
489 repo={repo}
490 currentRef={ref}
491 branches={branches}
492 pathType="tree"
493 subPath={treePath}
494 />
fc1817aClaude495 <Breadcrumb owner={owner} repo={repo} ref={ref} path={treePath} />
496 <FileTable
497 entries={tree}
498 owner={owner}
499 repo={repo}
500 ref={ref}
501 path={treePath}
502 />
503 </Layout>
504 );
505});
506
06d5ffeClaude507// View file blob with syntax highlighting
fc1817aClaude508web.get("/:owner/:repo/blob/:ref{.+$}", async (c) => {
509 const { owner, repo } = c.req.param();
06d5ffeClaude510 const user = c.get("user");
fc1817aClaude511 const refAndPath = c.req.param("ref");
512
513 const branches = await listBranches(owner, repo);
514 let ref = "";
515 let filePath = "";
516
517 for (const branch of branches) {
518 if (refAndPath.startsWith(branch + "/")) {
519 ref = branch;
520 filePath = refAndPath.slice(branch.length + 1);
521 break;
522 }
523 }
524
525 if (!ref) {
526 const slashIdx = refAndPath.indexOf("/");
527 if (slashIdx === -1) return c.text("Not found", 404);
528 ref = refAndPath.slice(0, slashIdx);
529 filePath = refAndPath.slice(slashIdx + 1);
530 }
531
532 const blob = await getBlob(owner, repo, ref, filePath);
533 if (!blob) {
534 return c.html(
06d5ffeClaude535 <Layout title="Not Found" user={user}>
fc1817aClaude536 <div class="empty-state">
537 <h2>File not found</h2>
538 </div>
539 </Layout>,
540 404
541 );
542 }
543
06d5ffeClaude544 const fileName = filePath.split("/").pop() || filePath;
fc1817aClaude545
546 return c.html(
06d5ffeClaude547 <Layout title={`${filePath} — ${owner}/${repo}`} user={user}>
fc1817aClaude548 <RepoHeader owner={owner} repo={repo} />
549 <RepoNav owner={owner} repo={repo} active="code" />
06d5ffeClaude550 <BranchSwitcher
551 owner={owner}
552 repo={repo}
553 currentRef={ref}
554 branches={branches}
555 pathType="blob"
556 subPath={filePath}
557 />
fc1817aClaude558 <Breadcrumb owner={owner} repo={repo} ref={ref} path={filePath} />
559 <div class="blob-view">
560 <div class="blob-header">
06d5ffeClaude561 <span>{fileName} — {blob.size} bytes</span>
79136bbClaude562 <span style="display: flex; gap: 12px">
563 <a href={`/${owner}/${repo}/raw/${ref}/${filePath}`} style="font-size: 12px">
564 Raw
565 </a>
566 <a href={`/${owner}/${repo}/blame/${ref}/${filePath}`} style="font-size: 12px">
567 Blame
568 </a>
0074234Claude569 {user && (
570 <a href={`/${owner}/${repo}/edit/${ref}/${filePath}`} style="font-size: 12px">
571 Edit
572 </a>
573 )}
79136bbClaude574 </span>
fc1817aClaude575 </div>
576 {blob.isBinary ? (
577 <div style="padding: 16px; color: var(--text-muted)">
578 Binary file not shown.
579 </div>
06d5ffeClaude580 ) : (() => {
581 const { html: highlighted, language } = highlightCode(
582 blob.content,
583 fileName
584 );
585 const lineCount = blob.content.split("\n").length;
586 // Trim trailing newline from count
587 const adjustedCount =
588 blob.content.endsWith("\n") ? lineCount - 1 : lineCount;
589
590 if (language) {
591 return (
592 <HighlightedCode
593 highlightedHtml={highlighted}
594 lineCount={adjustedCount}
595 />
596 );
597 }
598 const lines = blob.content.split("\n");
599 if (lines[lines.length - 1] === "") lines.pop();
600 return <PlainCode lines={lines} />;
601 })()}
fc1817aClaude602 </div>
603 </Layout>
604 );
605});
606
607// Commit log
608web.get("/:owner/:repo/commits/:ref?", async (c) => {
609 const { owner, repo } = c.req.param();
06d5ffeClaude610 const user = c.get("user");
fc1817aClaude611 const ref =
612 c.req.param("ref") || (await getDefaultBranch(owner, repo)) || "main";
06d5ffeClaude613 const branches = await listBranches(owner, repo);
fc1817aClaude614
615 const commits = await listCommits(owner, repo, ref, 50);
616
617 return c.html(
06d5ffeClaude618 <Layout title={`Commits — ${owner}/${repo}`} user={user}>
fc1817aClaude619 <RepoHeader owner={owner} repo={repo} />
620 <RepoNav owner={owner} repo={repo} active="commits" />
06d5ffeClaude621 <BranchSwitcher
622 owner={owner}
623 repo={repo}
624 currentRef={ref}
625 branches={branches}
626 pathType="commits"
627 />
fc1817aClaude628 {commits.length === 0 ? (
629 <div class="empty-state">
630 <p>No commits yet.</p>
631 </div>
632 ) : (
633 <CommitList commits={commits} owner={owner} repo={repo} />
634 )}
635 </Layout>
636 );
637});
638
639// Single commit with diff
640web.get("/:owner/:repo/commit/:sha", async (c) => {
641 const { owner, repo, sha } = c.req.param();
06d5ffeClaude642 const user = c.get("user");
fc1817aClaude643
644 const commit = await getCommit(owner, repo, sha);
645 if (!commit) {
646 return c.html(
06d5ffeClaude647 <Layout title="Not Found" user={user}>
fc1817aClaude648 <div class="empty-state">
649 <h2>Commit not found</h2>
650 </div>
651 </Layout>,
652 404
653 );
654 }
655
656 const fullMessage = await getCommitFullMessage(owner, repo, sha);
657 const { files, raw } = await getDiff(owner, repo, sha);
658
659 return c.html(
06d5ffeClaude660 <Layout title={`${commit.message} — ${owner}/${repo}`} user={user}>
fc1817aClaude661 <RepoHeader owner={owner} repo={repo} />
662 <div
663 style="background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 20px"
664 >
665 <div style="font-size: 18px; font-weight: 600; margin-bottom: 8px">
666 {commit.message}
667 </div>
668 {fullMessage !== commit.message && (
669 <div style="white-space: pre-wrap; color: var(--text-muted); font-size: 14px; margin-bottom: 12px">
670 {fullMessage}
671 </div>
672 )}
673 <div style="font-size: 13px; color: var(--text-muted)">
674 <strong style="color: var(--text)">{commit.author}</strong>{" "}
675 committed on{" "}
676 {new Date(commit.date).toLocaleDateString("en-US", {
677 month: "long",
678 day: "numeric",
679 year: "numeric",
680 })}
681 </div>
682 <div style="margin-top: 8px">
683 <span class="commit-sha">{commit.sha}</span>
684 {commit.parentShas.length > 0 && (
685 <span style="margin-left: 12px; font-size: 13px; color: var(--text-muted)">
686 Parent:{" "}
687 {commit.parentShas.map((p) => (
688 <a
689 href={`/${owner}/${repo}/commit/${p}`}
690 class="commit-sha"
691 style="margin-left: 4px"
692 >
693 {p.slice(0, 7)}
694 </a>
695 ))}
696 </span>
697 )}
698 </div>
699 </div>
700 <DiffView raw={raw} files={files} />
701 </Layout>
702 );
703});
704
79136bbClaude705// Raw file download
706web.get("/:owner/:repo/raw/:ref{.+$}", async (c) => {
707 const { owner, repo } = c.req.param();
708 const refAndPath = c.req.param("ref");
709
710 const branches = await listBranches(owner, repo);
711 let ref = "";
712 let filePath = "";
713
714 for (const branch of branches) {
715 if (refAndPath.startsWith(branch + "/")) {
716 ref = branch;
717 filePath = refAndPath.slice(branch.length + 1);
718 break;
719 }
720 }
721
722 if (!ref) {
723 const slashIdx = refAndPath.indexOf("/");
724 if (slashIdx === -1) return c.text("Not found", 404);
725 ref = refAndPath.slice(0, slashIdx);
726 filePath = refAndPath.slice(slashIdx + 1);
727 }
728
729 const data = await getRawBlob(owner, repo, ref, filePath);
730 if (!data) return c.text("Not found", 404);
731
732 const fileName = filePath.split("/").pop() || "file";
45e31d0Claude733 return new Response(data.buffer as ArrayBuffer, {
79136bbClaude734 headers: {
735 "Content-Type": "application/octet-stream",
736 "Content-Disposition": `attachment; filename="${fileName}"`,
737 "Cache-Control": "no-cache",
738 },
739 });
740});
741
742// Blame view
743web.get("/:owner/:repo/blame/:ref{.+$}", async (c) => {
744 const { owner, repo } = c.req.param();
745 const user = c.get("user");
746 const refAndPath = c.req.param("ref");
747
748 const branches = await listBranches(owner, repo);
749 let ref = "";
750 let filePath = "";
751
752 for (const branch of branches) {
753 if (refAndPath.startsWith(branch + "/")) {
754 ref = branch;
755 filePath = refAndPath.slice(branch.length + 1);
756 break;
757 }
758 }
759
760 if (!ref) {
761 const slashIdx = refAndPath.indexOf("/");
762 if (slashIdx === -1) return c.text("Not found", 404);
763 ref = refAndPath.slice(0, slashIdx);
764 filePath = refAndPath.slice(slashIdx + 1);
765 }
766
767 const blameLines = await getBlame(owner, repo, ref, filePath);
768 if (blameLines.length === 0) {
769 return c.html(
770 <Layout title="Not Found" user={user}>
771 <div class="empty-state">
772 <h2>File not found</h2>
773 </div>
774 </Layout>,
775 404
776 );
777 }
778
779 const fileName = filePath.split("/").pop() || filePath;
780
781 return c.html(
782 <Layout title={`Blame: ${filePath} — ${owner}/${repo}`} user={user}>
783 <RepoHeader owner={owner} repo={repo} />
784 <RepoNav owner={owner} repo={repo} active="code" />
785 <Breadcrumb owner={owner} repo={repo} ref={ref} path={filePath} />
786 <div class="blob-view">
787 <div class="blob-header">
788 <span>{fileName} — blame</span>
789 <a href={`/${owner}/${repo}/blob/${ref}/${filePath}`} style="font-size: 12px">
790 Normal view
791 </a>
792 </div>
793 <div class="blob-code" style="overflow-x: auto">
794 <table style="width: 100%; border-collapse: collapse; font-size: 13px; font-family: var(--font-mono)">
795 <tbody>
796 {blameLines.map((line, i) => {
797 const showInfo =
798 i === 0 || blameLines[i - 1].sha !== line.sha;
799 return (
800 <tr style="border-bottom: 1px solid var(--border)">
801 <td
802 style={`width: 200px; padding: 0 8px; font-size: 11px; color: var(--text-muted); white-space: nowrap; vertical-align: top; ${showInfo ? "border-top: 1px solid var(--border)" : ""}`}
803 >
804 {showInfo && (
805 <>
806 <a
807 href={`/${owner}/${repo}/commit/${line.sha}`}
808 style="color: var(--text-link); font-family: var(--font-mono)"
809 >
810 {line.sha.slice(0, 7)}
811 </a>{" "}
812 <span>{line.author}</span>
813 </>
814 )}
815 </td>
816 <td class="line-num">{line.lineNum}</td>
817 <td class="line-content">{line.content}</td>
818 </tr>
819 );
820 })}
821 </tbody>
822 </table>
823 </div>
824 </div>
825 </Layout>
826 );
827});
828
829// Search
830web.get("/:owner/:repo/search", async (c) => {
831 const { owner, repo } = c.req.param();
832 const user = c.get("user");
833 const q = c.req.query("q") || "";
834
835 if (!(await repoExists(owner, repo))) return c.notFound();
836
837 const defaultBranch = (await getDefaultBranch(owner, repo)) || "main";
838 let results: Array<{ file: string; lineNum: number; line: string }> = [];
839
840 if (q.trim()) {
841 results = await searchCode(owner, repo, defaultBranch, q.trim());
842 }
843
844 return c.html(
845 <Layout title={`Search — ${owner}/${repo}`} user={user}>
846 <RepoHeader owner={owner} repo={repo} />
847 <RepoNav owner={owner} repo={repo} active="code" />
848 <form
45e31d0Claude849 method="get"
79136bbClaude850 action={`/${owner}/${repo}/search`}
851 style="margin-bottom: 20px"
852 >
853 <div style="display: flex; gap: 8px">
854 <input
855 type="text"
856 name="q"
857 value={q}
858 placeholder="Search code..."
859 style="flex: 1; padding: 8px 12px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); font-size: 14px"
860 />
861 <button type="submit" class="btn btn-primary">
862 Search
863 </button>
864 </div>
865 </form>
866 {q && (
867 <p style="font-size: 14px; color: var(--text-muted); margin-bottom: 16px">
868 {results.length} result{results.length !== 1 ? "s" : ""} for{" "}
869 <strong style="color: var(--text)">"{q}"</strong>
870 </p>
871 )}
872 {results.length > 0 && (
873 <div class="search-results">
874 {(() => {
875 // Group by file
876 const grouped: Record<
877 string,
878 Array<{ lineNum: number; line: string }>
879 > = {};
880 for (const r of results) {
881 if (!grouped[r.file]) grouped[r.file] = [];
882 grouped[r.file].push({ lineNum: r.lineNum, line: r.line });
883 }
884 return Object.entries(grouped).map(([file, matches]) => (
885 <div class="diff-file" style="margin-bottom: 12px">
886 <div class="diff-file-header">
887 <a
888 href={`/${owner}/${repo}/blob/${defaultBranch}/${file}`}
889 >
890 {file}
891 </a>
892 </div>
893 <div class="blob-code">
894 <table>
895 <tbody>
896 {matches.map((m) => (
897 <tr>
898 <td class="line-num">{m.lineNum}</td>
899 <td class="line-content">{m.line}</td>
900 </tr>
901 ))}
902 </tbody>
903 </table>
904 </div>
905 </div>
906 ));
907 })()}
908 </div>
909 )}
910 </Layout>
911 );
912});
913
fc1817aClaude914export default web;