mirror of
https://github.com/gradio-app/gradio.git
synced 2024-12-21 02:19:59 +08:00
561579d9b7
* fix-tests * [tmp] Comment-out * Fix the URL constructor calls in `resolve_wasm_src()`, `should_proxy_wasm_src()`, and `<DownloadLink />` to handle relative URLs * Remove a circular dependency between lite/index.ts and lite/custom-element/index.ts to solve a bug that the dev app is mounted twice sometimes * Fix js/app/test/image_component_events.spec.ts * Set the `testIgnore` in `.config/playwright.config.js` * Fix the Lite dev mode only to create an app and expose the controller for Playwright, without editors etc. * add changeset * Set the mocked ruff version as 0.2.2 * Extend timeout * Fix to use the built lite files instead of the dev server * add changeset * comment out failed tests * Revert "comment out failed tests" This reverts commit3580d79887
. * Fix the Gellery component to work in Wasm * Fix js/app/test/file_explorer_component_events.spec.ts to run on Wasm * Ignore queue_full_e2e_test.spec.ts * Revert "[tmp] Comment-out" This reverts commitc775c0cc29
. * Revert "Extend timeout" This reverts commit742d1e1e83
. * Remove a commented out line * Refactor file_explorer_component_events.spec.ts * Revert "fix-tests", restoring the original test-functional.yml content This reverts commit9ff2a7ddc5
. * Set CI step names * [tmp] Revert "Revert "fix-tests", restoring the original test-functional.yml content" This reverts commitde2dbe3317
. * Revert "[tmp] Revert "Revert "fix-tests", restoring the original test-functional.yml content"" This reverts commit32154f3bb1
. * [tmp] Revert "Revert "[tmp] Revert "Revert "fix-tests", restoring the original test-functional.yml content""" This reverts commit204075e190
. * Fix vite.config.js removing unnecessary code * Revert "Set the `testIgnore` in `.config/playwright.config.js`" This reverts commit98dccc5be9
. * Add gallery_component_events.spec.ts * Revert js/app/test * tweak * tweak * revert workflow changes * add changeset --------- Co-authored-by: Yuichiro Tachibana (Tsuchiya) <t.yic.yt@gmail.com> Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
56 lines
1.4 KiB
TypeScript
56 lines
1.4 KiB
TypeScript
import { getWorkerProxyContext } from "./context";
|
|
import { is_self_host } from "../network/host";
|
|
import { getHeaderValue } from "../src/http";
|
|
|
|
type MediaSrc = string | undefined | null;
|
|
|
|
export function should_proxy_wasm_src(src: MediaSrc): boolean {
|
|
if (src == null) {
|
|
return false;
|
|
}
|
|
|
|
const url = new URL(src, window.location.href);
|
|
if (!is_self_host(url)) {
|
|
// `src` is not accessing a local server resource, so we don't need to proxy this request to the Wasm worker.
|
|
return false;
|
|
}
|
|
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
// `src` can be a data URL.
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
export async function resolve_wasm_src(src: MediaSrc): Promise<MediaSrc> {
|
|
if (src == null || !should_proxy_wasm_src(src)) {
|
|
return src;
|
|
}
|
|
|
|
const maybeWorkerProxy = getWorkerProxyContext();
|
|
if (maybeWorkerProxy == null) {
|
|
// We are not in the Wasm env. Just use the src as is.
|
|
return src;
|
|
}
|
|
|
|
const url = new URL(src, window.location.href);
|
|
const path = url.pathname;
|
|
return maybeWorkerProxy
|
|
.httpRequest({
|
|
method: "GET",
|
|
path,
|
|
headers: {},
|
|
query_string: ""
|
|
})
|
|
.then((response) => {
|
|
if (response.status !== 200) {
|
|
throw new Error(`Failed to get file ${path} from the Wasm worker.`);
|
|
}
|
|
const blob = new Blob([response.body], {
|
|
type: getHeaderValue(response.headers, "content-type")
|
|
});
|
|
const blobUrl = URL.createObjectURL(blob);
|
|
return blobUrl;
|
|
});
|
|
}
|