mirror of
https://github.com/scottlamb/moonfire-nvr.git
synced 2025-12-03 14:31:25 -05:00
make json api more idiomatic
* camelCase * lose the "days":null in the overall cameras dict
This commit is contained in:
@@ -43,6 +43,7 @@ pub struct ListCameras<'a> {
|
||||
/// JSON serialization wrapper for a single camera when processing `/cameras/` and
|
||||
/// `/cameras/<uuid>/`. See `design/api.md` for details.
|
||||
#[derive(Debug, Serialize)]
|
||||
#[serde(rename_all="camelCase")]
|
||||
pub struct Camera<'a> {
|
||||
pub uuid: Uuid,
|
||||
pub short_name: &'a str,
|
||||
@@ -53,6 +54,7 @@ pub struct Camera<'a> {
|
||||
pub total_duration_90k: i64,
|
||||
pub total_sample_file_bytes: i64,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[serde(serialize_with = "Camera::serialize_days")]
|
||||
pub days: Option<&'a BTreeMap<db::CameraDayKey, db::CameraDayValue>>,
|
||||
}
|
||||
@@ -94,6 +96,7 @@ impl<'a> Camera<'a> {
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
#[serde(rename_all="camelCase")]
|
||||
struct CameraDayValue {
|
||||
pub start_time_90k: i64,
|
||||
pub end_time_90k: i64,
|
||||
@@ -120,6 +123,7 @@ pub struct ListRecordings {
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
#[serde(rename_all="camelCase")]
|
||||
pub struct Recording {
|
||||
pub start_time_90k: i64,
|
||||
pub end_time_90k: i64,
|
||||
|
||||
10
src/web.rs
10
src/web.rs
@@ -326,8 +326,8 @@ impl Service {
|
||||
for (key, value) in form_urlencoded::parse(q.as_bytes()) {
|
||||
let (key, value) = (key.borrow(), value.borrow());
|
||||
match key {
|
||||
"start_time" => time.start = recording::Time::parse(value)?,
|
||||
"end_time" => time.end = recording::Time::parse(value)?,
|
||||
"startTime" => time.start = recording::Time::parse(value)?,
|
||||
"endTime" => time.end = recording::Time::parse(value)?,
|
||||
"trim" if value == "true" => trim = true,
|
||||
_ => {},
|
||||
}
|
||||
@@ -556,7 +556,7 @@ impl Service {
|
||||
Ok(http_entity::serve(mp4, req))
|
||||
}
|
||||
|
||||
/// Parses optional `start_time_90k` and `end_time_90k` query parameters, defaulting to the
|
||||
/// Parses optional `startTime90k` and `endTime90k` query parameters, defaulting to the
|
||||
/// full range of possible values.
|
||||
fn get_optional_range(query: Option<&str>) -> Result<Range<recording::Time>, Error> {
|
||||
let mut start = i64::min_value();
|
||||
@@ -565,8 +565,8 @@ impl Service {
|
||||
for (key, value) in form_urlencoded::parse(q.as_bytes()) {
|
||||
let (key, value) = (key.borrow(), value.borrow());
|
||||
match key {
|
||||
"start_time_90k" => start = i64::from_str(value)?,
|
||||
"end_time_90k" => end = i64::from_str(value)?,
|
||||
"startTime90k" => start = i64::from_str(value)?,
|
||||
"endTime90k" => end = i64::from_str(value)?,
|
||||
_ => {},
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user