Unverified Commit e1518729 authored by Hong Minhee's avatar Hong Minhee
Browse files

Example blog: Expose Person.published

parent a4156e66
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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:
+5 −0
Original line number Diff line number Diff line
/// <reference lib="deno.unstable" />
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<void> {
@@ -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),
@@ -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> {
@@ -66,6 +70,7 @@ export async function getBlog(): Promise<Blog | null> {
      true,
      ["verify"],
    ),
    published: Temporal.Instant.from(entry.value.published),
  };
}