Skip to content

Commit

Permalink
Move video label request to request folder
Browse files Browse the repository at this point in the history
  • Loading branch information
hanydd committed Sep 13, 2024
1 parent 4e522c9 commit ef071c4
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/utils/videoLabels.ts → src/requests/videoLabels.ts
Original file line number Diff line number Diff line change
@@ -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();

Expand Down Expand Up @@ -55,7 +55,7 @@ async function getLabelHashBlock(hashPrefix: string): Promise<LabelCacheEntry |
}

export async function getVideoLabel(videoID: VideoID): Promise<Category | null> {
const prefix = (await getHash(videoID, 1)).slice(0, 3);
const prefix = (await getVideoIDHash(videoID)).slice(0, 3);
const result = await getLabelHashBlock(prefix);

if (result) {
Expand Down
2 changes: 1 addition & 1 deletion src/thumbnail-utils/thumbnails.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
await Promise.all(thumbnails.map((t) => labelThumbnail(t as HTMLImageElement)));
Expand Down
4 changes: 2 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/utils/hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ export async function getHash<T extends string>(value: T, times = 5000): Promise

return hashHex as T & HashedValue;
}

export async function getVideoIDHash(videoID: string): Promise<string> {
return getHash(videoID, 1);
}

0 comments on commit ef071c4

Please sign in to comment.