From b3876e80b64dbbb8a2c2fb6e3395bf7eb21931f9 Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Tue, 30 May 2023 14:39:47 +0200 Subject: [PATCH] Properly set mime time and mtime from asset bundle --- common/spaces/asset_bundle_space_primitives.ts | 14 ++++++-------- web/service_worker.ts | 1 + web/space.ts | 8 ++------ 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/common/spaces/asset_bundle_space_primitives.ts b/common/spaces/asset_bundle_space_primitives.ts index 5fb64447..695529fd 100644 --- a/common/spaces/asset_bundle_space_primitives.ts +++ b/common/spaces/asset_bundle_space_primitives.ts @@ -1,9 +1,7 @@ import { FileMeta } from "../types.ts"; import { SpacePrimitives } from "./space_primitives.ts"; import { AssetBundle } from "../../plugos/asset_bundle/bundle.ts"; -import { mime } from "../deps.ts"; -const bootTime = Date.now(); export class AssetBundlePlugSpacePrimitives implements SpacePrimitives { constructor( private wrapped: SpacePrimitives, @@ -16,8 +14,8 @@ export class AssetBundlePlugSpacePrimitives implements SpacePrimitives { return this.assetBundle.listFiles() .map((p) => ({ name: p, - contentType: mime.getType(p) || "application/octet-stream", - lastModified: bootTime, + contentType: this.assetBundle.getMimeType(p), + lastModified: this.assetBundle.getMtime(p), perm: "ro", size: -1, } as FileMeta)).concat(files); @@ -32,10 +30,10 @@ export class AssetBundlePlugSpacePrimitives implements SpacePrimitives { return Promise.resolve({ data, meta: { - lastModified: bootTime, + contentType: this.assetBundle.getMimeType(name), + lastModified: this.assetBundle.getMtime(name), size: data.byteLength, perm: "ro", - contentType: this.assetBundle.getMimeType(name), } as FileMeta, }); } @@ -46,10 +44,10 @@ export class AssetBundlePlugSpacePrimitives implements SpacePrimitives { if (this.assetBundle.has(name)) { const data = this.assetBundle.readFileSync(name); return Promise.resolve({ - lastModified: bootTime, + contentType: this.assetBundle.getMimeType(name), + lastModified: this.assetBundle.getMtime(name), size: data.byteLength, perm: "ro", - contentType: this.assetBundle.getMimeType(name), } as FileMeta); } return this.wrapped.getFileMeta(name); diff --git a/web/service_worker.ts b/web/service_worker.ts index b61bd457..73d24461 100644 --- a/web/service_worker.ts +++ b/web/service_worker.ts @@ -83,6 +83,7 @@ self.addEventListener("fetch", (event: any) => { const requestUrl = new URL(event.request.url); const pathname = requestUrl.pathname; + // console.log("In service worker, pathname is", pathname); // If this is a /.fs request, this can either be a plug worker load or an attachment load if (pathname.startsWith("/.fs")) { if (fileContentTable && !event.request.headers.has("x-sync-mode")) { diff --git a/web/space.ts b/web/space.ts index 0b469788..39b736b6 100644 --- a/web/space.ts +++ b/web/space.ts @@ -200,13 +200,9 @@ export class Space extends EventEmitter { writeAttachment( name: string, data: Uint8Array, - selfUpdate?: boolean | undefined, + selfUpdate?: boolean, ): Promise { - return this.spacePrimitives.writeFile( - name, - data as Uint8Array, - selfUpdate, - ); + return this.spacePrimitives.writeFile(name, data, selfUpdate); } deleteAttachment(name: string): Promise {