Skip to content

Commit

Permalink
Support submitting thumbnails with server-side rendered ads
Browse files Browse the repository at this point in the history
  • Loading branch information
ajayyy committed Sep 5, 2024
1 parent 517550f commit ed82a52
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/submission/ThumbnailComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from "react";
import { drawCenteredToCanvas, renderThumbnail, setupPreRenderedThumbnail } from "../thumbnails/thumbnailRenderer";
import { waitFor } from "../../maze-utils/src"
import { VideoID } from "../../maze-utils/src/video";
import { getCurrentTime, verifyCurrentTime, VideoID } from "../../maze-utils/src/video";
import { ThumbnailSubmission } from "../thumbnails/thumbnailData";
import { logError } from "../utils/logger";
import { isFirefoxOrSafari } from "../../maze-utils/src";
Expand Down Expand Up @@ -80,7 +80,7 @@ export const ThumbnailComponent = (props: ThumbnailComponentProps) => {

if (props.type === ThumbnailType.SpecifiedTime) {
canvasRef.current?.getContext("2d")?.clearRect(0, 0, canvasRef.current?.width, canvasRef.current?.height);
if (props.video.paused && props.time === props.video.currentTime) {
if (props.video.paused && props.time === getCurrentTime()) {
// Skip rendering and just use existing video frame
renderCurrentFrame(props, canvasRef, inRenderingLoop, false, true);
} else {
Expand Down Expand Up @@ -115,11 +115,16 @@ export const ThumbnailComponent = (props: ThumbnailComponentProps) => {
if (submitted) return;
submitted = true;

if (props.type === ThumbnailType.CurrentTime) {
// To handle server-side ads
verifyCurrentTime();
}

props.onClick?.(props.type === ThumbnailType.Original ? {
original: true
} : {
original: false,
timestamp: props.type === ThumbnailType.CurrentTime ? props.video.currentTime : props.time!
timestamp: props.type === ThumbnailType.CurrentTime ? (getCurrentTime() || 0) : props.time!
});
}

Expand Down
7 changes: 6 additions & 1 deletion src/submission/submitButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from "react";
import { createRoot, Root } from "react-dom/client";
import { BrandingResult, replaceCurrentVideoBranding } from "../videoBranding/videoBranding";
import { SubmissionComponent } from "./SubmissionComponent";
import { getVideo, getVideoID, getYouTubeVideoID, isOnMobileYouTube } from "../../maze-utils/src/video";
import { getVideo, getVideoID, getYouTubeVideoID, isCurrentTimeWrong, isOnMobileYouTube } from "../../maze-utils/src/video";
import { log, logError } from "../utils/logger";
import { TitleSubmission } from "../titles/titleData";
import { ThumbnailSubmission } from "../thumbnails/thumbnailData";
Expand Down Expand Up @@ -222,6 +222,11 @@ export class SubmitButton {
alert(chrome.i18n.getMessage("videoIDWrongWhenSubmittingError"));
return false;
}

if (isCurrentTimeWrong()) {
alert(chrome.i18n.getMessage("submissionFailedServerSideAds"));
return false;
}

const result = await submitVideoBranding(getVideoID()!, title, thumbnail, false, actAsVip);

Expand Down

0 comments on commit ed82a52

Please sign in to comment.