Skip to content

Commit

Permalink
Revert "feat(debugger): frame image validation (#373)" (#374)
Browse files Browse the repository at this point in the history
This reverts commit c7a3b2b.
  • Loading branch information
stephancill authored May 8, 2024
1 parent fc8e469 commit e8e3685
Show file tree
Hide file tree
Showing 14 changed files with 6 additions and 380 deletions.
5 changes: 0 additions & 5 deletions .changeset/funny-toys-confess.md

This file was deleted.

99 changes: 5 additions & 94 deletions packages/debugger/app/components/frame-debugger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
type Frame,
ParsingReport,
SupportedParsingSpecification,
FrameFlattened,
} from "frames.js";
import { Dispatch, SetStateAction, useEffect, useMemo, useState } from "react";
import React from "react";
Expand Down Expand Up @@ -45,11 +44,9 @@ import { cn } from "@/lib/utils";
import { hasWarnings } from "../lib/utils";
import { useRouter } from "next/navigation";
import { WithTooltip } from "./with-tooltip";
import { InvalidImageAspectRatioError, InvalidImageError, InvalidImageTypeError, validateFrameImage } from "../lib/validateFrameImage";

type FrameDebuggerFramePropertiesTableRowsProps = {
stackItem: FramesStackItem;
specification: SupportedParsingSpecification;
};

function paramsToObject(entries: IterableIterator<[string, string]>): object {
Expand All @@ -74,29 +71,27 @@ function isPropertyExperimental([key, value]: [string, string]) {

function FrameDebuggerFramePropertiesTableRow({
stackItem,
specification,
}: FrameDebuggerFramePropertiesTableRowsProps) {
const [currentStackItem, setCurrentStackItem] = useState(stackItem);
const properties = useMemo(() => {
/** tuple of key and value */
const validProperties: [string, string][] = [];
/** tuple of key and error message */
const invalidProperties: [string, ParsingReport[]][] = [];
const visitedInvalidProperties: string[] = [];

if (currentStackItem.status === "pending") {
if (stackItem.status === "pending") {
return { validProperties, invalidProperties, isValid: true };
}

if (currentStackItem.status === "requestError") {
if (stackItem.status === "requestError") {
return { validProperties, invalidProperties, isValid: false };
}

if (currentStackItem.status === "message") {
if (stackItem.status === "message") {
return { validProperties, invalidProperties, isValid: true };
}

const result = currentStackItem.frame;
const result = stackItem.frame;

// we need to check validation errors first because getFrame incorrectly return a value for a key even if it's invalid
for (const [key, errors] of Object.entries(result.reports)) {
Expand All @@ -107,8 +102,7 @@ function FrameDebuggerFramePropertiesTableRow({

const flattenedFrame = getFrameFlattened(result.frame, {
"frames.js:version":
"frames.js:version" in result.frame &&
typeof result.frame["frames.js:version"] === "string"
"frames.js:version" in result.frame && typeof result.frame["frames.js:version"] === "string"
? result.frame["frames.js:version"]
: undefined,
});
Expand Down Expand Up @@ -136,90 +130,8 @@ function FrameDebuggerFramePropertiesTableRow({
isValid: invalidProperties.length === 0,
hasExperimentalProperties,
};
}, [currentStackItem]);

useEffect(() => {
setCurrentStackItem(stackItem);
}, [stackItem]);

useEffect(() => {
if (stackItem.status === "done" && stackItem.frame.frame.image) {
const imageKey: keyof FrameFlattened =
specification === "farcaster" ? "fc:frame:image" : "of:image";
const imageAspectRatioKey: keyof FrameFlattened =
specification === "farcaster"
? "fc:frame:image:aspect_ratio"
: "of:image:aspect_ratio";


const src = stackItem.frame.frame.image;

validateFrameImage({
src,
aspectRatio: stackItem.frame.frame.imageAspectRatio ?? "",
}).catch(e => {
if (e instanceof InvalidImageAspectRatioError) {
setCurrentStackItem({
...stackItem,
frame: {
...stackItem.frame,
status: "failure",
reports: {
...stackItem.frame.reports,
[imageAspectRatioKey]: [
...(stackItem.frame.reports[imageAspectRatioKey] ?? []),
{
source: specification,
level: "error",
message: e.message,
},
],
},
},
});
} else if (e instanceof InvalidImageTypeError || e instanceof InvalidImageError) {
setCurrentStackItem({
...stackItem,
frame: {
...stackItem.frame,
status: "failure",
reports: {
...stackItem.frame.reports,
[imageKey]: [
...(stackItem.frame.reports[imageKey] ?? []),
{
source: specification,
level: "error",
message: e.message,
},
],
},
},
});
} else {
setCurrentStackItem({
...stackItem,
frame: {
...stackItem.frame,
status: "failure",
reports: {
...stackItem.frame.reports,
[imageKey]: [
...(stackItem.frame.reports[imageKey] ?? []),
{
source: specification,
level: "error",
message: e instanceof Error ? e.message : `Failed to load image, invalid file type or corrupted image file`,
},
],
},
},
});
}
});
}
}, [stackItem, specification]);

return (
<>
{properties.validProperties.map(([propertyKey, value]) => {
Expand Down Expand Up @@ -855,7 +767,6 @@ export function FrameDebugger({
</TableCell>
</TableRow>
<FrameDebuggerFramePropertiesTableRow
specification={specification}
stackItem={frameState.frame}
></FrameDebuggerFramePropertiesTableRow>
</TableBody>
Expand Down
18 changes: 0 additions & 18 deletions packages/debugger/app/image-proxy/route.ts

This file was deleted.

99 changes: 0 additions & 99 deletions packages/debugger/app/lib/validateFrameImage.ts

This file was deleted.

13 changes: 1 addition & 12 deletions packages/debugger/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const nextConfig = {
},
],
},
webpack: (config, context) => {
webpack: (config) => {
config.externals.push(
"pino-pretty",
"lokijs",
Expand All @@ -28,17 +28,6 @@ const nextConfig = {
// so it is installed on user's system
"@xmtp/user-preferences-bindings-wasm"
);

// fixes file-types package so we can import it client side
config.plugins.push(
new context.webpack.NormalModuleReplacementPlugin(
/^node:/,
(resource) => {
resource.request = resource.request.replace(/^node:/, "");
}
)
);

return config;
},
};
Expand Down
1 change: 0 additions & 1 deletion packages/debugger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
"cmdk": "^0.2.1",
"eslint": "^8.56.0",
"eslint-config-next": "^14.1.0",
"file-type": "^19.0.0",
"frames.js": "^0.15.2",
"lucide-react": "^0.344.0",
"postcss": "^8",
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit e8e3685

Please sign in to comment.