fix(prns): url encode unicode
This commit is contained in:
parent
ccd546759b
commit
cd3e4ef6c5
|
@ -1003,12 +1003,13 @@ version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"dotenvy",
|
"dotenvy",
|
||||||
"log",
|
"log",
|
||||||
"pronouns",
|
"pronounslib",
|
||||||
"rocket",
|
"rocket",
|
||||||
"simple_logger",
|
"simple_logger",
|
||||||
"sqlx",
|
"sqlx",
|
||||||
"time",
|
"time",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
"urlencoding",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1034,7 +1035,7 @@ dependencies = [
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pronouns"
|
name = "pronounslib"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
|
@ -1971,6 +1972,12 @@ dependencies = [
|
||||||
"percent-encoding",
|
"percent-encoding",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "urlencoding"
|
||||||
|
version = "2.1.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "valuable"
|
name = "valuable"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
[workspace]
|
[workspace]
|
||||||
members = [
|
members = [
|
||||||
"pronouns",
|
"pronounslib",
|
||||||
"prns",
|
"prns",
|
||||||
]
|
]
|
||||||
|
|
|
@ -6,7 +6,7 @@ edition = "2021"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
pronouns = { path = "../pronouns" }
|
pronounslib = { path = "../pronounslib" }
|
||||||
time = { version = "0.3.23", features = ["formatting", "serde"] }
|
time = { version = "0.3.23", features = ["formatting", "serde"] }
|
||||||
sqlx = { version = "0.6.3", features = ["runtime-tokio-rustls", "postgres", "json"]}
|
sqlx = { version = "0.6.3", features = ["runtime-tokio-rustls", "postgres", "json"]}
|
||||||
rocket = "0.5.0-rc.3"
|
rocket = "0.5.0-rc.3"
|
||||||
|
@ -14,3 +14,4 @@ tokio = { version = "1.27.0", features = ["full"] }
|
||||||
dotenvy = "0.15.7"
|
dotenvy = "0.15.7"
|
||||||
simple_logger = "4.2.0"
|
simple_logger = "4.2.0"
|
||||||
log = "0.4.19"
|
log = "0.4.19"
|
||||||
|
urlencoding = "2.1.3"
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
pub mod models;
|
pub mod models;
|
||||||
|
|
||||||
|
use crate::models::{Member, User};
|
||||||
use rocket::{response::Redirect, Config, State};
|
use rocket::{response::Redirect, Config, State};
|
||||||
use simple_logger;
|
use simple_logger;
|
||||||
use sqlx::{postgres::PgPoolOptions, Pool, Postgres};
|
use sqlx::{postgres::PgPoolOptions, Pool, Postgres};
|
||||||
use std::{env, path::PathBuf};
|
use std::{env, path::PathBuf};
|
||||||
use crate::models::{User, Member};
|
use urlencoding::encode;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate rocket;
|
extern crate rocket;
|
||||||
|
|
||||||
|
@ -27,7 +28,7 @@ async fn redirect(state: &State<AppState>, path: PathBuf) -> Redirect {
|
||||||
.await
|
.await
|
||||||
.map_or_else(
|
.map_or_else(
|
||||||
|_| Redirect::temporary(state.base_url.clone()),
|
|_| Redirect::temporary(state.base_url.clone()),
|
||||||
|u| Redirect::temporary(format!("{}/@{}", state.base_url, u.username)),
|
|u| Redirect::temporary(format!("{}/@{}", state.base_url, encode(&u.username))),
|
||||||
),
|
),
|
||||||
6 => {
|
6 => {
|
||||||
let member = match sqlx::query_as!(
|
let member = match sqlx::query_as!(
|
||||||
|
@ -54,7 +55,7 @@ async fn redirect(state: &State<AppState>, path: PathBuf) -> Redirect {
|
||||||
|u| {
|
|u| {
|
||||||
Redirect::temporary(format!(
|
Redirect::temporary(format!(
|
||||||
"{}/@{}/{}",
|
"{}/@{}/{}",
|
||||||
state.base_url, u.username, member.name
|
state.base_url, encode(&u.username), encode(&member.name)
|
||||||
))
|
))
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
[package]
|
[package]
|
||||||
name = "pronouns"
|
name = "pronounslib"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
Loading…
Reference in New Issue