Add server, routes, views, CLI, CSS, and integration tests
- Server factory with Fastify plugins (JWT, cookie, multipart, formbody, static) - Auth middleware: requireAuth preHandler (401 for API, redirect for pages) - Auth API routes: POST /api/v1/auth/login, POST /api/v1/auth/logout - File API routes: GET/POST /api/v1/files, DELETE /api/v1/files/:id - Page routes: /, /login, /logout, /upload, /files, /files/:id/delete, /f/:id, /f/:id/raw - HTML views: layout, login, upload, file-list, file-view, not-found - CLI register-user script - public/style.css dark theme - Test helpers: createTestApp, loginAs, buildMultipart - Integration tests for auth API, file API, and page routes (51 tests passing) - Update CLAUDE.md with red/green TDD and commit instructions Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
33
src/cli/register-user.ts
Normal file
33
src/cli/register-user.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { parseArgs } from 'util';
|
||||
import { loadConfig } from '../config.ts';
|
||||
import { initDb } from '../db/schema.ts';
|
||||
import { createUser, getUserByUsername } from '../db/users.ts';
|
||||
import { hashPassword } from '../services/auth.ts';
|
||||
|
||||
const { values } = parseArgs({
|
||||
args: process.argv.slice(2),
|
||||
options: {
|
||||
username: { type: 'string' },
|
||||
password: { type: 'string' },
|
||||
},
|
||||
});
|
||||
|
||||
const { username, password } = values;
|
||||
|
||||
if (!username || !password) {
|
||||
console.error('Usage: npm run register-user -- --username <user> --password <pass>');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const config = loadConfig();
|
||||
const db = initDb(config.dbPath);
|
||||
|
||||
const existing = getUserByUsername(db, username);
|
||||
if (existing) {
|
||||
console.error(`User "${username}" already exists.`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const passwordHash = await hashPassword(password);
|
||||
createUser(db, { username, passwordHash });
|
||||
console.log(`User "${username}" created successfully.`);
|
||||
Reference in New Issue
Block a user