Can import ZIP

This commit is contained in:
2025-05-05 20:38:46 +02:00
parent f335b9d0c0
commit aac878a245
11 changed files with 193 additions and 17 deletions

View File

@@ -97,3 +97,11 @@ pub async fn delete(id: AccountID) -> anyhow::Result<()> {
Ok(())
}
/// Delete all the accounts of a user
pub async fn delete_all_user(user: UserID) -> anyhow::Result<()> {
for account in get_list_user(user).await? {
delete(account.id()).await?;
}
Ok(())
}

View File

@@ -13,6 +13,8 @@ use mime_guess::Mime;
enum FilesServiceError {
#[error("UnknownMimeType!")]
UnknownMimeType,
#[error("Could not delete all the files of the user: a file is still referenced!")]
DeleteAllUserFileStillReferenced,
}
pub async fn create_file_with_file_name(
@@ -84,11 +86,11 @@ pub async fn get_file_content(file: &File) -> anyhow::Result<Vec<u8>> {
/// Delete the file if it is not referenced anymore in the database. Returns true
/// if the file was actually deleted, false otherwise
pub async fn delete_file_if_unused(id: FileID) -> anyhow::Result<bool> {
pub async fn delete_file_if_unused(id: FileID, skip_age_check: bool) -> anyhow::Result<bool> {
let file = get_file_with_id(id)?;
// Check if the file is old enough
if file.time_create as u64 + constants::MIN_FILE_LIFETIME > time() {
if file.time_create as u64 + constants::MIN_FILE_LIFETIME > time() && !skip_age_check {
return Ok(false);
}
@@ -129,10 +131,21 @@ pub async fn run_garbage_collector() -> anyhow::Result<usize> {
let mut count_deleted = 0;
for file in get_entire_list().await? {
if delete_file_if_unused(file.id()).await? {
if delete_file_if_unused(file.id(), false).await? {
count_deleted += 1;
}
}
Ok(count_deleted)
}
/// Delete all the files of a given user
pub async fn delete_all_user(user_id: UserID) -> anyhow::Result<()> {
for file in get_all_files_user(user_id).await? {
if !delete_file_if_unused(file.id(), true).await? {
return Err(FilesServiceError::DeleteAllUserFileStillReferenced.into());
}
}
Ok(())
}