replace node-fetch with axios in src

This commit is contained in:
Michael C
2021-09-23 01:21:10 -04:00
parent a23387c877
commit 6433f50edf
10 changed files with 150 additions and 107 deletions

View File

@@ -1,6 +1,6 @@
import {config} from "../config";
import {Logger} from "../utils/logger";
import fetch from "node-fetch";
import axios from "axios";
function getVoteAuthorRaw(submissionCount: number, isVIP: boolean, isOwnSubmission: boolean): string {
if (isOwnSubmission) {
@@ -37,9 +37,10 @@ function dispatchEvent(scope: string, data: Record<string, unknown>): void {
const scopes = webhook.scopes || [];
if (!scopes.includes(scope.toLowerCase())) return;
fetch(webhookURL, {
axios.request({
url: webhookURL,
method: "POST",
body: JSON.stringify(data),
data,
headers: {
"Authorization": authKey,
"Event-Type": scope, // Maybe change this in the future?

View File

@@ -1,8 +1,8 @@
import fetch from "node-fetch";
import {config} from "../config";
import {Logger} from "./logger";
import { APIVideoData, APIVideoInfo } from "../types/youtubeApi.model";
import DiskCache from "./diskCache";
import axios from "axios";
export class YouTubeAPI {
static async listVideos(videoID: string, ignoreCache = false): Promise<APIVideoInfo> {
@@ -27,10 +27,10 @@ export class YouTubeAPI {
if (!config.newLeafURLs || config.newLeafURLs.length <= 0) return {err: "NewLeaf URL not found", data: null};
try {
const result = await fetch(`${config.newLeafURLs[Math.floor(Math.random() * config.newLeafURLs.length)]}/api/v1/videos/${videoID}`, { method: "GET" });
const result = await axios.get(`${config.newLeafURLs[Math.floor(Math.random() * config.newLeafURLs.length)]}/api/v1/videos/${videoID}`);
if (result.ok) {
const data = await result.json();
if (result.status === 200) {
const data = result.data;
if (data.error) {
Logger.warn(`NewLeaf API Error for ${videoID}: ${data.error}`);
return { err: data.error, data: null };