mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
feat: create deleteZapSplitsController
This commit is contained in:
parent
2e66af26db
commit
449a3497ba
2 changed files with 33 additions and 1 deletions
|
|
@ -42,6 +42,7 @@ import { bookmarksController } from '@/controllers/api/bookmarks.ts';
|
|||
import {
|
||||
adminRelaysController,
|
||||
adminSetRelaysController,
|
||||
deleteZapSplitsController,
|
||||
nameRequestController,
|
||||
nameRequestsController,
|
||||
updateZapSplitsController,
|
||||
|
|
@ -272,7 +273,7 @@ app.post('/api/v1/ditto/names', requireSigner, nameRequestController);
|
|||
app.get('/api/v1/ditto/names', requireSigner, nameRequestsController);
|
||||
|
||||
app.put('/api/v1/admin/ditto/zap_splits', requireRole('admin'), updateZapSplitsController);
|
||||
//app.delete('/api/v1/admin/ditto/zap_splits', requireRole('admin'), deleteZapSplitsController);
|
||||
app.delete('/api/v1/admin/ditto/zap_splits', requireRole('admin'), deleteZapSplitsController);
|
||||
|
||||
app.post('/api/v1/ditto/zap', requireSigner, zapController);
|
||||
app.get('/api/v1/ditto/statuses/:id{[0-9a-f]{64}}/zapped_by', zappedByController);
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ 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';
|
||||
|
||||
const markerSchema = z.enum(['read', 'write']);
|
||||
|
||||
|
|
@ -181,3 +182,33 @@ export const updateZapSplitsController: AppController = async (c) => {
|
|||
|
||||
return c.json(200);
|
||||
};
|
||||
|
||||
const deleteZapSplitSchema = z.array(n.id()).min(1);
|
||||
|
||||
export const deleteZapSplitsController: AppController = async (c) => {
|
||||
const body = await parseBody(c.req.raw);
|
||||
const result = deleteZapSplitSchema.safeParse(body);
|
||||
const store = c.get('store');
|
||||
|
||||
if (!result.success) {
|
||||
return c.json({ error: result.error }, 400);
|
||||
}
|
||||
|
||||
const zap_split = await getZapSplits(store, Conf.pubkey);
|
||||
if (!zap_split) {
|
||||
return c.json({ error: 'Zap split not activated, visit `/api/v1/instance` to activate it.' }, 404);
|
||||
}
|
||||
|
||||
const { data } = result;
|
||||
|
||||
await updateListAdminEvent(
|
||||
{ kinds: [30078], authors: [Conf.pubkey], '#d': ['pub.ditto.zapSplits'], limit: 1 },
|
||||
(tags) =>
|
||||
data.reduce((accumulator, currentValue) => {
|
||||
return deleteTag(accumulator, ['p', currentValue]);
|
||||
}, tags),
|
||||
c,
|
||||
);
|
||||
|
||||
return c.json(200);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue