Skip to content

Commit

Permalink
feat: Improve worker
Browse files Browse the repository at this point in the history
  • Loading branch information
ppodolsky committed Nov 23, 2023
1 parent 7597039 commit fdfdb0c
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 23 deletions.
2 changes: 1 addition & 1 deletion aiosumma/aiosumma/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion aiosumma/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[email protected]" }]
description = "Async client for Summa Search"
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion summa-wasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "summa-wasm"
version = "0.133.5"
version = "0.135.7"
authors = ["Pasha Podolsky <[email protected]>"]
edition = "2021"
license-file = "LICENSE"
Expand Down
2 changes: 1 addition & 1 deletion summa-wasm/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "summa-wasm",
"description": "WASM-bindings for Summa",
"version": "0.133.5",
"version": "0.135.7",
"keywords": [
"search",
"database",
Expand Down
13 changes: 7 additions & 6 deletions summa-wasm/src/service-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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") ||
Expand Down Expand Up @@ -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));
});
30 changes: 17 additions & 13 deletions summa-wasm/src/utils.ts
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -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 };
}

0 comments on commit fdfdb0c

Please sign in to comment.