mirror of
https://github.com/spacebarchat/server.git
synced 2026-05-25 20:44:59 +00:00
Drop node-fetch-commonjs, proxy-agent as deprecated
This commit is contained in:
Binary file not shown.
Generated
BIN
Binary file not shown.
@@ -55,7 +55,6 @@
|
||||
"@types/multer": "^2.0.0",
|
||||
"@types/murmurhash-js": "^1.0.6",
|
||||
"@types/node": "^24.10.1",
|
||||
"@types/node-fetch": "^2.6.13",
|
||||
"@types/nodemailer": "^7.0.4",
|
||||
"@types/probe-image-size": "^7.2.5",
|
||||
"@types/sharp": "^0.31.1",
|
||||
@@ -104,11 +103,9 @@
|
||||
"multer": "^2.0.2",
|
||||
"murmurhash-js": "^1.0.0",
|
||||
"node-2fa": "^2.0.3",
|
||||
"node-fetch-commonjs": "^3.3.2",
|
||||
"pg": "^8.16.3",
|
||||
"picocolors": "^1.1.1",
|
||||
"probe-image-size": "^7.2.3",
|
||||
"proxy-agent": "^6.5.0",
|
||||
"reflect-metadata": "^0.2.2",
|
||||
"sqlite3": "^5.1.7",
|
||||
"tslib": "^2.8.1",
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
const fetch = require("node-fetch");
|
||||
const ENDPOINT = process.env.API || "http://localhost:3001";
|
||||
|
||||
async function main() {
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
*/
|
||||
|
||||
require("dotenv").config({ quiet: true });
|
||||
const fetch = require("node-fetch");
|
||||
const count = Number(process.env.COUNT) || 50;
|
||||
const endpoint = process.env.API || "http://localhost:3001";
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ import { Config, JimpType } from "@spacebar/util";
|
||||
import { Request, Response } from "express";
|
||||
import { yellow } from "picocolors";
|
||||
import crypto from "crypto";
|
||||
import fetch from "node-fetch-commonjs";
|
||||
|
||||
let sharp: undefined | false | { default: typeof import("sharp") } = undefined;
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@ import {
|
||||
} from "@spacebar/util";
|
||||
import { Request, Response, Router } from "express";
|
||||
import { CloudAttachment } from "@spacebar/util";
|
||||
import fetch from "node-fetch-commonjs";
|
||||
import { UploadAttachmentRequestSchema, UploadAttachmentResponseSchema } from "@spacebar/schemas"
|
||||
|
||||
const router: Router = Router({ mergeParams: true });
|
||||
|
||||
@@ -22,8 +22,6 @@ import {
|
||||
parseGifResult,
|
||||
} from "@spacebar/util";
|
||||
import { Request, Response, Router } from "express";
|
||||
import fetch from "node-fetch-commonjs";
|
||||
import { ProxyAgent } from "proxy-agent";
|
||||
import http from "http";
|
||||
import { TenorGif, TenorMediaTypes } from "@spacebar/schemas"
|
||||
|
||||
@@ -62,12 +60,9 @@ router.get(
|
||||
|
||||
const apiKey = getGifApiKey();
|
||||
|
||||
const agent = new ProxyAgent();
|
||||
|
||||
const response = await fetch(
|
||||
`https://g.tenor.com/v1/search?q=${q}&media_format=${media_format}&locale=${locale}&key=${apiKey}`,
|
||||
{
|
||||
agent: agent as http.Agent,
|
||||
method: "get",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
},
|
||||
|
||||
@@ -22,9 +22,6 @@ import {
|
||||
parseGifResult,
|
||||
} from "@spacebar/util";
|
||||
import { Request, Response, Router } from "express";
|
||||
import fetch from "node-fetch-commonjs";
|
||||
import { ProxyAgent } from "proxy-agent";
|
||||
import http from "http";
|
||||
import { TenorGif, TenorMediaTypes } from "@spacebar/schemas"
|
||||
|
||||
const router = Router({ mergeParams: true });
|
||||
@@ -57,12 +54,9 @@ router.get(
|
||||
|
||||
const apiKey = getGifApiKey();
|
||||
|
||||
const agent = new ProxyAgent();
|
||||
|
||||
const response = await fetch(
|
||||
`https://g.tenor.com/v1/trending?media_format=${media_format}&locale=${locale}&key=${apiKey}`,
|
||||
{
|
||||
agent: agent as http.Agent,
|
||||
method: "get",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
},
|
||||
|
||||
@@ -22,9 +22,6 @@ import {
|
||||
parseGifResult,
|
||||
} from "@spacebar/util";
|
||||
import { Request, Response, Router } from "express";
|
||||
import fetch from "node-fetch-commonjs";
|
||||
import { ProxyAgent } from "proxy-agent";
|
||||
import http from "http";
|
||||
import { TenorCategoriesResults, TenorTrendingResults } from "@spacebar/schemas"
|
||||
|
||||
const router = Router({ mergeParams: true });
|
||||
@@ -52,13 +49,10 @@ router.get(
|
||||
|
||||
const apiKey = getGifApiKey();
|
||||
|
||||
const agent = new ProxyAgent();
|
||||
|
||||
const [responseSource, trendGifSource] = await Promise.all([
|
||||
fetch(
|
||||
`https://g.tenor.com/v1/categories?locale=${locale}&key=${apiKey}`,
|
||||
{
|
||||
agent: agent as http.Agent,
|
||||
method: "get",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
},
|
||||
@@ -66,7 +60,6 @@ router.get(
|
||||
fetch(
|
||||
`https://g.tenor.com/v1/trending?locale=${locale}&key=${apiKey}`,
|
||||
{
|
||||
agent: agent as http.Agent,
|
||||
method: "get",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
},
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
import { route } from "@spacebar/api";
|
||||
import { Config, DiscordApiErrors, Guild, Member, Template } from "@spacebar/util";
|
||||
import { Request, Response, Router } from "express";
|
||||
import fetch from "node-fetch-commonjs";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { GuildTemplateCreateSchema } from "@spacebar/schemas"
|
||||
|
||||
|
||||
@@ -50,7 +50,6 @@ import {
|
||||
} from "@spacebar/util";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { In, Or, Equal, IsNull } from "typeorm";
|
||||
import fetch from "node-fetch-commonjs";
|
||||
import { ChannelType, Embed, EmbedType, MessageCreateAttachment, MessageCreateCloudAttachment, MessageCreateSchema, MessageType, Reaction } from "@spacebar/schemas";
|
||||
const allow_empty = false;
|
||||
// TODO: check webhook, application, system author, stickers
|
||||
@@ -206,7 +205,7 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> {
|
||||
}
|
||||
if (opts.avatar_url) {
|
||||
const avatarData = await fetch(opts.avatar_url);
|
||||
const base64 = await avatarData.buffer().then((x) => x.toString("base64"));
|
||||
const base64 = await avatarData.text().then((x) => btoa(x));
|
||||
|
||||
const dataUri = "data:" + avatarData.headers.get("content-type") + ";base64," + base64;
|
||||
|
||||
|
||||
@@ -20,19 +20,16 @@ import { Config }from "@spacebar/util";
|
||||
import { Embed, EmbedImage, EmbedType } from "@spacebar/schemas";
|
||||
import * as cheerio from "cheerio";
|
||||
import crypto from "crypto";
|
||||
import fetch, { RequestInit } from "node-fetch-commonjs";
|
||||
import { yellow } from "picocolors";
|
||||
import probe from "probe-image-size";
|
||||
|
||||
export const DEFAULT_FETCH_OPTIONS: RequestInit = {
|
||||
redirect: "follow",
|
||||
follow: 1,
|
||||
headers: {
|
||||
"user-agent":
|
||||
"Mozilla/5.0 (compatible; Spacebar/1.0; +https://github.com/spacebarchat/server)",
|
||||
},
|
||||
// size: 1024 * 1024 * 5, // grabbed from config later
|
||||
compress: true,
|
||||
method: "GET",
|
||||
};
|
||||
|
||||
@@ -130,10 +127,16 @@ export const getMetaDescriptions = (text: string) => {
|
||||
|
||||
const doFetch = async (url: URL) => {
|
||||
try {
|
||||
return await fetch(url, {
|
||||
const res = await fetch(url, {
|
||||
...DEFAULT_FETCH_OPTIONS,
|
||||
size: Config.get().limits.message.maxEmbedDownloadSize,
|
||||
});
|
||||
if (res.headers.get("content-length")) {
|
||||
const contentLength = parseInt(res.headers.get("content-length")!);
|
||||
if (Config.get().limits.message.maxEmbedDownloadSize && contentLength > Config.get().limits.message.maxEmbedDownloadSize) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
*/
|
||||
|
||||
import { Config } from "@spacebar/util";
|
||||
import fetch from "node-fetch-commonjs";
|
||||
|
||||
export interface hcaptchaResponse {
|
||||
success: boolean;
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
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-commonjs";
|
||||
|
||||
const exampleData = {
|
||||
ip: "",
|
||||
|
||||
@@ -16,12 +16,9 @@
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import fetch from "node-fetch-commonjs";
|
||||
import { ProxyAgent } from "proxy-agent";
|
||||
import readline from "readline";
|
||||
import fs from "fs/promises";
|
||||
import path from "path";
|
||||
import http from "http";
|
||||
|
||||
const rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
@@ -74,9 +71,8 @@ async function download(url: string, dir: string) {
|
||||
try {
|
||||
// TODO: use file stream instead of buffer (to prevent crash because of high memory usage for big files)
|
||||
// TODO check file hash
|
||||
const agent = new ProxyAgent();
|
||||
const response = await fetch(url, { agent: agent as http.Agent });
|
||||
const buffer = await response.buffer();
|
||||
const response = await fetch(url);
|
||||
const buffer = await response.bytes();
|
||||
const tempDir = await fs.mkdtemp("spacebar");
|
||||
await fs.writeFile(path.join(tempDir, "Spacebar.zip"), buffer);
|
||||
} catch (error) {
|
||||
@@ -97,8 +93,7 @@ async function getCurrentVersion(dir: string) {
|
||||
|
||||
async function getLatestVersion(url: string) {
|
||||
try {
|
||||
const agent = new ProxyAgent();
|
||||
const response = await fetch(url, { agent: agent as http.Agent });
|
||||
const response = await fetch(url);
|
||||
const content = (await response.json()) as { version: string };
|
||||
return content.version;
|
||||
} catch (error) {
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
import FormData from "form-data";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import fetch from "node-fetch-commonjs";
|
||||
import { Attachment } from "../entities";
|
||||
import { Config } from "./Config";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user