Handle CW/subject tags in render, fix schema for status create params
This commit is contained in:
parent
4edebaa105
commit
07b406c25c
|
@ -7,20 +7,20 @@ import { toStatus } from '@/transmute.ts';
|
|||
import { parseBody } from '@/utils.ts';
|
||||
|
||||
const createStatusSchema = z.object({
|
||||
in_reply_to_id: z.string().regex(/[0-9a-f]{64}/).optional(),
|
||||
language: z.string().refine(ISO6391.validate).optional(),
|
||||
media_ids: z.string().array().optional(),
|
||||
in_reply_to_id: z.string().regex(/[0-9a-f]{64}/).nullish(),
|
||||
language: z.string().refine(ISO6391.validate).nullish(),
|
||||
media_ids: z.string().array().nullish(),
|
||||
poll: z.object({
|
||||
options: z.string().array(),
|
||||
expires_in: z.number(),
|
||||
multiple: z.boolean().default(false),
|
||||
hide_totals: z.boolean().default(false),
|
||||
}).optional(),
|
||||
scheduled_at: z.string().datetime().optional(),
|
||||
sensitive: z.boolean().optional(),
|
||||
spoiler_text: z.string().optional(),
|
||||
status: z.string().optional(),
|
||||
visibility: z.enum(['public', 'unlisted', 'private', 'direct']).optional(),
|
||||
}).nullish(),
|
||||
scheduled_at: z.string().datetime().nullish(),
|
||||
sensitive: z.boolean().nullish(),
|
||||
spoiler_text: z.string().nullish(),
|
||||
status: z.string().nullish(),
|
||||
visibility: z.enum(['public', 'unlisted', 'private', 'direct']).nullish(),
|
||||
}).refine(
|
||||
(data) => Boolean(data.status || data.media_ids?.length),
|
||||
{ message: 'Status must contain text or media.' },
|
||||
|
|
|
@ -7,6 +7,7 @@ import { getAuthor } from './client.ts';
|
|||
import { verifyNip05Cached } from './nip05.ts';
|
||||
import { getMediaLinks, type MediaLink, parseNoteContent } from './note.ts';
|
||||
import { type Nip05, parseNip05 } from './utils.ts';
|
||||
import { isCWTag } from 'https://gitlab.com/soapbox-pub/mostr/-/raw/c67064aee5ade5e01597c6d23e22e53c628ef0e2/src/nostr/tags.ts';
|
||||
|
||||
const DEFAULT_AVATAR = 'https://gleasonator.com/images/avi.png';
|
||||
const DEFAULT_BANNER = 'https://gleasonator.com/images/banner.png';
|
||||
|
@ -117,6 +118,9 @@ async function toStatus(event: Event<1>) {
|
|||
|
||||
const content = buildInlineRecipients(mentions) + html;
|
||||
|
||||
const cw = event.tags.find(isCWTag);
|
||||
const subject = event.tags.find((tag) => tag[0] === 'subject');
|
||||
|
||||
return {
|
||||
id: event.id,
|
||||
account,
|
||||
|
@ -125,10 +129,10 @@ async function toStatus(event: Event<1>) {
|
|||
created_at: new Date(event.created_at * 1000).toISOString(),
|
||||
in_reply_to_id: replyTag ? replyTag[1] : null,
|
||||
in_reply_to_account_id: null,
|
||||
sensitive: false,
|
||||
spoiler_text: '',
|
||||
sensitive: !!cw,
|
||||
spoiler_text: (cw ? cw[1] : subject?.[1]) || null,
|
||||
visibility: 'public',
|
||||
language: 'en',
|
||||
language: event.tags.find((tag) => tag[0] === 'lang')?.[1] || null,
|
||||
replies_count: 0,
|
||||
reblogs_count: 0,
|
||||
favourites_count: 0,
|
||||
|
|
Loading…
Reference in New Issue