1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2025-01-30 14:03:00 +00:00

Deprecate old movies system

This commit is contained in:
Pierre HUBERT 2021-02-13 11:12:17 +01:00
parent a6c32d763f
commit 3a22c89b87
16 changed files with 9 additions and 207 deletions

View File

@ -11,7 +11,6 @@ use crate::api_data::conversation_message_api::ConversationMessageAPI;
use crate::api_data::entities_constructor::EntitiesConstructor;
use crate::api_data::friend_api::FriendAPI;
use crate::api_data::group_api::GroupApi;
use crate::api_data::movie_api::MovieAPI;
use crate::api_data::post_api::PostAPI;
use crate::api_data::survey_response_api::SurveyResponseAPI;
use crate::api_data::user_info::APIUserInfo;
@ -32,7 +31,6 @@ pub struct AccountExportAPI {
comments: Vec<CommentAPI>,
likes: Vec<UserLikeAPI>,
survey_responses: Vec<SurveyResponseAPI>,
movies: Vec<MovieAPI>,
all_conversation_messages: Vec<ConversationMessageAPI>,
conversations_list: Vec<ConversationAPI>,
conversations_messages: HashMap<u64, Vec<ConversationMessageAPI>>,
@ -51,7 +49,6 @@ impl AccountExportAPI {
comments: CommentAPI::for_list(&export.comments, &curr_user_id.as_option())?,
likes: UserLikeAPI::for_list(&export.likes),
survey_responses: SurveyResponseAPI::for_list(&export.survey_responses),
movies: MovieAPI::for_list(&export.movies),
all_conversation_messages: ConversationMessageAPI::for_list(&export.all_conversation_messages),
conversations_list: ConversationAPI::for_list(&export.conversations),
conversations_messages: export.conversation_messages

View File

@ -31,7 +31,6 @@ pub mod group_member_api;
pub mod friend_api;
pub mod friendship_status_api;
pub mod post_api;
pub mod movie_api;
pub mod survey_choice_api;
pub mod survey_api;
pub mod comment_api;

View File

@ -1,38 +0,0 @@
//! # Movie API information
//!
//! @author Pierre Hubert
use serde::Serialize;
use crate::data::movie::Movie;
use crate::utils::user_data_utils::user_data_url;
#[derive(Serialize)]
#[allow(non_snake_case)]
pub struct MovieAPI {
id: u64,
uri: String,
url: String,
userID: u64,
name: String,
file_type: String,
size: usize,
}
impl MovieAPI {
/// Construct a new instance of movie
pub fn new(m: &Movie) -> MovieAPI {
MovieAPI {
id: m.id,
uri: m.uri.clone(),
url: user_data_url(m.uri.as_str()),
userID: m.user_id.id(),
name: m.name.clone(),
file_type: m.file_type.clone(),
size: m.size,
}
}
pub fn for_list(l: &Vec<Movie>) -> Vec<MovieAPI> {
l.iter().map(Self::new).collect()
}
}

View File

@ -4,12 +4,11 @@
use serde::Serialize;
use crate::api_data::comment_api::CommentAPI;
use crate::api_data::movie_api::MovieAPI;
use crate::api_data::survey_api::SurveyAPI;
use crate::data::error::ResultBoxError;
use crate::data::post::{Post, PostKind};
use crate::data::user::UserID;
use crate::helpers::{comments_helper, likes_helper, movies_helper, posts_helper, survey_helper};
use crate::helpers::{comments_helper, likes_helper, posts_helper, survey_helper};
use crate::helpers::likes_helper::LikeType;
use crate::utils::user_data_utils::user_data_url;
@ -38,10 +37,6 @@ pub struct PostAPI {
link_description: Option<String>,
link_image: Option<String>,
// Movie specific
video_id: Option<u64>,
video_info: Option<MovieAPI>,
// Countdown timer specific
time_end: Option<u64>,
@ -82,10 +77,6 @@ impl PostAPI {
link_description: None,
link_image: None,
// Movie specific
video_id: None,
video_info: None,
// Countdown timer-specific
time_end: None,
@ -120,11 +111,6 @@ impl PostAPI {
post.link_image = link.image.clone();
}
PostKind::POST_KIND_MOVIE(movie_id) => {
post.video_id = Some(*movie_id);
post.video_info = Some(MovieAPI::new(&movies_helper::get_info(*movie_id)?))
}
PostKind::POST_KIND_COUNTDOWN(time_end) => post.time_end = Some(*time_end),
PostKind::POST_KIND_SURVEY =>

View File

@ -16,7 +16,6 @@ pub mod comments_controller;
pub mod likes_controller;
pub mod surveys_controller;
pub mod notifications_controller;
pub mod movies_controller;
pub mod virtual_directory_controller;
pub mod web_app_controller;
pub mod calls_controller;

View File

@ -1,25 +0,0 @@
//! # Movies controller
//!
//! @author Pierre Hubert
use crate::api_data::movie_api::MovieAPI;
use crate::controllers::routes::RequestResult;
use crate::data::base_request_handler::BaseRequestHandler;
use crate::data::http_request_handler::HttpRequestHandler;
use crate::helpers::movies_helper;
/// Get the list of movies of the current user
pub fn get_list(r: &mut HttpRequestHandler) -> RequestResult {
let list = movies_helper::get_list_user(r.user_id_ref()?)?;
r.set_response(MovieAPI::for_list(&list))
}
/// Remove a movie
pub fn delete(r: &mut HttpRequestHandler) -> RequestResult {
let movie_id = r.post_movie_id("movieID")?;
movies_helper::delete(&movies_helper::get_info(movie_id)?)?;
r.success("Movie deleted.")
}

View File

@ -158,13 +158,6 @@ pub fn create_post(r: &mut HttpRequestHandler) -> RequestResult {
PostKind::POST_KIND_YOUTUBE(youtube)
}
// Movies posts
"movie" => {
let movie_id = r.post_movie_id("movieID")?;
PostKind::POST_KIND_MOVIE(movie_id)
}
// Weblink posts
"weblink" => {
let url = r.post_url_opt("url", true)?

View File

@ -1,6 +1,6 @@
use std::error::Error;
use crate::controllers::{account_controller, calls_controller, comments_controller, conversations_controller, friends_controller, groups_controller, likes_controller, movies_controller, notifications_controller, posts_controller, search_controller, server_controller, settings_controller, surveys_controller, user_controller, user_ws_controller, virtual_directory_controller, web_app_controller};
use crate::controllers::{account_controller, calls_controller, comments_controller, conversations_controller, friends_controller, groups_controller, likes_controller, notifications_controller, posts_controller, search_controller, server_controller, settings_controller, surveys_controller, user_controller, user_ws_controller, virtual_directory_controller, web_app_controller};
use crate::controllers::routes::Method::{GET, POST};
use crate::data::http_request_handler::HttpRequestHandler;
@ -277,11 +277,6 @@ pub fn get_routes() -> Vec<Route> {
Route::post("/notifications/delete_all", Box::new(notifications_controller::delete_all)),
// Movies controller
Route::post("/movies/get_list", Box::new(movies_controller::get_list)),
Route::post("/movies/delete", Box::new(movies_controller::delete)),
// Virtual directory controller
Route::post("/user/findbyfolder", Box::new(virtual_directory_controller::find_user)),
Route::post("/virtualDirectory/find", Box::new(virtual_directory_controller::find)),

View File

@ -10,7 +10,6 @@ use crate::data::conversation_message::ConversationMessage;
use crate::data::error::ResultBoxError;
use crate::data::friend::Friend;
use crate::data::group_id::GroupID;
use crate::data::movie::Movie;
use crate::data::post::{Post, PostPageKind};
use crate::data::survey_response::SurveyResponse;
use crate::data::user::{User, UserID};
@ -23,7 +22,6 @@ pub struct AccountExport {
pub comments: Vec<Comment>,
pub likes: Vec<UserLike>,
pub survey_responses: Vec<SurveyResponse>,
pub movies: Vec<Movie>,
pub all_conversation_messages: Vec<ConversationMessage>,
pub conversations: Vec<Conversation>,
pub conversation_messages: HashMap<u64, Vec<ConversationMessage>>,

View File

@ -20,7 +20,7 @@ use crate::data::group::GroupAccessLevel;
use crate::data::group_id::GroupID;
use crate::data::post::{Post, PostAccessLevel};
use crate::data::user::UserID;
use crate::helpers::{account_helper, comments_helper, conversations_helper, custom_emojies_helper, friends_helper, groups_helper, movies_helper, posts_helper, user_helper, virtual_directory_helper};
use crate::helpers::{account_helper, comments_helper, conversations_helper, custom_emojies_helper, friends_helper, groups_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_emoji_code, check_string_before_insert, check_url, remove_html_nodes};
@ -536,17 +536,6 @@ pub trait BaseRequestHandler {
Ok(comment)
}
/// Get the ID of a movie included in the request
fn post_movie_id(&mut self, name: &str) -> ResultBoxError<u64> {
let movie_id = self.post_u64(name)?;
if !movies_helper::does_user_has(self.user_id_ref()?, movie_id)? {
self.forbidden("You are not authorized to use this movie!".to_string())?;
}
Ok(movie_id)
}
/// Get a content of a post and satinize it
fn post_content(&mut self, name: &str, min_len: usize, required: bool) -> ResultBoxError<String> {
let content = self.post_string_opt(name, min_len, required)?;

View File

@ -96,10 +96,10 @@ pub enum PostKind {
POST_KIND_IMAGE(PostFile),
POST_KIND_WEBLINK(PostWebLink),
POST_KIND_PDF(PostFile),
POST_KIND_MOVIE(u64),
// The ID of the movie
/// Countdown. Value : end time
POST_KIND_COUNTDOWN(u64),
// End time
POST_KIND_SURVEY,
POST_KIND_YOUTUBE(String),
}
@ -111,7 +111,6 @@ impl PostKind {
PostKind::POST_KIND_IMAGE(_) => "image",
PostKind::POST_KIND_WEBLINK(_) => "weblink",
PostKind::POST_KIND_PDF(_) => "pdf",
PostKind::POST_KIND_MOVIE(_) => "movie",
PostKind::POST_KIND_COUNTDOWN(_) => "countdown",
PostKind::POST_KIND_SURVEY => "survey",
PostKind::POST_KIND_YOUTUBE(_) => "youtube",

View File

@ -12,7 +12,7 @@ use crate::data::new_account::NewAccount;
use crate::data::security_settings::SecuritySettings;
use crate::data::user::{AccountImageVisibility, User, UserID, UserPageStatus};
use crate::data::user_token::UserAccessToken;
use crate::helpers::{comments_helper, conversations_helper, custom_emojies_helper, database, events_helper, friends_helper, groups_helper, likes_helper, movies_helper, notifications_helper, posts_helper, survey_helper, user_helper};
use crate::helpers::{comments_helper, conversations_helper, custom_emojies_helper, database, events_helper, friends_helper, groups_helper, likes_helper, notifications_helper, posts_helper, survey_helper, user_helper};
use crate::helpers::database::{DeleteQuery, InsertQuery, QueryInfo};
use crate::helpers::events_helper::Event;
use crate::helpers::likes_helper::LikeType;
@ -287,7 +287,6 @@ pub fn export(user_id: &UserID) -> ResultBoxError<AccountExport> {
comments: comments_helper::export_all_user(user_id)?,
likes: likes_helper::export_all_user(user_id)?,
survey_responses: survey_helper::export_all_user_responses(user_id)?,
movies: movies_helper::get_list_user(user_id)?,
all_conversation_messages: conversations_helper::export_all_user_messages(user_id)?,
conversations: conversations_helper::get_list_user(user_id)?,
conversation_messages: Default::default(),
@ -324,9 +323,6 @@ pub fn delete(user_id: &UserID) -> ResultBoxError {
// Delete all the likes created by the user
likes_helper::delete_all_user(user_id)?;
// Delete all user movies
movies_helper::delete_all_user(user_id)?;
// Delete all conversation messages
conversations_helper::delete_all_user_messages(user_id)?;

View File

@ -11,7 +11,6 @@ pub mod groups_helper;
pub mod posts_helper;
pub mod conversations_helper;
pub mod virtual_directory_helper;
pub mod movies_helper;
pub mod survey_helper;
pub mod comments_helper;
pub mod notifications_helper;

View File

@ -1,71 +0,0 @@
//! # Movies helper
//!
//! @author Pierre Hubert
use crate::constants::database_tables_names::MOVIES_TABLE;
use crate::data::error::ResultBoxError;
use crate::data::movie::Movie;
use crate::data::user::UserID;
use crate::helpers::{database, posts_helper};
use crate::utils::user_data_utils::user_data_path;
/// Get the list of movies of the current
pub fn get_list_user(user_id: &UserID) -> ResultBoxError<Vec<Movie>> {
database::QueryInfo::new(MOVIES_TABLE)
.cond_user_id("ID_user", user_id)
.set_order("ID DESC")
.exec(db_to_movie)
}
/// Get all movies
pub fn get_all() -> ResultBoxError<Vec<Movie>> {
database::QueryInfo::new(MOVIES_TABLE)
.exec(db_to_movie)
}
/// Get information about a single movie
pub fn get_info(movie_id: u64) -> ResultBoxError<Movie> {
database::QueryInfo::new(MOVIES_TABLE)
.cond_u64("ID", movie_id)
.query_row(db_to_movie)
}
/// Check out whether a user own a movie or not
pub fn does_user_has(user_id: &UserID, movie_id: u64) -> ResultBoxError<bool> {
Ok(get_info(movie_id).map(|m| &m.user_id == user_id).unwrap_or(false))
}
/// Remove permanently a movie from the database
pub fn delete(movie: &Movie) -> ResultBoxError {
posts_helper::delete_all_with_movie(movie)?;
let movie_path = user_data_path(movie.uri.as_ref());
if movie_path.exists() {
std::fs::remove_file(movie_path)?;
}
database::DeleteQuery::new(MOVIES_TABLE)
.cond_u64("ID", movie.id)
.exec()
}
/// Delete all the movies of a user
pub fn delete_all_user(user_id: &UserID) -> ResultBoxError {
for movie in &get_list_user(user_id)? {
delete(movie)?;
}
Ok(())
}
/// Turn a database entry into a movie object
fn db_to_movie(row: &database::RowResult) -> ResultBoxError<Movie> {
Ok(Movie {
id: row.get_u64("ID")?,
user_id: row.get_user_id("ID_user")?,
name: row.get_str("nom_video")?,
uri: row.get_str("URL")?,
file_type: row.get_str("file_type")?,
size: row.get_usize("size")?,
})
}

View File

@ -10,7 +10,7 @@ use crate::data::group_id::GroupID;
use crate::data::group_member::GroupMembershipLevel;
use crate::data::movie::Movie;
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::post::PostKind::{POST_KIND_COUNTDOWN, POST_KIND_IMAGE, POST_KIND_PDF, POST_KIND_SURVEY, POST_KIND_WEBLINK, POST_KIND_YOUTUBE};
use crate::data::user::UserID;
use crate::helpers::{comments_helper, database, friends_helper, groups_helper, likes_helper, notifications_helper, survey_helper, user_helper};
use crate::helpers::likes_helper::LikeType;
@ -45,7 +45,6 @@ impl PostKind {
POST_KIND_IMAGE(_) => "image",
POST_KIND_WEBLINK(_) => "webpage_link",
POST_KIND_PDF(_) => "pdf",
POST_KIND_MOVIE(_) => "video",
POST_KIND_COUNTDOWN(_) => "count_down",
POST_KIND_SURVEY => "sondage",
POST_KIND_YOUTUBE(_) => "youtube",
@ -93,11 +92,6 @@ pub fn create(p: &Post) -> ResultBoxError<u64> {
.add_str("type", "youtube");
}
// Movie post
POST_KIND_MOVIE(id) => {
insert_query = insert_query.add_u64("idvideo", *id);
}
// Weblink
POST_KIND_WEBLINK(weblink) => {
insert_query = insert_query
@ -540,8 +534,6 @@ fn db_to_post(res: &database::RowResult) -> ResultBoxError<Post> {
"pdf" => post.kind = POST_KIND_PDF(file?),
"video" => post.kind = POST_KIND_MOVIE(res.get_u64("idvideo")?),
"count_down" => post.kind = POST_KIND_COUNTDOWN(res.get_u64("time_end").unwrap_or(0)),
"sondage" => post.kind = POST_KIND_SURVEY,

View File

@ -1,6 +1,6 @@
use comunic_server::controllers::server;
use comunic_server::data::config::{conf, Config};
use comunic_server::helpers::{database, movies_helper};
use comunic_server::helpers::database;
#[actix_rt::main]
async fn main() -> std::io::Result<()> {
@ -15,12 +15,6 @@ async fn main() -> std::io::Result<()> {
// Connect to the database
database::connect(&conf().database).expect("Could not connect to database!");
// TODO : remove after application
// Remove all movies
for movie in movies_helper::get_all().unwrap() {
movies_helper::delete(&movie).unwrap();
}
// Start the server
server::start_server(conf()).await
}