Merge branch 'captcha-n' into 'main'

Switch captcha_solved from a label event to an n-tag on a user event

See merge request soapbox-pub/ditto!547
This commit is contained in:
Alex Gleason 2024-10-11 22:43:39 +00:00
commit 7dff4e88d4
4 changed files with 9 additions and 38 deletions

View file

@ -51,7 +51,7 @@ const verifyCredentialsController: AppController = async (c) => {
const store = await Storages.db();
const [author, [settingsEvent], [captcha]] = await Promise.all([
const [author, [settingsEvent]] = await Promise.all([
getAuthor(pubkey, { signal: AbortSignal.timeout(5000) }),
store.query([{
@ -60,15 +60,6 @@ const verifyCredentialsController: AppController = async (c) => {
'#d': ['pub.ditto.pleroma_settings_store'],
limit: 1,
}]),
store.query([{
kinds: [1985],
authors: [Conf.pubkey],
'#L': ['pub.ditto.captcha'],
'#l': ['solved'],
'#p': [pubkey],
limit: 1,
}]),
]);
let settingsStore: Record<string, unknown> | undefined;
@ -79,8 +70,8 @@ const verifyCredentialsController: AppController = async (c) => {
}
const account = author
? await renderAccount(author, { withSource: true, settingsStore, captcha })
: await accountFromPubkey(pubkey, { withSource: true, settingsStore, captcha });
? await renderAccount(author, { withSource: true, settingsStore })
: await accountFromPubkey(pubkey, { withSource: true, settingsStore });
return c.json(account);
};
@ -285,7 +276,6 @@ const updateCredentialsController: AppController = async (c) => {
const pubkey = await signer.getPublicKey();
const body = await parseBody(c.req.raw);
const result = updateCredentialsSchema.safeParse(body);
const store = await Storages.db();
if (!result.success) {
return c.json(result.error, 422);
@ -335,17 +325,8 @@ const updateCredentialsController: AppController = async (c) => {
c,
);
const [captcha] = await store.query([{
kinds: [1985],
authors: [Conf.pubkey],
'#L': ['pub.ditto.captcha'],
'#l': ['solved'],
'#p': [pubkey],
limit: 1,
}]);
const settingsStore = result.data.pleroma_settings_store;
const account = await renderAccount(event, { withSource: true, settingsStore, captcha });
const account = await renderAccount(event, { withSource: true, settingsStore });
if (settingsStore) {
await createEvent({

View file

@ -4,7 +4,7 @@ import { z } from 'zod';
import { AppController } from '@/app.ts';
import { Conf } from '@/config.ts';
import { createAdminEvent } from '@/utils/api.ts';
import { updateUser } from '@/utils/api.ts';
interface Point {
x: number;
@ -169,16 +169,7 @@ export const captchaVerifyController: AppController = async (c) => {
if (solved) {
captchas.delete(id);
await createAdminEvent({
kind: 1985,
tags: [
['L', 'pub.ditto.captcha'],
['l', 'solved', 'pub.ditto.captcha'],
['p', pubkey, Conf.relay],
],
}, c);
await updateUser(pubkey, { captcha_solved: true }, c);
return new Response(null, { status: 204 });
}

View file

@ -1,4 +1,4 @@
import { Context } from '@hono/hono';
import { type Context } from '@hono/hono';
import { HTTPException } from '@hono/hono/http-exception';
import { NostrEvent, NostrFilter } from '@nostrify/nostrify';
import Debug from '@soapbox/stickynotes/debug';

View file

@ -1,4 +1,4 @@
import { type NostrEvent, NSchema as n } from '@nostrify/nostrify';
import { NSchema as n } from '@nostrify/nostrify';
import { escape } from 'entities';
import { nip19, UnsignedEvent } from 'nostr-tools';
@ -15,7 +15,6 @@ import { renderEmojis } from '@/views/mastodon/emojis.ts';
type ToAccountOpts = {
withSource: true;
settingsStore: Record<string, unknown> | undefined;
captcha: NostrEvent | undefined;
} | {
withSource?: false;
};
@ -91,7 +90,7 @@ async function renderAccount(
nip05,
},
ditto: {
captcha_solved: Boolean(opts.captcha),
captcha_solved: names.has('captcha_solved'),
},
}
: undefined,