From e1518729271deef2ed57fa687b9e155ad9eac937 Mon Sep 17 00:00:00 2001 From: Hong Minhee Date: Mon, 4 Mar 2024 17:03:19 +0900 Subject: [PATCH] Example blog: Expose Person.published --- examples/blog/federation/mod.ts | 1 + examples/blog/models/blog.ts | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/examples/blog/federation/mod.ts b/examples/blog/federation/mod.ts index f9ca4a3c..99a4ef1e 100644 --- a/examples/blog/federation/mod.ts +++ b/examples/blog/federation/mod.ts @@ -50,6 +50,7 @@ federation.setActorDispatcher("/users/{handle}", async (ctx, handle, key) => { summary: blog.description, preferredUsername: handle, url: new URL("/", ctx.request.url), + published: blog.published, // A `Context` object has several purposes, and one of // them is to provide a way to generate URIs for the dispatchers and // the collections: diff --git a/examples/blog/models/blog.ts b/examples/blog/models/blog.ts index 226313af..5dfa183c 100644 --- a/examples/blog/models/blog.ts +++ b/examples/blog/models/blog.ts @@ -1,4 +1,5 @@ /// +import { Temporal } from "npm:@js-temporal/polyfill@^0.4.4"; import { hash, verify } from "scrypt"; import { openKv } from "./kv.ts"; @@ -16,6 +17,7 @@ export interface Blog extends BlogBase { passwordHash: string; privateKey: CryptoKey; publicKey: CryptoKey; + published: Temporal.Instant; } export async function setBlog(blog: BlogInput): Promise { @@ -34,6 +36,7 @@ export async function setBlog(blog: BlogInput): Promise { handle: blog.handle, title: blog.title, description: blog.description, + published: new Date().toISOString(), passwordHash: hash(blog.password, undefined, "scrypt"), privateKey: await crypto.subtle.exportKey("jwk", privateKey), publicKey: await crypto.subtle.exportKey("jwk", publicKey), @@ -44,6 +47,7 @@ export interface BlogInternal extends BlogBase { passwordHash: string; privateKey: Record; publicKey: Record; + published: string; } export async function getBlog(): Promise { @@ -66,6 +70,7 @@ export async function getBlog(): Promise { true, ["verify"], ), + published: Temporal.Instant.from(entry.value.published), }; }