generated from nhcarrigan/template
fix: safely extract first chunk to satisfy noUncheckedIndexedAccess
This commit is contained in:
@@ -37,11 +37,13 @@ export const announceOnDiscourse = async(
|
||||
}
|
||||
|
||||
const chunks = chunkContent(content, discourseLimit);
|
||||
const firstChunk = chunks[0] ?? "";
|
||||
const remainingChunks = chunks.slice(1);
|
||||
|
||||
const response = await fetch("https://support.nhcarrigan.com/posts.json", {
|
||||
body: JSON.stringify({
|
||||
category: announcementCategoryId,
|
||||
raw: chunks[0],
|
||||
raw: firstChunk,
|
||||
tags: [ tags[type] ],
|
||||
title: title,
|
||||
}),
|
||||
@@ -60,7 +62,7 @@ export const announceOnDiscourse = async(
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Fetch does not accept generic.
|
||||
const data = (await response.json()) as { topic_id?: number };
|
||||
|
||||
for (const chunk of chunks.slice(1)) {
|
||||
for (const chunk of remainingChunks) {
|
||||
if (data.topic_id === undefined) {
|
||||
return "Failed to retrieve Discourse topic ID for continuation posts.";
|
||||
}
|
||||
|
||||
@@ -43,6 +43,8 @@ export const announceOnReddit = async(
|
||||
}
|
||||
|
||||
const chunks = chunkContent(content, redditLimit);
|
||||
const firstChunk = chunks[0] ?? "";
|
||||
const remainingChunks = chunks.slice(1);
|
||||
|
||||
const tokenResponse = await fetch(
|
||||
"https://www.reddit.com/api/v1/access_token",
|
||||
@@ -81,7 +83,7 @@ export const announceOnReddit = async(
|
||||
flair_text: type,
|
||||
kind: "self",
|
||||
sr: "nhcarrigan",
|
||||
text: chunks[0],
|
||||
text: firstChunk,
|
||||
title: title,
|
||||
}),
|
||||
headers: {
|
||||
@@ -108,7 +110,7 @@ export const announceOnReddit = async(
|
||||
|
||||
let parentName = redditData.json.data?.name;
|
||||
|
||||
for (const chunk of chunks.slice(1)) {
|
||||
for (const chunk of remainingChunks) {
|
||||
if (parentName === undefined) {
|
||||
return "Failed to get Reddit post fullname for chaining replies.";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user