diff --git a/src/controllers/PostsController.ts b/src/controllers/PostsController.ts index 4d3dad0..f2c0def 100644 --- a/src/controllers/PostsController.ts +++ b/src/controllers/PostsController.ts @@ -11,6 +11,8 @@ import { CommentsHelper } from "../helpers/CommentsHelper"; import { CommentsController } from "./CommentsController"; import { GroupsAccessLevel } from "../entities/Group"; import { GroupsHelper } from "../helpers/GroupsHelper"; +import { time } from "../utils/DateUtils"; +import { findKey } from "../utils/ArrayUtils"; /** * Posts controller @@ -130,10 +132,26 @@ export class PostsController { } + // Initialize new post information + const newPost = new Post({ + // Basic information about the post + id: -1, + userID: h.getUserId(), + timeCreate: time(), + kind: h.postString("kind"), + content: h.postContent("content"), + visibilityLevel: this.PostVisibilityLevel(h, "visibility"), + + // Post target + kindPage: kindPage, + pageID: pageID, + + }); + + console.info(newPost); h.success("Go on."); } - /** * Send multiple posts to the API * @@ -208,4 +226,17 @@ export class PostsController { return data; } + + /** + * Get the visibility level for a POST included in a request + * + * @param h Request handler + * @param name The name of the POST field containing the visibility level of the user + */ + private static PostVisibilityLevel(h: RequestHandler, name: string) : PostVisibilityLevel { + const levelKey = findKey(VISIBILITY_LEVELS_API, h.postString(name, 3)); + if(levelKey == null) + h.error(400, "Post visibility level level not recognized!"); + return Number(levelKey); + } } \ No newline at end of file diff --git a/src/entities/RequestHandler.ts b/src/entities/RequestHandler.ts index d639a49..00a3f2c 100644 --- a/src/entities/RequestHandler.ts +++ b/src/entities/RequestHandler.ts @@ -1,7 +1,7 @@ import { Response, Request } from "express"; import { APIHelper } from "../helpers/APIHelper"; import { APIClient } from "./APIClient"; -import { checkMail } from "../utils/StringUtils"; +import { checkMail, removeHTMLNodes } from "../utils/StringUtils"; import { AccountHelper } from "../helpers/AccountHelper"; import { UploadedFile } from "express-fileupload"; import { prepareFileCreation, generateNewUserDataFileName, pathUserData } from "../utils/UserDataUtils"; @@ -81,6 +81,20 @@ export class RequestHandler { return this.hasPostParameter(name) && this.getPostParam(name).length >= minLength; } + /** + * Get some content for post and satinize it (remove HTML nodes) + * + * @param name The name of the POST field + */ + public postContent(name: string) : string { + const content = this.postString(name); + + if(content.match(/data:image/)) + this.error(401, "Please do not include inline images!"); + + return removeHTMLNodes(content); + } + /** * Get an email address included in a post request *