feat(services/autumn): work towards upload API

This commit is contained in:
Paul Makles
2024-09-01 16:42:28 +01:00
parent ebbbb5e174
commit 24dc96f80f
12 changed files with 453 additions and 97 deletions

View File

@@ -21,8 +21,9 @@ auto_derived_partial!(
/// ID of user who uploaded this file
pub uploaded_id: Option<String>, // these are Option<>s to not break file uploads on legacy Autumn
// TODO: used_for: field
//
/// What the file was used for
pub used_for: Option<FileUsedFor>,
/// Whether this file was deleted
#[serde(skip_serializing_if = "Option::is_none")]
pub deleted: Option<bool>,
@@ -55,6 +56,30 @@ auto_derived_partial!(
"PartialFile"
);
auto_derived!(
/// Type of object file was used for
pub enum FileUsedForType {
// TODO: changing this requires a db migration
message,
serverBanner,
emoji,
userAvatar,
userProfileBackground,
legacyGroupIcon,
channelIcon,
serverIcon,
}
/// Information about what the file was used for
pub struct FileUsedFor {
/// Type of the object
#[serde(rename = "type")]
pub object_type: FileUsedForType,
/// ID of the object
pub id: String,
}
);
impl File {
/// Get the hash entry for this file
pub async fn as_hash(&self, db: &Database) -> Result<FileHash> {

View File

@@ -1,7 +1,7 @@
use revolt_models::v0::*;
use revolt_permissions::{calculate_user_permissions, UserPermission};
use crate::{util::permissions::DatabasePermissionQuery, Database};
use crate::{util::permissions::DatabasePermissionQuery, Database, FileUsedFor};
impl crate::Bot {
pub fn into_public_bot(self, user: crate::User) -> PublicBot {
@@ -422,6 +422,7 @@ impl From<File> for crate::File {
hash: None,
uploaded_at: None,
uploaded_id: None,
used_for: None,
}
}
}