v0.1.2 944de91

+server.ts RawHistoryFolder

1import { error } from '@sveltejs/kit';
2import db from '$lib/db/db.server';
3import { users } from '$lib/db/schema';
4import { eq } from 'drizzle-orm';
5import { validateSessionToken, generateSessionToken, createSession } from '$lib/api/session.server';
6import { setSessionTokenCookie } from '$lib/api/session.cookie';
7import { createSafeUser } from '$lib/types/chat';
8import { createLogger } from '$lib/utils/logger.server';
9
10const log = createLogger('status-server');
11
12export async function POST({ request, cookies, locals }) {
13    if (!locals.user) {
14        log.warn('Authentication required');
15        throw error(401, 'Authentication required');
16    }
17
18    const { status } = await request.json();
19    const validStatuses = ['online', 'away', 'busy', 'offline'];
20    if (!validStatuses.includes(status)) {
21        log.warn('Invalid status received', { status });
22        throw error(400, 'Invalid status');
23    }
24
25    const userId = locals.user.id;
26    const maskedUserId = `${userId.slice(0, 4)}...${userId.slice(-4)}`;
27    log.debug('Updating user status', { userId: maskedUserId, status });
28
29    const now = Date.now();
30
31    // Update the user status in the database
32    // Always update lastSeen to support timeout detection
33    const updatedUser = await db.update(users)
34        .set({ 
35            status, 
36            lastSeen: now // Always update lastSeen for proper timeout detection
37        })
38        .where(eq(users.id, userId))
39        .returning()
40        .get();
41    log.debug('Database updated successfully', { userId: maskedUserId, status });
42
43    // Renew session if status is online and session is near expiry
44    if (status === 'online') {
45        const token = cookies.get('session');
46        if (token) {
47            const result = await validateSessionToken(token);
48            if (result.session) {
49                const remaining = result.session.expiresAt - now;
50                const threshold = 15 * 60 * 1000; // 15 minutes in milliseconds
51                if (remaining < threshold) {
52                    const newToken = generateSessionToken();
53                    const newSession = await createSession(newToken, userId);
54                    setSessionTokenCookie({ cookies }, newToken, newSession.expiresAt);
55                    log.info('Session renewed', { 
56                        userId: maskedUserId, 
57                        expiresAt: new Date(newSession.expiresAt).toISOString() 
58                    });
59                }
60            }
61        }
62    }
63
64    return new Response(JSON.stringify({ 
65        success: true,
66        user: createSafeUser(updatedUser)
67    }), { 
68        status: 200, 
69        headers: { 'Content-Type': 'application/json' } 
70    });
71}

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