From efbeaf7dd4e20b6e50ba1f50b7edf87d13e3726b Mon Sep 17 00:00:00 2001 From: Sven Sauleau Date: Tue, 17 Jan 2023 10:25:19 +0000 Subject: [PATCH] Pleroma-compatible version string Refs https://github.com/cloudflare/wildebeest/pull/70 --- backend/test/mastodon.spec.ts | 2 ++ config/versions.ts | 10 ++++++++++ functions/api/v1/instance.ts | 5 ++--- functions/api/v2/instance.ts | 5 ++--- jest.config.js | 2 +- package.json | 2 +- 6 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 config/versions.ts diff --git a/backend/test/mastodon.spec.ts b/backend/test/mastodon.spec.ts index 8bb2760..0609a1d 100644 --- a/backend/test/mastodon.spec.ts +++ b/backend/test/mastodon.spec.ts @@ -45,6 +45,7 @@ describe('Mastodon APIs', () => { assert.equal(data.title, 'a') assert.equal(data.email, 'b') assert.equal(data.description, 'c') + assert(data.version.includes('Wildebeest')) } }) @@ -82,6 +83,7 @@ describe('Mastodon APIs', () => { assert.equal(data.title, 'a') assert.equal(data.contact.email, 'b') assert.equal(data.description, 'c') + assert(data.version.includes('Wildebeest')) } }) }) diff --git a/config/versions.ts b/config/versions.ts new file mode 100644 index 0000000..3abed88 --- /dev/null +++ b/config/versions.ts @@ -0,0 +1,10 @@ +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 function getVersion(): string { + return `${MASTODON_API_VERSION} (compatible; Wildebeest ${WILDEBEEST_VERSION})` +} diff --git a/functions/api/v1/instance.ts b/functions/api/v1/instance.ts index d42a143..c0e8142 100644 --- a/functions/api/v1/instance.ts +++ b/functions/api/v1/instance.ts @@ -1,7 +1,6 @@ import type { Env } from 'wildebeest/backend/src/types/env' import { DEFAULT_THUMBNAIL } from 'wildebeest/backend/src/config' - -const INSTANCE_VERSION = '4.0.2' +import { getVersion } from 'wildebeest/config/versions' export const onRequest: PagesFunction = async ({ env, request }) => { const domain = new URL(request.url).hostname @@ -24,7 +23,7 @@ export async function handleRequest(domain: string, env: Env) { // The documentation is incorrect and registrations is a boolean. res.registrations = false - res.version = INSTANCE_VERSION + res.version = getVersion() res.rules = [] res.uri = domain res.title = env.INSTANCE_TITLE diff --git a/functions/api/v2/instance.ts b/functions/api/v2/instance.ts index 6e75426..9031f4d 100644 --- a/functions/api/v2/instance.ts +++ b/functions/api/v2/instance.ts @@ -1,8 +1,7 @@ import type { Env } from 'wildebeest/backend/src/types/env' import { DEFAULT_THUMBNAIL } from 'wildebeest/backend/src/config' import type { InstanceConfigV2 } from 'wildebeest/backend/src/types/configs' - -const INSTANCE_VERSION = '4.0.2' +import { getVersion } from 'wildebeest/config/versions' export const onRequest: PagesFunction = async ({ env, request }) => { const domain = new URL(request.url).hostname @@ -19,7 +18,7 @@ export async function handleRequest(domain: string, db: D1Database, env: Env) { const res: InstanceConfigV2 = { domain, title: env.INSTANCE_TITLE, - version: INSTANCE_VERSION, + version: getVersion(), source_url: 'https://github.com/cloudflare/wildebeest', description: env.INSTANCE_DESCR, thumbnail: { diff --git a/jest.config.js b/jest.config.js index 3e23f9f..e457895 100644 --- a/jest.config.js +++ b/jest.config.js @@ -2,7 +2,7 @@ export default { preset: 'ts-jest', verbose: true, - testMatch: ["/(backend|consumer)/test/**/(*.)+(spec|test).[jt]s?(x)"], + testMatch: ['/(backend|consumer)/test/**/(*.)+(spec|test).[jt]s?(x)'], testTimeout: 30000, testEnvironment: 'miniflare', // Configuration is automatically loaded from `.env`, `package.json` and diff --git a/package.json b/package.json index f258ae2..0b71854 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wildebeest", - "version": "0.0.0", + "version": "0.0.1", "type": "module", "author": "Sven Sauleau ", "devDependencies": {