Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default createProcessor(Tasks.GRANT_AUTHOR_ACHIEVEMENTS, async (job) => {
socials?: Record<string, string>;
};
const roles = meta.roles ?? [];
const githubLogin = meta.socials?.github;
const githubLogin = meta.socials?.["github"];

// ── Content stats ─────────────────────────────────────────────────────────

Expand Down
2 changes: 2 additions & 0 deletions apps/worker/src/tasks/sync-collection/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ export default createProcessor(
.values(result)
.returning({ id: collections.id });

if (!collectionRecord) throw new Error("undefined collectionRecord");

// Delete existing author associations for this collection
await tx
.delete(collectionAuthors)
Expand Down
3 changes: 3 additions & 0 deletions apps/worker/src/tasks/sync-post/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ export default createProcessor(Tasks.SYNC_POST, async (job, { signal }) => {
.insert(postGroups)
.values({})
.returning({ id: postGroups.id });
if (!newGroup) throw new Error("undefined newGroup");
groupId = newGroup.id;
}
}
Expand Down Expand Up @@ -217,6 +218,8 @@ export default createProcessor(Tasks.SYNC_POST, async (job, { signal }) => {
.values(postValues)
.returning({ id: posts.id });

if (!postRecord) throw new Error("undefined postRecord");

const authorSlugs = new Set<string>([author, ...(parsed.authors ?? [])]);
authorSlugs.forEach((authorSlug) => affectedAuthorSlugs.add(authorSlug));

Expand Down
5 changes: 2 additions & 3 deletions apps/worker/src/tasks/url-metadata/data-providers/youtube.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export async function getYouTubeOEmbedDataFromUrl(
signal: AbortSignal,
): Promise<YouTubeOEmbedResponse | null> {
const splitPath = url.pathname.split("/").filter(Boolean);
let videoId: string;
let videoId: string | undefined;
if (url.host === youtubeShortHost) {
videoId = splitPath[0];
} else if (splitPath[0] === "watch") {
Expand All @@ -40,10 +40,9 @@ export async function getYouTubeOEmbedDataFromUrl(
// https://www.youtube.com/shorts/Fdbha07mFzo
} else if (splitPath[0] === "shorts") {
videoId = splitPath[1];
} else {
return null;
}

if (!videoId) return null;
const youtubeUrl = `https://www.youtube.com/watch?v=${videoId}`;

return await fetchAsBot({
Expand Down
6 changes: 2 additions & 4 deletions apps/worker/src/tasks/url-metadata/getEmbedDataFromGist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@ export async function getEmbedDataFromGist(
inputUrl: URL,
signal: AbortSignal,
): Promise<EmbedData> {
let error = false;

// https://gist.github.com/crutchcorn/36fe5553219c05ea38bacf1c7396085b
const gistPathParts = inputUrl.pathname.split("/").filter(Boolean);
const githubUsername = gistPathParts[0];
const gistId = gistPathParts[1];
if (!githubUsername || !gistId) {
console.error(`Invalid gist URL: ${inputUrl}`);
error = true;
return { error: true };
}

const data = await createAppClient()
Expand Down Expand Up @@ -114,6 +112,6 @@ export async function getEmbedDataFromGist(

return {
gistId,
error,
error: false,
};
}
6 changes: 3 additions & 3 deletions apps/worker/src/tasks/url-metadata/getEmbedDataFromVideo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ export async function getEmbedDataFromVideo(
let embedHeight: number | undefined = undefined;
if (videoData?.html) {
const attributes = getIFrameAttributes(videoData.html);
if (attributes.src) embedSrc = String(attributes.src);
const width = Number(attributes.width);
const height = Number(attributes.height);
if (attributes["src"]) embedSrc = String(attributes["src"]);
const width = Number(attributes["width"]);
const height = Number(attributes["height"]);
if (isFinite(width)) embedWidth = width;
if (isFinite(height)) embedHeight = height;
}
Expand Down
6 changes: 4 additions & 2 deletions apps/worker/src/tasks/url-metadata/utils/fetchPageHtml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ export async function getOpenGraphImages(
if (!headNode) return results;

visit(headNode, { type: "element", tagName: "meta" }, (e: Element) => {
if (["twitter:image", "og:image"].includes(String(e.properties.property))) {
if (
["twitter:image", "og:image"].includes(String(e.properties["property"]))
) {
try {
const url = new URL(String(e.properties.content), baseUrl);
const url = new URL(String(e.properties["content"]), baseUrl);
results.push(url);
} catch (_e) {
// ignore
Expand Down
10 changes: 5 additions & 5 deletions apps/worker/src/tasks/url-metadata/utils/fetchPageIcons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export async function fetchPageIcons(

// Try getting icon from link tags first
visit(headNode, { type: "element", tagName: "link" }, (node: Element) => {
const rel = String(node.properties?.rel ?? "");
const href = String(node.properties?.href ?? "");
const rel = String(node.properties?.["rel"] ?? "");
const href = String(node.properties?.["href"] ?? "");
if (!rel.includes("icon")) return;

try {
Expand All @@ -34,11 +34,11 @@ export async function fetchPageIcons(
(node) =>
isElement(node) &&
node.tagName === "link" &&
String(node.properties.rel).includes("manifest"),
String(node.properties["rel"]).includes("manifest"),
);

if (manifestLink?.properties?.href) {
const manifestUrl = new URL(String(manifestLink.properties.href), src);
if (manifestLink?.properties?.["href"]) {
const manifestUrl = new URL(String(manifestLink.properties["href"]), src);
const manifest = await fetchAsBot({
url: manifestUrl,
method: "GET",
Expand Down
1 change: 1 addition & 0 deletions apps/worker/src/tasks/url-metadata/utils/processImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,4 +297,5 @@ export async function processImages(
return result;
}
}
return undefined;
}
2 changes: 1 addition & 1 deletion apps/worker/src/utils/extractLocale.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export function extractLocale(filename: string): string {
const match = filename.match(/index\.([a-z]+)\.md$/);
return match ? match[1] : "en";
return match?.[1] ?? "en";
}
2 changes: 1 addition & 1 deletion packages/bullmq/src/tasks/delete-s3-object.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ afterEach(() => {
});

function jobIdFromCall(callIndex: number): string {
return vi.mocked(createJob).mock.calls[callIndex][1] as string;
return vi.mocked(createJob).mock.calls[callIndex]?.[1] as string;
}

test("reuses the same job id when lastModified is unchanged across calls", async () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/github-api/src/getAuthorGitHubStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ export async function getAuthorGitHubStats(
client: Octokit,
githubLogin: string,
): Promise<AuthorGitHubStats | undefined> {
const userResult = (await client.graphql<Record<string, { id: string }>>(
const userResult = await client.graphql<Record<string, { id: string }>>(
`query($login: String!) { user(login: $login) { id } }`,
{ login: githubLogin },
)) as Record<string, { id: string }>;
);

const userId = userResult?.user?.id;
const userId = userResult?.["user"]?.id;
if (!userId) return undefined;

const response = await client.graphql<StatsResponse>(statsQuery, {
Expand Down
3 changes: 2 additions & 1 deletion packages/post-images/src/fetch-post-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ export async function fetchPostData(
.then((json) => Value.Parse(TagsInfo, json));
const tags = (indexInfo.tags ?? [])
.map((tagId) => tagsJson[tagId])
.filter((tag) => tag?.emoji || (tag?.image && tag.shownWithBranding))
.filter((tag) => !!tag)
.filter((tag) => tag.emoji || (tag.image && tag.shownWithBranding))
.map((tag) => ({
displayName: tag.displayName,
emoji: tag.emoji,
Expand Down
2 changes: 2 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"esModuleInterop": true,
"noImplicitOverride": true,
"noFallthroughCasesInSwitch": true,
"noPropertyAccessFromIndexSignature": true,
"noUncheckedIndexedAccess": true,
"forceConsistentCasingInFileNames": true,
"allowJs": true
},
Expand Down
Loading