🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
55 lines
1.4 KiB
TypeScript
55 lines
1.4 KiB
TypeScript
import { defineEventHandler, readBody, createError } from 'h3'
|
|
import { promises as fs } from 'fs'
|
|
import { join } from 'path'
|
|
|
|
const CONFIG_FILE = join(process.cwd(), '.autostart-config')
|
|
const CORRECT_PASSWORD = '431522'
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
try {
|
|
const body = await readBody(event)
|
|
|
|
// Verificar contraseña
|
|
if (body.password !== CORRECT_PASSWORD) {
|
|
throw createError({
|
|
statusCode: 401,
|
|
message: 'Contraseña incorrecta'
|
|
})
|
|
}
|
|
|
|
// Actualizar configuración
|
|
if (body.action === 'toggle-autostart') {
|
|
const currentConfig = await fs.readFile(CONFIG_FILE, 'utf-8').catch(() => 'enabled')
|
|
const newConfig = currentConfig.trim() === 'enabled' ? 'disabled' : 'enabled'
|
|
await fs.writeFile(CONFIG_FILE, newConfig, 'utf-8')
|
|
|
|
return {
|
|
success: true,
|
|
autostart: newConfig === 'enabled'
|
|
}
|
|
}
|
|
|
|
// Obtener estado actual
|
|
if (body.action === 'get-status') {
|
|
const currentConfig = await fs.readFile(CONFIG_FILE, 'utf-8').catch(() => 'enabled')
|
|
return {
|
|
success: true,
|
|
autostart: currentConfig.trim() === 'enabled'
|
|
}
|
|
}
|
|
|
|
throw createError({
|
|
statusCode: 400,
|
|
message: 'Acción inválida'
|
|
})
|
|
} catch (error: any) {
|
|
if (error.statusCode) {
|
|
throw error
|
|
}
|
|
throw createError({
|
|
statusCode: 500,
|
|
message: 'Error al actualizar configuración'
|
|
})
|
|
}
|
|
})
|