kopia lustrzana https://github.com/cloudflare/wildebeest
make getDatabase async
rodzic
98d0e1bcbb
commit
d89ed5a8af
|
@ -23,6 +23,6 @@ export interface PreparedStatement {
|
||||||
raw<T = unknown>(): Promise<T[]>
|
raw<T = unknown>(): Promise<T[]>
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getDatabase(env: Pick<Env, 'DATABASE'>): Database {
|
export async function getDatabase(env: Pick<Env, 'DATABASE'>): Promise<Database> {
|
||||||
return d1(env)
|
return d1(env)
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,7 +97,7 @@ export async function main(context: EventContext<Env, any, any>) {
|
||||||
// configuration, which are used to verify the JWT.
|
// configuration, which are used to verify the JWT.
|
||||||
// TODO: since we don't load the instance configuration anymore, we
|
// TODO: since we don't load the instance configuration anymore, we
|
||||||
// don't need to load the user before anymore.
|
// don't need to load the user before anymore.
|
||||||
if (!(await loadContextData(getDatabase(context.env), clientId, payload.email, context))) {
|
if (!(await loadContextData(await getDatabase(context.env), clientId, payload.email, context))) {
|
||||||
return errors.notAuthorized('failed to load context data')
|
return errors.notAuthorized('failed to load context data')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,12 +8,12 @@ import { deliverToActor } from 'wildebeest/backend/src/activitypub/deliver'
|
||||||
|
|
||||||
export async function handleDeliverMessage(env: Env, actor: Actor, message: DeliverMessageBody) {
|
export async function handleDeliverMessage(env: Env, actor: Actor, message: DeliverMessageBody) {
|
||||||
const toActorId = new URL(message.toActorId)
|
const toActorId = new URL(message.toActorId)
|
||||||
const targetActor = await actors.getAndCache(toActorId, getDatabase(env))
|
const targetActor = await actors.getAndCache(toActorId, await getDatabase(env))
|
||||||
if (targetActor === null) {
|
if (targetActor === null) {
|
||||||
console.warn(`actor ${toActorId} not found`)
|
console.warn(`actor ${toActorId} not found`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const signingKey = await getSigningKey(message.userKEK, getDatabase(env), actor)
|
const signingKey = await getSigningKey(message.userKEK, await getDatabase(env), actor)
|
||||||
await deliverToActor(signingKey, actor, targetActor, message.activity, env.DOMAIN)
|
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) {
|
export async function handleInboxMessage(env: Env, actor: Actor, message: InboxMessageBody) {
|
||||||
const domain = env.DOMAIN
|
const domain = env.DOMAIN
|
||||||
const db = getDatabase(env)
|
const db = await getDatabase(env)
|
||||||
const adminEmail = env.ADMIN_EMAIL
|
const adminEmail = env.ADMIN_EMAIL
|
||||||
const cache = cacheFromEnv(env)
|
const cache = cacheFromEnv(env)
|
||||||
const activity = message.activity
|
const activity = message.activity
|
||||||
|
|
|
@ -20,7 +20,7 @@ export type Env = {
|
||||||
export default {
|
export default {
|
||||||
async queue(batch: MessageBatch<MessageBody>, env: Env, ctx: ExecutionContext) {
|
async queue(batch: MessageBatch<MessageBody>, env: Env, ctx: ExecutionContext) {
|
||||||
const sentry = initSentryQueue(env, ctx)
|
const sentry = initSentryQueue(env, ctx)
|
||||||
const db = getDatabase(env)
|
const db = await getDatabase(env)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (const message of batch.messages) {
|
for (const message of batch.messages) {
|
||||||
|
|
|
@ -14,7 +14,7 @@ export const clientLoader = loader$<Promise<Client>, { DATABASE: D1Database }>(a
|
||||||
const client_id = query.get('client_id') || ''
|
const client_id = query.get('client_id') || ''
|
||||||
let client: Client | null = null
|
let client: Client | null = null
|
||||||
try {
|
try {
|
||||||
client = await getClientById(getDatabase(platform), client_id)
|
client = await getClientById(await getDatabase(platform), client_id)
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
const error = e as { stack: string; cause: string }
|
const error = e as { stack: string; cause: string }
|
||||||
console.warn(error.stack, error.cause)
|
console.warn(error.stack, error.cause)
|
||||||
|
@ -49,10 +49,10 @@ export const userLoader = loader$<
|
||||||
throw html(500, getErrorHtml("The Access JWT doesn't contain an email"))
|
throw html(500, getErrorHtml("The Access JWT doesn't contain an email"))
|
||||||
}
|
}
|
||||||
|
|
||||||
const person = await getPersonByEmail(getDatabase(platform), payload.email)
|
const person = await getPersonByEmail(await getDatabase(platform), payload.email)
|
||||||
if (person === null) {
|
if (person === null) {
|
||||||
const isFirstLogin = true
|
const isFirstLogin = true
|
||||||
const res = await buildRedirect(getDatabase(platform), request as Request, isFirstLogin, jwt.value)
|
const res = await buildRedirect(await getDatabase(platform), request as Request, isFirstLogin, jwt.value)
|
||||||
if (res.status === 302) {
|
if (res.status === 302) {
|
||||||
throw redirect(302, res.headers.get('location') || '')
|
throw redirect(302, res.headers.get('location') || '')
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -19,7 +19,7 @@ export const statusLoader = loader$<
|
||||||
let statusText = ''
|
let statusText = ''
|
||||||
try {
|
try {
|
||||||
const statusResponse = await statusAPI.handleRequestGet(
|
const statusResponse = await statusAPI.handleRequestGet(
|
||||||
getDatabase(platform),
|
await getDatabase(platform),
|
||||||
params.statusId,
|
params.statusId,
|
||||||
domain,
|
domain,
|
||||||
{} as Person
|
{} as Person
|
||||||
|
@ -37,7 +37,7 @@ export const statusLoader = loader$<
|
||||||
const statusTextContent = await getTextContent(status.content)
|
const statusTextContent = await getTextContent(status.content)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const contextResponse = await contextAPI.handleRequest(domain, getDatabase(platform), params.statusId)
|
const contextResponse = await contextAPI.handleRequest(domain, await getDatabase(platform), params.statusId)
|
||||||
const contextText = await contextResponse.text()
|
const contextText = await contextResponse.text()
|
||||||
const context = JSON.parse(contextText ?? null) as StatusContext | null
|
const context = JSON.parse(contextText ?? null) as StatusContext | null
|
||||||
if (!context) {
|
if (!context) {
|
||||||
|
|
|
@ -22,7 +22,7 @@ export const statusesLoader = loader$<
|
||||||
|
|
||||||
const handle = parseHandle(accountId)
|
const handle = parseHandle(accountId)
|
||||||
accountId = handle.localPart
|
accountId = handle.localPart
|
||||||
const response = await getLocalStatuses(request as Request, getDatabase(platform), handle, 0, false)
|
const response = await getLocalStatuses(request as Request, await getDatabase(platform), handle, 0, false)
|
||||||
statuses = await response.json<Array<MastodonStatus>>()
|
statuses = await response.json<Array<MastodonStatus>>()
|
||||||
} catch {
|
} catch {
|
||||||
throw html(
|
throw html(
|
||||||
|
|
|
@ -25,14 +25,14 @@ export const accountPageLoader = loader$<
|
||||||
const accountId = url.pathname.split('/')[1]
|
const accountId = url.pathname.split('/')[1]
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const statusResponse = await statusAPI.handleRequestGet(getDatabase(platform), params.statusId, domain)
|
const statusResponse = await statusAPI.handleRequestGet(await getDatabase(platform), params.statusId, domain)
|
||||||
const statusText = await statusResponse.text()
|
const statusText = await statusResponse.text()
|
||||||
isValidStatus = !!statusText
|
isValidStatus = !!statusText
|
||||||
} catch {
|
} catch {
|
||||||
isValidStatus = false
|
isValidStatus = false
|
||||||
}
|
}
|
||||||
|
|
||||||
account = await getAccount(domain, accountId, getDatabase(platform))
|
account = await getAccount(domain, accountId, await getDatabase(platform))
|
||||||
} catch {
|
} catch {
|
||||||
throw html(
|
throw html(
|
||||||
500,
|
500,
|
||||||
|
|
|
@ -23,7 +23,7 @@ export const statusesLoader = loader$<
|
||||||
|
|
||||||
const handle = parseHandle(accountId)
|
const handle = parseHandle(accountId)
|
||||||
accountId = handle.localPart
|
accountId = handle.localPart
|
||||||
const response = await getLocalStatuses(request as Request, getDatabase(platform), handle, 0, true)
|
const response = await getLocalStatuses(request as Request, await getDatabase(platform), handle, 0, true)
|
||||||
statuses = await response.json<Array<MastodonStatus>>()
|
statuses = await response.json<Array<MastodonStatus>>()
|
||||||
} catch {
|
} catch {
|
||||||
throw html(
|
throw html(
|
||||||
|
|
|
@ -11,7 +11,7 @@ export const statusesLoader = loader$<Promise<MastodonStatus[]>, { DATABASE: D1D
|
||||||
async ({ platform, html }) => {
|
async ({ platform, html }) => {
|
||||||
try {
|
try {
|
||||||
// TODO: use the "trending" API endpoint here.
|
// TODO: use the "trending" API endpoint here.
|
||||||
const response = await timelines.handleRequest(platform.domain, getDatabase(platform))
|
const response = await timelines.handleRequest(platform.domain, await getDatabase(platform))
|
||||||
const results = await response.text()
|
const results = await response.text()
|
||||||
// Manually parse the JSON to ensure that Qwik finds the resulting objects serializable.
|
// Manually parse the JSON to ensure that Qwik finds the resulting objects serializable.
|
||||||
return JSON.parse(results) as MastodonStatus[]
|
return JSON.parse(results) as MastodonStatus[]
|
||||||
|
|
|
@ -12,7 +12,7 @@ export const statusesLoader = loader$<Promise<MastodonStatus[]>, { DATABASE: D1D
|
||||||
async ({ platform, html }) => {
|
async ({ platform, html }) => {
|
||||||
try {
|
try {
|
||||||
// TODO: use the "trending" API endpoint here.
|
// TODO: use the "trending" API endpoint here.
|
||||||
const response = await timelines.handleRequest(platform.domain, getDatabase(platform))
|
const response = await timelines.handleRequest(platform.domain, await getDatabase(platform))
|
||||||
const results = await response.text()
|
const results = await response.text()
|
||||||
// Manually parse the JSON to ensure that Qwik finds the resulting objects serializable.
|
// Manually parse the JSON to ensure that Qwik finds the resulting objects serializable.
|
||||||
return JSON.parse(results) as MastodonStatus[]
|
return JSON.parse(results) as MastodonStatus[]
|
||||||
|
|
|
@ -12,7 +12,7 @@ export const statusesLoader = loader$<Promise<MastodonStatus[]>, { DATABASE: D1D
|
||||||
async ({ platform, html }) => {
|
async ({ platform, html }) => {
|
||||||
try {
|
try {
|
||||||
// TODO: use the "trending" API endpoint here.
|
// TODO: use the "trending" API endpoint here.
|
||||||
const response = await timelines.handleRequest(platform.domain, getDatabase(platform), { local: true })
|
const response = await timelines.handleRequest(platform.domain, await getDatabase(platform), { local: true })
|
||||||
const results = await response.text()
|
const results = await response.text()
|
||||||
// Manually parse the JSON to ensure that Qwik finds the resulting objects serializable.
|
// Manually parse the JSON to ensure that Qwik finds the resulting objects serializable.
|
||||||
return JSON.parse(results) as MastodonStatus[]
|
return JSON.parse(results) as MastodonStatus[]
|
||||||
|
|
|
@ -7,7 +7,7 @@ import type { WebFingerResponse } from '../../backend/src/webfinger'
|
||||||
import { type Database, getDatabase } from 'wildebeest/backend/src/database'
|
import { type Database, getDatabase } from 'wildebeest/backend/src/database'
|
||||||
|
|
||||||
export const onRequest: PagesFunction<Env, any> = async ({ request, env }) => {
|
export const onRequest: PagesFunction<Env, any> = async ({ request, env }) => {
|
||||||
return handleRequest(request, getDatabase(env))
|
return handleRequest(request, await getDatabase(env))
|
||||||
}
|
}
|
||||||
|
|
||||||
const headers = {
|
const headers = {
|
||||||
|
|
|
@ -5,7 +5,7 @@ import * as objects from 'wildebeest/backend/src/activitypub/objects'
|
||||||
|
|
||||||
export const onRequest: PagesFunction<Env, any> = async ({ params, request, env }) => {
|
export const onRequest: PagesFunction<Env, any> = async ({ params, request, env }) => {
|
||||||
const domain = new URL(request.url).hostname
|
const domain = new URL(request.url).hostname
|
||||||
return handleRequest(domain, getDatabase(env), params.id as string)
|
return handleRequest(domain, await getDatabase(env), params.id as string)
|
||||||
}
|
}
|
||||||
|
|
||||||
const headers = {
|
const headers = {
|
||||||
|
|
|
@ -7,7 +7,7 @@ import * as actors from 'wildebeest/backend/src/activitypub/actors'
|
||||||
|
|
||||||
export const onRequest: PagesFunction<Env, any> = async ({ params, request, env }) => {
|
export const onRequest: PagesFunction<Env, any> = async ({ params, request, env }) => {
|
||||||
const domain = new URL(request.url).hostname
|
const domain = new URL(request.url).hostname
|
||||||
return handleRequest(domain, getDatabase(env), params.id as string)
|
return handleRequest(domain, await getDatabase(env), params.id as string)
|
||||||
}
|
}
|
||||||
|
|
||||||
const headers = {
|
const headers = {
|
||||||
|
|
|
@ -11,7 +11,7 @@ const headers = {
|
||||||
|
|
||||||
export const onRequest: PagesFunction<Env, any> = async ({ params, request, env }) => {
|
export const onRequest: PagesFunction<Env, any> = async ({ params, request, env }) => {
|
||||||
const domain = new URL(request.url).hostname
|
const domain = new URL(request.url).hostname
|
||||||
return handleRequest(domain, getDatabase(env), params.id as string)
|
return handleRequest(domain, await getDatabase(env), params.id as string)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function handleRequest(domain: string, db: Database, id: string): Promise<Response> {
|
export async function handleRequest(domain: string, db: Database, id: string): Promise<Response> {
|
||||||
|
|
|
@ -8,7 +8,7 @@ import type { Env } from 'wildebeest/backend/src/types/env'
|
||||||
|
|
||||||
export const onRequest: PagesFunction<Env, any, ContextData> = async ({ request, env, params }) => {
|
export const onRequest: PagesFunction<Env, any, ContextData> = async ({ request, env, params }) => {
|
||||||
const domain = new URL(request.url).hostname
|
const domain = new URL(request.url).hostname
|
||||||
return handleRequest(domain, getDatabase(env), params.id as string)
|
return handleRequest(domain, await getDatabase(env), params.id as string)
|
||||||
}
|
}
|
||||||
|
|
||||||
const headers = {
|
const headers = {
|
||||||
|
|
|
@ -11,7 +11,7 @@ const headers = {
|
||||||
|
|
||||||
export const onRequest: PagesFunction<Env, any> = async ({ params, request, env }) => {
|
export const onRequest: PagesFunction<Env, any> = async ({ params, request, env }) => {
|
||||||
const domain = new URL(request.url).hostname
|
const domain = new URL(request.url).hostname
|
||||||
return handleRequest(domain, getDatabase(env), params.id as string)
|
return handleRequest(domain, await getDatabase(env), params.id as string)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function handleRequest(domain: string, db: Database, id: string): Promise<Response> {
|
export async function handleRequest(domain: string, db: Database, id: string): Promise<Response> {
|
||||||
|
|
|
@ -8,7 +8,7 @@ import type { Env } from 'wildebeest/backend/src/types/env'
|
||||||
|
|
||||||
export const onRequest: PagesFunction<Env, any, ContextData> = async ({ request, env, params }) => {
|
export const onRequest: PagesFunction<Env, any, ContextData> = async ({ request, env, params }) => {
|
||||||
const domain = new URL(request.url).hostname
|
const domain = new URL(request.url).hostname
|
||||||
return handleRequest(domain, getDatabase(env), params.id as string)
|
return handleRequest(domain, await getDatabase(env), params.id as string)
|
||||||
}
|
}
|
||||||
|
|
||||||
const headers = {
|
const headers = {
|
||||||
|
|
|
@ -41,7 +41,7 @@ export const onRequest: PagesFunction<Env, any> = async ({ params, request, env
|
||||||
const domain = new URL(request.url).hostname
|
const domain = new URL(request.url).hostname
|
||||||
return handleRequest(
|
return handleRequest(
|
||||||
domain,
|
domain,
|
||||||
getDatabase(env),
|
await getDatabase(env),
|
||||||
params.id as string,
|
params.id as string,
|
||||||
activity,
|
activity,
|
||||||
env.QUEUE,
|
env.QUEUE,
|
||||||
|
|
|
@ -7,7 +7,7 @@ import type { Env } from 'wildebeest/backend/src/types/env'
|
||||||
|
|
||||||
export const onRequest: PagesFunction<Env, any, ContextData> = async ({ request, env, params }) => {
|
export const onRequest: PagesFunction<Env, any, ContextData> = async ({ request, env, params }) => {
|
||||||
const domain = new URL(request.url).hostname
|
const domain = new URL(request.url).hostname
|
||||||
return handleRequest(domain, getDatabase(env), params.id as string, env.userKEK)
|
return handleRequest(domain, await getDatabase(env), params.id as string, env.userKEK)
|
||||||
}
|
}
|
||||||
|
|
||||||
const headers = {
|
const headers = {
|
||||||
|
|
|
@ -12,7 +12,7 @@ import { PUBLIC_GROUP } from 'wildebeest/backend/src/activitypub/activities'
|
||||||
|
|
||||||
export const onRequest: PagesFunction<Env, any, ContextData> = async ({ request, env, params }) => {
|
export const onRequest: PagesFunction<Env, any, ContextData> = async ({ request, env, params }) => {
|
||||||
const domain = new URL(request.url).hostname
|
const domain = new URL(request.url).hostname
|
||||||
return handleRequest(domain, getDatabase(env), params.id as string)
|
return handleRequest(domain, await getDatabase(env), params.id as string)
|
||||||
}
|
}
|
||||||
|
|
||||||
const headers = {
|
const headers = {
|
||||||
|
|
|
@ -13,7 +13,7 @@ const headers = {
|
||||||
|
|
||||||
export const onRequest: PagesFunction<Env, any, ContextData> = async ({ request, env, params }) => {
|
export const onRequest: PagesFunction<Env, any, ContextData> = async ({ request, env, params }) => {
|
||||||
const domain = new URL(request.url).hostname
|
const domain = new URL(request.url).hostname
|
||||||
return handleRequest(domain, params.id as string, getDatabase(env))
|
return handleRequest(domain, params.id as string, await getDatabase(env))
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function handleRequest(domain: string, id: string, db: Database): Promise<Response> {
|
export async function handleRequest(domain: string, id: string, db: Database): Promise<Response> {
|
||||||
|
|
|
@ -13,7 +13,7 @@ import type { Relationship } from 'wildebeest/backend/src/types/account'
|
||||||
import { addFollowing } from 'wildebeest/backend/src/mastodon/follow'
|
import { addFollowing } from 'wildebeest/backend/src/mastodon/follow'
|
||||||
|
|
||||||
export const onRequest: PagesFunction<Env, any, ContextData> = async ({ request, env, params, data }) => {
|
export const onRequest: PagesFunction<Env, any, ContextData> = async ({ request, env, params, data }) => {
|
||||||
return handleRequest(request, getDatabase(env), params.id as string, data.connectedActor, env.userKEK)
|
return handleRequest(request, await getDatabase(env), params.id as string, data.connectedActor, env.userKEK)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function handleRequest(
|
export async function handleRequest(
|
||||||
|
|
|
@ -16,7 +16,7 @@ import { getFollowers, loadActors } from 'wildebeest/backend/src/activitypub/act
|
||||||
import * as localFollow from 'wildebeest/backend/src/mastodon/follow'
|
import * as localFollow from 'wildebeest/backend/src/mastodon/follow'
|
||||||
|
|
||||||
export const onRequest: PagesFunction<Env, any, ContextData> = async ({ params, request, env }) => {
|
export const onRequest: PagesFunction<Env, any, ContextData> = async ({ params, request, env }) => {
|
||||||
return handleRequest(request, getDatabase(env), params.id as string)
|
return handleRequest(request, await getDatabase(env), params.id as string)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function handleRequest(request: Request, db: Database, id: string): Promise<Response> {
|
export async function handleRequest(request: Request, db: Database, id: string): Promise<Response> {
|
||||||
|
|
|
@ -16,7 +16,7 @@ import * as webfinger from 'wildebeest/backend/src/webfinger'
|
||||||
import { getFollowing, loadActors } from 'wildebeest/backend/src/activitypub/actors/follow'
|
import { getFollowing, loadActors } from 'wildebeest/backend/src/activitypub/actors/follow'
|
||||||
|
|
||||||
export const onRequest: PagesFunction<Env, any, ContextData> = async ({ params, request, env }) => {
|
export const onRequest: PagesFunction<Env, any, ContextData> = async ({ params, request, env }) => {
|
||||||
return handleRequest(request, getDatabase(env), params.id as string)
|
return handleRequest(request, await getDatabase(env), params.id as string)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function handleRequest(request: Request, db: Database, id: string): Promise<Response> {
|
export async function handleRequest(request: Request, db: Database, id: string): Promise<Response> {
|
||||||
|
|
|
@ -26,7 +26,7 @@ const headers = {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const onRequest: PagesFunction<Env, any, ContextData> = async ({ request, env, params }) => {
|
export const onRequest: PagesFunction<Env, any, ContextData> = async ({ request, env, params }) => {
|
||||||
return handleRequest(request, getDatabase(env), params.id as string)
|
return handleRequest(request, await getDatabase(env), params.id as string)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function handleRequest(request: Request, db: Database, id: string): Promise<Response> {
|
export async function handleRequest(request: Request, db: Database, id: string): Promise<Response> {
|
||||||
|
|
|
@ -12,7 +12,7 @@ import type { Relationship } from 'wildebeest/backend/src/types/account'
|
||||||
import { removeFollowing } from 'wildebeest/backend/src/mastodon/follow'
|
import { removeFollowing } from 'wildebeest/backend/src/mastodon/follow'
|
||||||
|
|
||||||
export const onRequest: PagesFunction<Env, any, ContextData> = async ({ request, env, params, data }) => {
|
export const onRequest: PagesFunction<Env, any, ContextData> = async ({ request, env, params, data }) => {
|
||||||
return handleRequest(request, getDatabase(env), params.id as string, data.connectedActor, env.userKEK)
|
return handleRequest(request, await getDatabase(env), params.id as string, data.connectedActor, env.userKEK)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function handleRequest(
|
export async function handleRequest(
|
||||||
|
|
|
@ -8,7 +8,7 @@ import type { ContextData } from 'wildebeest/backend/src/types/context'
|
||||||
import { getFollowingAcct, getFollowingRequestedAcct } from 'wildebeest/backend/src/mastodon/follow'
|
import { getFollowingAcct, getFollowingRequestedAcct } from 'wildebeest/backend/src/mastodon/follow'
|
||||||
|
|
||||||
export const onRequest: PagesFunction<Env, any, ContextData> = async ({ request, env, data }) => {
|
export const onRequest: PagesFunction<Env, any, ContextData> = async ({ request, env, data }) => {
|
||||||
return handleRequest(request, getDatabase(env), data.connectedActor)
|
return handleRequest(request, await getDatabase(env), data.connectedActor)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function handleRequest(req: Request, db: Database, connectedActor: Person): Promise<Response> {
|
export async function handleRequest(req: Request, db: Database, connectedActor: Person): Promise<Response> {
|
||||||
|
|
|
@ -22,7 +22,7 @@ const headers = {
|
||||||
|
|
||||||
export const onRequest: PagesFunction<Env, any, ContextData> = async ({ request, data, env }) => {
|
export const onRequest: PagesFunction<Env, any, ContextData> = async ({ request, data, env }) => {
|
||||||
return handleRequest(
|
return handleRequest(
|
||||||
getDatabase(env),
|
await getDatabase(env),
|
||||||
request,
|
request,
|
||||||
data.connectedActor,
|
data.connectedActor,
|
||||||
env.CF_ACCOUNT_ID,
|
env.CF_ACCOUNT_ID,
|
||||||
|
|
|
@ -12,7 +12,7 @@ export const onRequest: PagesFunction<Env, any, ContextData> = async ({ data, en
|
||||||
if (!data.connectedActor) {
|
if (!data.connectedActor) {
|
||||||
return errors.notAuthorized('no connected user')
|
return errors.notAuthorized('no connected user')
|
||||||
}
|
}
|
||||||
const user = await loadLocalMastodonAccount(getDatabase(env), data.connectedActor)
|
const user = await loadLocalMastodonAccount(await getDatabase(env), data.connectedActor)
|
||||||
|
|
||||||
const res: CredentialAccount = {
|
const res: CredentialAccount = {
|
||||||
...user,
|
...user,
|
||||||
|
|
|
@ -17,7 +17,7 @@ type AppsPost = {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const onRequest: PagesFunction<Env, any, ContextData> = async ({ request, env }) => {
|
export const onRequest: PagesFunction<Env, any, ContextData> = async ({ request, env }) => {
|
||||||
return handleRequest(getDatabase(env), request, getVAPIDKeys(env))
|
return handleRequest(await getDatabase(env), request, getVAPIDKeys(env))
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function handleRequest(db: Database, request: Request, vapidKeys: JWK) {
|
export async function handleRequest(db: Database, request: Request, vapidKeys: JWK) {
|
||||||
|
|
|
@ -4,7 +4,7 @@ import type { Env } from 'wildebeest/backend/src/types/env'
|
||||||
import { getPeers } from 'wildebeest/backend/src/activitypub/peers'
|
import { getPeers } from 'wildebeest/backend/src/activitypub/peers'
|
||||||
|
|
||||||
export const onRequest: PagesFunction<Env, any> = async ({ env }) => {
|
export const onRequest: PagesFunction<Env, any> = async ({ env }) => {
|
||||||
return handleRequest(getDatabase(env))
|
return handleRequest(await getDatabase(env))
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function handleRequest(db: Database): Promise<Response> {
|
export async function handleRequest(db: Database): Promise<Response> {
|
||||||
|
|
|
@ -15,7 +15,7 @@ const headers = {
|
||||||
|
|
||||||
export const onRequest: PagesFunction<Env, any, ContextData> = async ({ data, request, env, params }) => {
|
export const onRequest: PagesFunction<Env, any, ContextData> = async ({ data, request, env, params }) => {
|
||||||
const domain = new URL(request.url).hostname
|
const domain = new URL(request.url).hostname
|
||||||
return handleRequest(domain, params.id as string, getDatabase(env), data.connectedActor)
|
return handleRequest(domain, params.id as string, await getDatabase(env), data.connectedActor)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function handleRequest(
|
export async function handleRequest(
|
||||||
|
|
|
@ -12,11 +12,11 @@ import { VAPIDPublicKey } from 'wildebeest/backend/src/mastodon/subscription'
|
||||||
import { type Database, getDatabase } from 'wildebeest/backend/src/database'
|
import { type Database, getDatabase } from 'wildebeest/backend/src/database'
|
||||||
|
|
||||||
export const onRequestGet: PagesFunction<Env, any, ContextData> = async ({ request, env, data }) => {
|
export const onRequestGet: PagesFunction<Env, any, ContextData> = async ({ request, env, data }) => {
|
||||||
return handleGetRequest(getDatabase(env), request, data.connectedActor, data.clientId, getVAPIDKeys(env))
|
return handleGetRequest(await getDatabase(env), request, data.connectedActor, data.clientId, getVAPIDKeys(env))
|
||||||
}
|
}
|
||||||
|
|
||||||
export const onRequestPost: PagesFunction<Env, any, ContextData> = async ({ request, env, data }) => {
|
export const onRequestPost: PagesFunction<Env, any, ContextData> = async ({ request, env, data }) => {
|
||||||
return handlePostRequest(getDatabase(env), request, data.connectedActor, data.clientId, getVAPIDKeys(env))
|
return handlePostRequest(await getDatabase(env), request, data.connectedActor, data.clientId, getVAPIDKeys(env))
|
||||||
}
|
}
|
||||||
|
|
||||||
const headers = {
|
const headers = {
|
||||||
|
|
|
@ -39,7 +39,7 @@ type StatusCreate = {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const onRequest: PagesFunction<Env, any, ContextData> = async ({ request, env, data }) => {
|
export const onRequest: PagesFunction<Env, any, ContextData> = async ({ request, env, data }) => {
|
||||||
return handleRequest(request, getDatabase(env), data.connectedActor, env.userKEK, env.QUEUE, cacheFromEnv(env))
|
return handleRequest(request, await getDatabase(env), data.connectedActor, env.userKEK, env.QUEUE, cacheFromEnv(env))
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: add tests for delivery to followers and mentions to a specific Actor.
|
// FIXME: add tests for delivery to followers and mentions to a specific Actor.
|
||||||
|
|
|
@ -20,13 +20,13 @@ import { type Database, getDatabase } from 'wildebeest/backend/src/database'
|
||||||
|
|
||||||
export const onRequestGet: PagesFunction<Env, any, ContextData> = async ({ params, env, request, data }) => {
|
export const onRequestGet: PagesFunction<Env, any, ContextData> = async ({ params, env, request, data }) => {
|
||||||
const domain = new URL(request.url).hostname
|
const domain = new URL(request.url).hostname
|
||||||
return handleRequestGet(getDatabase(env), params.id as UUID, domain, data.connectedActor)
|
return handleRequestGet(await getDatabase(env), params.id as UUID, domain, data.connectedActor)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const onRequestDelete: PagesFunction<Env, any, ContextData> = async ({ params, env, request, data }) => {
|
export const onRequestDelete: PagesFunction<Env, any, ContextData> = async ({ params, env, request, data }) => {
|
||||||
const domain = new URL(request.url).hostname
|
const domain = new URL(request.url).hostname
|
||||||
return handleRequestDelete(
|
return handleRequestDelete(
|
||||||
getDatabase(env),
|
await getDatabase(env),
|
||||||
params.id as UUID,
|
params.id as UUID,
|
||||||
data.connectedActor,
|
data.connectedActor,
|
||||||
domain,
|
domain,
|
||||||
|
|
|
@ -10,7 +10,7 @@ import { type Database, getDatabase } from 'wildebeest/backend/src/database'
|
||||||
|
|
||||||
export const onRequest: PagesFunction<Env, any, ContextData> = async ({ request, env, params }) => {
|
export const onRequest: PagesFunction<Env, any, ContextData> = async ({ request, env, params }) => {
|
||||||
const domain = new URL(request.url).hostname
|
const domain = new URL(request.url).hostname
|
||||||
return handleRequest(domain, getDatabase(env), params.id as string)
|
return handleRequest(domain, await getDatabase(env), params.id as string)
|
||||||
}
|
}
|
||||||
|
|
||||||
const headers = {
|
const headers = {
|
||||||
|
|
|
@ -17,7 +17,7 @@ import { type Database, getDatabase } from 'wildebeest/backend/src/database'
|
||||||
|
|
||||||
export const onRequest: PagesFunction<Env, any, ContextData> = async ({ env, data, params, request }) => {
|
export const onRequest: PagesFunction<Env, any, ContextData> = async ({ env, data, params, request }) => {
|
||||||
const domain = new URL(request.url).hostname
|
const domain = new URL(request.url).hostname
|
||||||
return handleRequest(getDatabase(env), params.id as string, data.connectedActor, env.userKEK, domain)
|
return handleRequest(await getDatabase(env), params.id as string, data.connectedActor, env.userKEK, domain)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function handleRequest(
|
export async function handleRequest(
|
||||||
|
|
|
@ -17,7 +17,7 @@ import { type Database, getDatabase } from 'wildebeest/backend/src/database'
|
||||||
|
|
||||||
export const onRequest: PagesFunction<Env, any, ContextData> = async ({ env, data, params, request }) => {
|
export const onRequest: PagesFunction<Env, any, ContextData> = async ({ env, data, params, request }) => {
|
||||||
const domain = new URL(request.url).hostname
|
const domain = new URL(request.url).hostname
|
||||||
return handleRequest(getDatabase(env), params.id as string, data.connectedActor, env.userKEK, env.QUEUE, domain)
|
return handleRequest(await getDatabase(env), params.id as string, data.connectedActor, env.userKEK, env.QUEUE, domain)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function handleRequest(
|
export async function handleRequest(
|
||||||
|
|
|
@ -14,7 +14,7 @@ const headers = {
|
||||||
|
|
||||||
export const onRequestGet: PagesFunction<Env, any, ContextData> = async ({ params, env, request }) => {
|
export const onRequestGet: PagesFunction<Env, any, ContextData> = async ({ params, env, request }) => {
|
||||||
const domain = new URL(request.url).hostname
|
const domain = new URL(request.url).hostname
|
||||||
return handleRequestGet(getDatabase(env), domain, params.tag as string)
|
return handleRequestGet(await getDatabase(env), domain, params.tag as string)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function handleRequestGet(db: Database, domain: string, value: string): Promise<Response> {
|
export async function handleRequestGet(db: Database, domain: string, value: string): Promise<Response> {
|
||||||
|
|
|
@ -16,7 +16,7 @@ export const onRequest: PagesFunction<Env, any, ContextData> = async ({ request,
|
||||||
const only_media = searchParams.get('only_media') === 'true'
|
const only_media = searchParams.get('only_media') === 'true'
|
||||||
const offset = Number.parseInt(searchParams.get('offset') ?? '0')
|
const offset = Number.parseInt(searchParams.get('offset') ?? '0')
|
||||||
const domain = new URL(request.url).hostname
|
const domain = new URL(request.url).hostname
|
||||||
return handleRequest(domain, getDatabase(env), { local, remote, only_media, offset })
|
return handleRequest(domain, await getDatabase(env), { local, remote, only_media, offset })
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function handleRequest(
|
export async function handleRequest(
|
||||||
|
|
|
@ -11,7 +11,7 @@ const headers = {
|
||||||
|
|
||||||
export const onRequest: PagesFunction<Env, any, ContextData> = async ({ request, env, params }) => {
|
export const onRequest: PagesFunction<Env, any, ContextData> = async ({ request, env, params }) => {
|
||||||
const domain = new URL(request.url).hostname
|
const domain = new URL(request.url).hostname
|
||||||
return handleRequest(getDatabase(env), request, domain, params.tag as string)
|
return handleRequest(await getDatabase(env), request, domain, params.tag as string)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function handleRequest(db: Database, request: Request, domain: string, tag: string): Promise<Response> {
|
export async function handleRequest(db: Database, request: Request, domain: string, tag: string): Promise<Response> {
|
||||||
|
|
|
@ -7,7 +7,7 @@ import { type Database, getDatabase } from 'wildebeest/backend/src/database'
|
||||||
|
|
||||||
export const onRequest: PagesFunction<Env, any> = async ({ env, request }) => {
|
export const onRequest: PagesFunction<Env, any> = async ({ env, request }) => {
|
||||||
const domain = new URL(request.url).hostname
|
const domain = new URL(request.url).hostname
|
||||||
return handleRequest(domain, getDatabase(env), env)
|
return handleRequest(domain, await getDatabase(env), env)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function handleRequest(domain: string, db: Database, env: Env) {
|
export async function handleRequest(domain: string, db: Database, env: Env) {
|
||||||
|
|
|
@ -9,7 +9,7 @@ import { mastodonIdSymbol } from 'wildebeest/backend/src/activitypub/objects'
|
||||||
import { type Database, getDatabase } from 'wildebeest/backend/src/database'
|
import { type Database, getDatabase } from 'wildebeest/backend/src/database'
|
||||||
|
|
||||||
export const onRequestPost: PagesFunction<Env, any, ContextData> = async ({ request, env, data }) => {
|
export const onRequestPost: PagesFunction<Env, any, ContextData> = async ({ request, env, data }) => {
|
||||||
return handleRequestPost(request, getDatabase(env), data.connectedActor, env.CF_ACCOUNT_ID, env.CF_API_TOKEN)
|
return handleRequestPost(request, await getDatabase(env), data.connectedActor, env.CF_ACCOUNT_ID, env.CF_API_TOKEN)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function handleRequestPost(
|
export async function handleRequestPost(
|
||||||
|
|
|
@ -14,7 +14,7 @@ import { updateObjectProperty } from 'wildebeest/backend/src/activitypub/objects
|
||||||
import { type Database, getDatabase } from 'wildebeest/backend/src/database'
|
import { type Database, getDatabase } from 'wildebeest/backend/src/database'
|
||||||
|
|
||||||
export const onRequestPut: PagesFunction<Env, any, ContextData> = async ({ params, env, request }) => {
|
export const onRequestPut: PagesFunction<Env, any, ContextData> = async ({ params, env, request }) => {
|
||||||
return handleRequestPut(getDatabase(env), params.id as UUID, request)
|
return handleRequestPut(await getDatabase(env), params.id as UUID, request)
|
||||||
}
|
}
|
||||||
|
|
||||||
type UpdateMedia = {
|
type UpdateMedia = {
|
||||||
|
|
|
@ -22,7 +22,7 @@ type SearchResult = {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const onRequest: PagesFunction<Env, any> = async ({ request, env }) => {
|
export const onRequest: PagesFunction<Env, any> = async ({ request, env }) => {
|
||||||
return handleRequest(getDatabase(env), request)
|
return handleRequest(await getDatabase(env), request)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function handleRequest(db: Database, request: Request): Promise<Response> {
|
export async function handleRequest(db: Database, request: Request): Promise<Response> {
|
||||||
|
|
|
@ -8,7 +8,7 @@ import * as errors from 'wildebeest/backend/src/errors'
|
||||||
import { type Database, getDatabase } from 'wildebeest/backend/src/database'
|
import { type Database, getDatabase } from 'wildebeest/backend/src/database'
|
||||||
|
|
||||||
export const onRequestPost: PagesFunction<Env, any, ContextData> = async ({ env, request, data }) => {
|
export const onRequestPost: PagesFunction<Env, any, ContextData> = async ({ env, request, data }) => {
|
||||||
return handleRequestPost(getDatabase(env), request, data.connectedActor)
|
return handleRequestPost(await getDatabase(env), request, data.connectedActor)
|
||||||
}
|
}
|
||||||
|
|
||||||
type AddAliasRequest = {
|
type AddAliasRequest = {
|
||||||
|
|
|
@ -9,7 +9,7 @@ import * as access from 'wildebeest/backend/src/access'
|
||||||
import { type Database, getDatabase } from 'wildebeest/backend/src/database'
|
import { type Database, getDatabase } from 'wildebeest/backend/src/database'
|
||||||
|
|
||||||
export const onRequestPost: PagesFunction<Env, any, ContextData> = async ({ request, env }) => {
|
export const onRequestPost: PagesFunction<Env, any, ContextData> = async ({ request, env }) => {
|
||||||
return handlePostRequest(request, getDatabase(env), env.userKEK, env.ACCESS_AUTH_DOMAIN, env.ACCESS_AUD)
|
return handlePostRequest(request, await getDatabase(env), env.userKEK, env.ACCESS_AUTH_DOMAIN, env.ACCESS_AUD)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function handlePostRequest(
|
export async function handlePostRequest(
|
||||||
|
|
|
@ -13,7 +13,7 @@ import { type Database, getDatabase } from 'wildebeest/backend/src/database'
|
||||||
const extractJWTFromRequest = (request: Request) => request.headers.get('Cf-Access-Jwt-Assertion') || ''
|
const extractJWTFromRequest = (request: Request) => request.headers.get('Cf-Access-Jwt-Assertion') || ''
|
||||||
|
|
||||||
export const onRequestPost: PagesFunction<Env, any, ContextData> = async ({ request, env }) => {
|
export const onRequestPost: PagesFunction<Env, any, ContextData> = async ({ request, env }) => {
|
||||||
return handleRequestPost(request, getDatabase(env), env.userKEK, env.ACCESS_AUTH_DOMAIN, env.ACCESS_AUD)
|
return handleRequestPost(request, await getDatabase(env), env.userKEK, env.ACCESS_AUTH_DOMAIN, env.ACCESS_AUD)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function buildRedirect(
|
export async function buildRedirect(
|
||||||
|
|
|
@ -12,7 +12,7 @@ type Body = {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const onRequest: PagesFunction<Env, any> = async ({ request, env }) => {
|
export const onRequest: PagesFunction<Env, any> = async ({ request, env }) => {
|
||||||
return handleRequest(getDatabase(env), request)
|
return handleRequest(await getDatabase(env), request)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function handleRequest(db: Database, request: Request): Promise<Response> {
|
export async function handleRequest(db: Database, request: Request): Promise<Response> {
|
||||||
|
|
Ładowanie…
Reference in New Issue