Initial commit: Video player with HLS support
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
54
server/api/config.post.ts
Normal file
54
server/api/config.post.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
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'
|
||||
})
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user