kopia lustrzana https://github.com/cloudflare/wildebeest
MOW-130: NodeInfo 2.0 and 2.1
Closes https://github.com/cloudflare/wildebeest/issues/160pull/181/head
rodzic
74ae726bfc
commit
5929db73f8
|
@ -0,0 +1,32 @@
|
|||
import { strict as assert } from 'node:assert/strict'
|
||||
import * as nodeinfo_21 from 'wildebeest/functions/nodeinfo/2.1'
|
||||
import * as nodeinfo_20 from 'wildebeest/functions/nodeinfo/2.0'
|
||||
import * as nodeinfo from 'wildebeest/functions/.well-known/nodeinfo'
|
||||
|
||||
const domain = 'example.com'
|
||||
|
||||
describe('NodeInfo', () => {
|
||||
test('well-known returns links', async () => {
|
||||
const res = await nodeinfo.handleRequest(domain)
|
||||
assert.equal(res.status, 200)
|
||||
|
||||
const data = await res.json<any>()
|
||||
assert.equal(data.links.length, 2)
|
||||
})
|
||||
|
||||
test('expose NodeInfo version 2.0', async () => {
|
||||
const res = await nodeinfo_20.handleRequest()
|
||||
assert.equal(res.status, 200)
|
||||
|
||||
const data = await res.json<any>()
|
||||
assert.equal(data.version, '2.0')
|
||||
})
|
||||
|
||||
test('expose NodeInfo version 2.1', async () => {
|
||||
const res = await nodeinfo_21.handleRequest()
|
||||
assert.equal(res.status, 200)
|
||||
|
||||
const data = await res.json<any>()
|
||||
assert.equal(data.version, '2.1')
|
||||
})
|
||||
})
|
|
@ -3,7 +3,7 @@ import * as packagejson from '../package.json'
|
|||
// https://github.com/mastodon/mastodon/blob/main/CHANGELOG.md
|
||||
const MASTODON_API_VERSION = '4.0.2'
|
||||
|
||||
const WILDEBEEST_VERSION = packagejson.version
|
||||
export const WILDEBEEST_VERSION = packagejson.version
|
||||
|
||||
export function getVersion(): string {
|
||||
return `${MASTODON_API_VERSION} (compatible; Wildebeest ${WILDEBEEST_VERSION})`
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
import type { Env } from 'wildebeest/backend/src/types/env'
|
||||
|
||||
const headers = {
|
||||
'content-type': 'application/json',
|
||||
'cache-control': 'max-age=259200, public',
|
||||
}
|
||||
|
||||
export const onRequest: PagesFunction<Env, any> = async ({ env }) => {
|
||||
return handleRequest(env.DOMAIN)
|
||||
}
|
||||
|
||||
export async function handleRequest(domain: string): Promise<Response> {
|
||||
const res = {
|
||||
links: [
|
||||
{
|
||||
rel: 'http://nodeinfo.diaspora.software/ns/schema/2.0',
|
||||
href: `https://${domain}/nodeinfo/2.0`,
|
||||
},
|
||||
{
|
||||
rel: 'http://nodeinfo.diaspora.software/ns/schema/2.1',
|
||||
href: `https://${domain}/nodeinfo/2.1`,
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
return new Response(JSON.stringify(res), { headers })
|
||||
}
|
|
@ -55,5 +55,5 @@ export async function handleRequest(request: Request, db: D1Database): Promise<R
|
|||
],
|
||||
}
|
||||
|
||||
return new Response(JSON.stringify(res), { status: 200, headers })
|
||||
return new Response(JSON.stringify(res), { headers })
|
||||
}
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
import type { Env } from 'wildebeest/backend/src/types/env'
|
||||
import { WILDEBEEST_VERSION } from 'wildebeest/config/versions'
|
||||
|
||||
const headers = {
|
||||
'content-type': 'application/json',
|
||||
'cache-control': 'max-age=259200, public',
|
||||
}
|
||||
|
||||
export const onRequest: PagesFunction<Env, any> = async () => {
|
||||
return handleRequest()
|
||||
}
|
||||
|
||||
export async function handleRequest(): Promise<Response> {
|
||||
const res = {
|
||||
version: '2.0',
|
||||
software: { name: 'Wildebeest', version: WILDEBEEST_VERSION },
|
||||
protocols: ['activitypub'],
|
||||
services: { outbound: [], inbound: [] },
|
||||
usage: { users: {} },
|
||||
openRegistrations: false,
|
||||
metadata: {},
|
||||
}
|
||||
|
||||
return new Response(JSON.stringify(res), { headers })
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
import type { Env } from 'wildebeest/backend/src/types/env'
|
||||
import { WILDEBEEST_VERSION } from 'wildebeest/config/versions'
|
||||
|
||||
const headers = {
|
||||
'content-type': 'application/json',
|
||||
'cache-control': 'max-age=259200, public',
|
||||
}
|
||||
|
||||
export const onRequest: PagesFunction<Env, any> = async () => {
|
||||
return handleRequest()
|
||||
}
|
||||
|
||||
export async function handleRequest(): Promise<Response> {
|
||||
const res = {
|
||||
version: '2.1',
|
||||
software: {
|
||||
name: 'Wildebeest',
|
||||
version: WILDEBEEST_VERSION,
|
||||
repository: 'https://github.com/cloudflare/wildebeest',
|
||||
},
|
||||
protocols: ['activitypub'],
|
||||
services: { outbound: [], inbound: [] },
|
||||
usage: { users: {} },
|
||||
openRegistrations: false,
|
||||
metadata: {},
|
||||
}
|
||||
|
||||
return new Response(JSON.stringify(res), { headers })
|
||||
}
|
Ładowanie…
Reference in New Issue