Don't send attachments over API

This commit is contained in:
jude 2024-03-28 19:34:30 +00:00
parent 15dbed2f0f
commit 30f011fcd5
3 changed files with 53 additions and 22 deletions

View File

@ -17,7 +17,9 @@ use crate::web::{
consts::MIN_INTERVAL,
guards::transaction::Transaction,
routes::{
dashboard::{create_database_channel, create_reminder, PatchReminder, Reminder},
dashboard::{
create_database_channel, create_reminder, CreateReminder, GetReminder, PatchReminder,
},
JsonResult,
},
Database,
@ -26,7 +28,7 @@ use crate::web::{
#[post("/api/guild/<id>/reminders", data = "<reminder>")]
pub async fn create_guild_reminder(
id: u64,
reminder: Json<Reminder>,
reminder: Json<CreateReminder>,
cookies: &CookieJar<'_>,
ctx: &State<Context>,
mut transaction: Transaction<'_>,
@ -78,9 +80,9 @@ pub async fn get_reminders(
.join(",");
sqlx::query_as_unchecked!(
Reminder,
"SELECT
reminders.attachment,
GetReminder,
"
SELECT
reminders.attachment_name,
reminders.avatar,
channels.channel,
@ -192,7 +194,7 @@ pub async fn edit_reminder(
.await
.map_err(|e| {
warn!("Error updating reminder interval: {:?}", e);
json!({ "reminder": Option::<Reminder>::None, "errors": vec!["Unknown error"] })
json!({ "reminder": Option::<GetReminder>::None, "errors": vec!["Unknown error"] })
})?
.days
.unwrap_or(0),
@ -206,7 +208,7 @@ pub async fn edit_reminder(
.await
.map_err(|e| {
warn!("Error updating reminder interval: {:?}", e);
json!({ "reminder": Option::<Reminder>::None, "errors": vec!["Unknown error"] })
json!({ "reminder": Option::<GetReminder>::None, "errors": vec!["Unknown error"] })
})?
.months
.unwrap_or(0),
@ -220,7 +222,7 @@ pub async fn edit_reminder(
.await
.map_err(|e| {
warn!("Error updating reminder interval: {:?}", e);
json!({ "reminder": Option::<Reminder>::None, "errors": vec!["Unknown error"] })
json!({ "reminder": Option::<GetReminder>::None, "errors": vec!["Unknown error"] })
})?
.seconds
.unwrap_or(0),
@ -249,7 +251,7 @@ pub async fn edit_reminder(
.await
.map_err(|e| {
warn!("Error updating reminder interval: {:?}", e);
json!({ "reminder": Option::<Reminder>::None, "errors": vec!["Unknown error"] })
json!({ "reminder": Option::<GetReminder>::None, "errors": vec!["Unknown error"] })
})?;
}
@ -321,8 +323,9 @@ pub async fn edit_reminder(
}
match sqlx::query_as_unchecked!(
Reminder,
"SELECT reminders.attachment,
GetReminder,
"
SELECT
reminders.attachment_name,
reminders.avatar,
channels.channel,
@ -361,7 +364,7 @@ pub async fn edit_reminder(
Err(e) => {
warn!("Error exiting `edit_reminder': {:?}", e);
Err(json!({"reminder": Option::<Reminder>::None, "errors": vec!["Unknown error"]}))
Err(json!({"reminder": Option::<GetReminder>::None, "errors": vec!["Unknown error"]}))
}
}
}

View File

@ -19,8 +19,7 @@ use crate::web::{
guards::transaction::Transaction,
routes::{
dashboard::{
create_reminder, generate_uid, ImportBody, Reminder, ReminderCsv, ReminderTemplateCsv,
TodoCsv,
create_reminder, CreateReminder, ImportBody, ReminderCsv, ReminderTemplateCsv, TodoCsv,
},
JsonResult,
},
@ -150,7 +149,7 @@ pub(crate) async fn import_reminders(
match channel_id.parse::<u64>() {
Ok(channel_id) => {
let reminder = Reminder {
let reminder = CreateReminder {
attachment: record.attachment,
attachment_name: record.attachment_name,
avatar: record.avatar,
@ -177,7 +176,6 @@ pub(crate) async fn import_reminders(
name: record.name,
restartable: record.restartable,
tts: record.tts,
uid: generate_uid(),
username: record.username,
utc_time: record.utc_time,
};

View File

@ -146,9 +146,39 @@ pub struct EmbedField {
inline: bool,
}
#[derive(Serialize, Deserialize)]
pub struct Reminder {
#[derive(Deserialize)]
pub struct CreateReminder {
attachment: Option<Attachment>,
attachment_name: Option<String>,
avatar: Option<String>,
#[serde(with = "string")]
channel: u64,
content: String,
embed_author: String,
embed_author_url: Option<String>,
embed_color: u32,
embed_description: String,
embed_footer: String,
embed_footer_url: Option<String>,
embed_image_url: Option<String>,
embed_thumbnail_url: Option<String>,
embed_title: String,
embed_fields: Option<Json<Vec<EmbedField>>>,
enabled: bool,
expires: Option<NaiveDateTime>,
interval_seconds: Option<u32>,
interval_days: Option<u32>,
interval_months: Option<u32>,
#[serde(default = "name_default")]
name: String,
restartable: bool,
tts: bool,
username: Option<String>,
utc_time: NaiveDateTime,
}
#[derive(Serialize)]
pub struct GetReminder {
attachment_name: Option<String>,
avatar: Option<String>,
#[serde(with = "string")]
@ -363,7 +393,7 @@ pub(crate) async fn create_reminder(
transaction: &mut Transaction<'_>,
guild_id: GuildId,
user_id: UserId,
reminder: Reminder,
reminder: CreateReminder,
) -> JsonResult {
// check guild in db
match sqlx::query!("SELECT 1 as A FROM guilds WHERE guild = ?", guild_id.get())
@ -545,9 +575,9 @@ pub(crate) async fn create_reminder(
.await
{
Ok(_) => sqlx::query_as_unchecked!(
Reminder,
"SELECT
reminders.attachment,
GetReminder,
"
SELECT
reminders.attachment_name,
reminders.avatar,
channels.channel,