rust
Elnu 1 year ago
parent 8674adb1a5
commit 136852171e

@ -4,7 +4,7 @@ use std::str::FromStr;
use serde::{Deserialize, Deserializer, Serialize}; use serde::{Deserialize, Deserializer, Serialize};
use serde_yaml::Value; use serde_yaml::Value;
use crate::kyujitai::{Kyujitai, self}; use crate::kyujitai::Kyujitai;
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]
pub struct Challenge { pub struct Challenge {
@ -46,22 +46,16 @@ impl<'de> Deserialize<'de> for ChallengeWord {
)); ));
}; };
let text = map.get("text").map(|value| match value { let text = map.get("text").map(|value| match value {
Value::String(string) => vec![Furigana::new( Value::String(string) => vec![Furigana::new(string.clone(), None)],
string.clone(),
None,
)],
Value::Sequence(sequence) => sequence Value::Sequence(sequence) => sequence
.iter() .iter()
.map(|value| match value { .map(|value| match value {
Value::String(kanji) => Furigana::new( Value::String(kanji) => Furigana::new(kanji.to_owned(), None),
kanji.to_owned(),
None,
),
Value::Mapping(mapping) => { Value::Mapping(mapping) => {
let (kanji, furigana) = mapping.iter().next().unwrap(); let (kanji, furigana) = mapping.iter().next().unwrap();
Furigana::new( Furigana::new(
kanji.as_str().unwrap().to_owned(), kanji.as_str().unwrap().to_owned(),
Some(furigana.as_str().unwrap().to_owned()) Some(furigana.as_str().unwrap().to_owned()),
) )
} }
_ => panic!(), _ => panic!(),
@ -79,7 +73,12 @@ impl<'de> Deserialize<'de> for ChallengeWord {
}), }),
_ => panic!("dictionary must be string!"), _ => panic!("dictionary must be string!"),
}, },
None => text.as_ref().map(|furigana| furigana.iter().map(|segment| segment.kanji.clone()).collect()), None => text.as_ref().map(|furigana| {
furigana
.iter()
.map(|segment| segment.kanji.clone())
.collect()
}),
}; };
let pos: Option<PartOfSpeech> = map let pos: Option<PartOfSpeech> = map
.get("pos") .get("pos")

@ -362,11 +362,11 @@ impl Kyujitai for String {
'outer: for shinjitai in self.chars() { 'outer: for shinjitai in self.chars() {
for (other_shinjitai, kyujitai) in KYUJITAI { for (other_shinjitai, kyujitai) in KYUJITAI {
if shinjitai == *other_shinjitai { if shinjitai == *other_shinjitai {
output.push(kyujitai.clone()); output.push(*kyujitai);
continue 'outer; continue 'outer;
} }
} }
output.push(shinjitai.clone()); output.push(shinjitai);
} }
output output
} }
@ -376,11 +376,11 @@ impl Kyujitai for String {
'outer: for kyujitai in self.chars() { 'outer: for kyujitai in self.chars() {
for (shinjitai, other_kyujitai) in KYUJITAI { for (shinjitai, other_kyujitai) in KYUJITAI {
if kyujitai == *other_kyujitai { if kyujitai == *other_kyujitai {
output.push(shinjitai.clone()); output.push(*shinjitai);
continue 'outer; continue 'outer;
} }
} }
output.push(kyujitai.clone()); output.push(kyujitai);
} }
output output
} }

@ -2,17 +2,17 @@
extern crate rocket; extern crate rocket;
use core::panic; use core::panic;
use rocket::fs::{relative, FileServer};
use rocket::http::{Cookie, CookieJar};
use rocket::request::{FlashMessage, FromRequest};
use rocket::response::{Flash, Redirect};
use rocket::{request, Request};
use rocket_dyn_templates::{context, Template};
use sass_rocket_fairing::SassFairing;
use std::collections::HashMap; use std::collections::HashMap;
use std::convert::Infallible; use std::convert::Infallible;
use std::env; use std::env;
use rocket::fs::{FileServer, relative};
use rocket::{Request, request};
use rocket::http::{Cookie, CookieJar};
use rocket::request::{FromRequest, FlashMessage};
use rocket::response::{Redirect, Flash};
use rocket_dyn_templates::{context, Template};
use std::fs; use std::fs;
use sass_rocket_fairing::SassFairing;
mod challenge; mod challenge;
use challenge::Challenge; use challenge::Challenge;
@ -108,10 +108,13 @@ fn logout(cookies: &CookieJar<'_>, referer: Referer) -> Redirect {
params.insert("token", token); params.insert("token", token);
params params
}; };
match client.post("https://discord.com/api/oauth2/token/revoke") match client
.post("https://discord.com/api/oauth2/token/revoke")
.header("Content-Type", "application/x-www-form-urlencoded") .header("Content-Type", "application/x-www-form-urlencoded")
.form(&params) .form(&params)
.send().await { .send()
.await
{
Ok(_) => println!("Successfully revoked token"), Ok(_) => println!("Successfully revoked token"),
Err(error) => println!("Failed to revoke token: {:?}", error), Err(error) => println!("Failed to revoke token: {:?}", error),
}; };

Loading…
Cancel
Save