mirror of
https://github.com/chrisbenincasa/tunarr.git
synced 2026-04-18 09:03:35 -04:00
* This is a nightmare * Checkpointing.... getting closer * First cut - packaging the server in a docker container * Remove busted bundles * Minify build * Some common commands for building - we're going to look into proper monorepo solutions soon * Remove dependency on serve-static * Add web serving, full-stack docker target, and Nvidia container support * Remove test action graph for now
93 lines
2.5 KiB
TypeScript
93 lines
2.5 KiB
TypeScript
import { FastifyPluginCallback } from 'fastify';
|
|
import { isError } from 'lodash-es';
|
|
import { HdhrSettings } from '../dao/settings.js';
|
|
import createLogger from '../logger.js';
|
|
import { firstDefined } from '../util.js';
|
|
|
|
const logger = createLogger(import.meta);
|
|
|
|
export const hdhrSettingsRouter: FastifyPluginCallback = (
|
|
fastify,
|
|
_opts,
|
|
done,
|
|
) => {
|
|
fastify.get('/api/hdhr-settings', (req, res) => {
|
|
try {
|
|
const hdhr = req.serverCtx.settings.hdhrSettings();
|
|
return res.send(hdhr);
|
|
} catch (err) {
|
|
logger.error(err);
|
|
return res.status(500).send('error');
|
|
}
|
|
});
|
|
|
|
fastify.put<{ Body: HdhrSettings }>(
|
|
'/api/hdhr-settings',
|
|
async (req, res) => {
|
|
try {
|
|
await req.serverCtx.settings.updateSettings('hdhr', req.body);
|
|
const hdhr = req.serverCtx.settings.hdhrSettings();
|
|
await res.send(hdhr);
|
|
req.serverCtx.eventService.push({
|
|
type: 'settings-update',
|
|
message: 'HDHR configuration updated.',
|
|
module: 'hdhr',
|
|
detail: {
|
|
action: 'update',
|
|
},
|
|
level: 'success',
|
|
});
|
|
} catch (err) {
|
|
logger.error(err);
|
|
await res.status(500).send('error');
|
|
req.serverCtx.eventService.push({
|
|
type: 'settings-update',
|
|
message: 'Error updating HDHR configuration',
|
|
module: 'hdhr',
|
|
detail: {
|
|
action: 'action',
|
|
error: isError(err) ? firstDefined(err, 'message') : 'unknown',
|
|
},
|
|
level: 'error',
|
|
});
|
|
}
|
|
},
|
|
);
|
|
|
|
fastify.post('/api/hdhr-settings', async (req, res) => {
|
|
try {
|
|
await req.serverCtx.settings.updateSettings('hdhr', {
|
|
// _id: req.body._id,
|
|
tunerCount: 1,
|
|
autoDiscoveryEnabled: true,
|
|
});
|
|
const hdhr = req.serverCtx.settings.hdhrSettings();
|
|
await res.send(hdhr);
|
|
req.serverCtx.eventService.push({
|
|
type: 'settings-update',
|
|
message: 'HDHR configuration reset.',
|
|
module: 'hdhr',
|
|
detail: {
|
|
action: 'reset',
|
|
},
|
|
level: 'warning',
|
|
});
|
|
} catch (err) {
|
|
logger.error(err);
|
|
await res.status(500).send('error');
|
|
req.serverCtx.eventService.push({
|
|
type: 'settings-update',
|
|
message: 'Error reseting HDHR configuration',
|
|
module: 'hdhr',
|
|
detail: {
|
|
action: 'reset',
|
|
error: isError(err) ? firstDefined(err, 'message') : 'unknown',
|
|
},
|
|
level: 'error',
|
|
});
|
|
}
|
|
});
|
|
|
|
done();
|
|
};
|