Real-time collaboration within space (#411)
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -63,7 +63,7 @@ export class DiskSpacePrimitives implements SpacePrimitives {
|
||||
};
|
||||
} catch {
|
||||
// console.error("Error while reading file", name, e);
|
||||
throw Error(`Could not read file ${name}`);
|
||||
throw Error("Not found");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ export class EventedSpacePrimitives implements SpacePrimitives {
|
||||
text = decoder.decode(data);
|
||||
|
||||
this.eventHook
|
||||
.dispatchEvent("page:saved", pageName)
|
||||
.dispatchEvent("page:saved", pageName, newMeta)
|
||||
.then(() => {
|
||||
return this.eventHook.dispatchEvent("page:index_text", {
|
||||
name: pageName,
|
||||
|
||||
@@ -37,7 +37,10 @@ export class SpaceSync {
|
||||
) {
|
||||
}
|
||||
|
||||
async syncFiles(snapshot: Map<string, SyncStatusItem>): Promise<number> {
|
||||
async syncFiles(
|
||||
snapshot: Map<string, SyncStatusItem>,
|
||||
isSyncCandidate = this.options.isSyncCandidate,
|
||||
): Promise<number> {
|
||||
let operations = 0;
|
||||
console.log("[sync]", "Fetching snapshot from primary");
|
||||
const primaryAllPages = this.syncCandidates(
|
||||
@@ -73,6 +76,9 @@ export class SpaceSync {
|
||||
// console.log("[sync]", "Iterating over all files");
|
||||
let filesProcessed = 0;
|
||||
for (const name of sortedFilenames) {
|
||||
if (isSyncCandidate && !isSyncCandidate(name)) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
operations += await this.syncFile(
|
||||
snapshot,
|
||||
|
||||
Reference in New Issue
Block a user