Merge branch 'master' of https://github.com/ajayyy/SponsorBlockServer into reWriteAxios

This commit is contained in:
Michael C
2021-09-26 18:08:30 -04:00
7 changed files with 157 additions and 141 deletions

View File

@@ -1,7 +1,7 @@
import { hashPrefixTester } from "../utils/hashPrefixTester";
import { getSegmentsByHash } from "./getSkipSegments";
import { Request, Response } from "express";
import { ActionType, Category, SegmentUUID, VideoIDHash } from "../types/segments.model";
import { ActionType, Category, SegmentUUID, VideoIDHash, Service } from "../types/segments.model";
import { getService } from "../utils/getService";
export async function getSkipSegmentsByHash(req: Request, res: Response): Promise<Response> {
@@ -59,7 +59,7 @@ export async function getSkipSegmentsByHash(req: Request, res: Response): Promis
return res.status(400).send("Bad parameter: requiredSegments (invalid JSON)");
}
const service = getService(req.query.service, req.body.service);
const service: Service = getService(req.query.service, req.body.service);
// filter out none string elements, only flat array with strings is valid
categories = categories.filter((item: any) => typeof item === "string");

View File

@@ -56,7 +56,7 @@ function updateExtensionUsers() {
const chromeExtensionUrl = "https://chrome.google.com/webstore/detail/sponsorblock-for-youtube/mnjggcdmjocbbbhaepdhchncahnbgone";
fetch(mozillaAddonsUrl)
.then(res => res.json())
.then(res => res.json() as Record<string, any>)
.then(data => {
firefoxUsersCache = data.average_daily_users;
fetch(chromeExtensionUrl)

View File

@@ -240,7 +240,7 @@ async function autoModerateSubmission(apiVideoInfo: APIVideoInfo,
&segments=${nbString.substring(0, nbString.length - 1)}`);
if (!response.ok) return false;
const nbPredictions = await response.json();
const nbPredictions = await response.json() as Record<string, any>;
let nbDecision = false;
let predictionIdx = 0; //Keep track because only sponsor categories were submitted
for (let i = 0; i < segments.length; i++) {
@@ -461,8 +461,8 @@ async function updateDataIfVideoDurationChange(videoID: VideoID, service: string
let apiVideoInfo: APIVideoInfo = null;
if (service == Service.YouTube) {
// Don't use cache if we don't know the video duraton, or the client claims that it has changed
apiVideoInfo = await getYouTubeVideoInfo(videoID, !videoDurationParam || videoDurationChanged(videoDurationParam));
// Don't use cache if we don't know the video duration, or the client claims that it has changed
apiVideoInfo = await getYouTubeVideoInfo(videoID, !videoDurationParam || previousSubmissions.length === 0 || videoDurationChanged(videoDurationParam));
}
const apiVideoDuration = apiVideoInfo?.data?.lengthSeconds as VideoDuration;
if (!videoDurationParam || (apiVideoDuration && Math.abs(videoDurationParam - apiVideoDuration) > 2)) {

View File

@@ -30,17 +30,17 @@ export class YouTubeAPI {
const result = await fetch(`${config.newLeafURLs[Math.floor(Math.random() * config.newLeafURLs.length)]}/api/v1/videos/${videoID}`, { method: "GET" });
if (result.ok) {
const data = await result.json();
if (data.error) {
const data = await result.json() as (Record<string, any>);
if (data.error as Record<string, string>) {
Logger.warn(`NewLeaf API Error for ${videoID}: ${data.error}`);
return { err: data.error, data: null };
}
DiskCache.set(cacheKey, JSON.stringify(data))
const apiResult = data as APIVideoData;
DiskCache.set(cacheKey, JSON.stringify(apiResult))
.catch((err: any) => Logger.warn(err))
.then(() => Logger.debug(`YouTube API: video information cache set for: ${videoID}`));
return { err: false, data };
return { err: false, data: apiResult };
} else {
return { err: result.statusText, data: null };
}