Added pageNamespace hook support

This commit is contained in:
Zef Hemel
2022-05-17 11:53:17 +02:00
parent cd89634fd6
commit 9a6a86f8b5
14 changed files with 302 additions and 15 deletions
+3 -1
View File
@@ -4,12 +4,14 @@ import { CronHookT } from "@plugos/plugos/hooks/node_cron";
import { EventHookT } from "@plugos/plugos/hooks/event";
import { CommandHookT } from "@silverbulletmd/web/hooks/command";
import { SlashCommandHookT } from "@silverbulletmd/web/hooks/slash_command";
import { PageNamespaceHookT } from "../server/hooks/page_namespace";
export type SilverBulletHooks = CommandHookT &
SlashCommandHookT &
EndpointHookT &
CronHookT &
EventHookT;
EventHookT &
PageNamespaceHookT;
export type SyntaxExtensions = {
syntax?: { [key: string]: NodeDef };
@@ -56,6 +56,7 @@ export class DiskSpacePrimitives implements SpacePrimitives {
meta: {
name: pageName,
lastModified: s.mtime.getTime(),
perm: "rw",
},
};
} catch (e) {
@@ -88,6 +89,7 @@ export class DiskSpacePrimitives implements SpacePrimitives {
return {
name: pageName,
lastModified: s.mtime.getTime(),
perm: "rw",
};
} catch (e) {
console.error("Error while writing page", pageName, e);
@@ -102,6 +104,7 @@ export class DiskSpacePrimitives implements SpacePrimitives {
return {
name: pageName,
lastModified: s.mtime.getTime(),
perm: "rw",
};
} catch (e) {
console.error("Error while getting page meta", pageName, e);
@@ -132,6 +135,7 @@ export class DiskSpacePrimitives implements SpacePrimitives {
pages.add({
name: this.pathToPageName(fullPath),
lastModified: s.mtime.getTime(),
perm: "rw",
});
}
}
@@ -42,6 +42,7 @@ export class HttpSpacePrimitives implements SpacePrimitives {
result.add({
name: pageName,
lastModified: meta.lastModified,
perm: "rw",
});
});
@@ -160,10 +161,10 @@ export class HttpSpacePrimitives implements SpacePrimitives {
}
private responseToMeta(name: string, res: Response): PageMeta {
const meta = {
return {
name,
lastModified: +(res.headers.get("Last-Modified") || "0"),
perm: (res.headers.get("X-Permission") as "rw" | "ro") || "rw",
};
return meta;
}
}
@@ -72,9 +72,10 @@ export class IndexedDBSpacePrimitives implements SpacePrimitives {
selfUpdate?: boolean,
lastModified?: number
): Promise<PageMeta> {
let meta = {
const meta: PageMeta = {
name,
lastModified: lastModified ? lastModified : Date.now() + this.timeSkew,
perm: "rw",
};
await this.pageTable.put({
name,
+2 -1
View File
@@ -31,9 +31,10 @@ export class Space extends EventEmitter<SpaceEvents> {
newPageList.pages.forEach((meta) => {
const pageName = meta.name;
const oldPageMeta = this.pageMetaCache.get(pageName);
const newPageMeta = {
const newPageMeta: PageMeta = {
name: pageName,
lastModified: meta.lastModified,
perm: meta.perm,
};
if (
!oldPageMeta &&