fix: safely extract first chunk to satisfy noUncheckedIndexedAccess
Node.js CI / CI (pull_request) Successful in 48s
Security Scan and Upload / Security & DefectDojo Upload (pull_request) Successful in 1m14s

This commit is contained in:
2026-03-03 18:03:53 -08:00
committed by Naomi Carrigan
parent 2ebeddd890
commit f3197245db
2 changed files with 8 additions and 4 deletions
+4 -2
View File
@@ -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.";
}
+4 -2
View File
@@ -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.";
}