diff --git a/src/helpers/posts_helper.rs b/src/helpers/posts_helper.rs index 7b5214e..b01d08c 100644 --- a/src/helpers/posts_helper.rs +++ b/src/helpers/posts_helper.rs @@ -11,9 +11,10 @@ use crate::data::group_member::GroupMembershipLevel; use crate::data::post::{Post, PostAccessLevel, PostFile, PostKind, PostPageKind, PostVisibilityLevel, PostWebLink}; use crate::data::post::PostKind::{POST_KIND_COUNTDOWN, POST_KIND_IMAGE, POST_KIND_MOVIE, POST_KIND_PDF, POST_KIND_SURVEY, POST_KIND_WEBLINK, POST_KIND_YOUTUBE}; use crate::data::user::UserID; -use crate::helpers::{database, friends_helper, groups_helper, likes_helper, user_helper, comments_helper}; +use crate::helpers::{comments_helper, database, friends_helper, groups_helper, likes_helper, user_helper}; use crate::helpers::likes_helper::LikeType; use crate::utils::date_utils::{mysql_date, time}; +use crate::utils::user_data_utils::user_data_path; impl PostVisibilityLevel { pub fn to_db(&self) -> u32 { @@ -410,6 +411,20 @@ pub fn delete(p: &Post) -> ResultBoxError { // Delete all the comments associated to the post comments_helper::delete_all(p.id)?; + // Delete associated file / resource (if any) + match &p.kind { + + // Image / PDF + PostKind::POST_KIND_IMAGE(file) | PostKind::POST_KIND_PDF(file) => { + let path = user_data_path(file.path.as_ref()); + if path.exists() { + std::fs::remove_file(path)?; + } + } + + _ => { /* Nothing to be done */ } + } + Ok(()) }