v0.1.1 88fcae1

hooks.server.ts RawHistoryFolder

1import type { Handle } from "@sveltejs/kit";
2import { validateSessionToken } from "$lib/api/session.server";
3import { setSessionTokenCookie, deleteSessionTokenCookie } from "$lib/api/session.cookie";
4import { initializeDatabase } from "$lib/db/db.server";
5import { handleRateLimit } from "$lib/api/rate-limiter";
6
7// Initialize database when the server starts
8console.debug("Initializing database on server start...");
9initializeDatabase().catch(error => {
10    console.error('Failed to initialize database:', error);
11});
12
13export const handle: Handle = async ({ event, resolve }) => {
14    console.debug("Handling request:", event.url.pathname);
15    
16    // Apply rate limiting for API routes
17    const rateLimitResponse = await handleRateLimit(event);
18    if (rateLimitResponse) {
19        return rateLimitResponse;
20    }
21    
22    // Check if this is a public chat messages request
23    const isPublicChatRequest = 
24        event.url.pathname === '/api/chat/messages' && 
25        event.url.searchParams.get('public') === 'true' &&
26        event.request.method === 'GET';
27    
28    // Check if this is a public room request
29    const isPublicRoomRequest = 
30        event.url.pathname.startsWith('/api/rooms/') && 
31        event.url.searchParams.get('public') === 'true' &&
32        event.request.method === 'GET';
33    
34    // Public routes that don't require authentication
35    const publicRoutes = [
36        "/",
37        "/api/session/login",
38        "/api/session/validate",
39        "/api/register",
40        "/login",
41        "/register"
42    ];
43    
44    // Get session token from cookies
45    const token = event.cookies.get("session") ?? null;
46
47    // Handle public requests separately: always clear session
48    if (isPublicChatRequest || isPublicRoomRequest) {
49        console.debug("Public request accessed:", event.url.pathname);
50        event.locals.user = null;
51        event.locals.session = null; // Public access doesn't require a session
52        return resolve(event);
53    }
54    
55    // Handle public routes: if token exists, validate and propagate
56    if (publicRoutes.includes(event.url.pathname)) {
57        console.debug("Public route accessed:", event.url.pathname);
58        if (token) {
59            const { session, user } = await validateSessionToken(token);
60            if (session !== null) {
61                console.debug("Valid session found on public route for user:", user?.nickname);
62                setSessionTokenCookie(event, token, session.expiresAt);
63                event.locals.session = session;
64                event.locals.user = user;
65            }
66        }
67        return resolve(event);
68    }
69
70    // Protected routes: ensure authentication
71    if (token === null) {
72        console.debug("No session token found");
73        event.locals.user = null;
74        event.locals.session = null;
75        return new Response("Unauthorized", { status: 401 });
76    }
77    
78    const { session, user } = await validateSessionToken(token);
79    if (session !== null) {
80        console.debug("Valid session found for user:", user?.nickname);
81        setSessionTokenCookie(event, token, session.expiresAt);
82        event.locals.session = session;
83        event.locals.user = user;
84        return resolve(event);
85    } else {
86        console.debug("Invalid session token");
87        deleteSessionTokenCookie(event);
88        event.locals.session = null;
89        event.locals.user = null;
90        return new Response("Unauthorized", { status: 401 });
91    }
92}; 

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 3

Tags 8

↑↓ moveenter openesc close