1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2025-06-20 16:35:17 +00:00

Can create PDF posts

This commit is contained in:
2020-07-08 17:14:55 +02:00
parent 82b1f5e473
commit 24469101bc
7 changed files with 326 additions and 41 deletions

View File

@ -20,6 +20,7 @@ use crate::data::post::{Post, PostAccessLevel};
use crate::data::user::UserID;
use crate::helpers::{account_helper, api_helper, conversations_helper, friends_helper, groups_helper, movies_helper, posts_helper, user_helper, virtual_directory_helper};
use crate::helpers::virtual_directory_helper::VirtualDirType;
use crate::utils::pdf_utils::is_valid_pdf;
use crate::utils::string_utils::{check_url, remove_html_nodes};
use crate::utils::user_data_utils::{generate_new_user_data_file_name, prepare_file_creation, user_data_path};
use crate::utils::virtual_directories_utils::check_virtual_directory;
@ -339,6 +340,28 @@ impl HttpRequestHandler {
Ok(target_file_path.to_string_lossy().to_string())
}
/// Save a pdf included in the request
pub fn save_post_pdf(&mut self, name: &str, folder: &str) -> ResultBoxError<String> {
let file = self.post_file(name)?;
if !is_valid_pdf(&file.buff)? {
self.bad_request(format!("Invalid PDF specified in {} !", name))?;
unreachable!();
}
// Avoid memory warnings
let copied_buff = file.buff.clone();
// Determine pdf file destination
let target_user_data_folder = prepare_file_creation(self.user_id_ref()?, folder)?;
let target_file_path = generate_new_user_data_file_name(target_user_data_folder.as_path(), "pdf")?;
let target_sys_path = user_data_path(target_file_path.as_path());
std::fs::write(target_sys_path, &copied_buff.as_ref())?;
Ok(target_file_path.to_string_lossy().to_string())
}
/// Get an integer included in the POST request
pub fn post_i64(&mut self, name: &str) -> ResultBoxError<i64> {
Ok(self.post_string(name)?.parse::<i64>()?)