refactor: capture errors with line numbers

refactor: update file api
This commit is contained in:
Paul Makles
2024-09-29 14:37:08 +01:00
parent 4fd66b2719
commit 3080ec1f5a
22 changed files with 273 additions and 130 deletions

View File

@@ -124,7 +124,7 @@ pub async fn edit(
}
if let Some(icon_id) = data.icon {
partial.icon = Some(File::use_icon(db, &icon_id, id).await?);
partial.icon = Some(File::use_channel_icon(db, &icon_id, id, &user.id).await?);
*icon = partial.icon.clone();
}

View File

@@ -1,6 +1,6 @@
use revolt_database::{
util::{permissions::DatabasePermissionQuery, reference::Reference},
Channel, Database, User, Webhook,
Channel, Database, File, User, Webhook,
};
use revolt_models::v0;
use revolt_permissions::{
@@ -43,10 +43,7 @@ pub async fn create_webhook(
let webhook_id = Ulid::new().to_string();
let avatar = match &data.avatar {
Some(id) => Some(
db.find_and_use_attachment(id, "avatars", "user", &webhook_id)
.await?,
),
Some(id) => Some(File::use_webhook_avatar(db, id, &webhook_id, &user.id).await?),
None => None,
};
@@ -54,6 +51,7 @@ pub async fn create_webhook(
id: webhook_id,
name: data.name,
avatar,
creator_id: user.id,
channel_id: channel.id().to_string(),
permissions: *DEFAULT_WEBHOOK_PERMISSIONS,
token: Some(nanoid::nanoid!(64)),

View File

@@ -55,7 +55,7 @@ pub async fn create_emoji(
};
// Find the relevant attachment
let attachment = File::use_emoji(db, &id, &id).await?;
let attachment = File::use_emoji(db, &id, &id, &user.id).await?;
// Create the emoji object
let emoji = Emoji {

View File

@@ -142,7 +142,7 @@ pub async fn edit(
// 2. Apply new avatar
if let Some(avatar) = avatar {
partial.avatar = Some(File::use_avatar(db, &avatar, &user.id).await?);
partial.avatar = Some(File::use_user_avatar(db, &avatar, &user.id, &user.id).await?);
}
member

View File

@@ -138,13 +138,13 @@ pub async fn edit(
// 3. Apply new icon
if let Some(icon) = icon {
partial.icon = Some(File::use_server_icon(db, &icon, &server.id).await?);
partial.icon = Some(File::use_server_icon(db, &icon, &server.id, &user.id).await?);
server.icon = partial.icon.clone();
}
// 4. Apply new banner
if let Some(banner) = banner {
partial.banner = Some(File::use_banner(db, &banner, &server.id).await?);
partial.banner = Some(File::use_server_banner(db, &banner, &server.id, &user.id).await?);
server.banner = partial.banner.clone();
}

View File

@@ -89,7 +89,7 @@ pub async fn edit(
// 2. Apply new avatar
if let Some(avatar) = data.avatar {
partial.avatar = Some(File::use_avatar(db, &avatar, &user.id).await?);
partial.avatar = Some(File::use_user_avatar(db, &avatar, &user.id, &user.id).await?);
}
// 3. Apply new status
@@ -114,7 +114,8 @@ pub async fn edit(
}
if let Some(background) = profile.background {
new_profile.background = Some(File::use_background(db, &background, &user.id).await?);
new_profile.background =
Some(File::use_background(db, &background, &user.id, &user.id).await?);
}
partial.profile = Some(new_profile);

View File

@@ -1,6 +1,6 @@
use revolt_database::{
util::{permissions::DatabasePermissionQuery, reference::Reference},
Database, PartialWebhook, User,
Database, File, PartialWebhook, User,
};
use revolt_models::v0::{DataEditWebhook, Webhook};
use revolt_permissions::{calculate_channel_permissions, ChannelPermission};
@@ -52,10 +52,7 @@ pub async fn webhook_edit(
};
if let Some(avatar) = avatar {
let file = db
.find_and_use_attachment(&avatar, "avatars", "user", &webhook.id)
.await?;
let file = File::use_webhook_avatar(db, &avatar, &webhook.id, &webhook.creator_id).await?;
partial.avatar = Some(file)
}

View File

@@ -1,5 +1,5 @@
use revolt_database::util::reference::Reference;
use revolt_database::{Database, PartialWebhook};
use revolt_database::{Database, File, PartialWebhook};
use revolt_models::v0::{DataEditWebhook, Webhook};
use revolt_models::validator::Validate;
use revolt_result::{create_error, Result};
@@ -34,7 +34,7 @@ pub async fn webhook_edit_token(
name,
avatar,
permissions,
remove
remove,
} = data;
let mut partial = PartialWebhook {
@@ -44,10 +44,7 @@ pub async fn webhook_edit_token(
};
if let Some(avatar) = avatar {
let file = db
.find_and_use_attachment(&avatar, "avatars", "user", &webhook.id)
.await?;
let file = File::use_webhook_avatar(db, &avatar, &webhook.id, &webhook.creator_id).await?;
partial.avatar = Some(file)
}