mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
Add "streak" app, letting users forfeit through the API
This commit is contained in:
parent
430fd196d7
commit
ca9246a20a
3 changed files with 29 additions and 3 deletions
|
|
@ -108,6 +108,7 @@ import {
|
|||
zapController,
|
||||
zappedByController,
|
||||
} from '@/controllers/api/statuses.ts';
|
||||
import streakApp from '@/controllers/api/streak.ts';
|
||||
import { streamingController } from '@/controllers/api/streaming.ts';
|
||||
import {
|
||||
localSuggestionsController,
|
||||
|
|
@ -382,6 +383,7 @@ app.put('/api/v1/admin/ditto/relays', requireRole('admin'), adminSetRelaysContro
|
|||
|
||||
app.put('/api/v1/admin/ditto/instance', requireRole('admin'), updateInstanceController);
|
||||
|
||||
app.route('/api/v1/ditto/streak', streakApp);
|
||||
app.post('/api/v1/ditto/names', requireSigner, nameRequestController);
|
||||
app.get('/api/v1/ditto/names', requireSigner, nameRequestsController);
|
||||
|
||||
|
|
|
|||
24
src/controllers/api/streak.ts
Normal file
24
src/controllers/api/streak.ts
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import { Hono } from '@hono/hono';
|
||||
|
||||
import { Conf } from '@/config.ts';
|
||||
import { requireSigner } from '@/middleware/requireSigner.ts';
|
||||
import { updateAdminEvent } from '@/utils/api.ts';
|
||||
|
||||
const app = new Hono();
|
||||
|
||||
app.post('/forfeit', requireSigner, async (c) => {
|
||||
const pubkey = await c.get('signer').getPublicKey();
|
||||
|
||||
await updateAdminEvent(
|
||||
{ kinds: [30382], authors: [Conf.pubkey], '#d': [pubkey], limit: 1 },
|
||||
(prev) => {
|
||||
const tags = prev?.tags.filter(([name]) => !['ditto.streak.start', 'ditto.streak.end'].includes(name)) ?? [];
|
||||
return { ...prev, kind: 30382, tags };
|
||||
},
|
||||
c,
|
||||
);
|
||||
|
||||
return c.newResponse(null, 204);
|
||||
});
|
||||
|
||||
export default app;
|
||||
|
|
@ -80,7 +80,7 @@ function updateListEvent(
|
|||
}
|
||||
|
||||
/** Publish an admin event through the pipeline. */
|
||||
async function createAdminEvent(t: EventStub, c: AppContext): Promise<NostrEvent> {
|
||||
async function createAdminEvent(t: EventStub, c: Context): Promise<NostrEvent> {
|
||||
const signer = new AdminSigner();
|
||||
|
||||
const event = await signer.signEvent({
|
||||
|
|
@ -110,7 +110,7 @@ function updateListAdminEvent(
|
|||
async function updateAdminEvent<E extends EventStub>(
|
||||
filter: UpdateEventFilter,
|
||||
fn: (prev: NostrEvent | undefined) => E,
|
||||
c: AppContext,
|
||||
c: Context,
|
||||
): Promise<NostrEvent> {
|
||||
const store = await Storages.db();
|
||||
const [prev] = await store.query([filter], { limit: 1, signal: c.req.raw.signal });
|
||||
|
|
@ -156,7 +156,7 @@ async function updateNames(k: number, d: string, n: Record<string, boolean>, c:
|
|||
}
|
||||
|
||||
/** Push the event through the pipeline, rethrowing any RelayError. */
|
||||
async function publishEvent(event: NostrEvent, c: AppContext): Promise<NostrEvent> {
|
||||
async function publishEvent(event: NostrEvent, c: Context): Promise<NostrEvent> {
|
||||
logi({ level: 'info', ns: 'ditto.event', source: 'api', id: event.id, kind: event.kind });
|
||||
try {
|
||||
await pipeline.handleEvent(event, { source: 'api', signal: c.req.raw.signal });
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue