mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
feat: create getZapSplitsController
This commit is contained in:
parent
975294b8a4
commit
baa00e45a6
2 changed files with 37 additions and 6 deletions
|
|
@ -40,6 +40,7 @@ import {
|
|||
adminRelaysController,
|
||||
adminSetRelaysController,
|
||||
deleteZapSplitsController,
|
||||
getZapSplitsController,
|
||||
nameRequestController,
|
||||
nameRequestsController,
|
||||
updateZapSplitsController,
|
||||
|
|
@ -263,6 +264,8 @@ app.put('/api/v1/admin/ditto/relays', requireRole('admin'), adminSetRelaysContro
|
|||
app.post('/api/v1/ditto/names', requireSigner, nameRequestController);
|
||||
app.get('/api/v1/ditto/names', requireSigner, nameRequestsController);
|
||||
|
||||
app.get('/api/v1/ditto/zap_splits', getZapSplitsController);
|
||||
|
||||
app.put('/api/v1/admin/ditto/zap_splits', requireRole('admin'), updateZapSplitsController);
|
||||
app.delete('/api/v1/admin/ditto/zap_splits', requireRole('admin'), deleteZapSplitsController);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,18 +1,21 @@
|
|||
import { NostrEvent, NostrFilter, NSchema as n } from '@nostrify/nostrify';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { accountFromPubkey } from '@/views/mastodon/accounts.ts';
|
||||
import { AppController } from '@/app.ts';
|
||||
import { addTag } from '@/utils/tags.ts';
|
||||
import { AdminSigner } from '@/signers/AdminSigner.ts';
|
||||
import { booleanParamSchema } from '@/schema.ts';
|
||||
import { Conf } from '@/config.ts';
|
||||
import { Storages } from '@/storages.ts';
|
||||
import { hydrateEvents } from '@/storages/hydrate.ts';
|
||||
import { createEvent, paginated, paginationSchema, parseBody } from '@/utils/api.ts';
|
||||
import { renderNameRequest } from '@/views/ditto.ts';
|
||||
import { getZapSplits } from '@/utils/zap-split.ts';
|
||||
import { updateListAdminEvent } from '@/utils/api.ts';
|
||||
import { addTag } from '@/utils/tags.ts';
|
||||
import { deleteTag } from '@/utils/tags.ts';
|
||||
import { DittoZapSplits, getZapSplits } from '@/utils/zap-split.ts';
|
||||
import { getAuthor } from '@/queries.ts';
|
||||
import { hydrateEvents } from '@/storages/hydrate.ts';
|
||||
import { renderNameRequest } from '@/views/ditto.ts';
|
||||
import { renderAccount } from '@/views/mastodon/accounts.ts';
|
||||
import { Storages } from '@/storages.ts';
|
||||
import { updateListAdminEvent } from '@/utils/api.ts';
|
||||
|
||||
const markerSchema = z.enum(['read', 'write']);
|
||||
|
||||
|
|
@ -223,3 +226,28 @@ export const deleteZapSplitsController: AppController = async (c) => {
|
|||
|
||||
return c.json(200);
|
||||
};
|
||||
|
||||
export const getZapSplitsController: AppController = async (c) => {
|
||||
const store = c.get('store');
|
||||
|
||||
const zap_split: DittoZapSplits | undefined = await getZapSplits(store, Conf.pubkey) ?? {};
|
||||
if (!zap_split) {
|
||||
return c.json({ error: 'Zap split not activated, restart the server.' }, 404);
|
||||
}
|
||||
|
||||
const pubkeys = Object.keys(zap_split);
|
||||
|
||||
const zap_splits_mastodon = await Promise.all(pubkeys.map(async (pubkey) => {
|
||||
const author = await getAuthor(pubkey);
|
||||
|
||||
const account = author ? await renderAccount(author) : await accountFromPubkey(pubkey);
|
||||
|
||||
return {
|
||||
account,
|
||||
amount: zap_split[pubkey].amount,
|
||||
message: zap_split[pubkey].message,
|
||||
};
|
||||
}));
|
||||
|
||||
return c.json(zap_splits_mastodon, 200);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue