add: store avatars and banners in uploads

This commit is contained in:
trisua 2025-08-23 15:36:26 -04:00
parent 1e50ace8b2
commit dbed2b2457
36 changed files with 211 additions and 363 deletions

View file

@ -49,4 +49,4 @@ oiseau = { version = "0.1.2", default-features = false, features = [
], optional = true }
paste = { version = "1.0.15", optional = true }
tokio = { version = "1.47.1", features = ["macros", "rt-multi-thread"] }
buckets-core = "1.0.1"
buckets-core = "1.0.4"

View file

@ -11,8 +11,6 @@ use crate::model::{
ACHIEVEMENTS, AppliedConfigType,
},
};
use pathbufd::PathBufD;
use std::fs::{exists, remove_file};
use tetratto_shared::{
hash::{hash_salted, salt},
unix_epoch_timestamp,
@ -618,35 +616,6 @@ impl DataManager {
self.delete_app(app.id, &user).await?;
}
// remove images
let avatar = PathBufD::current().extend(&[
self.0.0.dirs.media.as_str(),
"avatars",
&format!(
"{}.{}",
&(user.id as i64),
user.settings.avatar_mime.replace("image/", "")
),
]);
let banner = PathBufD::current().extend(&[
self.0.0.dirs.media.as_str(),
"banners",
&format!(
"{}.{}",
&(user.id as i64),
user.settings.banner_mime.replace("image/", "")
),
]);
if exists(&avatar).unwrap() {
remove_file(avatar).unwrap();
}
if exists(&banner).unwrap() {
remove_file(banner).unwrap();
}
// delete uploads
for upload in match self.2.get_uploads_by_owner_all(user.id).await {
Ok(x) => x,

View file

@ -18,6 +18,7 @@ impl DataManager {
pub async fn new(config: Config) -> Result<Self> {
let buckets_manager = BucketsManager::new(BucketsConfig {
directory: format!("{}/{}", config.dirs.media, "uploads"),
bucket_defaults: HashMap::new(),
database: config.database.clone(),
})
.await

View file

@ -1657,7 +1657,7 @@ impl DataManager {
let res = query_rows!(
&conn,
&format!(
"SELECT * FROM posts WHERE (owner = {} {query_string}) AND replying_to = 0 AND is_deleted = 0 ORDER BY created DESC LIMIT $1 OFFSET $2",
"SELECT * FROM posts WHERE (owner = {id} OR owner = {} {query_string}) AND replying_to = 0 AND is_deleted = 0 ORDER BY created DESC LIMIT $1 OFFSET $2",
first.receiver
),
&[&(batch as i64), &((page * batch) as i64)],

View file

@ -298,9 +298,6 @@ pub struct UserSettings {
/// The user's status. Shows over connection info.
#[serde(default)]
pub status: String,
/// The mime type of the user's avatar.
#[serde(default = "mime_avif")]
pub avatar_mime: String,
/// The mime type of the user's banner.
#[serde(default = "mime_avif")]
pub banner_mime: String,