mirror of
https://github.com/aljazceru/ditto.git
synced 2026-02-02 12:04:19 +01:00
Make verify_credentials and update_credentials return a consistent CredentialAccount object
This commit is contained in:
@@ -51,7 +51,7 @@ const verifyCredentialsController: AppController = async (c) => {
|
||||
|
||||
const store = await Storages.db();
|
||||
|
||||
const [author, [settingsStore], [captcha]] = await Promise.all([
|
||||
const [author, [settingsEvent], [captcha]] = await Promise.all([
|
||||
getAuthor(pubkey, { signal: AbortSignal.timeout(5000) }),
|
||||
|
||||
store.query([{
|
||||
@@ -71,21 +71,16 @@ const verifyCredentialsController: AppController = async (c) => {
|
||||
}]),
|
||||
]);
|
||||
|
||||
let settingsStore: Record<string, unknown> | undefined;
|
||||
try {
|
||||
settingsStore = n.json().pipe(z.record(z.string(), z.unknown())).parse(settingsEvent?.content);
|
||||
} catch {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
const account = author
|
||||
? await renderAccount(author, { withSource: true })
|
||||
: await accountFromPubkey(pubkey, { withSource: true });
|
||||
|
||||
if (settingsStore) {
|
||||
try {
|
||||
account.pleroma.settings_store = JSON.parse(settingsStore.content);
|
||||
} catch {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
|
||||
if (captcha && account.source) {
|
||||
account.source.ditto.captcha_solved = true;
|
||||
}
|
||||
? await renderAccount(author, { withSource: true, settingsStore, captcha })
|
||||
: await accountFromPubkey(pubkey, { withSource: true, settingsStore, captcha });
|
||||
|
||||
return c.json(account);
|
||||
};
|
||||
@@ -280,7 +275,7 @@ const updateCredentialsSchema = z.object({
|
||||
bot: z.boolean().optional(),
|
||||
discoverable: z.boolean().optional(),
|
||||
nip05: z.string().email().or(z.literal('')).optional(),
|
||||
pleroma_settings_store: z.unknown().optional(),
|
||||
pleroma_settings_store: z.record(z.string(), z.unknown()).optional(),
|
||||
lud16: z.string().email().or(z.literal('')).optional(),
|
||||
website: z.string().url().or(z.literal('')).optional(),
|
||||
});
|
||||
@@ -290,6 +285,7 @@ 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);
|
||||
@@ -339,8 +335,17 @@ const updateCredentialsController: AppController = async (c) => {
|
||||
c,
|
||||
);
|
||||
|
||||
const account = await renderAccount(event, { withSource: true });
|
||||
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 });
|
||||
|
||||
if (settingsStore) {
|
||||
await createEvent({
|
||||
@@ -350,8 +355,6 @@ const updateCredentialsController: AppController = async (c) => {
|
||||
}, c);
|
||||
}
|
||||
|
||||
account.pleroma.settings_store = settingsStore;
|
||||
|
||||
return c.json(account);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user