From ef071c494b224417523ab50363a2ecdae5da1720 Mon Sep 17 00:00:00 2001 From: hanyd Date: Fri, 13 Sep 2024 23:30:58 +0800 Subject: [PATCH] Move video label request to request folder --- src/{utils => requests}/videoLabels.ts | 8 ++++---- src/thumbnail-utils/thumbnails.ts | 2 +- src/utils.ts | 4 ++-- src/utils/hash.ts | 4 ++++ 4 files changed, 11 insertions(+), 7 deletions(-) rename src/{utils => requests}/videoLabels.ts (90%) diff --git a/src/utils/videoLabels.ts b/src/requests/videoLabels.ts similarity index 90% rename from src/utils/videoLabels.ts rename to src/requests/videoLabels.ts index 9e19dc26..41dacadf 100644 --- a/src/utils/videoLabels.ts +++ b/src/requests/videoLabels.ts @@ -1,8 +1,8 @@ -import { asyncRequestToServer } from "../requests/requests"; import { Category, CategorySkipOption, VideoID } from "../types"; import Utils from "../utils"; -import { getHash } from "../utils/hash"; -import { logWarn } from "./logger"; +import { getVideoIDHash } from "../utils/hash"; +import { logWarn } from "../utils/logger"; +import { asyncRequestToServer } from "./requests"; const utils = new Utils(); @@ -55,7 +55,7 @@ async function getLabelHashBlock(hashPrefix: string): Promise { - const prefix = (await getHash(videoID, 1)).slice(0, 3); + const prefix = (await getVideoIDHash(videoID)).slice(0, 3); const result = await getLabelHashBlock(prefix); if (result) { diff --git a/src/thumbnail-utils/thumbnails.ts b/src/thumbnail-utils/thumbnails.ts index a49a2485..de2d3322 100644 --- a/src/thumbnail-utils/thumbnails.ts +++ b/src/thumbnail-utils/thumbnails.ts @@ -1,7 +1,7 @@ import Config from "../config"; import { waitFor } from "../utils/"; import { getBvIDFromURL } from "../utils/parseVideoID"; -import { getVideoLabel } from "../utils/videoLabels"; +import { getVideoLabel } from "../requests/videoLabels"; export async function labelThumbnails(thumbnails: HTMLElement[]): Promise { await Promise.all(thumbnails.map((t) => labelThumbnail(t as HTMLImageElement))); diff --git a/src/utils.ts b/src/utils.ts index 48e15f40..b4840299 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -11,7 +11,7 @@ import { import { isSafari } from "./config/config"; import { findValidElementFromSelector } from "./utils/dom"; -import { getHash, HashedValue } from "./utils/hash"; +import { getHash, getVideoIDHash, HashedValue } from "./utils/hash"; export default class Utils { // Contains functions needed from the background script @@ -245,7 +245,7 @@ export default class Utils { ) return; - const hashedVideoID = (await getHash(videoID, 1)).slice(0, 4) as VideoID & HashedValue; + const hashedVideoID = (await getVideoIDHash(videoID)).slice(0, 4) as VideoID & HashedValue; const UUIDHash = await getHash(segmentUUID, 1); const allDownvotes = Config.local.downvotedSegments; diff --git a/src/utils/hash.ts b/src/utils/hash.ts index d5002d04..8f930bf0 100644 --- a/src/utils/hash.ts +++ b/src/utils/hash.ts @@ -26,3 +26,7 @@ export async function getHash(value: T, times = 5000): Promise return hashHex as T & HashedValue; } + +export async function getVideoIDHash(videoID: string): Promise { + return getHash(videoID, 1); +}