mirror of
https://github.com/siteboon/claudecodeui.git
synced 2025-12-09 19:09:45 +00:00
94 lines
2.7 KiB
JavaScript
94 lines
2.7 KiB
JavaScript
import express from 'express';
|
|
import { userDb } from '../database/db.js';
|
|
import { authenticateToken } from '../middleware/auth.js';
|
|
import { exec } from 'child_process';
|
|
import { promisify } from 'util';
|
|
|
|
const execAsync = promisify(exec);
|
|
const router = express.Router();
|
|
|
|
router.get('/git-config', authenticateToken, async (req, res) => {
|
|
try {
|
|
const userId = req.user.id;
|
|
const gitConfig = userDb.getGitConfig(userId);
|
|
|
|
res.json({
|
|
success: true,
|
|
gitName: gitConfig?.git_name || null,
|
|
gitEmail: gitConfig?.git_email || null
|
|
});
|
|
} catch (error) {
|
|
console.error('Error getting git config:', error);
|
|
res.status(500).json({ error: 'Failed to get git configuration' });
|
|
}
|
|
});
|
|
|
|
// Apply git config globally via git config --global
|
|
router.post('/git-config', authenticateToken, async (req, res) => {
|
|
try {
|
|
const userId = req.user.id;
|
|
const { gitName, gitEmail } = req.body;
|
|
|
|
if (!gitName || !gitEmail) {
|
|
return res.status(400).json({ error: 'Git name and email are required' });
|
|
}
|
|
|
|
// Validate email format
|
|
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
if (!emailRegex.test(gitEmail)) {
|
|
return res.status(400).json({ error: 'Invalid email format' });
|
|
}
|
|
|
|
userDb.updateGitConfig(userId, gitName, gitEmail);
|
|
|
|
try {
|
|
await execAsync(`git config --global user.name "${gitName.replace(/"/g, '\\"')}"`);
|
|
await execAsync(`git config --global user.email "${gitEmail.replace(/"/g, '\\"')}"`);
|
|
console.log(`Applied git config globally: ${gitName} <${gitEmail}>`);
|
|
} catch (gitError) {
|
|
console.error('Error applying git config:', gitError);
|
|
}
|
|
|
|
res.json({
|
|
success: true,
|
|
gitName,
|
|
gitEmail
|
|
});
|
|
} catch (error) {
|
|
console.error('Error updating git config:', error);
|
|
res.status(500).json({ error: 'Failed to update git configuration' });
|
|
}
|
|
});
|
|
|
|
router.post('/complete-onboarding', authenticateToken, async (req, res) => {
|
|
try {
|
|
const userId = req.user.id;
|
|
userDb.completeOnboarding(userId);
|
|
|
|
res.json({
|
|
success: true,
|
|
message: 'Onboarding completed successfully'
|
|
});
|
|
} catch (error) {
|
|
console.error('Error completing onboarding:', error);
|
|
res.status(500).json({ error: 'Failed to complete onboarding' });
|
|
}
|
|
});
|
|
|
|
router.get('/onboarding-status', authenticateToken, async (req, res) => {
|
|
try {
|
|
const userId = req.user.id;
|
|
const hasCompleted = userDb.hasCompletedOnboarding(userId);
|
|
|
|
res.json({
|
|
success: true,
|
|
hasCompletedOnboarding: hasCompleted
|
|
});
|
|
} catch (error) {
|
|
console.error('Error checking onboarding status:', error);
|
|
res.status(500).json({ error: 'Failed to check onboarding status' });
|
|
}
|
|
});
|
|
|
|
export default router;
|