merge: fix(prns): url encode unicode

This commit is contained in:
sam 2023-08-12 15:00:38 +02:00
commit 2f34cd20ba
No known key found for this signature in database
GPG Key ID: B4EF20DDE721CAA1
5 changed files with 31 additions and 6 deletions

11
Cargo.lock generated
View File

@ -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"

View File

@ -1,5 +1,5 @@
[workspace] [workspace]
members = [ members = [
"pronouns", "pronounslib",
"prns", "prns",
] ]

View File

@ -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"

View File

@ -1,8 +1,11 @@
use pronouns::models::{member::Member, user::User}; 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 urlencoding::encode;
#[macro_use] #[macro_use]
extern crate rocket; extern crate rocket;
@ -25,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!(
@ -52,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)
)) ))
}, },
) )

14
prns/src/models.rs Normal file
View File

@ -0,0 +1,14 @@
#[derive(Debug)]
pub struct User {
pub id: String,
pub sid: String,
pub username: String,
}
#[derive(Debug)]
pub struct Member {
pub id: String,
pub user_id: String,
pub sid: String,
pub name: String,
}