1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-11-22 05:19:22 +00:00

Add support for image posts

This commit is contained in:
Pierre HUBERT 2020-01-04 18:45:29 +01:00
parent 037916e7eb
commit 43a429e106
3 changed files with 34 additions and 1 deletions

5
package-lock.json generated
View File

@ -59,6 +59,11 @@
"integrity": "sha512-FwI9gX75FgVBJ7ywgnq/P7tw+/o1GUbtP0KzbtusLigAOgIgNISRK0ZPl4qertvXSIE8YbsVJueQ90cDt9YYyw==",
"dev": true
},
"@types/mime-types": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/@types/mime-types/-/mime-types-2.1.0.tgz",
"integrity": "sha1-nKUs2jY/aZxpRmwqbM2q2RPqenM="
},
"@types/mysql": {
"version": "2.15.8",
"resolved": "https://registry.npmjs.org/@types/mysql/-/mysql-2.15.8.tgz",

View File

@ -9,6 +9,7 @@
"author": "",
"license": "MIT",
"dependencies": {
"@types/mime-types": "^2.1.0",
"express": "^4.17.1",
"express-fileupload": "^1.1.6",
"mysql": "^2.17.1",

View File

@ -1,7 +1,7 @@
import { RequestHandler } from "../entities/RequestHandler";
import { UserHelper } from "../helpers/UserHelper";
import { PostsHelper } from "../helpers/PostsHelper";
import { Post, PostVisibilityLevel, PostKind, PostAccessLevel, PostPageKind } from "../entities/Post";
import { Post, PostVisibilityLevel, PostKind, PostAccessLevel, PostPageKind, PostFile } from "../entities/Post";
import { MoviesController } from "./MoviesController";
import { MoviesHelper } from "../helpers/MoviesHelper";
import { SurveyHelper } from "../helpers/SurveyHelper";
@ -14,6 +14,9 @@ import { GroupsHelper } from "../helpers/GroupsHelper";
import { time } from "../utils/DateUtils";
import { findKey } from "../utils/ArrayUtils";
import { check_string_before_insert } from "../utils/StringUtils";
import { pathUserData } from "../utils/UserDataUtils";
import { statSync } from "fs";
import { lookup } from "mime-types";
/**
* Posts controller
@ -160,6 +163,30 @@ export class PostsController {
h.error(400, "Specified post content is invalid!");
break;
// Image posts
case PostKind.POST_KIND_IMAGE:
if(!h.hasFile("image"))
h.error(400, "An error occured while receiving the image!");
// Save image
const path = await h.savePostImage("image", "imgpost", 2000, 2000);
newPost.file = new PostFile({
path: path,
type: <string>lookup(pathUserData(path, true)),
size: statSync(pathUserData(path, true)).size
});
break;
default:
h.error(500, "Unsupported kind of post!");