mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Merge branch 'metadata-conf' into 'main'
Remove `@/config.ts` import from utils/instance.ts See merge request soapbox-pub/ditto!702
This commit is contained in:
commit
214d68d87b
7 changed files with 28 additions and 23 deletions
|
|
@ -14,10 +14,10 @@ export class DittoPush {
|
|||
private server: Promise<ApplicationServer | undefined>;
|
||||
|
||||
constructor(opts: DittoPushOpts) {
|
||||
const { conf, relay } = opts;
|
||||
const { conf } = opts;
|
||||
|
||||
this.server = (async () => {
|
||||
const meta = await getInstanceMetadata(relay);
|
||||
const meta = await getInstanceMetadata(opts);
|
||||
const keys = await conf.vapidKeys;
|
||||
|
||||
if (keys) {
|
||||
|
|
|
|||
|
|
@ -327,7 +327,7 @@ const updateInstanceSchema = z.object({
|
|||
});
|
||||
|
||||
export const updateInstanceController: AppController = async (c) => {
|
||||
const { conf, relay, signal } = c.var;
|
||||
const { conf } = c.var;
|
||||
|
||||
const body = await parseBody(c.req.raw);
|
||||
const result = updateInstanceSchema.safeParse(body);
|
||||
|
|
@ -337,7 +337,7 @@ export const updateInstanceController: AppController = async (c) => {
|
|||
return c.json(result.error, 422);
|
||||
}
|
||||
|
||||
const meta = await getInstanceMetadata(relay, signal);
|
||||
const meta = await getInstanceMetadata(c.var);
|
||||
|
||||
await updateAdminEvent(
|
||||
{ kinds: [0], authors: [pubkey], limit: 1 },
|
||||
|
|
|
|||
|
|
@ -15,9 +15,9 @@ const features = [
|
|||
];
|
||||
|
||||
const instanceV1Controller: AppController = async (c) => {
|
||||
const { conf, relay, signal } = c.var;
|
||||
const { conf } = c.var;
|
||||
const { host, protocol } = conf.url;
|
||||
const meta = await getInstanceMetadata(relay, signal);
|
||||
const meta = await getInstanceMetadata(c.var);
|
||||
|
||||
/** Protocol to use for WebSocket URLs, depending on the protocol of the `LOCAL_DOMAIN`. */
|
||||
const wsProtocol = protocol === 'http:' ? 'ws:' : 'wss:';
|
||||
|
|
@ -75,9 +75,9 @@ const instanceV1Controller: AppController = async (c) => {
|
|||
};
|
||||
|
||||
const instanceV2Controller: AppController = async (c) => {
|
||||
const { conf, relay, signal } = c.var;
|
||||
const { conf } = c.var;
|
||||
const { host, protocol } = conf.url;
|
||||
const meta = await getInstanceMetadata(relay, signal);
|
||||
const meta = await getInstanceMetadata(c.var);
|
||||
|
||||
/** Protocol to use for WebSocket URLs, depending on the protocol of the `LOCAL_DOMAIN`. */
|
||||
const wsProtocol = protocol === 'http:' ? 'ws:' : 'wss:';
|
||||
|
|
@ -164,9 +164,7 @@ const instanceV2Controller: AppController = async (c) => {
|
|||
};
|
||||
|
||||
const instanceDescriptionController: AppController = async (c) => {
|
||||
const { relay, signal } = c.var;
|
||||
|
||||
const meta = await getInstanceMetadata(relay, signal);
|
||||
const meta = await getInstanceMetadata(c.var);
|
||||
|
||||
return c.json({
|
||||
content: meta.about,
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ async function getEntities(c: AppContext, params: { acct?: string; statusId?: st
|
|||
const { relay } = c.var;
|
||||
|
||||
const entities: MetadataEntities = {
|
||||
instance: await getInstanceMetadata(relay),
|
||||
instance: await getInstanceMetadata(c.var),
|
||||
};
|
||||
|
||||
if (params.statusId) {
|
||||
|
|
|
|||
|
|
@ -3,9 +3,7 @@ import { WebManifestCombined } from '@/types/webmanifest.ts';
|
|||
import { getInstanceMetadata } from '@/utils/instance.ts';
|
||||
|
||||
export const manifestController: AppController = async (c) => {
|
||||
const { relay, signal } = c.var;
|
||||
|
||||
const meta = await getInstanceMetadata(relay, signal);
|
||||
const meta = await getInstanceMetadata(c.var);
|
||||
|
||||
const manifest: WebManifestCombined = {
|
||||
description: meta.about,
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@ import { AppController } from '@/app.ts';
|
|||
import { getInstanceMetadata } from '@/utils/instance.ts';
|
||||
|
||||
const relayInfoController: AppController = async (c) => {
|
||||
const { conf, relay, signal } = c.var;
|
||||
const { conf } = c.var;
|
||||
|
||||
const meta = await getInstanceMetadata(relay, signal);
|
||||
const meta = await getInstanceMetadata(c.var);
|
||||
|
||||
c.res.headers.set('access-control-allow-origin', '*');
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
import { NostrEvent, NostrMetadata, NSchema as n, NStore } from '@nostrify/nostrify';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { Conf } from '@/config.ts';
|
||||
import { screenshotsSchema, serverMetaSchema } from '@/schemas/nostr.ts';
|
||||
|
||||
import type { DittoConf } from '@ditto/conf';
|
||||
|
||||
/** Like NostrMetadata, but some fields are required and also contains some extra fields. */
|
||||
export interface InstanceMetadata extends NostrMetadata {
|
||||
about: string;
|
||||
|
|
@ -15,10 +16,18 @@ export interface InstanceMetadata extends NostrMetadata {
|
|||
screenshots: z.infer<typeof screenshotsSchema>;
|
||||
}
|
||||
|
||||
interface GetInstanceMetadataOpts {
|
||||
conf: DittoConf;
|
||||
relay: NStore;
|
||||
signal?: AbortSignal;
|
||||
}
|
||||
|
||||
/** Get and parse instance metadata from the kind 0 of the admin user. */
|
||||
export async function getInstanceMetadata(store: NStore, signal?: AbortSignal): Promise<InstanceMetadata> {
|
||||
const [event] = await store.query(
|
||||
[{ kinds: [0], authors: [await Conf.signer.getPublicKey()], limit: 1 }],
|
||||
export async function getInstanceMetadata(opts: GetInstanceMetadataOpts): Promise<InstanceMetadata> {
|
||||
const { conf, relay, signal } = opts;
|
||||
|
||||
const [event] = await relay.query(
|
||||
[{ kinds: [0], authors: [await conf.signer.getPublicKey()], limit: 1 }],
|
||||
{ signal },
|
||||
);
|
||||
|
||||
|
|
@ -33,8 +42,8 @@ export async function getInstanceMetadata(store: NStore, signal?: AbortSignal):
|
|||
name: meta.name ?? 'Ditto',
|
||||
about: meta.about ?? 'Nostr community server',
|
||||
tagline: meta.tagline ?? meta.about ?? 'Nostr community server',
|
||||
email: meta.email ?? `postmaster@${Conf.url.host}`,
|
||||
picture: meta.picture ?? Conf.local('/images/thumbnail.png'),
|
||||
email: meta.email ?? `postmaster@${conf.url.host}`,
|
||||
picture: meta.picture ?? conf.local('/images/thumbnail.png'),
|
||||
event,
|
||||
screenshots: meta.screenshots ?? [],
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue