Skip to content

Commit

Permalink
resolve lint error
Browse files Browse the repository at this point in the history
  • Loading branch information
Aliiiu committed Jan 9, 2025
1 parent d28d7e1 commit f631e66
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 59 deletions.
107 changes: 53 additions & 54 deletions src/lib/twitter-api-client.ts
Original file line number Diff line number Diff line change
@@ -1,70 +1,69 @@
import crypto from "node:crypto";
import OAuth from "oauth-1.0a";

import crypto from 'crypto'
import OAuth from 'oauth-1.0a'

type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'
type HttpMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH";

interface IDiscordLogger {
log(data: DiscordLogData): Promise<void>
log(data: DiscordLogData): Promise<void>;
}

type DiscordLogData = {
message: string
title?: string
color?: number
}
message: string;
title?: string;
color?: number;
};

export const oauth = new OAuth({
consumer: {
key: process.env.TWITTER_CONSUMER_KEY ?? '',
secret: process.env.TWITTER_CONSUMER_SECRET ?? '',
},
signature_method: 'HMAC-SHA1',
hash_function: (base_string, key) => {
return crypto.createHmac('sha1', key).update(base_string).digest('base64')
},
})
consumer: {
key: process.env.TWITTER_CONSUMER_KEY ?? "",
secret: process.env.TWITTER_CONSUMER_SECRET ?? "",
},
signature_method: "HMAC-SHA1",
hash_function: (base_string, key) => {
return crypto.createHmac("sha1", key).update(base_string).digest("base64");
},
});

const twitterAuthConfig = {
key: process.env.TWITTER_ACCESS_TOKEN ?? '',
secret: process.env.TWITTER_ACCESS_TOKEN_SECRET ?? '',
}
key: process.env.TWITTER_ACCESS_TOKEN ?? "",
secret: process.env.TWITTER_ACCESS_TOKEN_SECRET ?? "",
};

export async function sendTwitterApiRequest(
url: string,
method: HttpMethod,
logger?: IDiscordLogger,
body?: string,
url: string,
method: HttpMethod,
logger?: IDiscordLogger,
body?: string,
): Promise<Response> {
const oauth_headers = oauth.toHeader(
oauth.authorize(
{
url,
method,
},
twitterAuthConfig,
),
)
const oauth_headers = oauth.toHeader(
oauth.authorize(
{
url,
method,
},
twitterAuthConfig,
),
);

const response = await fetch(url, {
method,
headers: {
...oauth_headers,
'Content-Type': 'application/json',
},
body,
})
const response = await fetch(url, {
method,
headers: {
...oauth_headers,
"Content-Type": "application/json",
},
body,
});

if (!response.ok) {
const errorBody = await response.text()
logger?.log({
message: `🚨 HTTP error! status: ${response.status} ${response.statusText}. Body: ${errorBody}`,
title: 'Twitter Authentication: makeAuthenticatedRequest',
})
throw new Error(
`HTTP error! status: ${response.status} ${response.statusText}. Body: ${errorBody}`,
)
}
if (!response.ok) {
const errorBody = await response.text();
logger?.log({
message: `🚨 HTTP error! status: ${response.status} ${response.statusText}. Body: ${errorBody}`,
title: "Twitter Authentication: makeAuthenticatedRequest",
});
throw new Error(
`HTTP error! status: ${response.status} ${response.statusText}. Body: ${errorBody}`,
);
}

return response
}
return response;
}
14 changes: 9 additions & 5 deletions src/lib/wiki-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
MediaType,
type MetaData,
Tag,
Wiki,
} from "../schema";

// ===============================
Expand Down Expand Up @@ -103,12 +104,15 @@ export function isMediaContentAndCountValid(media: Media[]): boolean {
// ===============================
// Wiki-specific validation helpers
// ===============================
export function isEventWikiValid(wiki: any): boolean {
if (wiki.tags.some((tag: any) => tag.id === "Events")) {
export function isEventWikiValid(wiki: {
tags: { id: string }[];
metadata: { id: string; value: string }[];
events: unknown[];
}): boolean {
if (wiki.tags.some((tag) => tag.id === "Events")) {
const referencesData =
wiki.metadata.find(
(meta: any) => meta.id === CommonMetaIds.Enum.references,
)?.value || "[]";
wiki.metadata.find((meta) => meta.id === CommonMetaIds.Enum.references)
?.value || "[]";
const references: { description: string }[] = JSON.parse(
referencesData,
) as { description: string }[];
Expand Down

0 comments on commit f631e66

Please sign in to comment.