Feature: Boton para reiniciar conexion de instancia
All checks were successful
build-and-deploy / build-and-deploy (push) Successful in 51s
All checks were successful
build-and-deploy / build-and-deploy (push) Successful in 51s
This commit is contained in:
33
server/api/instances/[id]/reset.post.ts
Normal file
33
server/api/instances/[id]/reset.post.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* POST /api/instances/[id]/reset
|
||||
* Reset instance connection (disconnect and clear QR)
|
||||
*/
|
||||
import { query } from '../../../utils/database'
|
||||
import { baileysManager } from '../../../services/baileys/manager'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const username = getHeader(event, 'x-authentik-username')
|
||||
if (!username) {
|
||||
throw createError({ statusCode: 401, message: 'Unauthorized' })
|
||||
}
|
||||
|
||||
const id = getRouterParam(event, 'id')
|
||||
if (!id) {
|
||||
throw createError({ statusCode: 400, message: 'Instance ID required' })
|
||||
}
|
||||
|
||||
// Disconnect if connected
|
||||
try {
|
||||
await baileysManager.disconnect(id)
|
||||
} catch (e) {
|
||||
// Ignore if not connected
|
||||
}
|
||||
|
||||
// Reset in database
|
||||
await query(
|
||||
`UPDATE instances SET status = 'disconnected', qr_code = NULL, pairing_code = NULL WHERE id = $1`,
|
||||
[id]
|
||||
)
|
||||
|
||||
return { success: true, message: 'Instance reset successfully' }
|
||||
})
|
||||
Reference in New Issue
Block a user