mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-25 23:09: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 { GroupsHelper } from "../helpers/GroupsHelper";
|
||||||
import { time } from "../utils/DateUtils";
|
import { time } from "../utils/DateUtils";
|
||||||
import { findKey } from "../utils/ArrayUtils";
|
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 { pathUserData } from "../utils/UserDataUtils";
|
||||||
import { statSync } from "fs";
|
import { statSync } from "fs";
|
||||||
import { lookup } from "mime-types";
|
import { lookup } from "mime-types";
|
||||||
@ -186,6 +186,25 @@ export class PostsController {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -58,3 +58,21 @@ export function removeHTMLNodes(input : string) : string {
|
|||||||
export function check_string_before_insert(s: string) : boolean {
|
export function check_string_before_insert(s: string) : boolean {
|
||||||
return s.trim().length >= 3;
|
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