From fdfdb0c2039f07b92541b9fe831feaaa9ee3bbc3 Mon Sep 17 00:00:00 2001 From: pasha Date: Thu, 23 Nov 2023 11:32:35 +0300 Subject: [PATCH] feat: Improve worker --- aiosumma/aiosumma/client.py | 2 +- aiosumma/pyproject.toml | 2 +- summa-wasm/Cargo.toml | 2 +- summa-wasm/package.json | 2 +- summa-wasm/src/service-worker.ts | 13 +++++++------ summa-wasm/src/utils.ts | 30 +++++++++++++++++------------- 6 files changed, 28 insertions(+), 23 deletions(-) diff --git a/aiosumma/aiosumma/client.py b/aiosumma/aiosumma/client.py index 13468c6d..c7c539a9 100644 --- a/aiosumma/aiosumma/client.py +++ b/aiosumma/aiosumma/client.py @@ -33,7 +33,7 @@ def setup_metadata(session_id, request_id): def prepare_search_request(search_request): if isinstance(search_request, Dict): dict_search_request = search_request - search_request = search_service_pb.SearchRequest() + search_request = query_pb.SearchRequest() ParseDict(dict_search_request, search_request) return search_request diff --git a/aiosumma/pyproject.toml b/aiosumma/pyproject.toml index ddb7ec7a..59da06db 100644 --- a/aiosumma/pyproject.toml +++ b/aiosumma/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "aiosumma" -version = "2.47.2" +version = "2.47.3" authors = [{ name = "Pasha Podolsky", email = "ppodolsky@me.com" }] description = "Async client for Summa Search" readme = "README.md" diff --git a/summa-wasm/Cargo.toml b/summa-wasm/Cargo.toml index da808dbc..1ad80a5c 100644 --- a/summa-wasm/Cargo.toml +++ b/summa-wasm/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "summa-wasm" -version = "0.133.5" +version = "0.135.7" authors = ["Pasha Podolsky "] edition = "2021" license-file = "LICENSE" diff --git a/summa-wasm/package.json b/summa-wasm/package.json index 3ddb3ab3..9adb34f2 100644 --- a/summa-wasm/package.json +++ b/summa-wasm/package.json @@ -1,7 +1,7 @@ { "name": "summa-wasm", "description": "WASM-bindings for Summa", - "version": "0.133.5", + "version": "0.135.7", "keywords": [ "search", "database", diff --git a/summa-wasm/src/service-worker.ts b/summa-wasm/src/service-worker.ts index 4e520c2a..58373097 100644 --- a/summa-wasm/src/service-worker.ts +++ b/summa-wasm/src/service-worker.ts @@ -65,14 +65,10 @@ async function handle_request(event: FetchEvent) { const request = event.request let filename = request.url; let url = request.url; - let is_development = (new URL(request.url)).host == "localhost:5173" - let is_api_request = request.url.endsWith('/search'); + let host = (new URL(request.url)).host; + let is_development = host == "localhost:5173" let is_force = request.url.endsWith("?force"); - if (is_api_request) { - return fetch(event.request) - } - let is_immutable_file = filename.endsWith(".fast") || filename.endsWith(".term") || filename.endsWith(".pos") || @@ -175,5 +171,10 @@ self.addEventListener("fetch", (event) => { ) { return; } + let host = (new URL(event.request.url)).host; + let is_api_request = event.request.url.indexOf('/embed/view') !== -1 || event.request.url.endsWith('/search') || host === "comments.app" || host === "tg.dev" ; + if (is_api_request) { + return; + } event.respondWith(handle_request(event)); }); \ No newline at end of file diff --git a/summa-wasm/src/utils.ts b/summa-wasm/src/utils.ts index 80711226..e616329e 100644 --- a/summa-wasm/src/utils.ts +++ b/summa-wasm/src/utils.ts @@ -1,20 +1,24 @@ export function get_ipfs_hostname() { - let ipfs_url: string; - const hostname_parts = window.location.hostname.split("."); - if (hostname_parts[-1] === "localhost") { - ipfs_url = "http://localhost"; - } else if (window.location.hostname === "ipfs.io") { - ipfs_url = "https://ipfs.io"; + let hostname: string = window.location.hostname; + let protocol: string = window.location.protocol; + const hostname_parts = hostname.split("."); + if (hostname_parts[hostname_parts.length - 1] === "localhost") { + hostname = "localhost"; + protocol = "http:"; + } else if (hostname === "ipfs.io") { + hostname = "ipfs.io"; + protocol = "https:"; } else { const ipfs_domain_index = hostname_parts.findIndex( (el) => el === "ipfs" || el === "ipns" ); - if (ipfs_domain_index !== undefined) { - ipfs_url = `${window.location.protocol}//${hostname_parts + if (ipfs_domain_index !== -1) { + hostname = hostname_parts .slice(ipfs_domain_index + 1) - .join(".")}`; + .join("."); } else { - ipfs_url = "https://ipfs.io"; + hostname = "ipfs.io"; + protocol = "https:"; } } if ( @@ -23,10 +27,10 @@ export function get_ipfs_hostname() { window.location.port !== "80" ) { if (window.location.port !== "5173") { - ipfs_url = `${ipfs_url}:${window.location.port}`; + hostname = `${hostname}:${window.location.port}`; } else { - ipfs_url = `${ipfs_url}:8080`; + hostname = `${hostname}:8080`; } } - return ipfs_url; + return { ipfs_hostname: hostname, ipfs_protocol: protocol }; } \ No newline at end of file