Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testnets #142

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/app/[pohid]/claim/Video.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ import { IS_IOS } from "utils/media";
import { useAccount } from "wagmi";
import { MediaState } from "./Form";

const ALLOWED_VIDEO_TYPES = [
"video/webm",
"video/mp4",
"video/avi",
"video/mov",
];
const MIN_DIMS = { width: 352, height: 352 }; // PXs
//const MAX_DURATION = 20; // Seconds
//const MAX_SIZE = 7; // Megabytes
Expand All @@ -22,6 +28,8 @@ const ERROR_MSG = {
duration: `Video is too long. Maximum allowed duration is ${MAX_DURATION} seconds long`,
dimensions: `Video dimensions are too small. Minimum dimensions are ${MIN_DIMS.width}px by ${MIN_DIMS.height}px`,
size: `Video is oversized. Maximum allowed size is ${MAX_SIZE}mb`,
fileType: `Unsupported video format. Please use ${ALLOWED_VIDEO_TYPES.map((t) => t.split("/")[1]).join(", ")}`,
unexpected: "Unexpected error. Check format/codecs used.",
};
interface PhotoProps {
advance: () => void;
Expand Down Expand Up @@ -142,6 +150,14 @@ function VideoStep({ advance, video$, isRenewal, videoError }: PhotoProps) {
onDrop={async (received) => {
try {
const file = received[0];
if (!ALLOWED_VIDEO_TYPES.includes(file.type)) {
const msg =
"Uploaded file type: " +
file.type.split("/")[1] +
". ".concat(ERROR_MSG.fileType);
videoError(msg);
return console.error(msg);
}
Comment on lines +153 to +160
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enhance file type validation robustness.

The current validation logic could be improved for better maintainability and reliability:

- if (!ALLOWED_VIDEO_TYPES.includes(file.type)) {
-   const msg =
-     "Uploaded file type: " +
-     file.type.split("/")[1] +
-     ". ".concat(ERROR_MSG.fileType);
-   videoError(msg);
-   return console.error(msg);
- }
+ const fileType = file.type.toLowerCase();
+ if (!ALLOWED_VIDEO_TYPES.map(t => t.toLowerCase()).includes(fileType)) {
+   const msg = `Uploaded file type: ${fileType.split("/")[1]}. ${ERROR_MSG.fileType}`;
+   videoError(msg);
+   return console.error(msg);
+ }

This change:

  1. Makes the validation case-insensitive
  2. Uses template literals for better readability
  3. Simplifies the error message construction
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (!ALLOWED_VIDEO_TYPES.includes(file.type)) {
const msg =
"Uploaded file type: " +
file.type.split("/")[1] +
". ".concat(ERROR_MSG.fileType);
videoError(msg);
return console.error(msg);
}
const fileType = file.type.toLowerCase();
if (!ALLOWED_VIDEO_TYPES.map(t => t.toLowerCase()).includes(fileType)) {
const msg = `Uploaded file type: ${fileType.split("/")[1]}. ${ERROR_MSG.fileType}`;
videoError(msg);
return console.error(msg);
}

const blob = new Blob([file], { type: file.type });
const uri = URL.createObjectURL(blob);

Expand All @@ -165,7 +181,7 @@ function VideoStep({ advance, video$, isRenewal, videoError }: PhotoProps) {
video$.set({ uri, content: blob });
});
} catch (error: any) {
videoError("Unexpected error. Check format/codecs used.");
videoError(ERROR_MSG.unexpected);
return console.error(error);
}
Comment on lines +184 to 186
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Improve error handling and debugging.

While using a generic error message for users is good, we should preserve error details for debugging:

- videoError(ERROR_MSG.unexpected);
- return console.error(error);
+ videoError(ERROR_MSG.unexpected);
+ return console.error('Video processing failed:', error);

Consider adding error tracking/monitoring for production environments to help identify and fix issues proactively.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
videoError(ERROR_MSG.unexpected);
return console.error(error);
}
videoError(ERROR_MSG.unexpected);
return console.error('Video processing failed:', error);
}

}}
Expand Down
Loading