feat: Implement user-specific camera settings storage using a user:cameraId key and track the user who updated them.
This commit is contained in:
17
server.js
17
server.js
@@ -212,11 +212,15 @@ function saveCameraSettings(settings) {
|
||||
fs.writeFileSync(SETTINGS_FILE, JSON.stringify(settings, null, 2));
|
||||
}
|
||||
|
||||
// Get camera settings
|
||||
// Get camera settings
|
||||
app.get('/settings/:cameraId', authenticate, (req, res) => {
|
||||
const { cameraId } = req.params;
|
||||
const user = req.authenticatedUser;
|
||||
const storageKey = `${user}:${cameraId}`;
|
||||
|
||||
const allSettings = loadCameraSettings();
|
||||
const settings = allSettings[cameraId] || {};
|
||||
const settings = allSettings[storageKey] || {};
|
||||
|
||||
res.json({
|
||||
cameraId,
|
||||
@@ -235,6 +239,8 @@ app.get('/settings/:cameraId', authenticate, (req, res) => {
|
||||
// Update camera settings
|
||||
app.put('/settings/:cameraId', authenticate, express.json(), (req, res) => {
|
||||
const { cameraId } = req.params;
|
||||
const user = req.authenticatedUser;
|
||||
const storageKey = `${user}:${cameraId}`;
|
||||
const newSettings = req.body;
|
||||
|
||||
if (!newSettings || typeof newSettings !== 'object') {
|
||||
@@ -242,10 +248,11 @@ app.put('/settings/:cameraId', authenticate, express.json(), (req, res) => {
|
||||
}
|
||||
|
||||
const allSettings = loadCameraSettings();
|
||||
allSettings[cameraId] = {
|
||||
...(allSettings[cameraId] || {}),
|
||||
allSettings[storageKey] = {
|
||||
...(allSettings[storageKey] || {}),
|
||||
...newSettings,
|
||||
updatedAt: new Date().toISOString()
|
||||
updatedAt: new Date().toISOString(),
|
||||
updatedBy: user
|
||||
};
|
||||
|
||||
try {
|
||||
@@ -253,7 +260,7 @@ app.put('/settings/:cameraId', authenticate, express.json(), (req, res) => {
|
||||
res.json({
|
||||
success: true,
|
||||
cameraId,
|
||||
settings: allSettings[cameraId]
|
||||
settings: allSettings[storageKey]
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: 'Failed to save settings', details: error.message });
|
||||
|
||||
Reference in New Issue
Block a user