parent
598e523733
commit
8d50d0fd76
@ -1,61 +0,0 @@
|
||||
use lazy_static::lazy_static;
|
||||
use regex::Regex;
|
||||
|
||||
use crate::Client;
|
||||
|
||||
// this lazy static stuff is so not to recompile the re every time
|
||||
// unwrap is ok here because compiler will catch it if the string is bad
|
||||
lazy_static! {
|
||||
static ref RE: Regex = Regex::new(r"^#!(?P<action>\w+)(?: (?P<text>.*))?$").unwrap();
|
||||
}
|
||||
|
||||
/// type of log action
|
||||
#[derive(Debug)]
|
||||
pub enum Action {
|
||||
/// specify client type
|
||||
Client(Client),
|
||||
|
||||
/// insert a comment in the log
|
||||
Comment(String),
|
||||
|
||||
/// delay replay
|
||||
/// duration is number of seconds or 1 if no seconds specified or if duration can't be parsed
|
||||
Delay(u64),
|
||||
|
||||
/// log line
|
||||
/// duration is amount of time to sleep before printing the line
|
||||
Line(String),
|
||||
|
||||
/// insert a marker
|
||||
Mark,
|
||||
|
||||
/// No match
|
||||
None,
|
||||
}
|
||||
|
||||
impl From<&str> for Action {
|
||||
fn from(line: &str) -> Self {
|
||||
if line.starts_with("#!") {
|
||||
let caps = RE.captures(&line).unwrap();
|
||||
|
||||
let action = if let Some(action) = caps.name("action") { action.as_str() } else { "" };
|
||||
|
||||
let text = if let Some(text) = caps.name("text") {
|
||||
text.as_str().to_owned()
|
||||
} else {
|
||||
String::new()
|
||||
};
|
||||
|
||||
match action {
|
||||
"client" => Self::Client(Client::from(&text)),
|
||||
"delay" => Self::Delay(text.parse::<u64>().unwrap_or(1)),
|
||||
"mark" => Self::Mark,
|
||||
_ => Self::None,
|
||||
}
|
||||
} else if line.starts_with("##") {
|
||||
Self::Comment(line.to_owned())
|
||||
} else {
|
||||
Self::Line(String::new())
|
||||
}
|
||||
}
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
//! Data from log submission form
|
||||
|
||||
use std::default::Default;
|
||||
|
||||
use actix_extract_multipart::{File, FileData};
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::Client;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(default = "FormData::default")]
|
||||
pub struct FormData {
|
||||
/// Client
|
||||
#[serde(rename = "submit_client")]
|
||||
pub client: Option<Client>,
|
||||
|
||||
/// Title
|
||||
#[serde(rename = "submit_title")]
|
||||
pub title: Option<String>,
|
||||
|
||||
/// Player
|
||||
#[serde(rename = "submit_player")]
|
||||
pub player: Option<String>,
|
||||
|
||||
/// Public
|
||||
#[serde(rename = "submit_public")]
|
||||
pub public: Option<String>,
|
||||
|
||||
/// Replay
|
||||
#[serde(rename = "submit_file")]
|
||||
pub replay: Option<File>,
|
||||
}
|
||||
|
||||
impl Default for FormData {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
client: None,
|
||||
title: None,
|
||||
player: None,
|
||||
public: None,
|
||||
replay: None,
|
||||
}
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
// use serde::Serialize;
|
||||
|
||||
// #[derive(Debug, Serialize)]
|
||||
// pub struct Line {
|
||||
// /// delay before printing the line, in milliseconds
|
||||
// pub delay: u64,
|
||||
|
||||
// /// text of the line
|
||||
// pub text: String,
|
||||
// }
|
||||
|
||||
// impl From<&str> for Line {
|
||||
// fn from(s: &str) -> Self {
|
||||
// Self {
|
||||
// delay: 0,
|
||||
// text: s.to_owned(),
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
pub trait Line {
|
||||
/// delay before printing the line, in milliseconds
|
||||
fn delay(&self) -> u64;
|
||||
|
||||
/// text to print
|
||||
fn text(&self) -> &str;
|
||||
}
|
Loading…
Reference in new issue