-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: janky stuff that is unfinished and probably never will be
- Loading branch information
1 parent
ee7b6c0
commit 204f7d4
Showing
7 changed files
with
183 additions
and
20 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
enum ParseState { | ||
Whitespace { | ||
expecting: bool, | ||
}, | ||
String { | ||
s: String, | ||
}, | ||
QuotedString { | ||
s: String, | ||
quote: char, | ||
prev_char: char, | ||
}, | ||
} | ||
|
||
pub enum ParseString { | ||
Unquoted(String), | ||
Quoted { | ||
s: String, | ||
quote: char, | ||
} | ||
} | ||
|
||
pub fn parse_command(s: &str) -> Option<Vec<ParseString>> { | ||
// TODO: some *probably* unnecessary usages of s.clone() in here :/ | ||
|
||
let mut result = vec![]; | ||
|
||
let mut state = ParseState::Whitespace { | ||
expecting: false, | ||
}; | ||
|
||
for c in s.chars() { | ||
let m_state = &mut state; | ||
match m_state { | ||
ParseState::Whitespace { expecting } => { | ||
if c.is_ascii_whitespace() { | ||
continue; | ||
} else if *expecting { | ||
return None; // fail parsing | ||
} else if c == '"' || c == '\'' { | ||
state = ParseState::QuotedString { s: String::new(), quote: c, prev_char: '\0' }; | ||
} else { | ||
let mut s = String::new(); | ||
s.push(c); | ||
state = ParseState::String { s }; | ||
} | ||
}, | ||
ParseState::String { s } => { | ||
if c.is_ascii_whitespace() { | ||
result.push(ParseString::Unquoted(s.clone())); | ||
state = ParseState::Whitespace { expecting: false }; | ||
} else { | ||
s.push(c); | ||
} | ||
}, | ||
ParseState::QuotedString { s, quote, prev_char } => { | ||
if c == *quote && *prev_char != '\\' { | ||
result.push(ParseString::Quoted { quote: *quote, s: s.clone() }); | ||
state = ParseState::Whitespace { expecting: true }; | ||
} else { | ||
s.push(c); | ||
*prev_char = c; | ||
} | ||
}, | ||
} | ||
} | ||
|
||
Some(result) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use warp::{Filter, Reply}; | ||
use xtra::prelude::*; | ||
|
||
use crate::{Controller, statistics::database::GetLeaderboardV2}; | ||
|
||
use super::{get_statistics_controller, handle_option_result, ApiResult}; | ||
|
||
pub fn build_v2(controller: Address<Controller>) -> warp::filters::BoxedFilter<(impl Reply,)> { | ||
let cors = warp::cors().allow_any_origin(); | ||
|
||
let leaderboards = warp::path("leaderboard") | ||
.and(warp::path::param::<String>()) | ||
.and_then({ | ||
let controller = controller.clone(); | ||
move |id| get_leaderboard(controller.clone(), id) | ||
}) | ||
.with(&cors) | ||
.boxed(); | ||
|
||
leaderboards | ||
} | ||
|
||
async fn get_leaderboard(controller: Address<Controller>, id: String) -> ApiResult { | ||
let statistics = get_statistics_controller(controller).await?; | ||
let res = statistics | ||
.send(GetLeaderboardV2(id)) | ||
.await | ||
.expect("controller disconnected"); | ||
handle_option_result(res) | ||
} |