|
1 | 1 | 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"; |
3 | 4 | import { Dashboard } from "@uppy/react";
|
4 | 5 | import Url from "@uppy/url";
|
5 | 6 | import Webcam from "@uppy/webcam";
|
6 | 7 | import XHR from "@uppy/xhr-upload";
|
7 | 8 | import mime from "mime-types";
|
8 | 9 | import React, { useEffect, useState } from "react";
|
9 | 10 | 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"; |
12 | 13 |
|
13 | 14 | export function GooeyFileInput({
|
14 | 15 | name,
|
@@ -262,30 +263,13 @@ async function loadPreview({
|
262 | 263 | }) {
|
263 | 264 | if (uppy.getFile(fileId).meta.type?.startsWith("image/")) return;
|
264 | 265 |
|
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; |
267 | 271 | 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; |
289 | 273 |
|
290 | 274 | if (!uppy.getFile(fileId)) return;
|
291 | 275 | uppy.setFileState(fileId, {
|
|
0 commit comments