Don't send attachments over API
This commit is contained in:
parent
15dbed2f0f
commit
30f011fcd5
@ -17,7 +17,9 @@ use crate::web::{
|
|||||||
consts::MIN_INTERVAL,
|
consts::MIN_INTERVAL,
|
||||||
guards::transaction::Transaction,
|
guards::transaction::Transaction,
|
||||||
routes::{
|
routes::{
|
||||||
dashboard::{create_database_channel, create_reminder, PatchReminder, Reminder},
|
dashboard::{
|
||||||
|
create_database_channel, create_reminder, CreateReminder, GetReminder, PatchReminder,
|
||||||
|
},
|
||||||
JsonResult,
|
JsonResult,
|
||||||
},
|
},
|
||||||
Database,
|
Database,
|
||||||
@ -26,7 +28,7 @@ use crate::web::{
|
|||||||
#[post("/api/guild/<id>/reminders", data = "<reminder>")]
|
#[post("/api/guild/<id>/reminders", data = "<reminder>")]
|
||||||
pub async fn create_guild_reminder(
|
pub async fn create_guild_reminder(
|
||||||
id: u64,
|
id: u64,
|
||||||
reminder: Json<Reminder>,
|
reminder: Json<CreateReminder>,
|
||||||
cookies: &CookieJar<'_>,
|
cookies: &CookieJar<'_>,
|
||||||
ctx: &State<Context>,
|
ctx: &State<Context>,
|
||||||
mut transaction: Transaction<'_>,
|
mut transaction: Transaction<'_>,
|
||||||
@ -78,9 +80,9 @@ pub async fn get_reminders(
|
|||||||
.join(",");
|
.join(",");
|
||||||
|
|
||||||
sqlx::query_as_unchecked!(
|
sqlx::query_as_unchecked!(
|
||||||
Reminder,
|
GetReminder,
|
||||||
"SELECT
|
"
|
||||||
reminders.attachment,
|
SELECT
|
||||||
reminders.attachment_name,
|
reminders.attachment_name,
|
||||||
reminders.avatar,
|
reminders.avatar,
|
||||||
channels.channel,
|
channels.channel,
|
||||||
@ -192,7 +194,7 @@ pub async fn edit_reminder(
|
|||||||
.await
|
.await
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
warn!("Error updating reminder interval: {:?}", 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
|
.days
|
||||||
.unwrap_or(0),
|
.unwrap_or(0),
|
||||||
@ -206,7 +208,7 @@ pub async fn edit_reminder(
|
|||||||
.await
|
.await
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
warn!("Error updating reminder interval: {:?}", 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
|
.months
|
||||||
.unwrap_or(0),
|
.unwrap_or(0),
|
||||||
@ -220,7 +222,7 @@ pub async fn edit_reminder(
|
|||||||
.await
|
.await
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
warn!("Error updating reminder interval: {:?}", 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
|
.seconds
|
||||||
.unwrap_or(0),
|
.unwrap_or(0),
|
||||||
@ -249,7 +251,7 @@ pub async fn edit_reminder(
|
|||||||
.await
|
.await
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
warn!("Error updating reminder interval: {:?}", 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!(
|
match sqlx::query_as_unchecked!(
|
||||||
Reminder,
|
GetReminder,
|
||||||
"SELECT reminders.attachment,
|
"
|
||||||
|
SELECT
|
||||||
reminders.attachment_name,
|
reminders.attachment_name,
|
||||||
reminders.avatar,
|
reminders.avatar,
|
||||||
channels.channel,
|
channels.channel,
|
||||||
@ -361,7 +364,7 @@ pub async fn edit_reminder(
|
|||||||
Err(e) => {
|
Err(e) => {
|
||||||
warn!("Error exiting `edit_reminder': {:?}", 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"]}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,8 +19,7 @@ use crate::web::{
|
|||||||
guards::transaction::Transaction,
|
guards::transaction::Transaction,
|
||||||
routes::{
|
routes::{
|
||||||
dashboard::{
|
dashboard::{
|
||||||
create_reminder, generate_uid, ImportBody, Reminder, ReminderCsv, ReminderTemplateCsv,
|
create_reminder, CreateReminder, ImportBody, ReminderCsv, ReminderTemplateCsv, TodoCsv,
|
||||||
TodoCsv,
|
|
||||||
},
|
},
|
||||||
JsonResult,
|
JsonResult,
|
||||||
},
|
},
|
||||||
@ -150,7 +149,7 @@ pub(crate) async fn import_reminders(
|
|||||||
|
|
||||||
match channel_id.parse::<u64>() {
|
match channel_id.parse::<u64>() {
|
||||||
Ok(channel_id) => {
|
Ok(channel_id) => {
|
||||||
let reminder = Reminder {
|
let reminder = CreateReminder {
|
||||||
attachment: record.attachment,
|
attachment: record.attachment,
|
||||||
attachment_name: record.attachment_name,
|
attachment_name: record.attachment_name,
|
||||||
avatar: record.avatar,
|
avatar: record.avatar,
|
||||||
@ -177,7 +176,6 @@ pub(crate) async fn import_reminders(
|
|||||||
name: record.name,
|
name: record.name,
|
||||||
restartable: record.restartable,
|
restartable: record.restartable,
|
||||||
tts: record.tts,
|
tts: record.tts,
|
||||||
uid: generate_uid(),
|
|
||||||
username: record.username,
|
username: record.username,
|
||||||
utc_time: record.utc_time,
|
utc_time: record.utc_time,
|
||||||
};
|
};
|
||||||
|
@ -146,9 +146,39 @@ pub struct EmbedField {
|
|||||||
inline: bool,
|
inline: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct Reminder {
|
pub struct CreateReminder {
|
||||||
attachment: Option<Attachment>,
|
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>,
|
attachment_name: Option<String>,
|
||||||
avatar: Option<String>,
|
avatar: Option<String>,
|
||||||
#[serde(with = "string")]
|
#[serde(with = "string")]
|
||||||
@ -363,7 +393,7 @@ pub(crate) async fn create_reminder(
|
|||||||
transaction: &mut Transaction<'_>,
|
transaction: &mut Transaction<'_>,
|
||||||
guild_id: GuildId,
|
guild_id: GuildId,
|
||||||
user_id: UserId,
|
user_id: UserId,
|
||||||
reminder: Reminder,
|
reminder: CreateReminder,
|
||||||
) -> JsonResult {
|
) -> JsonResult {
|
||||||
// check guild in db
|
// check guild in db
|
||||||
match sqlx::query!("SELECT 1 as A FROM guilds WHERE guild = ?", guild_id.get())
|
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
|
.await
|
||||||
{
|
{
|
||||||
Ok(_) => sqlx::query_as_unchecked!(
|
Ok(_) => sqlx::query_as_unchecked!(
|
||||||
Reminder,
|
GetReminder,
|
||||||
"SELECT
|
"
|
||||||
reminders.attachment,
|
SELECT
|
||||||
reminders.attachment_name,
|
reminders.attachment_name,
|
||||||
reminders.avatar,
|
reminders.avatar,
|
||||||
channels.channel,
|
channels.channel,
|
||||||
|
Loading…
Reference in New Issue
Block a user