Add implementation to fetch metadata
Signed-off-by: trivernis <trivernis@protonmail.com>main
parent
5295dc1803
commit
697f7463e7
@ -0,0 +1,34 @@
|
||||
use crate::hydrus_serializable::dictionary::HydrusDictionary;
|
||||
use crate::hydrus_serializable::metadata::HydrusMetadata;
|
||||
use crate::hydrus_serializable::wrapper::HydrusSerWrapper;
|
||||
use crate::{Endpoint, FromJson, GetEndpoint};
|
||||
use serde_json::Value;
|
||||
|
||||
pub struct MetadataEndpoint;
|
||||
|
||||
impl Endpoint for MetadataEndpoint {
|
||||
fn path() -> &'static str {
|
||||
"metadata"
|
||||
}
|
||||
}
|
||||
|
||||
impl GetEndpoint for MetadataEndpoint {
|
||||
type Response = MetadataResponse;
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct MetadataResponse(pub HydrusMetadata);
|
||||
|
||||
impl FromJson for MetadataResponse {
|
||||
fn from_json(value: Value) -> crate::Result<Self>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
let mut dict = HydrusDictionary::from_json(value)?;
|
||||
let metadata = dict
|
||||
.take_by_str::<HydrusSerWrapper<HydrusMetadata>>("metadata_slice")?
|
||||
.inner;
|
||||
|
||||
Ok(MetadataResponse(metadata))
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
use crate::hydrus_serializable::HydrusSerializable;
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize)]
|
||||
pub struct HydrusMetadata {
|
||||
pub entries: Vec<MetadataEntry>,
|
||||
pub next_update_due: u64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize)]
|
||||
pub struct MetadataEntry {
|
||||
pub update_index: u64,
|
||||
pub update_hashes: Vec<String>,
|
||||
pub time_begin: u64,
|
||||
pub time_end: u64,
|
||||
}
|
||||
|
||||
impl HydrusSerializable for HydrusMetadata {
|
||||
fn type_id() -> u64 {
|
||||
37
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue