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