mirror of
https://github.com/spacebarchat/server.git
synced 2026-08-28 18:08:16 +00:00
Update some patches, switch to node-fetch-commonjs, more updates
This commit is contained in:
committed by
Rory&
parent
a2ffc536aa
commit
168758924c
@@ -20,7 +20,7 @@ import { Config, JimpType } from "@spacebar/util";
|
||||
import { Request, Response } from "express";
|
||||
import { yellow } from "picocolors";
|
||||
import crypto from "crypto";
|
||||
import fetch from "node-fetch";
|
||||
import fetch from "node-fetch-commonjs";
|
||||
|
||||
let sharp: undefined | false | { default: typeof import("sharp") } = undefined;
|
||||
|
||||
|
||||
@@ -17,9 +17,14 @@
|
||||
*/
|
||||
|
||||
import { route } from "@spacebar/api";
|
||||
import { TenorMediaTypes, getGifApiKey, parseGifResult } from "@spacebar/util";
|
||||
import {
|
||||
TenorMediaTypes,
|
||||
getGifApiKey,
|
||||
parseGifResult,
|
||||
TenorGif,
|
||||
} from "@spacebar/util";
|
||||
import { Request, Response, Router } from "express";
|
||||
import fetch from "node-fetch";
|
||||
import fetch from "node-fetch-commonjs";
|
||||
import { ProxyAgent } from "proxy-agent";
|
||||
|
||||
const router = Router();
|
||||
@@ -68,7 +73,7 @@ router.get(
|
||||
},
|
||||
);
|
||||
|
||||
const { results } = await response.json();
|
||||
const { results } = (await response.json()) as { results: TenorGif[] };
|
||||
|
||||
res.json(results.map(parseGifResult)).status(200);
|
||||
},
|
||||
|
||||
@@ -17,9 +17,14 @@
|
||||
*/
|
||||
|
||||
import { route } from "@spacebar/api";
|
||||
import { TenorMediaTypes, getGifApiKey, parseGifResult } from "@spacebar/util";
|
||||
import {
|
||||
TenorMediaTypes,
|
||||
getGifApiKey,
|
||||
parseGifResult,
|
||||
TenorGif,
|
||||
} from "@spacebar/util";
|
||||
import { Request, Response, Router } from "express";
|
||||
import fetch from "node-fetch";
|
||||
import fetch from "node-fetch-commonjs";
|
||||
import { ProxyAgent } from "proxy-agent";
|
||||
|
||||
const router = Router();
|
||||
@@ -63,7 +68,7 @@ router.get(
|
||||
},
|
||||
);
|
||||
|
||||
const { results } = await response.json();
|
||||
const { results } = (await response.json()) as { results: TenorGif[] };
|
||||
|
||||
res.json(results.map(parseGifResult)).status(200);
|
||||
},
|
||||
|
||||
@@ -24,7 +24,7 @@ import {
|
||||
parseGifResult,
|
||||
} from "@spacebar/util";
|
||||
import { Request, Response, Router } from "express";
|
||||
import fetch from "node-fetch";
|
||||
import fetch from "node-fetch-commonjs";
|
||||
import { ProxyAgent } from "proxy-agent";
|
||||
|
||||
const router = Router();
|
||||
|
||||
@@ -28,7 +28,7 @@ import {
|
||||
Template,
|
||||
} from "@spacebar/util";
|
||||
import { Request, Response, Router } from "express";
|
||||
import fetch from "node-fetch";
|
||||
import fetch from "node-fetch-commonjs";
|
||||
const router: Router = Router();
|
||||
|
||||
router.get(
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
},
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user