From 22b0c1ebf9e38d5b0fe88e75701d7efdc24fcd8c Mon Sep 17 00:00:00 2001 From: MotorTruck1221 Date: Wed, 2 Oct 2024 19:28:28 -0600 Subject: [PATCH] Switch to libcurl for omnibox --- astro.config.mjs | 6 ------ package.json | 4 ++-- pnpm-lock.yaml | 16 ++++++++-------- src/pages/[lang]/index.astro | 18 +++++++----------- 4 files changed, 17 insertions(+), 27 deletions(-) diff --git a/astro.config.mjs b/astro.config.mjs index ae5d474..13967c5 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -8,15 +8,9 @@ import { baremuxPath } from '@mercuryworkshop/bare-mux'; import { epoxyPath } from '@mercuryworkshop/epoxy-transport'; import { libcurlPath } from '@mercuryworkshop/libcurl-transport'; import { uvPath } from '@titaniumnetwork-dev/ultraviolet'; - export default defineConfig({ integrations: [tailwind(), icon(), svelte()], vite: { - build: { - rollupOptions: { - external: ['@mercuryworkshop/epoxy-tls-new'] - } - }, plugins: [ viteStaticCopy({ targets: [ diff --git a/package.json b/package.json index c13a062..6a8916c 100644 --- a/package.json +++ b/package.json @@ -20,9 +20,9 @@ "@iconify-json/ph": "^1.2.0", "@mercuryworkshop/bare-mux": "1.1.1", "@mercuryworkshop/epoxy-tls": "2.0.0-3", - "@mercuryworkshop/libcurl-transport": "1.3.2", - "@mercuryworkshop/epoxy-tls-new": "npm:@mercuryworkshop/epoxy-tls@^2.1.4-1", + "libcurl.js-new": "npm:libcurl.js@^0.6.16", "@mercuryworkshop/epoxy-transport": "2.0.1", + "@mercuryworkshop/libcurl-transport": "1.3.2", "@titaniumnetwork-dev/ultraviolet": "3.1.2", "astro": "^4.15.9", "astro-icon": "^1.1.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4f4dca5..ae0f670 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -35,9 +35,6 @@ importers: '@mercuryworkshop/epoxy-tls': specifier: 2.0.0-3 version: 2.0.0-3 - '@mercuryworkshop/epoxy-tls-new': - specifier: npm:@mercuryworkshop/epoxy-tls@^2.1.4-1 - version: '@mercuryworkshop/epoxy-tls@2.1.4-1' '@mercuryworkshop/epoxy-transport': specifier: 2.0.1 version: 2.0.1(bufferutil@4.0.8)(typescript@5.6.2)(utf-8-validate@6.0.4) @@ -68,6 +65,9 @@ importers: formdata-node: specifier: ^6.0.3 version: 6.0.3 + libcurl.js-new: + specifier: npm:libcurl.js@^0.6.16 + version: libcurl.js@0.6.16 multer: specifier: 1.4.5-lts.1 version: 1.4.5-lts.1 @@ -606,9 +606,6 @@ packages: '@mercuryworkshop/epoxy-tls@2.0.0-3': resolution: {integrity: sha512-iC5CViTh2xn44xtjvDW4YW9qoeoJcCBOqcNmffBx3RHdK7FAzAWFHLTUBtdlnMVv6cjYZtV+eUTzxyreqlgOVA==} - '@mercuryworkshop/epoxy-tls@2.1.4-1': - resolution: {integrity: sha512-kRbW12tU4TAf9GuoLfyFYvUATqFZq6n9ScRSfwAECceOBWDlr+bACnSH45lLDXvjBKwxZotTyYE5aNc+Ow+M3Q==} - '@mercuryworkshop/epoxy-transport@2.0.1': resolution: {integrity: sha512-iGuH/CT5hCVRYBa+5ZrlTG0DWII9VOCMHnmv9CPFLM17obE84y9EUXpTp9hXdfENnuAcNzQVPizjwVas7HiYQA==} @@ -1996,6 +1993,9 @@ packages: libcurl.js@0.6.15: resolution: {integrity: sha512-rKcGhvJiju/V6RoH0mYW0l/w9GnTRFtidp8qC+3cMliHXHEHnbqwpOPzauMeOd2CtcEW5ZPZ29PpXLJ1bdHbyQ==} + libcurl.js@0.6.16: + resolution: {integrity: sha512-aR56ZgHjzUVRVU3l+XQIBIuZwTc7k6CUrwbH0v6GAyXreL5rluWjLOc3GtDAgK9JEBZi1aVSrNdBtqE669NGCw==} + light-my-request@5.13.0: resolution: {integrity: sha512-9IjUN9ZyCS9pTG+KqTDEQo68Sui2lHsYBrfMyVUTTZ3XhH8PMZq7xO94Kr+eP9dhi/kcKsx4N41p2IXEBil1pQ==} @@ -4172,8 +4172,6 @@ snapshots: '@mercuryworkshop/epoxy-tls@2.0.0-3': {} - '@mercuryworkshop/epoxy-tls@2.1.4-1': {} - '@mercuryworkshop/epoxy-transport@2.0.1(bufferutil@4.0.8)(typescript@5.6.2)(utf-8-validate@6.0.4)': dependencies: '@mercuryworkshop/epoxy-tls': 2.0.0-3 @@ -5813,6 +5811,8 @@ snapshots: libcurl.js@0.6.15: {} + libcurl.js@0.6.16: {} + light-my-request@5.13.0: dependencies: cookie: 0.6.0 diff --git a/src/pages/[lang]/index.astro b/src/pages/[lang]/index.astro index c3338e4..f3c2a24 100644 --- a/src/pages/[lang]/index.astro +++ b/src/pages/[lang]/index.astro @@ -44,7 +44,7 @@ const t = useTranslations(lang); import { initSw, setTransport } from "@utils/registerSW.ts"; //../../utils/registerSW.ts import { WispServerURLS, SearchEngines, Settings, cloak } from "@utils/settings"; import { search } from "@utils/search.ts"; //../../utils/search.ts - import initEpoxy, { EpoxyClient, EpoxyClientOptions } from "@mercuryworkshop/epoxy-tls-new"; + import { libcurl } from "libcurl.js-new/bundled"; type Suggestion = { phrase: string } @@ -70,9 +70,9 @@ const t = useTranslations(lang); const input = document.getElementById("nebula-input") as HTMLInputElement; const iframe = document.getElementById("neb-iframe") as HTMLIFrameElement; const omnibox = document.getElementById("omnibox") as HTMLDivElement; - let epoxyClientOptions: any = null; - let epoxyClient: any = null; - await initEpoxy(); //This ONLY runs once + await libcurl.load_wasm(); + libcurl.set_websocket(WispServerURLS.default); + console.debug("Libucurl ready?", libcurl.ready); input?.addEventListener("keypress", function (event: any) { if (event.key === "Enter") { initSw().then(() => { @@ -87,20 +87,15 @@ const t = useTranslations(lang); } }) input?.addEventListener("input", async function() { - if (!epoxyClient) { - console.debug("Creating epoxy client"); - epoxyClientOptions = new EpoxyClientOptions(); - epoxyClient = new EpoxyClient(WispServerURLS.default, epoxyClientOptions); - } const value = input?.value; input.classList.remove("rounded-b-2xl"); - omnibox.classList.remove("hidden"); + omnibox.classList.remove("hidden"); if (value.length === 0) { input.classList.add("rounded-b-2xl"); omnibox.classList.add("hidden"); } if (value.length >= 3) { - const resp = await epoxyClient.fetch(`https://api.duckduckgo.com/ac?q=${encodeURIComponent(value)}&format=json`); + const resp = await libcurl.fetch(`https://api.duckduckgo.com/ac?q=${encodeURIComponent(value)}&format=json`); const data = await resp.json(); if (data) { omnibox.innerHTML = ""; @@ -130,6 +125,7 @@ const t = useTranslations(lang); } catch (_) { //we purposely don't return anything + //console.debug(err); } });