kopia lustrzana https://github.com/cloudflare/wildebeest
Making requested changes
rodzic
ea5f3fa063
commit
3283c55e30
|
@ -1,9 +1,11 @@
|
|||
import type { InstanceStatistics } from 'wildebeest/backend/src/types/instance'
|
||||
import { instanceStatisticsQuery } from 'wildebeest/backend/src/mastodon/sql/instance'
|
||||
import { sqlMastoV1InstanceStats } from 'wildebeest/backend/src/mastodon/sql/instance'
|
||||
import { Database } from 'wildebeest/backend/src/database'
|
||||
|
||||
export async function calculateInstanceStatistics(origin: string, db: Database): Promise<InstanceStatistics> {
|
||||
const row: any = await db.prepare(instanceStatisticsQuery(origin)).first()
|
||||
const row: any = await db
|
||||
.prepare(sqlMastoV1InstanceStats(origin))
|
||||
.first<{ user_count: number; status_count: number; domain_count: number }>()
|
||||
|
||||
return {
|
||||
user_count: row?.user_count ?? 0,
|
||||
|
|
|
@ -1,8 +1,26 @@
|
|||
// Prepared statements for Mastodon Instance API endpoints
|
||||
export const instanceStatisticsQuery = (origin: string): string => {
|
||||
/** Returns a SQL statement that can be used to calculate the instance-level
|
||||
* statistics required by the Mastodon `GET /api/v1/instance` endpoint. The
|
||||
* string returned by this method should be passed as a prepared statement
|
||||
* to a `Database` object that references a Wildebeest database instance in order
|
||||
* to retrieve actual results. For example:
|
||||
*
|
||||
*
|
||||
* ```
|
||||
* const sqlQuery: string = sqlMastoV1InstanceStats('https://example.com')
|
||||
* const row: any = await db.prepare(sqlQuery).first<{ user_count: number, status_count: number, domain_count: number }>()
|
||||
*
|
||||
*
|
||||
* ```
|
||||
*
|
||||
* @param domain expects an HTTP **origin** (i.e. must include the https://)
|
||||
* @return a string value representing a SQL statement that can be used to
|
||||
* calculate instance-level aggregate statistics
|
||||
*/
|
||||
export const sqlMastoV1InstanceStats = (domain: string): string => {
|
||||
return `
|
||||
SELECT
|
||||
(SELECT count(1) FROM actors WHERE type IN ('Person', 'Service') AND id LIKE '%${origin}/ap/users/%') AS user_count,
|
||||
(SELECT count(1) FROM actors WHERE type IN ('Person', 'Service') AND id LIKE '%${domain}/ap/users/%') AS user_count,
|
||||
(SELECT count(1) FROM objects WHERE local = 1 AND type = 'Note') AS status_count,
|
||||
(SELECT count(1) FROM peers) + 1 AS domain_count
|
||||
;
|
||||
|
|
|
@ -21,9 +21,6 @@ export interface Env {
|
|||
INSTANCE_DESCR: string
|
||||
VAPID_JWK: string
|
||||
DOMAIN: string
|
||||
INSTANCE_ACCEPTING_REGISTRATIONS?: boolean
|
||||
INSTANCE_REGISTRATIONS_REQUIRE_APPROVAL?: boolean
|
||||
INSTANCE_CONFIG_STATUSES_MAX_CHARACTERS?: number
|
||||
|
||||
SENTRY_DSN: string
|
||||
SENTRY_ACCESS_CLIENT_ID: string
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { WILDEBEEST_VERSION, MASTODON_API_VERSION } from 'wildebeest/config/versions'
|
||||
|
||||
export function getFederationUA(domain: string): string {
|
||||
return `Wildebeest/${WILDEBEEST_VERSION} (Mastodon/${MASTODON_API_VERSION}; +${domain})`
|
||||
return `Wildebeest/${WILDEBEEST_VERSION} (Mastodon/${MASTODON_API_VERSION} compatible; +https://${domain})`
|
||||
}
|
||||
|
|
|
@ -4,9 +4,3 @@ import * as packagejson from '../package.json'
|
|||
export const MASTODON_API_VERSION = '4.0.2'
|
||||
|
||||
export const WILDEBEEST_VERSION = packagejson.version
|
||||
|
||||
export function getVersion(domain?: string): string {
|
||||
return `Wildebeest/${WILDEBEEST_VERSION} (Mastodon/${MASTODON_API_VERSION} compatible; +https://${
|
||||
domain ?? 'github.com/cloudflare/wildebeest'
|
||||
})`
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import type { Env } from 'wildebeest/backend/src/types/env'
|
|||
import { cors } from 'wildebeest/backend/src/utils/cors'
|
||||
import * as error from 'wildebeest/backend/src/errors'
|
||||
import { DEFAULT_THUMBNAIL } from 'wildebeest/backend/src/config'
|
||||
import { getVersion } from 'wildebeest/config/versions'
|
||||
import { getFederationUA } from 'wildebeest/config/ua'
|
||||
import { calculateInstanceStatistics } from 'wildebeest/backend/src/mastodon/instance'
|
||||
import { MastodonInstance, InstanceStatistics } from 'wildebeest/backend/src/types/instance'
|
||||
import { MastodonAccount } from 'wildebeest/backend/src/types/account'
|
||||
|
@ -31,20 +31,20 @@ export async function handleRequest(domain: string, env: Env, dbOverride?: Datab
|
|||
description: env?.INSTANCE_DESCR,
|
||||
short_description: env?.INSTANCE_DESCR,
|
||||
email: env?.ADMIN_EMAIL,
|
||||
version: getVersion(domain),
|
||||
version: getFederationUA(domain),
|
||||
languages: ['en'],
|
||||
registrations: env?.INSTANCE_ACCEPTING_REGISTRATIONS ?? false,
|
||||
approval_required: env?.INSTANCE_REGISTRATIONS_REQUIRE_APPROVAL ?? false,
|
||||
registrations: false,
|
||||
approval_required: false,
|
||||
invites_enabled: false,
|
||||
thumbnail: DEFAULT_THUMBNAIL,
|
||||
configuration: {
|
||||
statuses: {
|
||||
max_characters: env?.INSTANCE_CONFIG_STATUSES_MAX_CHARACTERS ?? 500,
|
||||
max_characters: 500,
|
||||
max_media_attachments: 4,
|
||||
characters_reserved_per_url: 23,
|
||||
},
|
||||
media_attachments: {
|
||||
supported_mime_types: ['image/jpeg', 'image/png', 'image/gif', 'image/webp', 'video/mp4'],
|
||||
supported_mime_types: ['image/jpeg', 'image/png', 'image/gif', 'image/webp'],
|
||||
image_size_limit: 10485760,
|
||||
image_matrix_limit: 16777216,
|
||||
video_size_limit: 41943040,
|
||||
|
@ -52,10 +52,10 @@ export async function handleRequest(domain: string, env: Env, dbOverride?: Datab
|
|||
video_matrix_limit: 2304000,
|
||||
},
|
||||
polls: {
|
||||
max_options: 4,
|
||||
max_characters_per_option: 50,
|
||||
min_expiration: 300,
|
||||
max_expiration: 2629746,
|
||||
max_options: 0,
|
||||
max_characters_per_option: 1,
|
||||
min_expiration: 1,
|
||||
max_expiration: 1,
|
||||
},
|
||||
},
|
||||
rules: [],
|
||||
|
|
|
@ -2,7 +2,7 @@ import type { Env } from 'wildebeest/backend/src/types/env'
|
|||
import { cors } from 'wildebeest/backend/src/utils/cors'
|
||||
import { DEFAULT_THUMBNAIL } from 'wildebeest/backend/src/config'
|
||||
import type { InstanceConfigV2 } from 'wildebeest/backend/src/types/configs'
|
||||
import { getVersion } from 'wildebeest/config/versions'
|
||||
import { getFederationUA } from 'wildebeest/config/ua'
|
||||
import { type Database, getDatabase } from 'wildebeest/backend/src/database'
|
||||
|
||||
export const onRequest: PagesFunction<Env, any> = async ({ env, request }) => {
|
||||
|
@ -19,7 +19,7 @@ export async function handleRequest(domain: string, db: Database, env: Env) {
|
|||
const res: InstanceConfigV2 = {
|
||||
domain,
|
||||
title: env.INSTANCE_TITLE,
|
||||
version: getVersion(domain),
|
||||
version: getFederationUA(domain),
|
||||
source_url: 'https://github.com/cloudflare/wildebeest',
|
||||
description: env.INSTANCE_DESCR,
|
||||
thumbnail: {
|
||||
|
|
Ładowanie…
Reference in New Issue