mirror of
https://github.com/LogicLabs-OU/OpenArchiver.git
synced 2026-04-06 00:31:57 +02:00
43 lines
1.4 KiB
TypeScript
43 lines
1.4 KiB
TypeScript
import type { Request, Response } from 'express';
|
|
import { SettingsService } from '../../services/SettingsService';
|
|
import { config } from '../../config';
|
|
import { UserService } from '../../services/UserService';
|
|
|
|
const settingsService = new SettingsService();
|
|
const userService = new UserService();
|
|
|
|
export const getSystemSettings = async (req: Request, res: Response) => {
|
|
try {
|
|
const settings = await settingsService.getSystemSettings();
|
|
res.status(200).json(settings);
|
|
} catch (error) {
|
|
// A more specific error could be logged here
|
|
res.status(500).json({ message: req.t('settings.failedToRetrieve') });
|
|
}
|
|
};
|
|
|
|
export const updateSystemSettings = async (req: Request, res: Response) => {
|
|
try {
|
|
// Basic validation can be performed here if necessary
|
|
if (config.app.isDemo) {
|
|
return res.status(403).json({ message: req.t('errors.demoMode') });
|
|
}
|
|
if (!req.user || !req.user.sub) {
|
|
return res.status(401).json({ message: 'Unauthorized' });
|
|
}
|
|
const actor = await userService.findById(req.user.sub);
|
|
if (!actor) {
|
|
return res.status(401).json({ message: 'Unauthorized' });
|
|
}
|
|
const updatedSettings = await settingsService.updateSystemSettings(
|
|
req.body,
|
|
actor,
|
|
req.ip || 'unknown'
|
|
);
|
|
res.status(200).json(updatedSettings);
|
|
} catch (error) {
|
|
// A more specific error could be logged here
|
|
res.status(500).json({ message: req.t('settings.failedToUpdate') });
|
|
}
|
|
};
|