mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Merge branch 'revert-70d30887' into 'main'
Revert "Merge branch 'fix-stop-overwite-kind-0-unnecessarily' into 'main'" See merge request soapbox-pub/ditto!600
This commit is contained in:
commit
0c2f082281
1 changed files with 45 additions and 60 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
import { NostrEvent, NostrFilter, NSchema as n } from '@nostrify/nostrify';
|
import { NostrFilter, NSchema as n } from '@nostrify/nostrify';
|
||||||
import { nip19 } from 'nostr-tools';
|
import { nip19 } from 'nostr-tools';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
|
|
@ -20,7 +20,6 @@ import { hydrateEvents } from '@/storages/hydrate.ts';
|
||||||
import { bech32ToPubkey } from '@/utils.ts';
|
import { bech32ToPubkey } from '@/utils.ts';
|
||||||
import { addTag, deleteTag, findReplyTag, getTagSet } from '@/utils/tags.ts';
|
import { addTag, deleteTag, findReplyTag, getTagSet } from '@/utils/tags.ts';
|
||||||
import { getPubkeysBySearch } from '@/utils/search.ts';
|
import { getPubkeysBySearch } from '@/utils/search.ts';
|
||||||
import { MastodonAccount } from '@/entities/MastodonAccount.ts';
|
|
||||||
|
|
||||||
const usernameSchema = z
|
const usernameSchema = z
|
||||||
.string().min(1).max(30)
|
.string().min(1).max(30)
|
||||||
|
|
@ -289,76 +288,62 @@ const updateCredentialsController: AppController = async (c) => {
|
||||||
const pubkey = await signer.getPublicKey();
|
const pubkey = await signer.getPublicKey();
|
||||||
const body = await parseBody(c.req.raw);
|
const body = await parseBody(c.req.raw);
|
||||||
const result = updateCredentialsSchema.safeParse(body);
|
const result = updateCredentialsSchema.safeParse(body);
|
||||||
const store = await Storages.db();
|
|
||||||
|
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
return c.json(result.error, 422);
|
return c.json(result.error, 422);
|
||||||
}
|
}
|
||||||
|
|
||||||
const keys = Object.keys(result.data);
|
const event = await updateEvent(
|
||||||
let event: NostrEvent | undefined;
|
{ kinds: [0], authors: [pubkey], limit: 1 },
|
||||||
|
async (prev) => {
|
||||||
|
const meta = n.json().pipe(metadataSchema).catch({}).parse(prev.content);
|
||||||
|
const {
|
||||||
|
avatar: avatarFile,
|
||||||
|
header: headerFile,
|
||||||
|
display_name,
|
||||||
|
fields_attributes,
|
||||||
|
note,
|
||||||
|
nip05,
|
||||||
|
lud16,
|
||||||
|
website,
|
||||||
|
bot,
|
||||||
|
} = result.data;
|
||||||
|
|
||||||
if (keys.length === 1 && keys[0] === 'pleroma_settings_store') {
|
const [avatar, header] = await Promise.all([
|
||||||
event = (await store.query([{ kinds: [0], authors: [pubkey] }]))[0];
|
avatarFile ? uploadFile(c, avatarFile, { pubkey }) : undefined,
|
||||||
} else {
|
headerFile ? uploadFile(c, headerFile, { pubkey }) : undefined,
|
||||||
event = await updateEvent(
|
]);
|
||||||
{ kinds: [0], authors: [pubkey], limit: 1 },
|
|
||||||
async (prev) => {
|
|
||||||
const meta = n.json().pipe(metadataSchema).catch({}).parse(prev.content);
|
|
||||||
const {
|
|
||||||
avatar: avatarFile,
|
|
||||||
header: headerFile,
|
|
||||||
display_name,
|
|
||||||
fields_attributes,
|
|
||||||
note,
|
|
||||||
nip05,
|
|
||||||
lud16,
|
|
||||||
website,
|
|
||||||
bot,
|
|
||||||
} = result.data;
|
|
||||||
|
|
||||||
const [avatar, header] = await Promise.all([
|
meta.name = display_name ?? meta.name;
|
||||||
avatarFile ? uploadFile(c, avatarFile, { pubkey }) : undefined,
|
meta.about = note ?? meta.about;
|
||||||
headerFile ? uploadFile(c, headerFile, { pubkey }) : undefined,
|
meta.picture = avatar?.url ?? meta.picture;
|
||||||
]);
|
meta.banner = header?.url ?? meta.banner;
|
||||||
|
meta.nip05 = nip05 ?? meta.nip05;
|
||||||
|
meta.lud16 = lud16 ?? meta.lud16;
|
||||||
|
meta.website = website ?? meta.website;
|
||||||
|
meta.bot = bot ?? meta.bot;
|
||||||
|
|
||||||
meta.name = display_name ?? meta.name;
|
if (avatarFile === '') delete meta.picture;
|
||||||
meta.about = note ?? meta.about;
|
if (headerFile === '') delete meta.banner;
|
||||||
meta.picture = avatar?.url ?? meta.picture;
|
if (nip05 === '') delete meta.nip05;
|
||||||
meta.banner = header?.url ?? meta.banner;
|
if (lud16 === '') delete meta.lud16;
|
||||||
meta.nip05 = nip05 ?? meta.nip05;
|
if (website === '') delete meta.website;
|
||||||
meta.lud16 = lud16 ?? meta.lud16;
|
|
||||||
meta.website = website ?? meta.website;
|
|
||||||
meta.bot = bot ?? meta.bot;
|
|
||||||
|
|
||||||
if (avatarFile === '') delete meta.picture;
|
if (fields_attributes) {
|
||||||
if (headerFile === '') delete meta.banner;
|
meta.fields = fields_attributes.map(({ name, value }) => [name, value]);
|
||||||
if (nip05 === '') delete meta.nip05;
|
}
|
||||||
if (lud16 === '') delete meta.lud16;
|
|
||||||
if (website === '') delete meta.website;
|
|
||||||
|
|
||||||
if (fields_attributes) {
|
return {
|
||||||
meta.fields = fields_attributes.map(({ name, value }) => [name, value]);
|
kind: 0,
|
||||||
}
|
content: JSON.stringify(meta),
|
||||||
|
tags: [],
|
||||||
return {
|
};
|
||||||
kind: 0,
|
},
|
||||||
content: JSON.stringify(meta),
|
c,
|
||||||
tags: [],
|
);
|
||||||
};
|
|
||||||
},
|
|
||||||
c,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const settingsStore = result.data.pleroma_settings_store;
|
const settingsStore = result.data.pleroma_settings_store;
|
||||||
|
const account = await renderAccount(event, { withSource: true, settingsStore });
|
||||||
let account: MastodonAccount;
|
|
||||||
if (event) {
|
|
||||||
account = await renderAccount(event, { withSource: true, settingsStore });
|
|
||||||
} else {
|
|
||||||
account = await accountFromPubkey(pubkey, { withSource: true, settingsStore });
|
|
||||||
}
|
|
||||||
|
|
||||||
if (settingsStore) {
|
if (settingsStore) {
|
||||||
await createEvent({
|
await createEvent({
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue