mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-22 05:19:22 +00:00
Can get information about an emoji included in a POST request
This commit is contained in:
parent
f70d01d8bb
commit
8693c1e556
@ -16,6 +16,8 @@ import { CommentsHelper } from "../helpers/CommentsHelper";
|
||||
import { checkVirtualDirectory } from "../utils/VirtualDirsUtils";
|
||||
import { ConversationsHelper } from "../helpers/ConversationsHelper";
|
||||
import { AbstractUserConnectionContainer } from "./UserConnectionContainer";
|
||||
import { CustomEmoji } from "./CustomEmoji";
|
||||
import { CustomEmojisHelper } from "../helpers/CustomEmojisHelper";
|
||||
|
||||
export abstract class BaseRequestsHandler implements AbstractUserConnectionContainer {
|
||||
|
||||
@ -412,11 +414,27 @@ export abstract class BaseRequestsHandler implements AbstractUserConnectionConta
|
||||
* @param name The name of the POST field containing the id of the emoji
|
||||
*/
|
||||
public postEmojiShorcut(name: string) : string {
|
||||
const emojiID = this.postString(name);
|
||||
const emojiShorcut = this.postString(name);
|
||||
|
||||
if(!checkEmojiCode(emojiID))
|
||||
if(!checkEmojiCode(emojiShorcut))
|
||||
this.error(401, "Invalid emoji specified at " + name + "!")
|
||||
|
||||
return emojiID;
|
||||
return emojiShorcut;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get information about an emoji included in a POST request
|
||||
*
|
||||
* @param name The name of the post field containing emoji ID
|
||||
*/
|
||||
public async postEmojiID(name: string) : Promise<CustomEmoji> {
|
||||
const eomjiID = this.postInt(name);
|
||||
|
||||
const info = await CustomEmojisHelper.GetSingle(eomjiID);
|
||||
|
||||
if(info.userID != this.getUserId())
|
||||
this.error(401, "You are not allowed to modify this emoji!");
|
||||
|
||||
return info;
|
||||
}
|
||||
}
|
@ -42,6 +42,25 @@ export class CustomEmojisHelper {
|
||||
})).map((e) => this.DbToCustomEmoji(e));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get information about a single emoji
|
||||
*
|
||||
* @param emojiID The ID of the emoji to get
|
||||
* @throws An error if the emoji was not found
|
||||
*/
|
||||
public static async GetSingle(emojiID: number) : Promise<CustomEmoji> {
|
||||
const row = await DatabaseHelper.QueryRow({
|
||||
table: EMOJIS_TABLE,
|
||||
where: {
|
||||
id: emojiID
|
||||
}
|
||||
});
|
||||
|
||||
if(row == null)
|
||||
throw new Error("Requested emoji was not found ! (emoji id " + emojiID + ")")
|
||||
|
||||
return this.DbToCustomEmoji(row);
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn a database entry into a custom emoji
|
||||
|
Loading…
Reference in New Issue
Block a user