mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-22 21:39:21 +00:00
Can create YouTube posts
This commit is contained in:
parent
8753f77227
commit
11051b28a0
@ -12,7 +12,7 @@ use crate::data::http_request_handler::HttpRequestHandler;
|
|||||||
use crate::data::post::{Post, PostAccessLevel, PostFile, PostKind, PostPageKind, PostVisibilityLevel};
|
use crate::data::post::{Post, PostAccessLevel, PostFile, PostKind, PostPageKind, PostVisibilityLevel};
|
||||||
use crate::helpers::{groups_helper, posts_helper, user_helper};
|
use crate::helpers::{groups_helper, posts_helper, user_helper};
|
||||||
use crate::utils::date_utils::time;
|
use crate::utils::date_utils::time;
|
||||||
use crate::utils::string_utils::check_string_before_insert;
|
use crate::utils::string_utils::{check_string_before_insert, check_youtube_id};
|
||||||
use crate::utils::user_data_utils::user_data_path;
|
use crate::utils::user_data_utils::user_data_path;
|
||||||
|
|
||||||
impl PostFile {
|
impl PostFile {
|
||||||
@ -141,6 +141,18 @@ pub fn create_post(r: &mut HttpRequestHandler) -> RequestResult {
|
|||||||
PostKind::POST_KIND_IMAGE(PostFile::new_from_created_file(&path)?)
|
PostKind::POST_KIND_IMAGE(PostFile::new_from_created_file(&path)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
"youtube" => {
|
||||||
|
let youtube = r.post_string("youtube_id")?;
|
||||||
|
|
||||||
|
if !check_youtube_id(&youtube) {
|
||||||
|
r.bad_request("Invalid YouTube ID!".to_string())?;
|
||||||
|
}
|
||||||
|
|
||||||
|
PostKind::POST_KIND_YOUTUBE(youtube)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO : add support for next types
|
||||||
|
|
||||||
_ => {
|
_ => {
|
||||||
r.internal_error(ExecError::boxed_new("Unsupported kind of post!"))?;
|
r.internal_error(ExecError::boxed_new("Unsupported kind of post!"))?;
|
||||||
unreachable!();
|
unreachable!();
|
||||||
|
@ -75,7 +75,7 @@ pub fn create(p: &Post) -> ResultBoxError<u64> {
|
|||||||
.add_opt_str("texte", p.content.as_ref());
|
.add_opt_str("texte", p.content.as_ref());
|
||||||
|
|
||||||
match &p.kind {
|
match &p.kind {
|
||||||
PostKind::POST_KIND_TEXT => {/* nothing to do */},
|
PostKind::POST_KIND_TEXT => { /* nothing to do */ }
|
||||||
|
|
||||||
// Posts with associated file
|
// Posts with associated file
|
||||||
POST_KIND_IMAGE(file) | POST_KIND_PDF(file) => {
|
POST_KIND_IMAGE(file) | POST_KIND_PDF(file) => {
|
||||||
@ -84,6 +84,11 @@ pub fn create(p: &Post) -> ResultBoxError<u64> {
|
|||||||
.add_opt_str("file_type", file.file_type.as_ref());
|
.add_opt_str("file_type", file.file_type.as_ref());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// YouTube posts
|
||||||
|
POST_KIND_YOUTUBE(id) => {
|
||||||
|
insert_query = insert_query.add_str("path", id)
|
||||||
|
.add_str("type", "youtube");
|
||||||
|
}
|
||||||
|
|
||||||
_ => unimplemented!()
|
_ => unimplemented!()
|
||||||
/*
|
/*
|
||||||
@ -91,7 +96,7 @@ pub fn create(p: &Post) -> ResultBoxError<u64> {
|
|||||||
POST_KIND_MOVIE(_) => {},
|
POST_KIND_MOVIE(_) => {},
|
||||||
POST_KIND_COUNTDOWN(_) => {},
|
POST_KIND_COUNTDOWN(_) => {},
|
||||||
POST_KIND_SURVEY => {},
|
POST_KIND_SURVEY => {},
|
||||||
POST_KIND_YOUTUBE(_) => {},*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute insertion
|
// Execute insertion
|
||||||
|
@ -51,3 +51,24 @@ pub fn check_url(url: &str) -> bool {
|
|||||||
pub fn check_string_before_insert(s: &str) -> bool {
|
pub fn check_string_before_insert(s: &str) -> bool {
|
||||||
s.trim().len() > 3
|
s.trim().len() > 3
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Check the validity of a YouTube ID
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// use comunic_server::utils::string_utils::check_youtube_id;
|
||||||
|
///
|
||||||
|
/// assert_eq!(check_youtube_id("/ab/"), false);
|
||||||
|
/// assert_eq!(check_youtube_id("abxZ96C"), true);
|
||||||
|
/// assert_eq!(check_youtube_id("a6C"), false);
|
||||||
|
/// ```
|
||||||
|
pub fn check_youtube_id(id: &str) -> bool {
|
||||||
|
id.len() >= 5
|
||||||
|
&& !id.contains("/")
|
||||||
|
&& !id.contains("\\")
|
||||||
|
&& !id.contains("@")
|
||||||
|
&& !id.contains("&")
|
||||||
|
&& !id.contains("?")
|
||||||
|
&& !id.contains(".")
|
||||||
|
&& !id.contains("'")
|
||||||
|
&& !id.contains("\"")
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user