feat: rebrand Hemmelig to paste.es for cloudhost.es
- Set Spanish as default language with ephemeral/encrypted privacy focus - Translate all user-facing strings and legal pages to Spanish - Replace Norwegian flag with Spanish flag in footer - Remove Hemmelig/terces.cloud links, add cloudhost.es sponsorship - Rewrite PrivacyPage: zero data collection, ephemeral design emphasis - Rewrite TermsPage: Spanish law, RGPD, paste.es/CloudHost.es references - Update PWA manifest, HTML meta tags, package.json branding - Rename webhook headers to X-Paste-Event / X-Paste-Signature - Update API docs title and contact to paste.es / cloudhost.es Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
82
api/routes/setup.ts
Normal file
82
api/routes/setup.ts
Normal file
@@ -0,0 +1,82 @@
|
||||
import { zValidator } from '@hono/zod-validator';
|
||||
import { Hono } from 'hono';
|
||||
import { z } from 'zod';
|
||||
import { auth } from '../auth';
|
||||
import prisma from '../lib/db';
|
||||
import { passwordSchema } from '../validations/password';
|
||||
|
||||
const setupSchema = z.object({
|
||||
email: z.string().email(),
|
||||
password: passwordSchema,
|
||||
username: z.string().min(3).max(32),
|
||||
name: z.string().min(1).max(100),
|
||||
});
|
||||
|
||||
const app = new Hono()
|
||||
// Check if setup is needed (no users exist)
|
||||
.get('/status', async (c) => {
|
||||
try {
|
||||
const userCount = await prisma.user.count();
|
||||
return c.json({
|
||||
needsSetup: userCount === 0,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Failed to check setup status:', error);
|
||||
return c.json({ error: 'Failed to check setup status' }, 500);
|
||||
}
|
||||
})
|
||||
// Complete initial setup - create first admin user
|
||||
.post('/complete', zValidator('json', setupSchema), async (c) => {
|
||||
try {
|
||||
// Check if any users already exist
|
||||
const userCount = await prisma.user.count();
|
||||
if (userCount > 0) {
|
||||
return c.json({ error: 'Setup already completed' }, 403);
|
||||
}
|
||||
|
||||
const { email, password, username, name } = c.req.valid('json');
|
||||
|
||||
// Create the admin user using better-auth
|
||||
const result = await auth.api.signUpEmail({
|
||||
body: {
|
||||
email,
|
||||
password,
|
||||
name,
|
||||
username,
|
||||
},
|
||||
});
|
||||
|
||||
if (!result.user) {
|
||||
return c.json({ error: 'Failed to create admin user' }, 500);
|
||||
}
|
||||
|
||||
// Update user to be admin
|
||||
await prisma.user.update({
|
||||
where: { id: result.user.id },
|
||||
data: { role: 'admin' },
|
||||
});
|
||||
|
||||
// Create initial instance settings if not exists
|
||||
const existingSettings = await prisma.instanceSettings.findFirst();
|
||||
if (!existingSettings) {
|
||||
await prisma.instanceSettings.create({
|
||||
data: {},
|
||||
});
|
||||
}
|
||||
|
||||
return c.json({
|
||||
success: true,
|
||||
message: 'Setup completed successfully',
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Failed to complete setup:', error);
|
||||
return c.json(
|
||||
{
|
||||
error: 'Failed to complete setup',
|
||||
},
|
||||
500
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
export default app;
|
||||
Reference in New Issue
Block a user