|
|
@ -1,10 +1,14 @@
|
|
|
|
|
|
|
|
use std::fs::{File, OpenOptions};
|
|
|
|
|
|
|
|
use std::io::Write;
|
|
|
|
|
|
|
|
use std::path::PathBuf;
|
|
|
|
|
|
|
|
|
|
|
|
use actix_multipart::Multipart;
|
|
|
|
use actix_multipart::Multipart;
|
|
|
|
use actix_web::Error;
|
|
|
|
use actix_web::Error;
|
|
|
|
|
|
|
|
|
|
|
|
use chrono::Utc;
|
|
|
|
use chrono::Utc;
|
|
|
|
use futures_util::StreamExt;
|
|
|
|
use futures_util::StreamExt;
|
|
|
|
use harsh::Harsh;
|
|
|
|
use harsh::Harsh;
|
|
|
|
use serde_json::{Map, Value};
|
|
|
|
use serde_json::{Map, Value, to_string_pretty};
|
|
|
|
|
|
|
|
|
|
|
|
use crate::{client, Client};
|
|
|
|
use crate::{client, Client};
|
|
|
|
|
|
|
|
|
|
|
@ -33,6 +37,18 @@ pub struct WotLog {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl WotLog {
|
|
|
|
impl WotLog {
|
|
|
|
|
|
|
|
fn generate_id() -> String {
|
|
|
|
|
|
|
|
let harsh = Harsh::default();
|
|
|
|
|
|
|
|
let ts = Utc::now();
|
|
|
|
|
|
|
|
harsh.encode(&[ts.timestamp_nanos() as u64])
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn new_id(&mut self) {
|
|
|
|
|
|
|
|
let harsh = Harsh::default();
|
|
|
|
|
|
|
|
let ts = Utc::now();
|
|
|
|
|
|
|
|
self.id = harsh.encode(&[ts.timestamp_nanos() as u64])
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn new() -> Self {
|
|
|
|
pub fn new() -> Self {
|
|
|
|
Self {
|
|
|
|
Self {
|
|
|
|
client: Client::None,
|
|
|
|
client: Client::None,
|
|
|
@ -103,4 +119,18 @@ impl WotLog {
|
|
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// save the json to disk
|
|
|
|
|
|
|
|
pub fn save(self: &mut Self) -> Result<(), Error> {
|
|
|
|
|
|
|
|
let path = PathBuf::from("replays");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if !path.is_dir() {
|
|
|
|
|
|
|
|
std::fs::create_dir(&path)?;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let mut file = OpenOptions::new().write(true).create_new(true).open(&path.join(&self.id))?;
|
|
|
|
|
|
|
|
file.write_all(to_string_pretty(&self.json)?.as_bytes())?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|