mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-22 13:29:22 +00:00
Add links support
This commit is contained in:
parent
7341475c24
commit
0a1626dc47
@ -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, PostFile } from "../entities/Post";
|
import { Post, PostVisibilityLevel, PostKind, PostAccessLevel, PostPageKind, PostFile, PostLink } 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";
|
||||||
@ -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, check_youtube_id } from "../utils/StringUtils";
|
import { check_string_before_insert, check_youtube_id, checkURL } 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";
|
||||||
@ -215,6 +215,22 @@ export class PostsController {
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
// Web links
|
||||||
|
case PostKind.POST_KIND_WEBLINK:
|
||||||
|
|
||||||
|
const url = h.postURL("url");
|
||||||
|
|
||||||
|
// For now, for safety, we do not fetch page content
|
||||||
|
newPost.link = new PostLink({
|
||||||
|
url: url,
|
||||||
|
title: undefined,
|
||||||
|
description: undefined,
|
||||||
|
image: undefined
|
||||||
|
});
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
h.error(500, "Unsupported kind of post!");
|
h.error(500, "Unsupported kind of post!");
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { Response, Request } from "express";
|
import { Response, Request } from "express";
|
||||||
import { APIHelper } from "../helpers/APIHelper";
|
import { APIHelper } from "../helpers/APIHelper";
|
||||||
import { APIClient } from "./APIClient";
|
import { APIClient } from "./APIClient";
|
||||||
import { checkMail, removeHTMLNodes } from "../utils/StringUtils";
|
import { checkMail, removeHTMLNodes, checkURL } from "../utils/StringUtils";
|
||||||
import { AccountHelper } from "../helpers/AccountHelper";
|
import { AccountHelper } from "../helpers/AccountHelper";
|
||||||
import { UploadedFile } from "express-fileupload";
|
import { UploadedFile } from "express-fileupload";
|
||||||
import { prepareFileCreation, generateNewUserDataFileName, pathUserData } from "../utils/UserDataUtils";
|
import { prepareFileCreation, generateNewUserDataFileName, pathUserData } from "../utils/UserDataUtils";
|
||||||
@ -337,6 +337,21 @@ export class RequestHandler {
|
|||||||
return dir;
|
return dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an URL included in a POST request
|
||||||
|
*
|
||||||
|
* @param name The name of the POST field containing
|
||||||
|
* the URL
|
||||||
|
*/
|
||||||
|
public postURL(name: string) : string {
|
||||||
|
const url = this.postString(name);
|
||||||
|
|
||||||
|
if(!checkURL(url))
|
||||||
|
this.error(401, "Specified URL in '"+name+"' seems to be invalid!");
|
||||||
|
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get information about an uploaded file
|
* Get information about an uploaded file
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user