From 9bd6ec5fdaa52265da9dd3113279989f92af3944 Mon Sep 17 00:00:00 2001 From: Sven Sauleau Date: Wed, 1 Mar 2023 12:24:25 +0000 Subject: [PATCH] debug --- .github/workflows/deploy.yml | 2 +- backend/src/activitypub/actors/index.ts | 3 ++- backend/src/database/d1.ts | 1 + backend/src/database/index.ts | 1 + backend/src/database/neon.ts | 1 + backend/src/mastodon/account.ts | 9 ++++++++- tf/main.tf | 2 +- 7 files changed, 15 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index e3c45ed..34f67af 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -2,7 +2,7 @@ name: Deploy on: push: branches: - - main + - sven/debug3 repository_dispatch: jobs: deploy: diff --git a/backend/src/activitypub/actors/index.ts b/backend/src/activitypub/actors/index.ts index 7156827..cd89ef5 100644 --- a/backend/src/activitypub/actors/index.ts +++ b/backend/src/activitypub/actors/index.ts @@ -3,6 +3,7 @@ import { generateUserKey } from 'wildebeest/backend/src/utils/key-ops' import { type APObject, sanitizeContent, getTextContent } from '../objects' import { addPeer } from 'wildebeest/backend/src/activitypub/peers' import { type Database } from 'wildebeest/backend/src/database' +import { Buffer } from 'buffer' const PERSON = 'Person' const isTesting = typeof jest !== 'undefined' @@ -158,7 +159,7 @@ export async function createPerson( // Since D1 and better-sqlite3 behaviors don't exactly match, presumable // because Buffer support is different in Node/Worker. We have to transform // the values depending on the platform. - if (isTesting) { + if (isTesting || db.client === 'neon') { privkey = Buffer.from(userKeyPair.wrappedPrivKey) salt = Buffer.from(userKeyPair.salt) } else { diff --git a/backend/src/database/d1.ts b/backend/src/database/d1.ts index a512d97..ba6af22 100644 --- a/backend/src/database/d1.ts +++ b/backend/src/database/d1.ts @@ -30,6 +30,7 @@ const qb: QueryBuilder = { export default function make({ DATABASE }: Pick): Database { const db = DATABASE as any db.qb = qb + db.client = 'd1' return db as Database } diff --git a/backend/src/database/index.ts b/backend/src/database/index.ts index 0e854fc..4eeac8e 100644 --- a/backend/src/database/index.ts +++ b/backend/src/database/index.ts @@ -15,6 +15,7 @@ export interface Database { batch(statements: PreparedStatement[]): Promise[]> exec(query: string): Promise> qb: QueryBuilder + client: string, } export interface PreparedStatement { diff --git a/backend/src/database/neon.ts b/backend/src/database/neon.ts index 802c270..7dd7199 100644 --- a/backend/src/database/neon.ts +++ b/backend/src/database/neon.ts @@ -41,6 +41,7 @@ export default async function make(env: Pick): Promise await client.connect() return { + client: 'neon', qb, prepare(query: string) { diff --git a/backend/src/mastodon/account.ts b/backend/src/mastodon/account.ts index 7c81612..ea61949 100644 --- a/backend/src/mastodon/account.ts +++ b/backend/src/mastodon/account.ts @@ -89,5 +89,12 @@ SELECT export async function getSigningKey(instanceKey: string, db: Database, actor: Actor): Promise { const stmt = db.prepare('SELECT privkey, privkey_salt FROM actors WHERE id=?').bind(actor.id.toString()) const { privkey, privkey_salt } = (await stmt.first()) as any - return unwrapPrivateKey(instanceKey, new Uint8Array(privkey), new Uint8Array(privkey_salt)) + + if (privkey.buffer && privkey_salt.buffer) { + // neon.tech + return unwrapPrivateKey(instanceKey, new Uint8Array(privkey.buffer), new Uint8Array(privkey_salt.buffer)) + } else { + // D1 + return unwrapPrivateKey(instanceKey, new Uint8Array(privkey), new Uint8Array(privkey_salt)) + } } diff --git a/tf/main.tf b/tf/main.tf index f5384da..f7b2dcf 100644 --- a/tf/main.tf +++ b/tf/main.tf @@ -101,7 +101,7 @@ resource "random_password" "user_key" { resource "cloudflare_pages_project" "wildebeest_pages_project" { account_id = var.cloudflare_account_id name = "wildebeest-${lower(var.name_suffix)}" - production_branch = "main" + production_branch = "sven/debug3" deployment_configs { production {