summary refs log tree commit diff
path: root/src/api/util
diff options
context:
space:
mode:
authorEmma [it/its]@Rory& <root@rory.gay>2024-10-15 12:20:41 +0200
committerRory& <root@rory.gay>2024-10-28 00:32:15 +0100
commit168758924ccc62c8aeef7b5737ca60c1b6f678a7 (patch)
tree5dbc75eba6f8966ba91fda2f2f388df2ceaff7fe /src/api/util
parentMore NPM updates (diff)
downloadserver-ts-168758924ccc62c8aeef7b5737ca60c1b6f678a7.tar.xz
Update some patches, switch to node-fetch-commonjs, more updates
Diffstat (limited to 'src/api/util')
-rw-r--r--src/api/util/handlers/Message.ts2
-rw-r--r--src/api/util/utility/EmbedHandlers.ts30
-rw-r--r--src/api/util/utility/captcha.ts2
-rw-r--r--src/api/util/utility/ipAddress.ts4
4 files changed, 29 insertions, 9 deletions
diff --git a/src/api/util/handlers/Message.ts b/src/api/util/handlers/Message.ts

index f037417a..1733f7cb 100644 --- a/src/api/util/handlers/Message.ts +++ b/src/api/util/handlers/Message.ts
@@ -48,7 +48,7 @@ import { } from "@spacebar/util"; import { HTTPError } from "lambert-server"; import { In } from "typeorm"; -import fetch from "node-fetch"; +import fetch from "node-fetch-commonjs"; const allow_empty = false; // TODO: check webhook, application, system author, stickers // TODO: embed gifs/videos/images diff --git a/src/api/util/utility/EmbedHandlers.ts b/src/api/util/utility/EmbedHandlers.ts
index 0f1e88a5..450d9d7e 100644 --- a/src/api/util/utility/EmbedHandlers.ts +++ b/src/api/util/utility/EmbedHandlers.ts
@@ -19,7 +19,7 @@ import { Config, Embed, EmbedImage, EmbedType } from "@spacebar/util"; import * as cheerio from "cheerio"; import crypto from "crypto"; -import fetch, { RequestInit } from "node-fetch"; +import fetch, { RequestInit } from "node-fetch-commonjs"; import { yellow } from "picocolors"; import probe from "probe-image-size"; @@ -221,7 +221,7 @@ export const EmbedHandlers: { ? { name: metas.site_name, url: url.origin, - } + } : undefined, }; }, @@ -269,7 +269,27 @@ export const EmbedHandlers: { authorization: `Bearer ${token}`, }, }); - const json = await response.json(); + const json = (await response.json()) as { + errors?: never[]; + includes: { + users: { + profile_image_url: string; + username: string; + name: string; + }[]; + media: { + type: string; + width: number; + height: number; + url: string; + }[]; + }; + data: { + text: string; + created_at: string; + public_metrics: { like_count: number; retweet_count: number }; + }; + }; if (json.errors) return null; const author = json.includes.users[0]; const text = json.data.text; @@ -508,7 +528,7 @@ export const EmbedHandlers: { ? { name: metas.author, // TODO: author channel url - } + } : undefined, }; }, @@ -533,7 +553,7 @@ export const EmbedHandlers: { footer: hoverText ? { text: hoverText, - } + } : undefined, }; }, diff --git a/src/api/util/utility/captcha.ts b/src/api/util/utility/captcha.ts
index db1b7957..3c0ac766 100644 --- a/src/api/util/utility/captcha.ts +++ b/src/api/util/utility/captcha.ts
@@ -17,7 +17,7 @@ */ import { Config } from "@spacebar/util"; -import fetch from "node-fetch"; +import fetch from "node-fetch-commonjs"; export interface hcaptchaResponse { success: boolean; diff --git a/src/api/util/utility/ipAddress.ts b/src/api/util/utility/ipAddress.ts
index c51daf6c..c19c7c35 100644 --- a/src/api/util/utility/ipAddress.ts +++ b/src/api/util/utility/ipAddress.ts
@@ -19,7 +19,7 @@ import { Config } from "@spacebar/util"; import { Request } from "express"; // use ipdata package instead of simple fetch because of integrated caching -import fetch from "node-fetch"; +import fetch from "node-fetch-commonjs"; const exampleData = { ip: "", @@ -85,7 +85,7 @@ export async function IPAnalysis(ip: string): Promise<typeof exampleData> { return ( await fetch(`https://api.ipdata.co/${ip}?api-key=${ipdataApiKey}`) - ).json(); + ).json() as Promise<typeof exampleData>; } export function isProxy(data: typeof exampleData) {