Skip to content

Commit

Permalink
Example blog: Expose Person.published
Browse files Browse the repository at this point in the history
  • Loading branch information
dahlia committed Mar 4, 2024
1 parent a4156e6 commit e151872
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/blog/federation/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TContextData>` object has several purposes, and one of
// them is to provide a way to generate URIs for the dispatchers and
// the collections:
Expand Down
5 changes: 5 additions & 0 deletions examples/blog/models/blog.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/// <reference lib="deno.unstable" />
import { Temporal } from "npm:@js-temporal/polyfill@^0.4.4";
import { hash, verify } from "scrypt";
import { openKv } from "./kv.ts";

Expand All @@ -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<void> {
Expand All @@ -34,6 +36,7 @@ export async function setBlog(blog: BlogInput): Promise<void> {
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),
Expand All @@ -44,6 +47,7 @@ export interface BlogInternal extends BlogBase {
passwordHash: string;
privateKey: Record<string, unknown>;
publicKey: Record<string, unknown>;
published: string;
}

export async function getBlog(): Promise<Blog | null> {
Expand All @@ -66,6 +70,7 @@ export async function getBlog(): Promise<Blog | null> {
true,
["verify"],
),
published: Temporal.Instant.from(entry.value.published),
};
}

Expand Down

0 comments on commit e151872

Please sign in to comment.