diff --git a/src/controllers/PostsController.ts b/src/controllers/PostsController.ts index 43bf2ef..55b96b0 100644 --- a/src/controllers/PostsController.ts +++ b/src/controllers/PostsController.ts @@ -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; + + + diff --git a/src/utils/StringUtils.ts b/src/utils/StringUtils.ts index 64aef91..064d5b9 100644 --- a/src/utils/StringUtils.ts +++ b/src/utils/StringUtils.ts @@ -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("\"") } \ No newline at end of file