From e181c64775d7bec43901e3a88c107ba96a0d54ce Mon Sep 17 00:00:00 2001 From: Ajay Date: Mon, 2 Sep 2024 02:04:32 -0400 Subject: [PATCH] Use consistent request url for better caching --- maze-utils | 2 +- src/content.ts | 12 +++++++++--- src/types.ts | 8 +++++++- src/utils/requests.ts | 10 ++++++---- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/maze-utils b/maze-utils index 3c778789..ab431ec8 160000 --- a/maze-utils +++ b/maze-utils @@ -1 +1 @@ -Subproject commit 3c7787897e1e65cf6b55e76f39c43f4ed081d24e +Subproject commit ab431ec8ba764b4a7a07d2debc91b5903c65db5e diff --git a/src/content.ts b/src/content.ts index b3e1e319..c8cd4879 100644 --- a/src/content.ts +++ b/src/content.ts @@ -1,6 +1,7 @@ import Config from "./config"; import { ActionType, + ActionTypes, Category, CategorySkipOption, ChannelIDInfo, @@ -17,6 +18,7 @@ import { VideoInfo, } from "./types"; import Utils from "./utils"; +import * as CompileConfig from "../config.json"; import PreviewBar, { PreviewBarSegment } from "./js-components/previewBar"; import SkipNotice from "./render/SkipNotice"; import SkipNoticeComponent from "./components/SkipNoticeComponent"; @@ -1145,19 +1147,23 @@ async function sponsorsLookup(keepOldSubmissions = true) { } const hashPrefix = (await getHash(videoID, 1)).slice(0, 4) as VideoID & HashedValue; const response = await asyncRequestToServer('GET', "/api/skipSegments/" + hashPrefix, { - categories, - actionTypes: getEnabledActionTypes(), - userAgent: `${chrome.runtime.id}`, + categories: CompileConfig.categoryList, + actionTypes: ActionTypes, ...extraRequestData + }, { + "X-CLIENT-NAME": `${chrome.runtime.id}/v${chrome.runtime.getManifest().version}` }); // store last response status lastResponseStatus = response?.status; if (response?.ok) { + const enabledActionTypes = getEnabledActionTypes(); + const receivedSegments: SponsorTime[] = JSON.parse(response.responseText) ?.filter((video) => video.videoID === getVideoID()) ?.map((video) => video.segments)?.[0] + ?.filter((segment) => enabledActionTypes.includes(segment.actionType) && categories.includes(segment.category)) ?.map((segment) => ({ ...segment, source: SponsorSourceType.Server diff --git a/src/types.ts b/src/types.ts index fdaee7b8..d8634c91 100644 --- a/src/types.ts +++ b/src/types.ts @@ -56,7 +56,13 @@ export enum ActionType { Poi = "poi" } -export const ActionTypes = [ActionType.Skip, ActionType.Mute]; +export const ActionTypes = [ + ActionType.Skip, + ActionType.Mute, + ActionType.Chapter, + ActionType.Full, + ActionType.Poi +]; export type SegmentUUID = string & { __segmentUUIDBrand: unknown }; export type Category = string & { __categoryBrand: unknown }; diff --git a/src/utils/requests.ts b/src/utils/requests.ts index 8c160eb0..acbde374 100644 --- a/src/utils/requests.ts +++ b/src/utils/requests.ts @@ -9,8 +9,8 @@ import { FetchResponse, sendRequestToCustomServer } from "../../maze-utils/src/b * @param address The address to add to the SponsorBlock server address * @param callback */ -export function asyncRequestToCustomServer(type: string, url: string, data = {}): Promise { - return sendRequestToCustomServer(type, url, data); +export function asyncRequestToCustomServer(type: string, url: string, data = {}, headers = {}): Promise { + return sendRequestToCustomServer(type, url, data, headers); } /** @@ -20,10 +20,12 @@ export function asyncRequestToCustomServer(type: string, url: string, data = {}) * @param address The address to add to the SponsorBlock server address * @param callback */ -export async function asyncRequestToServer(type: string, address: string, data = {}): Promise { +export async function asyncRequestToServer(type: string, address: string, data = {}, headers = {}): Promise { const serverAddress = Config.config.testingServer ? CompileConfig.testingServerAddress : Config.config.serverAddress; - return await (asyncRequestToCustomServer(type, serverAddress + address, data)); + console.log(address, headers) + + return await (asyncRequestToCustomServer(type, serverAddress + address, data, headers)); } /**