mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-22 05:19:22 +00:00
Add support for YouTube posts
This commit is contained in:
parent
43a429e106
commit
6edf39d971
@ -13,7 +13,7 @@ import { GroupsAccessLevel } from "../entities/Group";
|
||||
import { GroupsHelper } from "../helpers/GroupsHelper";
|
||||
import { time } from "../utils/DateUtils";
|
||||
import { findKey } from "../utils/ArrayUtils";
|
||||
import { check_string_before_insert } from "../utils/StringUtils";
|
||||
import { check_string_before_insert, check_youtube_id } from "../utils/StringUtils";
|
||||
import { pathUserData } from "../utils/UserDataUtils";
|
||||
import { statSync } from "fs";
|
||||
import { lookup } from "mime-types";
|
||||
@ -185,6 +185,25 @@ export class PostsController {
|
||||
break;
|
||||
|
||||
|
||||
|
||||
// YouTube posts
|
||||
case PostKind.POST_KIND_YOUTUBE:
|
||||
|
||||
const youtubeID = h.postString("youtube_id");
|
||||
|
||||
if(!check_youtube_id(youtubeID))
|
||||
h.error(400, "Invalid YouTube ID!");
|
||||
|
||||
newPost.file = new PostFile({
|
||||
path: youtubeID,
|
||||
size: 0,
|
||||
type: "youtube"
|
||||
})
|
||||
|
||||
break;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -57,4 +57,22 @@ export function removeHTMLNodes(input : string) : string {
|
||||
*/
|
||||
export function check_string_before_insert(s: string) : boolean {
|
||||
return s.trim().length >= 3;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check the validity of a YouTube ID
|
||||
*
|
||||
* @param s The id to check
|
||||
*/
|
||||
export function check_youtube_id(s: string) : boolean {
|
||||
return s.length >= 5
|
||||
&& !s.includes("/")
|
||||
&& !s.includes("\\")
|
||||
&& !s.includes("@")
|
||||
&& !s.includes("&")
|
||||
&& !s.includes("?")
|
||||
&& !s.includes(".")
|
||||
&& !s.includes("'")
|
||||
&& !s.includes("\"")
|
||||
}
|
Loading…
Reference in New Issue
Block a user