mirror of
				https://gitlab.com/comunic/comunicapiv2
				synced 2025-11-04 03:24:04 +00:00 
			
		
		
		
	Get basic post information
This commit is contained in:
		@@ -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: <PostKind>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 <PostVisibilityLevel>Number(levelKey);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -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
 | 
			
		||||
	 * 
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user