Skip to content

Commit

Permalink
Use consistent request url for better caching
Browse files Browse the repository at this point in the history
  • Loading branch information
ajayyy committed Sep 2, 2024
1 parent ac9b2d1 commit e181c64
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion maze-utils
12 changes: 9 additions & 3 deletions src/content.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Config from "./config";
import {
ActionType,
ActionTypes,
Category,
CategorySkipOption,
ChannelIDInfo,
Expand All @@ -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";
Expand Down Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
10 changes: 6 additions & 4 deletions src/utils/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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));
}

/**
Expand Down

0 comments on commit e181c64

Please sign in to comment.