Use consistent request url for better caching

This commit is contained in:
Ajay 2024-09-02 02:04:32 -04:00
parent ac9b2d12fe
commit e181c64775
4 changed files with 23 additions and 9 deletions

@ -1 +1 @@
Subproject commit 3c7787897e1e65cf6b55e76f39c43f4ed081d24e Subproject commit ab431ec8ba764b4a7a07d2debc91b5903c65db5e

View file

@ -1,6 +1,7 @@
import Config from "./config"; import Config from "./config";
import { import {
ActionType, ActionType,
ActionTypes,
Category, Category,
CategorySkipOption, CategorySkipOption,
ChannelIDInfo, ChannelIDInfo,
@ -17,6 +18,7 @@ import {
VideoInfo, VideoInfo,
} from "./types"; } from "./types";
import Utils from "./utils"; import Utils from "./utils";
import * as CompileConfig from "../config.json";
import PreviewBar, { PreviewBarSegment } from "./js-components/previewBar"; import PreviewBar, { PreviewBarSegment } from "./js-components/previewBar";
import SkipNotice from "./render/SkipNotice"; import SkipNotice from "./render/SkipNotice";
import SkipNoticeComponent from "./components/SkipNoticeComponent"; 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 hashPrefix = (await getHash(videoID, 1)).slice(0, 4) as VideoID & HashedValue;
const response = await asyncRequestToServer('GET', "/api/skipSegments/" + hashPrefix, { const response = await asyncRequestToServer('GET', "/api/skipSegments/" + hashPrefix, {
categories, categories: CompileConfig.categoryList,
actionTypes: getEnabledActionTypes(), actionTypes: ActionTypes,
userAgent: `${chrome.runtime.id}`,
...extraRequestData ...extraRequestData
}, {
"X-CLIENT-NAME": `${chrome.runtime.id}/v${chrome.runtime.getManifest().version}`
}); });
// store last response status // store last response status
lastResponseStatus = response?.status; lastResponseStatus = response?.status;
if (response?.ok) { if (response?.ok) {
const enabledActionTypes = getEnabledActionTypes();
const receivedSegments: SponsorTime[] = JSON.parse(response.responseText) const receivedSegments: SponsorTime[] = JSON.parse(response.responseText)
?.filter((video) => video.videoID === getVideoID()) ?.filter((video) => video.videoID === getVideoID())
?.map((video) => video.segments)?.[0] ?.map((video) => video.segments)?.[0]
?.filter((segment) => enabledActionTypes.includes(segment.actionType) && categories.includes(segment.category))
?.map((segment) => ({ ?.map((segment) => ({
...segment, ...segment,
source: SponsorSourceType.Server source: SponsorSourceType.Server

View file

@ -56,7 +56,13 @@ export enum ActionType {
Poi = "poi" 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 SegmentUUID = string & { __segmentUUIDBrand: unknown };
export type Category = string & { __categoryBrand: unknown }; export type Category = string & { __categoryBrand: unknown };

View file

@ -9,8 +9,8 @@ import { FetchResponse, sendRequestToCustomServer } from "../../maze-utils/src/b
* @param address The address to add to the SponsorBlock server address * @param address The address to add to the SponsorBlock server address
* @param callback * @param callback
*/ */
export function asyncRequestToCustomServer(type: string, url: string, data = {}): Promise<FetchResponse> { export function asyncRequestToCustomServer(type: string, url: string, data = {}, headers = {}): Promise<FetchResponse> {
return sendRequestToCustomServer(type, url, data); 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 address The address to add to the SponsorBlock server address
* @param callback * @param callback
*/ */
export async function asyncRequestToServer(type: string, address: string, data = {}): Promise<FetchResponse> { export async function asyncRequestToServer(type: string, address: string, data = {}, headers = {}): Promise<FetchResponse> {
const serverAddress = Config.config.testingServer ? CompileConfig.testingServerAddress : Config.config.serverAddress; 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));
} }
/** /**