Skip to content

Commit e0f4382

Browse files
committed
use meta scrapper api for preview
1 parent dee24f6 commit e0f4382

File tree

2 files changed

+12
-28
lines changed

2 files changed

+12
-28
lines changed

app/gooeyFileInput.tsx

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import Audio from "@uppy/audio";
2-
import Uppy, { UppyFile } from "@uppy/core";
2+
import type { UppyFile } from "@uppy/core";
3+
import Uppy from "@uppy/core";
34
import { Dashboard } from "@uppy/react";
45
import Url from "@uppy/url";
56
import Webcam from "@uppy/webcam";
67
import XHR from "@uppy/xhr-upload";
78
import mime from "mime-types";
89
import React, { useEffect, useState } from "react";
910
import { InputLabel } from "./gooeyInput";
10-
import { textResponseHead, urlToFilename } from "./urlUtils";
11-
import { TooltipPlacement } from "./components/GooeyTooltip";
11+
import { urlToFilename } from "./urlUtils";
12+
import type { TooltipPlacement } from "./components/GooeyTooltip";
1213

1314
export function GooeyFileInput({
1415
name,
@@ -262,30 +263,13 @@ async function loadPreview({
262263
}) {
263264
if (uppy.getFile(fileId).meta.type?.startsWith("image/")) return;
264265

265-
const response = await fetch(url);
266-
const contentType = response.headers.get("content-type") || "url/undefined";
266+
const response = await fetch(
267+
`https://metascraper.gooey.ai/fetchUrlMeta?url=${url}`
268+
);
269+
const data = await response.json();
270+
const { content_type: contentType, image } = data;
267271
const contentLength = response.headers.get("content-length");
268-
const text = await textResponseHead({ response });
269-
270-
preview = contentType?.startsWith("image/") ? url : preview;
271-
272-
if (text && contentType?.startsWith("text/html")) {
273-
const doc = new DOMParser().parseFromString(text, "text/html");
274-
275-
filename =
276-
doc.querySelector('meta[property="og:title"]')?.getAttribute("content") ||
277-
doc.querySelector("title")?.textContent ||
278-
filename;
279-
280-
preview =
281-
doc.querySelector('meta[property="og:image"]')?.getAttribute("content") ||
282-
preview;
283-
284-
if (!uppy.getFile(fileId)) return;
285-
uppy.setFileMeta(fileId, {
286-
name: filename,
287-
});
288-
}
272+
preview = contentType?.startsWith("image/") ? url : preview ? preview : image;
289273

290274
if (!uppy.getFile(fileId)) return;
291275
uppy.setFileState(fileId, {

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)