mirror of
https://github.com/screentinker/screentinker.git
synced 2026-05-15 07:32:23 -06:00
ScreenTinker - open source digital signage management software. MIT License, all features included, no license gates. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
24 lines
844 B
JavaScript
24 lines
844 B
JavaScript
const express = require('express');
|
|
const router = express.Router();
|
|
const { db } = require('../db/database');
|
|
|
|
// Provision (pair) a device by entering its pairing code
|
|
router.post('/', (req, res) => {
|
|
const { pairing_code } = req.body;
|
|
if (!pairing_code) return res.status(400).json({ error: 'pairing_code required' });
|
|
|
|
const device = db.prepare('SELECT * FROM devices WHERE pairing_code = ?').get(pairing_code);
|
|
if (!device) return res.status(404).json({ error: 'No device found with that pairing code' });
|
|
|
|
// Clear pairing code and set online
|
|
db.prepare(`
|
|
UPDATE devices SET pairing_code = NULL, status = 'online', updated_at = strftime('%s','now')
|
|
WHERE id = ?
|
|
`).run(device.id);
|
|
|
|
const updated = db.prepare('SELECT * FROM devices WHERE id = ?').get(device.id);
|
|
res.json(updated);
|
|
});
|
|
|
|
module.exports = router;
|