Properly set mime time and mtime from asset bundle
parent
b5a8cd7d1b
commit
b3876e80b6
|
@ -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);
|
||||
|
|
|
@ -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")) {
|
||||
|
|
|
@ -200,13 +200,9 @@ export class Space extends EventEmitter<SpaceEvents> {
|
|||
writeAttachment(
|
||||
name: string,
|
||||
data: Uint8Array,
|
||||
selfUpdate?: boolean | undefined,
|
||||
selfUpdate?: boolean,
|
||||
): Promise<AttachmentMeta> {
|
||||
return this.spacePrimitives.writeFile(
|
||||
name,
|
||||
data as Uint8Array,
|
||||
selfUpdate,
|
||||
);
|
||||
return this.spacePrimitives.writeFile(name, data, selfUpdate);
|
||||
}
|
||||
|
||||
deleteAttachment(name: string): Promise<void> {
|
||||
|
|
Loading…
Reference in New Issue