generated from nhcarrigan/template
fix: make announcement route resilient to platform failures
✨ This commit was made with love from Hikari~ 🌸
This commit is contained in:
@@ -21,6 +21,12 @@ import type { FastifyPluginAsync } from "fastify";
|
|||||||
|
|
||||||
const oneDay = 24 * 60 * 60 * 1000;
|
const oneDay = 24 * 60 * 60 * 1000;
|
||||||
|
|
||||||
|
const getPlatformResult = (result: PromiseSettledResult<string>): string => {
|
||||||
|
return result.status === "fulfilled"
|
||||||
|
? result.value
|
||||||
|
: `Unexpected error: ${String(result.reason)}`;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mounts the entry routes for the application. These routes
|
* Mounts the entry routes for the application. These routes
|
||||||
* should not require CORS, as they are used by external services
|
* should not require CORS, as they are used by external services
|
||||||
@@ -85,8 +91,8 @@ export const announcementRoutes: FastifyPluginAsync = async(server) => {
|
|||||||
const announcement = await generateAnnouncements(content);
|
const announcement = await generateAnnouncements(content);
|
||||||
|
|
||||||
if (announcement === null) {
|
if (announcement === null) {
|
||||||
return await reply.status(201).send({
|
return await reply.status(500).send({
|
||||||
message: `Failed to generate announcements.`,
|
error: `Failed to generate announcements.`,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,30 +111,30 @@ export const announcementRoutes: FastifyPluginAsync = async(server) => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const discordPost = await announceOnDiscord(
|
const [
|
||||||
markdownTitle,
|
discordResult,
|
||||||
markdownContent,
|
redditResult,
|
||||||
type,
|
blueskyResult,
|
||||||
);
|
twitterResult,
|
||||||
const redditPost = await announceOnReddit(
|
facebookResult,
|
||||||
markdownTitle,
|
threadsResult,
|
||||||
markdownContent,
|
mastodonResult,
|
||||||
type,
|
discourseResult,
|
||||||
);
|
] = await Promise.allSettled([
|
||||||
const blueskyPost = await announceOnBluesky(threaded);
|
announceOnDiscord(markdownTitle, markdownContent, type),
|
||||||
const twitterPost = await announceOnTwitter(threaded);
|
announceOnReddit(markdownTitle, markdownContent, type),
|
||||||
const facebookPost = await announceOnFacebook(plaintext);
|
announceOnBluesky(threaded),
|
||||||
const threadsPost = await announceOnThreads(threaded);
|
announceOnTwitter(threaded),
|
||||||
const mastodonPost = await announceOnMastodon(threaded);
|
announceOnFacebook(plaintext),
|
||||||
const discoursePost = await announceOnDiscourse(
|
announceOnThreads(threaded),
|
||||||
markdownTitle,
|
announceOnMastodon(threaded),
|
||||||
markdownContent,
|
announceOnDiscourse(markdownTitle, markdownContent, type),
|
||||||
type,
|
]);
|
||||||
);
|
|
||||||
return await reply.status(201).send({
|
return await reply.status(201).send({
|
||||||
alert: `Please remember to manually post to: LinkedIn, Peerlist, Ko-fi, and Patreon.`,
|
alert: `Please remember to manually post to: LinkedIn, Peerlist, Ko-fi, and Patreon.`,
|
||||||
cost: announcement.cost,
|
cost: announcement.cost,
|
||||||
message: `Announcement processed. Discord: ${discordPost}, Reddit: ${redditPost}, Bluesky: ${blueskyPost}, Twitter: ${twitterPost}, Facebook: ${facebookPost}, Threads: ${threadsPost}, Mastodon: ${mastodonPost}, Discourse: ${discoursePost}`,
|
message: `Announcement processed. Discord: ${getPlatformResult(discordResult)}, Reddit: ${getPlatformResult(redditResult)}, Bluesky: ${getPlatformResult(blueskyResult)}, Twitter: ${getPlatformResult(twitterResult)}, Facebook: ${getPlatformResult(facebookResult)}, Threads: ${getPlatformResult(threadsResult)}, Mastodon: ${getPlatformResult(mastodonResult)}, Discourse: ${getPlatformResult(discourseResult)}`,
|
||||||
rawPost: announcement.response,
|
rawPost: announcement.response,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user