mirror of
https://github.com/scottlamb/moonfire-nvr.git
synced 2024-12-26 07:05:56 -05:00
remove the JsonWrapper class
Let's follow the Google Style Guide, in which private variables are simply suffixed with "_". It's a sign, not a cop, but that's fine. I'd rather keep things simple, and code review should suffice for catching uses of a private variable outside the class.
This commit is contained in:
parent
a26c3d1649
commit
3fa48ab0da
@ -30,20 +30,19 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import JsonWrapper from './JsonWrapper';
|
||||
import Stream from './Stream';
|
||||
|
||||
/**
|
||||
* Camera JSON wrapper.
|
||||
*/
|
||||
export default class Camera extends JsonWrapper {
|
||||
export default class Camera {
|
||||
/**
|
||||
* Construct from JSON.
|
||||
*
|
||||
* @param {JSON} cameraJson JSON for single camera.
|
||||
*/
|
||||
constructor(cameraJson) {
|
||||
super(cameraJson);
|
||||
this.json_ = cameraJson;
|
||||
this.streams_ = {};
|
||||
Object.keys(cameraJson.streams).forEach((streamType) => {
|
||||
this.streams_[streamType] = new Stream(cameraJson.streams[streamType]);
|
||||
@ -52,17 +51,17 @@ export default class Camera extends JsonWrapper {
|
||||
|
||||
/** @return {String} */
|
||||
get uuid() {
|
||||
return this.json.uuid;
|
||||
return this.json_.uuid;
|
||||
}
|
||||
|
||||
/** @return {String} */
|
||||
get shortName() {
|
||||
return this.json.shortName;
|
||||
return this.json_.shortName;
|
||||
}
|
||||
|
||||
/** @return {String} */
|
||||
get description() {
|
||||
return this.json.description;
|
||||
return this.json_.description;
|
||||
}
|
||||
|
||||
/** @return {Object.<string, Stream>} */
|
||||
|
@ -1,80 +0,0 @@
|
||||
// vim: set et sw=2 ts=2:
|
||||
//
|
||||
// This file is part of Moonfire NVR, a security camera digital video recorder.
|
||||
// Copyright (C) 2018 Dolf Starreveld <dolf@starreveld.com>
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// In addition, as a special exception, the copyright holders give
|
||||
// permission to link the code of portions of this program with the
|
||||
// OpenSSL library under certain conditions as described in each
|
||||
// individual source file, and distribute linked combinations including
|
||||
// the two.
|
||||
//
|
||||
// You must obey the GNU General Public License in all respects for all
|
||||
// of the code used other than OpenSSL. If you modify file(s) with this
|
||||
// exception, you may extend this exception to your version of the
|
||||
// file(s), but you are not obligated to do so. If you do not wish to do
|
||||
// so, delete this exception statement from your version. If you delete
|
||||
// this exception statement from all source files in the program, then
|
||||
// also delete it here.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* WeakMap that keeps our private data.
|
||||
*
|
||||
* @type {WeakMap}
|
||||
*/
|
||||
let _json = new WeakMap();
|
||||
|
||||
/**
|
||||
* Class to encapsulate recording JSON data.
|
||||
* *
|
||||
* The JSON is kept internally, but in a manner that does not allow direct
|
||||
* access. If access is needed, use the "json()" method. Sub-classes for
|
||||
* specific models shoudl provide the necessary getters instead.
|
||||
*/
|
||||
export default class JsonWrapper {
|
||||
/**
|
||||
* Accept JSON data to be encapsulated
|
||||
*
|
||||
* @param {object} jsonData JSON data
|
||||
*/
|
||||
constructor(jsonData) {
|
||||
_json.set(this, jsonData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get associated JSON object.
|
||||
*
|
||||
* Use of this should be avoided. Use functions to access the
|
||||
* data instead.
|
||||
*
|
||||
* @return {object} The JSON object.
|
||||
*/
|
||||
get json() {
|
||||
return _json.get(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @override
|
||||
* @return {String} String version
|
||||
*/
|
||||
toString() {
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
return this.json.toString();
|
||||
} else {
|
||||
return super.toString();
|
||||
}
|
||||
}
|
||||
}
|
@ -30,45 +30,44 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import JsonWrapper from './JsonWrapper';
|
||||
import Range90k from '../models/Range90k';
|
||||
|
||||
/**
|
||||
* Class to encapsulate recording JSON data.
|
||||
*/
|
||||
export default class Recording extends JsonWrapper {
|
||||
export default class Recording {
|
||||
/**
|
||||
* Accept JSON data to be encapsulated
|
||||
*
|
||||
* @param {object} recordingJson JSON for a recording
|
||||
*/
|
||||
constructor(recordingJson) {
|
||||
super(recordingJson);
|
||||
this.json_ = recordingJson;
|
||||
}
|
||||
|
||||
/** @return {Number} */
|
||||
get startId() {
|
||||
return this.json.startId;
|
||||
return this.json_.startId;
|
||||
}
|
||||
|
||||
/** @return {Number} */
|
||||
get endId() {
|
||||
return this.json.endId;
|
||||
return this.json_.endId;
|
||||
}
|
||||
|
||||
/** @return {Number} */
|
||||
get openId() {
|
||||
return this.json.openId;
|
||||
return this.json_.openId;
|
||||
}
|
||||
|
||||
/** @return {Number} or undefined */
|
||||
get firstUncommitted() {
|
||||
return this.json.firstUncommitted;
|
||||
return this.json_.firstUncommitted;
|
||||
}
|
||||
|
||||
/** @return {Boolean} or undefined */
|
||||
get growing() {
|
||||
return this.json.growing;
|
||||
return this.json_.growing;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -76,7 +75,7 @@ export default class Recording extends JsonWrapper {
|
||||
* @return {Number} Time in units of 90k parts of a second
|
||||
*/
|
||||
get startTime90k() {
|
||||
return this.json.startTime90k;
|
||||
return this.json_.startTime90k;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -84,7 +83,7 @@ export default class Recording extends JsonWrapper {
|
||||
* @return {Number} Time in units of 90k parts of a second
|
||||
*/
|
||||
get endTime90k() {
|
||||
return this.json.endTime90k;
|
||||
return this.json_.endTime90k;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -92,8 +91,7 @@ export default class Recording extends JsonWrapper {
|
||||
* @return {Number} Time in units of 90k parts of a second
|
||||
*/
|
||||
get duration90k() {
|
||||
const data = this.json;
|
||||
return data.endTime90k - data.startTime90k;
|
||||
return this.json_.endTime90k - this.json_.startTime90k;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -121,7 +119,7 @@ export default class Recording extends JsonWrapper {
|
||||
* @return {Number} Total bytes used
|
||||
*/
|
||||
get sampleFileBytes() {
|
||||
return this.json.sampleFileBytes;
|
||||
return this.json_.sampleFileBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -130,7 +128,7 @@ export default class Recording extends JsonWrapper {
|
||||
* @return {Number} Total bytes used
|
||||
*/
|
||||
get frameCount() {
|
||||
return this.json.videoSamples;
|
||||
return this.json_.videoSamples;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -139,7 +137,7 @@ export default class Recording extends JsonWrapper {
|
||||
* @return {String} Hash
|
||||
*/
|
||||
get videoSampleEntryHash() {
|
||||
return this.json.videoSampleEntrySha1;
|
||||
return this.json_.videoSampleEntrySha1;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -148,7 +146,7 @@ export default class Recording extends JsonWrapper {
|
||||
* @return {Number} Width in pixels
|
||||
*/
|
||||
get videoSampleEntryWidth() {
|
||||
return this.json.videoSampleEntryWidth;
|
||||
return this.json_.videoSampleEntryWidth;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -157,6 +155,6 @@ export default class Recording extends JsonWrapper {
|
||||
* @return {Number} Height in pixels
|
||||
*/
|
||||
get videoSampleEntryHeight() {
|
||||
return this.json.videoSampleEntryHeight;
|
||||
return this.json_.videoSampleEntryHeight;
|
||||
}
|
||||
}
|
||||
|
@ -30,20 +30,19 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import JsonWrapper from './JsonWrapper';
|
||||
import Range90k from './Range90k';
|
||||
|
||||
/**
|
||||
* Stream JSON wrapper.
|
||||
*/
|
||||
export default class Stream extends JsonWrapper {
|
||||
export default class Stream {
|
||||
/**
|
||||
* Construct from JSON.
|
||||
*
|
||||
* @param {JSON} streamJson JSON for single stream.
|
||||
*/
|
||||
constructor(streamJson) {
|
||||
super(streamJson);
|
||||
this.json_ = streamJson;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -53,7 +52,7 @@ export default class Stream extends JsonWrapper {
|
||||
* @return {Number} Amount in bytes
|
||||
*/
|
||||
get retainBytes() {
|
||||
return this.json.retainBytes;
|
||||
return this.json_.retainBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -66,9 +65,9 @@ export default class Stream extends JsonWrapper {
|
||||
*/
|
||||
get range90k() {
|
||||
return new Range90k(
|
||||
this.json.minStartTime90k,
|
||||
this.json.maxEndTime90k,
|
||||
this.json.totalDuration90k
|
||||
this.json_.minStartTime90k,
|
||||
this.json_.maxEndTime90k,
|
||||
this.json_.totalDuration90k
|
||||
);
|
||||
}
|
||||
|
||||
@ -79,7 +78,7 @@ export default class Stream extends JsonWrapper {
|
||||
* @return {Number} Amount in bytes
|
||||
*/
|
||||
get totalSampleFileBytes() {
|
||||
return this.json.totalSampleFileBytes;
|
||||
return this.json_.totalSampleFileBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -95,7 +94,7 @@ export default class Stream extends JsonWrapper {
|
||||
*/
|
||||
get days() {
|
||||
return new Map(
|
||||
Object.entries(this.json.days).map(function(t) {
|
||||
Object.entries(this.json_.days).map(function(t) {
|
||||
let [k, v] = t;
|
||||
v = new Range90k(v.startTime90k, v.endTime90k, v.totalDuration90k);
|
||||
return [k, v];
|
||||
|
@ -81,9 +81,6 @@ module.exports = (env, args) => {
|
||||
],
|
||||
},
|
||||
plugins: [
|
||||
new webpack.DefinePlugin({
|
||||
'process.env.NODE_ENV': JSON.stringify(args.mode),
|
||||
}),
|
||||
new webpack.IgnorePlugin(/\.\/locale$/),
|
||||
new HtmlWebpackPlugin({
|
||||
title: nvrSettings.app_title,
|
||||
|
Loading…
Reference in New Issue
Block a user