kopia lustrzana https://github.com/cloudflare/wildebeest
commit
98d0e1bcbb
|
@ -1,6 +1,6 @@
|
|||
import { type Database } from 'wildebeest/backend/src/database'
|
||||
import type { Env } from 'wildebeest/backend/src/types/env'
|
||||
|
||||
export default function make(env: Env): Database {
|
||||
return env.DATABASE
|
||||
export default function make({ DATABASE }: Pick<Env, 'DATABASE'>): Database {
|
||||
return DATABASE
|
||||
}
|
||||
|
|
|
@ -23,6 +23,6 @@ export interface PreparedStatement {
|
|||
raw<T = unknown>(): Promise<T[]>
|
||||
}
|
||||
|
||||
export function getDatabase(env: Env): Database {
|
||||
export function getDatabase(env: Pick<Env, 'DATABASE'>): Database {
|
||||
return d1(env)
|
||||
}
|
||||
|
|
|
@ -8,12 +8,12 @@ import { deliverToActor } from 'wildebeest/backend/src/activitypub/deliver'
|
|||
|
||||
export async function handleDeliverMessage(env: Env, actor: Actor, message: DeliverMessageBody) {
|
||||
const toActorId = new URL(message.toActorId)
|
||||
const targetActor = await actors.getAndCache(toActorId, getDatabase(env as any))
|
||||
const targetActor = await actors.getAndCache(toActorId, getDatabase(env))
|
||||
if (targetActor === null) {
|
||||
console.warn(`actor ${toActorId} not found`)
|
||||
return
|
||||
}
|
||||
|
||||
const signingKey = await getSigningKey(message.userKEK, getDatabase(env as any), actor)
|
||||
const signingKey = await getSigningKey(message.userKEK, getDatabase(env), actor)
|
||||
await deliverToActor(signingKey, actor, targetActor, message.activity, env.DOMAIN)
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ import type { Env } from './'
|
|||
|
||||
export async function handleInboxMessage(env: Env, actor: Actor, message: InboxMessageBody) {
|
||||
const domain = env.DOMAIN
|
||||
const db = getDatabase(env as any)
|
||||
const db = getDatabase(env)
|
||||
const adminEmail = env.ADMIN_EMAIL
|
||||
const cache = cacheFromEnv(env)
|
||||
const activity = message.activity
|
||||
|
|
|
@ -20,7 +20,7 @@ export type Env = {
|
|||
export default {
|
||||
async queue(batch: MessageBatch<MessageBody>, env: Env, ctx: ExecutionContext) {
|
||||
const sentry = initSentryQueue(env, ctx)
|
||||
const db = getDatabase(env as any)
|
||||
const db = getDatabase(env)
|
||||
|
||||
try {
|
||||
for (const message of batch.messages) {
|
||||
|
|
|
@ -8,12 +8,13 @@ import { Avatar } from '~/components/avatar'
|
|||
import { getPersonByEmail } from 'wildebeest/backend/src/activitypub/actors'
|
||||
import { getErrorHtml } from '~/utils/getErrorHtml/getErrorHtml'
|
||||
import { buildRedirect } from 'wildebeest/functions/oauth/authorize'
|
||||
import { getDatabase } from 'wildebeest/backend/src/database'
|
||||
|
||||
export const clientLoader = loader$<Promise<Client>, { DATABASE: D1Database }>(async ({ platform, query, html }) => {
|
||||
const client_id = query.get('client_id') || ''
|
||||
let client: Client | null = null
|
||||
try {
|
||||
client = await getClientById(platform.DATABASE, client_id)
|
||||
client = await getClientById(getDatabase(platform), client_id)
|
||||
} catch (e: unknown) {
|
||||
const error = e as { stack: string; cause: string }
|
||||
console.warn(error.stack, error.cause)
|
||||
|
@ -48,10 +49,10 @@ export const userLoader = loader$<
|
|||
throw html(500, getErrorHtml("The Access JWT doesn't contain an email"))
|
||||
}
|
||||
|
||||
const person = await getPersonByEmail(platform.DATABASE, payload.email)
|
||||
const person = await getPersonByEmail(getDatabase(platform), payload.email)
|
||||
if (person === null) {
|
||||
const isFirstLogin = true
|
||||
const res = await buildRedirect(platform.DATABASE, request as Request, isFirstLogin, jwt.value)
|
||||
const res = await buildRedirect(getDatabase(platform), request as Request, isFirstLogin, jwt.value)
|
||||
if (res.status === 302) {
|
||||
throw redirect(302, res.headers.get('location') || '')
|
||||
} else {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { component$ } from '@builder.io/qwik'
|
||||
import { Database, getDatabase } from 'wildebeest/backend/src/database'
|
||||
import { MastodonStatus, StatusContext } from '~/types'
|
||||
import Status from '~/components/Status'
|
||||
import * as statusAPI from 'wildebeest/functions/api/v1/statuses/[id]'
|
||||
|
@ -12,12 +13,17 @@ import { Person } from 'wildebeest/backend/src/activitypub/actors'
|
|||
|
||||
export const statusLoader = loader$<
|
||||
Promise<{ status: MastodonStatus; statusTextContent: string; context: StatusContext }>,
|
||||
{ DATABASE: D1Database }
|
||||
{ DATABASE: Database }
|
||||
>(async ({ request, html, platform, params }) => {
|
||||
const domain = new URL(request.url).hostname
|
||||
let statusText = ''
|
||||
try {
|
||||
const statusResponse = await statusAPI.handleRequestGet(platform.DATABASE, params.statusId, domain, {} as Person)
|
||||
const statusResponse = await statusAPI.handleRequestGet(
|
||||
getDatabase(platform),
|
||||
params.statusId,
|
||||
domain,
|
||||
{} as Person
|
||||
)
|
||||
statusText = await statusResponse.text()
|
||||
} catch (e: unknown) {
|
||||
const error = e as { stack: string; cause: string }
|
||||
|
@ -31,7 +37,7 @@ export const statusLoader = loader$<
|
|||
const statusTextContent = await getTextContent(status.content)
|
||||
|
||||
try {
|
||||
const contextResponse = await contextAPI.handleRequest(domain, platform.DATABASE, params.statusId)
|
||||
const contextResponse = await contextAPI.handleRequest(domain, getDatabase(platform), params.statusId)
|
||||
const contextText = await contextResponse.text()
|
||||
const context = JSON.parse(contextText ?? null) as StatusContext | null
|
||||
if (!context) {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { $, component$ } from '@builder.io/qwik'
|
||||
import { getDatabase } from 'wildebeest/backend/src/database'
|
||||
import { loader$ } from '@builder.io/qwik-city'
|
||||
import { getErrorHtml } from '~/utils/getErrorHtml/getErrorHtml'
|
||||
import type { MastodonStatus } from '~/types'
|
||||
|
@ -21,7 +22,7 @@ export const statusesLoader = loader$<
|
|||
|
||||
const handle = parseHandle(accountId)
|
||||
accountId = handle.localPart
|
||||
const response = await getLocalStatuses(request as Request, platform.DATABASE, handle, 0, false)
|
||||
const response = await getLocalStatuses(request as Request, getDatabase(platform), handle, 0, false)
|
||||
statuses = await response.json<Array<MastodonStatus>>()
|
||||
} catch {
|
||||
throw html(
|
||||
|
|
|
@ -11,6 +11,7 @@ import { getErrorHtml } from '~/utils/getErrorHtml/getErrorHtml'
|
|||
import { getDocumentHead } from '~/utils/getDocumentHead'
|
||||
import * as statusAPI from 'wildebeest/functions/api/v1/statuses/[id]'
|
||||
import { useAccountUrl } from '~/utils/useAccountUrl'
|
||||
import { getDatabase } from 'wildebeest/backend/src/database'
|
||||
|
||||
export const accountPageLoader = loader$<
|
||||
Promise<{ account: MastodonAccount; accountHandle: string; isValidStatus: boolean }>,
|
||||
|
@ -24,14 +25,14 @@ export const accountPageLoader = loader$<
|
|||
const accountId = url.pathname.split('/')[1]
|
||||
|
||||
try {
|
||||
const statusResponse = await statusAPI.handleRequestGet(platform.DATABASE, params.statusId, domain)
|
||||
const statusResponse = await statusAPI.handleRequestGet(getDatabase(platform), params.statusId, domain)
|
||||
const statusText = await statusResponse.text()
|
||||
isValidStatus = !!statusText
|
||||
} catch {
|
||||
isValidStatus = false
|
||||
}
|
||||
|
||||
account = await getAccount(domain, accountId, platform.DATABASE)
|
||||
account = await getAccount(domain, accountId, getDatabase(platform))
|
||||
} catch {
|
||||
throw html(
|
||||
500,
|
||||
|
|
|
@ -6,6 +6,7 @@ import type { MastodonStatus } from '~/types'
|
|||
import { StatusesPanel } from '~/components/StatusesPanel/StatusesPanel'
|
||||
import { getLocalStatuses } from 'wildebeest/functions/api/v1/accounts/[id]/statuses'
|
||||
import { parseHandle } from 'wildebeest/backend/src/utils/parse'
|
||||
import { getDatabase } from 'wildebeest/backend/src/database'
|
||||
|
||||
export const statusesLoader = loader$<
|
||||
Promise<{
|
||||
|
@ -22,7 +23,7 @@ export const statusesLoader = loader$<
|
|||
|
||||
const handle = parseHandle(accountId)
|
||||
accountId = handle.localPart
|
||||
const response = await getLocalStatuses(request as Request, platform.DATABASE, handle, 0, true)
|
||||
const response = await getLocalStatuses(request as Request, getDatabase(platform), handle, 0, true)
|
||||
statuses = await response.json<Array<MastodonStatus>>()
|
||||
} catch {
|
||||
throw html(
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { $, component$ } from '@builder.io/qwik'
|
||||
import { getDatabase } from 'wildebeest/backend/src/database'
|
||||
import { DocumentHead, loader$ } from '@builder.io/qwik-city'
|
||||
import * as timelines from 'wildebeest/functions/api/v1/timelines/public'
|
||||
import { StatusesPanel } from '~/components/StatusesPanel/StatusesPanel'
|
||||
|
@ -10,7 +11,7 @@ export const statusesLoader = loader$<Promise<MastodonStatus[]>, { DATABASE: D1D
|
|||
async ({ platform, html }) => {
|
||||
try {
|
||||
// TODO: use the "trending" API endpoint here.
|
||||
const response = await timelines.handleRequest(platform.domain, platform.DATABASE)
|
||||
const response = await timelines.handleRequest(platform.domain, getDatabase(platform))
|
||||
const results = await response.text()
|
||||
// Manually parse the JSON to ensure that Qwik finds the resulting objects serializable.
|
||||
return JSON.parse(results) as MastodonStatus[]
|
||||
|
|
|
@ -6,12 +6,13 @@ import StickyHeader from '~/components/StickyHeader/StickyHeader'
|
|||
import { getDocumentHead } from '~/utils/getDocumentHead'
|
||||
import { StatusesPanel } from '~/components/StatusesPanel/StatusesPanel'
|
||||
import { getErrorHtml } from '~/utils/getErrorHtml/getErrorHtml'
|
||||
import { getDatabase } from 'wildebeest/backend/src/database'
|
||||
|
||||
export const statusesLoader = loader$<Promise<MastodonStatus[]>, { DATABASE: D1Database; domain: string }>(
|
||||
async ({ platform, html }) => {
|
||||
try {
|
||||
// TODO: use the "trending" API endpoint here.
|
||||
const response = await timelines.handleRequest(platform.domain, platform.DATABASE)
|
||||
const response = await timelines.handleRequest(platform.domain, getDatabase(platform))
|
||||
const results = await response.text()
|
||||
// Manually parse the JSON to ensure that Qwik finds the resulting objects serializable.
|
||||
return JSON.parse(results) as MastodonStatus[]
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { $, component$ } from '@builder.io/qwik'
|
||||
import { getDatabase } from 'wildebeest/backend/src/database'
|
||||
import { MastodonStatus } from '~/types'
|
||||
import * as timelines from 'wildebeest/functions/api/v1/timelines/public'
|
||||
import { DocumentHead, loader$ } from '@builder.io/qwik-city'
|
||||
|
@ -11,7 +12,7 @@ export const statusesLoader = loader$<Promise<MastodonStatus[]>, { DATABASE: D1D
|
|||
async ({ platform, html }) => {
|
||||
try {
|
||||
// TODO: use the "trending" API endpoint here.
|
||||
const response = await timelines.handleRequest(platform.domain, platform.DATABASE, { local: true })
|
||||
const response = await timelines.handleRequest(platform.domain, getDatabase(platform), { local: true })
|
||||
const results = await response.text()
|
||||
// Manually parse the JSON to ensure that Qwik finds the resulting objects serializable.
|
||||
return JSON.parse(results) as MastodonStatus[]
|
||||
|
|
Ładowanie…
Reference in New Issue