aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAjay <[email protected]>2024-09-02 02:04:32 -0400
committerAjay <[email protected]>2024-09-02 02:04:32 -0400
commite181c64775d7bec43901e3a88c107ba96a0d54ce (patch)
treee83569e032e744456e898116d64e6b032024b001
parentac9b2d12fe63537a213b7bba5205c2f039e5e251 (diff)
downloadSponsorBlock-e181c64775d7bec43901e3a88c107ba96a0d54ce.tar.gz
SponsorBlock-e181c64775d7bec43901e3a88c107ba96a0d54ce.zip
Use consistent request url for better caching
m---------maze-utils0
-rw-r--r--src/content.ts12
-rw-r--r--src/types.ts8
-rw-r--r--src/utils/requests.ts10
4 files changed, 22 insertions, 8 deletions
diff --git a/maze-utils b/maze-utils
-Subproject 3c7787897e1e65cf6b55e76f39c43f4ed081d24
+Subproject ab431ec8ba764b4a7a07d2debc91b5903c65db5
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<FetchResponse> {
- return sendRequestToCustomServer(type, url, data);
+export function asyncRequestToCustomServer(type: string, url: string, data = {}, headers = {}): Promise<FetchResponse> {
+ 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<FetchResponse> {
+export async function asyncRequestToServer(type: string, address: string, data = {}, headers = {}): Promise<FetchResponse> {
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));
}
/**