Can upload files

This commit is contained in:
2025-04-09 21:12:47 +02:00
parent 84e1c57dc9
commit 61a4ea62c6
24 changed files with 342 additions and 61 deletions

View File

@ -0,0 +1,47 @@
use crate::models::users::UserID;
use crate::schema::*;
use diesel::prelude::*;
#[derive(Debug, Clone, Copy, serde::Serialize, serde::Deserialize, PartialEq, Eq)]
pub struct FileID(pub i32);
#[derive(Queryable, Debug, serde::Serialize)]
pub struct File {
id: i32,
pub time_create: i64,
pub mime_type: String,
pub sha512: String,
pub file_size: i32,
pub file_name: String,
user_id: i32,
}
impl File {
pub fn id(&self) -> FileID {
FileID(self.id)
}
pub fn file_path(&self) -> String {
format!("blob/{}/{}", self.user_id, self.sha512)
}
pub fn user_id(&self) -> UserID {
UserID(self.id)
}
}
#[derive(Insertable)]
#[diesel(table_name = files)]
pub struct NewFile<'a> {
pub time_create: i64,
pub mime_type: &'a str,
pub sha512: &'a str,
pub file_size: i32,
pub file_name: &'a str,
pub user_id: i32,
}
impl NewFile<'_> {
pub fn file_path(&self) -> String {
format!("blob/{}/{}", self.user_id, self.sha512)
}
}

View File

@ -1,3 +1,4 @@
pub mod accounts;
pub mod files;
pub mod tokens;
pub mod users;

View File

@ -32,7 +32,7 @@ pub struct Token {
pub right_account: bool,
pub right_movement: bool,
pub right_inbox: bool,
pub right_attachment: bool,
pub right_file: bool,
pub right_auth: bool,
}
@ -76,6 +76,6 @@ pub struct NewToken<'a> {
pub right_account: bool,
pub right_movement: bool,
pub right_inbox: bool,
pub right_attachment: bool,
pub right_file: bool,
pub right_auth: bool,
}