mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2026-01-28 21:30:56 +03:00
Use consistent request url for better caching
This commit is contained in:
Submodule maze-utils updated: 3c7787897e...ab431ec8ba
@@ -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
|
||||||
|
|||||||
@@ -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 };
|
||||||
|
|||||||
@@ -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));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user