Skip to content

Commit

Permalink
Separate get segment api request
Browse files Browse the repository at this point in the history
  • Loading branch information
hanydd committed Sep 14, 2024
1 parent 60b0dbb commit 83db03f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
20 changes: 5 additions & 15 deletions src/content.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as CompileConfig from "../config.json";
import SkipNoticeComponent from "./components/SkipNoticeComponent";
import Config from "./config";
import { isSafari, Keybind, keybindEquals, keybindToString, StorageChangesObject } from "./config/config";
Expand All @@ -13,11 +12,11 @@ import { PlayerButton } from "./render/PlayerButton";
import SkipNotice from "./render/SkipNotice";
import SubmissionNotice from "./render/SubmissionNotice";
import { asyncRequestToServer } from "./requests/requests";
import { getSegmentsByHash } from "./requests/segments";
import { getVideoLabel } from "./requests/videoLabels";
import { setupThumbnailListener, updateAll } from "./thumbnail-utils/thumbnailManagement";
import {
ActionType,
ActionTypes,
Category,
CategorySkipOption,
ChannelIDInfo,
Expand All @@ -43,7 +42,7 @@ import { findValidElement } from "./utils/dom";
import { importTimes } from "./utils/exporter";
import { getErrorMessage, getFormattedTime } from "./utils/formating";
import { GenericUtils } from "./utils/genericUtils";
import { getHash, HashedValue } from "./utils/hash";
import { getHash, getVideoIDHash, HashedValue } from "./utils/hash";
import { logDebug } from "./utils/logger";
import { getControls, getHashParams, getProgressBar, isPlayingPlaylist } from "./utils/pageUtils";
import { getBilibiliVideoID } from "./utils/parseVideoID";
Expand All @@ -58,7 +57,7 @@ import {
getVideo,
getVideoID,
setupVideoModule,
updateFrameRate
updateFrameRate,
} from "./utils/video";
import { openWarningDialog } from "./utils/warnings";

Expand Down Expand Up @@ -1136,17 +1135,8 @@ async function sponsorsLookup(keepOldSubmissions = true, ignoreServerCache = fal
const hashParams = getHashParams();
if (hashParams.requiredSegment) extraRequestData.requiredSegment = hashParams.requiredSegment;

const hashPrefix = (await getHash(getVideoID(), 1)).slice(0, 4) as VideoID & HashedValue;
const response = await asyncRequestToServer(
"GET",
"/api/skipSegments/" + hashPrefix,
{
categories: CompileConfig.categoryList,
actionTypes: ActionTypes,
...extraRequestData,
},
ignoreServerCache
);
const hashPrefix = (await getVideoIDHash(getVideoID())).slice(0, 4) as VideoID & HashedValue;
const response = await getSegmentsByHash(hashPrefix, extraRequestData, ignoreServerCache);

// store last response status
lastResponseStatus = response?.status;
Expand Down
22 changes: 22 additions & 0 deletions src/requests/segments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import * as CompileConfig from "../../config.json";
import { ActionTypes } from "../types";
import { asyncRequestToServer } from "./requests";

export async function getSegmentsByHash(
hashPrefix: string,
extraRequestData: Record<string, unknown>,
ignoreServerCache: boolean
) {
const response = await asyncRequestToServer(
"GET",
"/api/skipSegments/" + hashPrefix,
{
categories: CompileConfig.categoryList,
actionTypes: ActionTypes,
...extraRequestData,
},
ignoreServerCache
);

return response;
}

0 comments on commit 83db03f

Please sign in to comment.