Skip to content

Commit

Permalink
Send data to server when a warning was ignored
Browse files Browse the repository at this point in the history
  • Loading branch information
ajayyy committed Oct 18, 2024
1 parent 35d8e9c commit f09719a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/dataFetching.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { VideoID, getVideo, getVideoID, getYouTubeVideoID } from "../maze-utils/src/video";
import { ThumbnailSubmission, ThumbnailWithRandomTimeResult, fetchVideoMetadata, isLiveSync } from "./thumbnails/thumbnailData";
import { TitleResult, TitleSubmission } from "./titles/titleData";
import { getCurrentPageTitle, TitleResult, TitleSubmission } from "./titles/titleData";
import { FetchResponse, sendRealRequestToCustomServer } from "../maze-utils/src/background-request-proxy";
import { BrandingLocation, BrandingResult, replaceCurrentVideoBranding, updateBrandingForVideo } from "./videoBranding/videoBranding";
import { logError } from "./utils/logger";
Expand All @@ -16,6 +16,7 @@ import { getThumbnailFallbackOption, getThumbnailFallbackOptionFastCheck, should
import { updateSubmitButton } from "./video";
import { sendRequestToServer } from "./utils/requests";
import { thumbnailDataCache } from "./thumbnails/thumbnailDataCache";
import { getAutoWarning } from "./submission/autoWarning";

interface VideoBrandingCacheRecord extends BrandingResult {
lastUsed: number;
Expand Down Expand Up @@ -490,14 +491,17 @@ export async function submitVideoBranding(videoID: VideoID, title: TitleSubmissi
Config.config!.firstThumbnailSubmitted = true;
}

const wasWarned = !!title && !!getAutoWarning(title.title, getCurrentPageTitle() || "");

const result = await sendRequestToServer("POST", "/api/branding", {
userID: Config.config!.userID,
videoID,
title,
thumbnail,
downvote,
autoLock: actAsVip,
videoDuration: getVideo()?.duration
videoDuration: getVideo()?.duration,
wasWarned
});

clearCache(videoID);
Expand Down
4 changes: 2 additions & 2 deletions src/submission/autoWarning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ const autoWarningChecks: AutoWarningCheck[] = [
}
];

function getAutoWarning(title: string, originalTitle: string): { id: string; text: string } | null {
export function getAutoWarning(title: string, originalTitle: string, ignoreShown = false): { id: string; text: string } | null {
for (const check of autoWarningChecks) {
const { found, match } = check.check(title, originalTitle);
if (found && !shownWarnings.includes(check.id)) {
if (found && (ignoreShown || !shownWarnings.includes(check.id))) {
return {
id: check.id,
text: check.error + (match ? `\n\n${chrome.i18n.getMessage("DetectedWord")}${match}` : "")
Expand Down

0 comments on commit f09719a

Please sign in to comment.