Compare commits
10 Commits
06e1474396
...
jude/react
Author | SHA1 | Date | |
---|---|---|---|
1a03c2471b | |||
a476f43f28 | |||
17192b0f89 | |||
0419863afa | |||
827a982a40 | |||
6e435bfc2e | |||
8ba0f02b98 | |||
d36438c6ce | |||
e0c60e2ce3 | |||
e7160215b0 |
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -1,3 +0,0 @@
|
||||
[submodule "reminder-dashboard"]
|
||||
path = reminder-dashboard
|
||||
url = gitea@gitea.jellypro.xyz:jude/reminder-dashboard
|
861
Cargo.lock
generated
861
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "reminder-rs"
|
||||
version = "1.6.48"
|
||||
version = "1.6.50"
|
||||
authors = ["Jude Southworth <judesouthworth@pm.me>"]
|
||||
edition = "2021"
|
||||
license = "AGPL-3.0 only"
|
||||
|
Submodule reminder-dashboard deleted from 8ba7a39ce5
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "reminder_web"
|
||||
version = "0.1.3"
|
||||
version = "0.1.4"
|
||||
authors = ["jellywx <judesouthworth@pm.me>"]
|
||||
edition = "2018"
|
||||
|
||||
|
@ -33,11 +33,9 @@ impl<'r> FromRequest<'r> for Transaction<'r> {
|
||||
match request.guard::<&State<Pool<Database>>>().await {
|
||||
Outcome::Success(pool) => match pool.begin().await {
|
||||
Ok(transaction) => Outcome::Success(Transaction(transaction)),
|
||||
Err(e) => {
|
||||
Outcome::Failure((Status::InternalServerError, TransactionError::Error(e)))
|
||||
}
|
||||
Err(e) => Outcome::Error((Status::InternalServerError, TransactionError::Error(e))),
|
||||
},
|
||||
Outcome::Failure(e) => Outcome::Failure((e.0, TransactionError::Missing)),
|
||||
Outcome::Error(e) => Outcome::Error((e.0, TransactionError::Missing)),
|
||||
Outcome::Forward(f) => Outcome::Forward(f),
|
||||
}
|
||||
}
|
||||
|
@ -235,6 +235,21 @@ pub async fn edit_reminder(
|
||||
]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
sqlx::query!(
|
||||
"
|
||||
UPDATE reminders
|
||||
SET interval_seconds = NULL, interval_days = NULL, interval_months = NULL
|
||||
WHERE uid = ?
|
||||
",
|
||||
reminder.uid
|
||||
)
|
||||
.execute(transaction.executor())
|
||||
.await
|
||||
.map_err(|e| {
|
||||
warn!("Error updating reminder interval: {:?}", e);
|
||||
json!({ "reminder": Option::<Reminder>::None, "errors": vec!["Unknown error"] })
|
||||
})?;
|
||||
}
|
||||
|
||||
if reminder.channel > 0 {
|
||||
|
@ -8,7 +8,7 @@ use rocket::{
|
||||
response::Redirect,
|
||||
serde::json::json,
|
||||
};
|
||||
use serde::{Deserialize, Deserializer, Serialize};
|
||||
use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
|
||||
use serenity::{
|
||||
client::Context,
|
||||
http::Http,
|
||||
@ -54,12 +54,27 @@ fn interval_default() -> Unset<Option<u32>> {
|
||||
None
|
||||
}
|
||||
|
||||
fn deserialize_optional_field<'de, T, D>(deserializer: D) -> Result<Option<Option<T>>, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
T: Deserialize<'de>,
|
||||
{
|
||||
Ok(Some(Option::deserialize(deserializer)?))
|
||||
#[derive(sqlx::Type)]
|
||||
#[sqlx(transparent)]
|
||||
struct Attachment(Vec<u8>);
|
||||
|
||||
impl<'de> Deserialize<'de> for Attachment {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Attachment, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
let string = String::deserialize(deserializer)?;
|
||||
Ok(Attachment(base64::decode(string).map_err(de::Error::custom)?))
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for Attachment {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.collect_str(&base64::encode(&self.0))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
@ -70,7 +85,7 @@ pub struct ReminderTemplate {
|
||||
guild_id: u32,
|
||||
#[serde(default = "template_name_default")]
|
||||
name: String,
|
||||
attachment: Option<Vec<u8>>,
|
||||
attachment: Option<Attachment>,
|
||||
attachment_name: Option<String>,
|
||||
avatar: Option<String>,
|
||||
content: String,
|
||||
@ -95,7 +110,7 @@ pub struct ReminderTemplate {
|
||||
pub struct ReminderTemplateCsv {
|
||||
#[serde(default = "template_name_default")]
|
||||
name: String,
|
||||
attachment: Option<Vec<u8>>,
|
||||
attachment: Option<Attachment>,
|
||||
attachment_name: Option<String>,
|
||||
avatar: Option<String>,
|
||||
content: String,
|
||||
@ -130,8 +145,7 @@ pub struct EmbedField {
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Reminder {
|
||||
#[serde(with = "base64s")]
|
||||
attachment: Option<Vec<u8>>,
|
||||
attachment: Option<Attachment>,
|
||||
attachment_name: Option<String>,
|
||||
avatar: Option<String>,
|
||||
#[serde(with = "string")]
|
||||
@ -164,8 +178,7 @@ pub struct Reminder {
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct ReminderCsv {
|
||||
#[serde(with = "base64s")]
|
||||
attachment: Option<Vec<u8>>,
|
||||
attachment: Option<Attachment>,
|
||||
attachment_name: Option<String>,
|
||||
avatar: Option<String>,
|
||||
channel: String,
|
||||
@ -198,7 +211,7 @@ pub struct PatchReminder {
|
||||
uid: String,
|
||||
#[serde(default)]
|
||||
#[serde(deserialize_with = "deserialize_optional_field")]
|
||||
attachment: Unset<Option<String>>,
|
||||
attachment: Unset<Option<Attachment>>,
|
||||
#[serde(default)]
|
||||
#[serde(deserialize_with = "deserialize_optional_field")]
|
||||
attachment_name: Unset<Option<String>>,
|
||||
@ -294,6 +307,14 @@ pub fn generate_uid() -> String {
|
||||
.join("")
|
||||
}
|
||||
|
||||
fn deserialize_optional_field<'de, T, D>(deserializer: D) -> Result<Option<Option<T>>, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
T: Deserialize<'de>,
|
||||
{
|
||||
Ok(Some(Option::deserialize(deserializer)?))
|
||||
}
|
||||
|
||||
// https://github.com/serde-rs/json/issues/329#issuecomment-305608405
|
||||
mod string {
|
||||
use std::{fmt::Display, str::FromStr};
|
||||
@ -318,29 +339,6 @@ mod string {
|
||||
}
|
||||
}
|
||||
|
||||
mod base64s {
|
||||
use serde::{de, Deserialize, Deserializer, Serializer};
|
||||
|
||||
pub fn serialize<S>(value: &Option<Vec<u8>>, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
if let Some(opt) = value {
|
||||
serializer.collect_str(&base64::encode(opt))
|
||||
} else {
|
||||
serializer.serialize_none()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn deserialize<'de, D>(deserializer: D) -> Result<Option<Vec<u8>>, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
let string = Option::<String>::deserialize(deserializer)?;
|
||||
Some(string.map(|b| base64::decode(b).map_err(de::Error::custom))).flatten().transpose()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct DeleteReminder {
|
||||
uid: String,
|
||||
|
@ -31,22 +31,20 @@ pub async fn discord_login(
|
||||
|
||||
// store the pkce secret to verify the authorization later
|
||||
cookies.add_private(
|
||||
Cookie::build("verify", pkce_verifier.secret().to_string())
|
||||
Cookie::build(("verify", pkce_verifier.secret().to_string()))
|
||||
.http_only(true)
|
||||
.path("/login")
|
||||
.same_site(SameSite::Lax)
|
||||
.expires(Expiration::Session)
|
||||
.finish(),
|
||||
.expires(Expiration::Session),
|
||||
);
|
||||
|
||||
// store the csrf token to verify no interference
|
||||
cookies.add_private(
|
||||
Cookie::build("csrf", csrf_token.secret().to_string())
|
||||
Cookie::build(("csrf", csrf_token.secret().to_string()))
|
||||
.http_only(true)
|
||||
.path("/login")
|
||||
.same_site(SameSite::Lax)
|
||||
.expires(Expiration::Session)
|
||||
.finish(),
|
||||
.expires(Expiration::Session),
|
||||
);
|
||||
|
||||
Redirect::to(auth_url.to_string())
|
||||
@ -54,9 +52,9 @@ pub async fn discord_login(
|
||||
|
||||
#[get("/discord/logout")]
|
||||
pub async fn discord_logout(cookies: &CookieJar<'_>) -> Redirect {
|
||||
cookies.remove_private(Cookie::named("username"));
|
||||
cookies.remove_private(Cookie::named("userid"));
|
||||
cookies.remove_private(Cookie::named("access_token"));
|
||||
cookies.remove_private(Cookie::from("username"));
|
||||
cookies.remove_private(Cookie::from("userid"));
|
||||
cookies.remove_private(Cookie::from("access_token"));
|
||||
|
||||
Redirect::to(uri!(routes::index))
|
||||
}
|
||||
@ -80,17 +78,16 @@ pub async fn discord_callback(
|
||||
.request_async(async_http_client)
|
||||
.await;
|
||||
|
||||
cookies.remove_private(Cookie::named("verify"));
|
||||
cookies.remove_private(Cookie::named("csrf"));
|
||||
cookies.remove_private(Cookie::from("verify"));
|
||||
cookies.remove_private(Cookie::from("csrf"));
|
||||
|
||||
match token_result {
|
||||
Ok(token) => {
|
||||
cookies.add_private(
|
||||
Cookie::build("access_token", token.access_token().secret().to_string())
|
||||
Cookie::build(("access_token", token.access_token().secret().to_string()))
|
||||
.secure(true)
|
||||
.http_only(true)
|
||||
.path("/dashboard")
|
||||
.finish(),
|
||||
.path("/dashboard"),
|
||||
);
|
||||
|
||||
let request_res = reqwest_client
|
||||
|
Reference in New Issue
Block a user