- Migration 043: agent_version in workstations, netup device type - agent-ws: sendCommandAndWait for async commands, save version on hello - workstations route: list-ports, test-device, update, update-all endpoints - agent-release route: GET /api/agents/latest-release reads latest.yml - app.ts: serve /agent-updates/ static files - api.ts: fix camelCase→snake_case for outgoing requests (fixes null:null) - api.ts: new methods testDevice, sendUpdate, updateAll, listPorts - EquipmentPage: version badge, update button, test (zap) button per device - EquipmentPage: COM-port dropdown loaded from agent when online Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
24 lines
1.1 KiB
TypeScript
24 lines
1.1 KiB
TypeScript
import { FastifyPluginAsync } from 'fastify'
|
|
import { readFile } from 'fs/promises'
|
|
import { join } from 'path'
|
|
|
|
const agentRelease: FastifyPluginAsync = async (fastify) => {
|
|
fastify.get('/api/agents/latest-release', { onRequest: [fastify.authenticate] }, async (_req, reply) => {
|
|
const updatesDir = process.env.AGENT_UPDATES_DIR ?? join(process.cwd(), '..', 'agent-updates')
|
|
try {
|
|
const yaml = await readFile(join(updatesDir, 'latest.yml'), 'utf8')
|
|
// Parse version: line like "version: 1.0.6"
|
|
const versionMatch = yaml.match(/^version:\s*(.+)$/m)
|
|
const pathMatch = yaml.match(/^path:\s*(.+)$/m)
|
|
if (!versionMatch) return reply.code(404).send({ error: 'latest.yml not found or invalid' })
|
|
const version = versionMatch[1].trim()
|
|
const fileName = pathMatch?.[1].trim() ?? `HotelSync Agent Setup ${version}.exe`
|
|
return { version, fileName, downloadUrl: `/agent-updates/${encodeURIComponent(fileName)}` }
|
|
} catch {
|
|
return reply.code(404).send({ error: 'No release available' })
|
|
}
|
|
})
|
|
}
|
|
|
|
export default agentRelease
|