mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-25 23:09:22 +00:00
Add support for image posts
This commit is contained in:
parent
037916e7eb
commit
43a429e106
5
package-lock.json
generated
5
package-lock.json
generated
@ -59,6 +59,11 @@
|
|||||||
"integrity": "sha512-FwI9gX75FgVBJ7ywgnq/P7tw+/o1GUbtP0KzbtusLigAOgIgNISRK0ZPl4qertvXSIE8YbsVJueQ90cDt9YYyw==",
|
"integrity": "sha512-FwI9gX75FgVBJ7ywgnq/P7tw+/o1GUbtP0KzbtusLigAOgIgNISRK0ZPl4qertvXSIE8YbsVJueQ90cDt9YYyw==",
|
||||||
"dev": true
|
"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": {
|
"@types/mysql": {
|
||||||
"version": "2.15.8",
|
"version": "2.15.8",
|
||||||
"resolved": "https://registry.npmjs.org/@types/mysql/-/mysql-2.15.8.tgz",
|
"resolved": "https://registry.npmjs.org/@types/mysql/-/mysql-2.15.8.tgz",
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
"author": "",
|
"author": "",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@types/mime-types": "^2.1.0",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"express-fileupload": "^1.1.6",
|
"express-fileupload": "^1.1.6",
|
||||||
"mysql": "^2.17.1",
|
"mysql": "^2.17.1",
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { RequestHandler } from "../entities/RequestHandler";
|
import { RequestHandler } from "../entities/RequestHandler";
|
||||||
import { UserHelper } from "../helpers/UserHelper";
|
import { UserHelper } from "../helpers/UserHelper";
|
||||||
import { PostsHelper } from "../helpers/PostsHelper";
|
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 { MoviesController } from "./MoviesController";
|
||||||
import { MoviesHelper } from "../helpers/MoviesHelper";
|
import { MoviesHelper } from "../helpers/MoviesHelper";
|
||||||
import { SurveyHelper } from "../helpers/SurveyHelper";
|
import { SurveyHelper } from "../helpers/SurveyHelper";
|
||||||
@ -14,6 +14,9 @@ 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 } from "../utils/StringUtils";
|
||||||
|
import { pathUserData } from "../utils/UserDataUtils";
|
||||||
|
import { statSync } from "fs";
|
||||||
|
import { lookup } from "mime-types";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Posts controller
|
* Posts controller
|
||||||
@ -161,6 +164,30 @@ export class PostsController {
|
|||||||
|
|
||||||
break;
|
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:
|
default:
|
||||||
h.error(500, "Unsupported kind of post!");
|
h.error(500, "Unsupported kind of post!");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user