Work on client modes

This commit is contained in:
Zef Hemel
2023-08-29 21:17:29 +02:00
parent 5ff1a8bae3
commit 9a005f26b5
54 changed files with 594 additions and 302 deletions
+6 -6
View File
@@ -89,6 +89,11 @@ self.addEventListener("fetch", (event: any) => {
return cachedResponse;
}
if (!fileContentTable) {
// Not initialzed yet, or in thin client mode, let's just proxy
return fetch(request);
}
const requestUrl = new URL(request.url);
const pathname = requestUrl.pathname;
@@ -119,17 +124,12 @@ async function handleLocalFileRequest(
request: Request,
pathname: string,
): Promise<Response> {
if (!fileContentTable) {
// Not initialzed yet, or explicitly in sync mode (so direct server communication requested)
return fetch(request);
}
if (!db?.isOpen()) {
console.log("Detected that the DB was closed, reopening");
await db!.open();
}
const path = decodeURIComponent(pathname.slice(1));
const data = await fileContentTable.get(path);
const data = await fileContentTable!.get(path);
if (data) {
// console.log("Serving from space", path);
if (!data.meta) {