From e01e92c9cee840f8ca52506f9553c29aab8613fa Mon Sep 17 00:00:00 2001 From: Jesse Wierzbinski Date: Tue, 28 Nov 2023 17:57:35 -1000 Subject: [PATCH] Fix various missing things and bugs --- database/entities/User.ts | 5 +- index.ts | 4 +- package.json | 2 +- .../v1/accounts/verify_credentials/index.ts | 8 --- server/api/api/v1/instance/index.ts | 52 ++++++++++++++++--- types/entities/account.ts | 1 + 6 files changed, 52 insertions(+), 20 deletions(-) diff --git a/database/entities/User.ts b/database/entities/User.ts index 462292ac..6c781fb6 100644 --- a/database/entities/User.ts +++ b/database/entities/User.ts @@ -376,7 +376,10 @@ export const userToAPI = ( discoverable: undefined, mute_expires_at: undefined, group: false, - role: undefined, + pleroma: { + is_admin: user.isAdmin, + is_moderator: user.isAdmin, + }, }; }; diff --git a/index.ts b/index.ts index b812efc9..b1aadd86 100644 --- a/index.ts +++ b/index.ts @@ -33,9 +33,9 @@ if (!(await requests_log.exists())) { } // Check if database is reachable -const postCount = 0; +let postCount = 0; try { - await client.status.count(); + postCount = await client.status.count(); } catch (e) { const error = e as PrismaClientInitializationError; console.error( diff --git a/package.json b/package.json index a8cbc3f1..fb68b757 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "lysand", "module": "index.ts", "type": "module", - "version": "0.0.1", + "version": "0.1.2", "description": "A project to build a federated social network", "author": { "email": "contact@cpluspatch.com", diff --git a/server/api/api/v1/accounts/verify_credentials/index.ts b/server/api/api/v1/accounts/verify_credentials/index.ts index 49964db5..94543895 100644 --- a/server/api/api/v1/accounts/verify_credentials/index.ts +++ b/server/api/api/v1/accounts/verify_credentials/index.ts @@ -23,13 +23,5 @@ export default async (req: Request): Promise => { return jsonResponse({ ...userToAPI(user, true), - // TODO: Add role support - role: { - id: 0, - name: "", - permissions: "", - color: "", - highlighted: false, - }, }); }; diff --git a/server/api/api/v1/instance/index.ts b/server/api/api/v1/instance/index.ts index 1904aa31..d9a87537 100644 --- a/server/api/api/v1/instance/index.ts +++ b/server/api/api/v1/instance/index.ts @@ -2,6 +2,9 @@ import { applyConfig } from "@api"; import { getConfig } from "@config"; import { jsonResponse } from "@response"; import { client } from "~database/datasource"; +import { userRelations, userToAPI } from "~database/entities/User"; +import type { APIInstance } from "~types/entities/instance"; +import manifest from "~package.json"; export const meta = applyConfig({ allowedMethods: ["GET"], @@ -22,6 +25,9 @@ export const meta = applyConfig({ export default async (): Promise => { const config = getConfig(); + // Get software version from package.json + const version = manifest.version; + const statusCount = await client.status.count({ where: { instanceId: null, @@ -33,12 +39,40 @@ export default async (): Promise => { }, }); + // Get the first created admin user + const contactAccount = await client.user.findFirst({ + where: { + instanceId: null, + isAdmin: true, + }, + orderBy: { + id: "asc", + }, + include: userRelations, + }); + + // Get user that have posted once in the last 30 days + const monthlyActiveUsers = await client.user.count({ + where: { + instanceId: null, + statuses: { + some: { + createdAt: { + gte: new Date(Date.now() - 30 * 24 * 60 * 60 * 1000), + }, + }, + }, + }, + }); + + const knownDomainsCount = await client.instance.count(); + // TODO: fill in more values return jsonResponse({ approval_required: false, configuration: { media_attachments: { - image_matrix_limit: 10, + image_matrix_limit: config.validation.max_media_attachments, image_size_limit: config.validation.max_media_size, supported_mime_types: config.validation.allowed_mime_types, video_frame_limit: 60, @@ -46,9 +80,10 @@ export default async (): Promise => { video_size_limit: config.validation.max_media_size, }, polls: { - max_characters_per_option: 100, - max_expiration: 60 * 60 * 24 * 365 * 100, // 100 years, - max_options: 40, + max_characters_per_option: + config.validation.max_poll_option_size, + max_expiration: config.validation.max_poll_duration, + max_options: config.validation.max_poll_options, min_expiration: 60, }, statuses: { @@ -70,7 +105,7 @@ export default async (): Promise => { languages: ["en"], rules: [], stats: { - domain_count: 1, + domain_count: knownDomainsCount, status_count: statusCount, user_count: userCount, }, @@ -80,7 +115,7 @@ export default async (): Promise => { urls: { streaming_api: "", }, - version: "4.2.0+glitch (compatible; Lysand 0.0.1)", + version: `4.2.0+glitch (compatible; Lysand ${version}})`, max_toot_chars: config.validation.max_note_size, pleroma: { metadata: { @@ -115,8 +150,9 @@ export default async (): Promise => { privileged_staff: false, }, stats: { - mau: 2, + mau: monthlyActiveUsers, }, }, - }); + contact_account: contactAccount ? userToAPI(contactAccount) : null, + } as APIInstance); }; diff --git a/types/entities/account.ts b/types/entities/account.ts index 6348dc09..0d418927 100644 --- a/types/entities/account.ts +++ b/types/entities/account.ts @@ -31,4 +31,5 @@ export interface APIAccount { source?: APISource; role?: APIRole; mute_expires_at?: string; + pleroma?: any; }