generated from nhcarrigan/template
feat: set up announcement and cors logic for server
This commit is contained in:
40
server/src/modules/announceOnForum.ts
Normal file
40
server/src/modules/announceOnForum.ts
Normal file
@ -0,0 +1,40 @@
|
||||
/**
|
||||
* @copyright nhcarrigan
|
||||
* @license Naomi's Public License
|
||||
* @author Naomi Carrigan
|
||||
*/
|
||||
/* eslint-disable @typescript-eslint/naming-convention -- we are making raw API calls. */
|
||||
/**
|
||||
* Forwards an announcement to our Discord server.
|
||||
* @param title - The title of the announcement.
|
||||
* @param content - The main body of the announcement.
|
||||
* @param type - Whether the announcement is for a product or community.
|
||||
* @returns A message indicating the success or failure of the operation.
|
||||
*/
|
||||
export const announceOnForum = async(
|
||||
title: string,
|
||||
content: string,
|
||||
type: "products" | "community",
|
||||
): Promise<string> => {
|
||||
const forumRequest = await fetch(
|
||||
`https://forum.nhcarrigan.com/posts.json`,
|
||||
{
|
||||
body: JSON.stringify({
|
||||
category: 14,
|
||||
raw: content,
|
||||
tags: [ type ],
|
||||
title: title,
|
||||
}),
|
||||
headers: {
|
||||
"Api-Key": process.env.FORUM_API_KEY ?? "",
|
||||
"Api-Username": "Hikari",
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
method: "POST",
|
||||
},
|
||||
);
|
||||
if (forumRequest.status !== 200) {
|
||||
return "Failed to send message to forum.";
|
||||
}
|
||||
return "Successfully sent message to forum.";
|
||||
};
|
Reference in New Issue
Block a user