Fix various missing things and bugs

This commit is contained in:
Jesse Wierzbinski 2023-11-28 17:57:35 -10:00
parent 0aeeeabb33
commit e01e92c9ce
No known key found for this signature in database
6 changed files with 52 additions and 20 deletions

View file

@ -376,7 +376,10 @@ export const userToAPI = (
discoverable: undefined, discoverable: undefined,
mute_expires_at: undefined, mute_expires_at: undefined,
group: false, group: false,
role: undefined, pleroma: {
is_admin: user.isAdmin,
is_moderator: user.isAdmin,
},
}; };
}; };

View file

@ -33,9 +33,9 @@ if (!(await requests_log.exists())) {
} }
// Check if database is reachable // Check if database is reachable
const postCount = 0; let postCount = 0;
try { try {
await client.status.count(); postCount = await client.status.count();
} catch (e) { } catch (e) {
const error = e as PrismaClientInitializationError; const error = e as PrismaClientInitializationError;
console.error( console.error(

View file

@ -2,7 +2,7 @@
"name": "lysand", "name": "lysand",
"module": "index.ts", "module": "index.ts",
"type": "module", "type": "module",
"version": "0.0.1", "version": "0.1.2",
"description": "A project to build a federated social network", "description": "A project to build a federated social network",
"author": { "author": {
"email": "contact@cpluspatch.com", "email": "contact@cpluspatch.com",

View file

@ -23,13 +23,5 @@ export default async (req: Request): Promise<Response> => {
return jsonResponse({ return jsonResponse({
...userToAPI(user, true), ...userToAPI(user, true),
// TODO: Add role support
role: {
id: 0,
name: "",
permissions: "",
color: "",
highlighted: false,
},
}); });
}; };

View file

@ -2,6 +2,9 @@ import { applyConfig } from "@api";
import { getConfig } from "@config"; import { getConfig } from "@config";
import { jsonResponse } from "@response"; import { jsonResponse } from "@response";
import { client } from "~database/datasource"; 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({ export const meta = applyConfig({
allowedMethods: ["GET"], allowedMethods: ["GET"],
@ -22,6 +25,9 @@ export const meta = applyConfig({
export default async (): Promise<Response> => { export default async (): Promise<Response> => {
const config = getConfig(); const config = getConfig();
// Get software version from package.json
const version = manifest.version;
const statusCount = await client.status.count({ const statusCount = await client.status.count({
where: { where: {
instanceId: null, instanceId: null,
@ -33,12 +39,40 @@ export default async (): Promise<Response> => {
}, },
}); });
// 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 // TODO: fill in more values
return jsonResponse({ return jsonResponse({
approval_required: false, approval_required: false,
configuration: { configuration: {
media_attachments: { media_attachments: {
image_matrix_limit: 10, image_matrix_limit: config.validation.max_media_attachments,
image_size_limit: config.validation.max_media_size, image_size_limit: config.validation.max_media_size,
supported_mime_types: config.validation.allowed_mime_types, supported_mime_types: config.validation.allowed_mime_types,
video_frame_limit: 60, video_frame_limit: 60,
@ -46,9 +80,10 @@ export default async (): Promise<Response> => {
video_size_limit: config.validation.max_media_size, video_size_limit: config.validation.max_media_size,
}, },
polls: { polls: {
max_characters_per_option: 100, max_characters_per_option:
max_expiration: 60 * 60 * 24 * 365 * 100, // 100 years, config.validation.max_poll_option_size,
max_options: 40, max_expiration: config.validation.max_poll_duration,
max_options: config.validation.max_poll_options,
min_expiration: 60, min_expiration: 60,
}, },
statuses: { statuses: {
@ -70,7 +105,7 @@ export default async (): Promise<Response> => {
languages: ["en"], languages: ["en"],
rules: [], rules: [],
stats: { stats: {
domain_count: 1, domain_count: knownDomainsCount,
status_count: statusCount, status_count: statusCount,
user_count: userCount, user_count: userCount,
}, },
@ -80,7 +115,7 @@ export default async (): Promise<Response> => {
urls: { urls: {
streaming_api: "", 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, max_toot_chars: config.validation.max_note_size,
pleroma: { pleroma: {
metadata: { metadata: {
@ -115,8 +150,9 @@ export default async (): Promise<Response> => {
privileged_staff: false, privileged_staff: false,
}, },
stats: { stats: {
mau: 2, mau: monthlyActiveUsers,
}, },
}, },
}); contact_account: contactAccount ? userToAPI(contactAccount) : null,
} as APIInstance);
}; };

View file

@ -31,4 +31,5 @@ export interface APIAccount {
source?: APISource; source?: APISource;
role?: APIRole; role?: APIRole;
mute_expires_at?: string; mute_expires_at?: string;
pleroma?: any;
} }