Configure server from the kind 0 event of the admin user
This commit is contained in:
parent
7c4590e6d4
commit
15810c1935
|
@ -58,10 +58,6 @@ const Conf = {
|
||||||
get postCharLimit() {
|
get postCharLimit() {
|
||||||
return Number(Deno.env.get('POST_CHAR_LIMIT') || 5000);
|
return Number(Deno.env.get('POST_CHAR_LIMIT') || 5000);
|
||||||
},
|
},
|
||||||
/** Admin contact to expose through various endpoints. This information is public. */
|
|
||||||
get adminEmail() {
|
|
||||||
return Deno.env.get('ADMIN_EMAIL') || 'webmaster@localhost';
|
|
||||||
},
|
|
||||||
/** S3 media storage configuration. */
|
/** S3 media storage configuration. */
|
||||||
s3: {
|
s3: {
|
||||||
get endPoint() {
|
get endPoint() {
|
||||||
|
|
|
@ -1,17 +1,22 @@
|
||||||
import { type AppController } from '@/app.ts';
|
import { type AppController } from '@/app.ts';
|
||||||
import { Conf } from '@/config.ts';
|
import { Conf } from '@/config.ts';
|
||||||
|
import { jsonServerMetaSchema } from '@/schemas/nostr.ts';
|
||||||
|
import { eventsDB } from '@/storages.ts';
|
||||||
|
|
||||||
const instanceController: AppController = (c) => {
|
const instanceController: AppController = async (c) => {
|
||||||
const { host, protocol } = Conf.url;
|
const { host, protocol } = Conf.url;
|
||||||
|
|
||||||
|
const [event] = await eventsDB.filter([{ kinds: [0], authors: [Conf.pubkey], limit: 1 }]);
|
||||||
|
const meta = jsonServerMetaSchema.parse(event?.content);
|
||||||
|
|
||||||
/** Protocol to use for WebSocket URLs, depending on the protocol of the `LOCAL_DOMAIN`. */
|
/** Protocol to use for WebSocket URLs, depending on the protocol of the `LOCAL_DOMAIN`. */
|
||||||
const wsProtocol = protocol === 'http:' ? 'ws:' : 'wss:';
|
const wsProtocol = protocol === 'http:' ? 'ws:' : 'wss:';
|
||||||
|
|
||||||
return c.json({
|
return c.json({
|
||||||
uri: host,
|
uri: host,
|
||||||
title: 'Ditto',
|
title: meta.name ?? 'Ditto',
|
||||||
description: 'Nostr and the Fediverse',
|
description: meta.about ?? 'Nostr and the Fediverse',
|
||||||
short_description: 'Nostr and the Fediverse',
|
short_description: meta.tagline ?? 'Nostr and the Fediverse',
|
||||||
registrations: Conf.registrations,
|
registrations: Conf.registrations,
|
||||||
max_toot_chars: Conf.postCharLimit,
|
max_toot_chars: Conf.postCharLimit,
|
||||||
configuration: {
|
configuration: {
|
||||||
|
@ -49,7 +54,7 @@ const instanceController: AppController = (c) => {
|
||||||
streaming_api: `${wsProtocol}//${host}`,
|
streaming_api: `${wsProtocol}//${host}`,
|
||||||
},
|
},
|
||||||
version: '0.0.0 (compatible; Ditto 0.0.1)',
|
version: '0.0.0 (compatible; Ditto 0.0.1)',
|
||||||
email: Conf.adminEmail,
|
email: meta.email ?? `postmaster@${host}`,
|
||||||
nostr: {
|
nostr: {
|
||||||
pubkey: Conf.pubkey,
|
pubkey: Conf.pubkey,
|
||||||
relay: `${wsProtocol}//${host}/relay`,
|
relay: `${wsProtocol}//${host}/relay`,
|
||||||
|
|
|
@ -1,13 +1,18 @@
|
||||||
import { AppController } from '@/app.ts';
|
import { AppController } from '@/app.ts';
|
||||||
import { Conf } from '@/config.ts';
|
import { Conf } from '@/config.ts';
|
||||||
|
import { jsonServerMetaSchema } from '@/schemas/nostr.ts';
|
||||||
|
import { eventsDB } from '@/storages.ts';
|
||||||
|
|
||||||
|
const relayInfoController: AppController = async (c) => {
|
||||||
|
const [event] = await eventsDB.filter([{ kinds: [0], authors: [Conf.pubkey], limit: 1 }]);
|
||||||
|
const meta = jsonServerMetaSchema.parse(event?.content);
|
||||||
|
|
||||||
const relayInfoController: AppController = (c) => {
|
|
||||||
return c.json({
|
return c.json({
|
||||||
name: 'Ditto',
|
name: meta.name ?? 'Ditto',
|
||||||
description: 'Nostr and the Fediverse.',
|
description: meta.about ?? 'Nostr and the Fediverse.',
|
||||||
pubkey: Conf.pubkey,
|
pubkey: Conf.pubkey,
|
||||||
contact: `mailto:${Conf.adminEmail}`,
|
contact: `mailto:${meta.email ?? `postmaster@${Conf.url.host}`}`,
|
||||||
supported_nips: [1, 5, 9, 11, 16, 45, 46, 98],
|
supported_nips: [1, 5, 9, 11, 16, 45, 50, 46, 98],
|
||||||
software: 'Ditto',
|
software: 'Ditto',
|
||||||
version: '0.0.0',
|
version: '0.0.0',
|
||||||
limitation: {
|
limitation: {
|
||||||
|
|
|
@ -85,6 +85,12 @@ const mediaDataSchema = z.object({
|
||||||
width: z.number().int().positive().optional().catch(undefined),
|
width: z.number().int().positive().optional().catch(undefined),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/** Kind 0 content schema for the Ditto server admin user. */
|
||||||
|
const serverMetaSchema = metaContentSchema.extend({
|
||||||
|
tagline: z.string().optional().catch(undefined),
|
||||||
|
email: z.string().optional().catch(undefined),
|
||||||
|
});
|
||||||
|
|
||||||
/** Media data from `"media"` tags. */
|
/** Media data from `"media"` tags. */
|
||||||
type MediaData = z.infer<typeof mediaDataSchema>;
|
type MediaData = z.infer<typeof mediaDataSchema>;
|
||||||
|
|
||||||
|
@ -94,6 +100,9 @@ const jsonMetaContentSchema = jsonSchema.pipe(metaContentSchema).catch({});
|
||||||
/** Parses media data from a JSON string. */
|
/** Parses media data from a JSON string. */
|
||||||
const jsonMediaDataSchema = jsonSchema.pipe(mediaDataSchema).catch({});
|
const jsonMediaDataSchema = jsonSchema.pipe(mediaDataSchema).catch({});
|
||||||
|
|
||||||
|
/** Parses server admin meta from a JSON string. */
|
||||||
|
const jsonServerMetaSchema = jsonSchema.pipe(serverMetaSchema).catch({});
|
||||||
|
|
||||||
/** NIP-11 Relay Information Document. */
|
/** NIP-11 Relay Information Document. */
|
||||||
const relayInfoDocSchema = z.object({
|
const relayInfoDocSchema = z.object({
|
||||||
name: z.string().transform((val) => val.slice(0, 30)).optional().catch(undefined),
|
name: z.string().transform((val) => val.slice(0, 30)).optional().catch(undefined),
|
||||||
|
@ -130,6 +139,7 @@ export {
|
||||||
filterSchema,
|
filterSchema,
|
||||||
jsonMediaDataSchema,
|
jsonMediaDataSchema,
|
||||||
jsonMetaContentSchema,
|
jsonMetaContentSchema,
|
||||||
|
jsonServerMetaSchema,
|
||||||
type MediaData,
|
type MediaData,
|
||||||
mediaDataSchema,
|
mediaDataSchema,
|
||||||
metaContentSchema,
|
metaContentSchema,
|
||||||
|
|
Loading…
Reference in New Issue