mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Add Web Push skeleton
This commit is contained in:
parent
be5350a0a5
commit
bece384124
4 changed files with 83 additions and 0 deletions
|
|
@ -68,6 +68,7 @@ import {
|
||||||
updateConfigController,
|
updateConfigController,
|
||||||
} from '@/controllers/api/pleroma.ts';
|
} from '@/controllers/api/pleroma.ts';
|
||||||
import { preferencesController } from '@/controllers/api/preferences.ts';
|
import { preferencesController } from '@/controllers/api/preferences.ts';
|
||||||
|
import { pushSubscribeController } from '@/controllers/api/push.ts';
|
||||||
import { deleteReactionController, reactionController, reactionsController } from '@/controllers/api/reactions.ts';
|
import { deleteReactionController, reactionController, reactionsController } from '@/controllers/api/reactions.ts';
|
||||||
import { relayController } from '@/controllers/nostr/relay.ts';
|
import { relayController } from '@/controllers/nostr/relay.ts';
|
||||||
import {
|
import {
|
||||||
|
|
@ -262,6 +263,8 @@ app.get('/api/v1/mutes', requireSigner, mutesController);
|
||||||
app.get('/api/v1/markers', requireProof(), markersController);
|
app.get('/api/v1/markers', requireProof(), markersController);
|
||||||
app.post('/api/v1/markers', requireProof(), updateMarkersController);
|
app.post('/api/v1/markers', requireProof(), updateMarkersController);
|
||||||
|
|
||||||
|
app.post('/api/v1/push/subscription', requireSigner, pushSubscribeController);
|
||||||
|
|
||||||
app.get('/api/v1/pleroma/statuses/:id{[0-9a-f]{64}}/reactions', reactionsController);
|
app.get('/api/v1/pleroma/statuses/:id{[0-9a-f]{64}}/reactions', reactionsController);
|
||||||
app.get('/api/v1/pleroma/statuses/:id{[0-9a-f]{64}}/reactions/:emoji', reactionsController);
|
app.get('/api/v1/pleroma/statuses/:id{[0-9a-f]{64}}/reactions/:emoji', reactionsController);
|
||||||
app.put('/api/v1/pleroma/statuses/:id{[0-9a-f]{64}}/reactions/:emoji', requireSigner, reactionController);
|
app.put('/api/v1/pleroma/statuses/:id{[0-9a-f]{64}}/reactions/:emoji', requireSigner, reactionController);
|
||||||
|
|
|
||||||
39
src/controllers/api/push.ts
Normal file
39
src/controllers/api/push.ts
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
import { z } from 'zod';
|
||||||
|
|
||||||
|
import { AppController } from '@/app.ts';
|
||||||
|
import { parseBody } from '@/utils/api.ts';
|
||||||
|
|
||||||
|
const pushSubscribeSchema = z.object({
|
||||||
|
subscription: z.object({
|
||||||
|
endpoint: z.string(),
|
||||||
|
keys: z.object({
|
||||||
|
p256dh: z.string(),
|
||||||
|
auth: z.string(),
|
||||||
|
}),
|
||||||
|
data: z.object({
|
||||||
|
alerts: z.object({
|
||||||
|
mention: z.boolean().optional(),
|
||||||
|
status: z.boolean().optional(),
|
||||||
|
reblog: z.boolean().optional(),
|
||||||
|
follow: z.boolean().optional(),
|
||||||
|
follow_request: z.boolean().optional(),
|
||||||
|
favourite: z.boolean().optional(),
|
||||||
|
poll: z.boolean().optional(),
|
||||||
|
update: z.boolean().optional(),
|
||||||
|
'admin.sign_up': z.boolean().optional(),
|
||||||
|
'admin.report': z.boolean().optional(),
|
||||||
|
}).optional(),
|
||||||
|
policy: z.enum(['all', 'followed', 'follower', 'none']).optional(),
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const pushSubscribeController: AppController = async (c) => {
|
||||||
|
const data = pushSubscribeSchema.safeParse(await parseBody(c.req.raw));
|
||||||
|
|
||||||
|
if (!data.success) {
|
||||||
|
return c.json({ error: 'Invalid request', schema: data.error }, 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.json({});
|
||||||
|
};
|
||||||
|
|
@ -9,6 +9,7 @@ export interface DittoTables extends NPostgresSchema {
|
||||||
event_stats: EventStatsRow;
|
event_stats: EventStatsRow;
|
||||||
pubkey_domains: PubkeyDomainRow;
|
pubkey_domains: PubkeyDomainRow;
|
||||||
event_zaps: EventZapRow;
|
event_zaps: EventZapRow;
|
||||||
|
push_subscriptions: PushSubscriptionRow;
|
||||||
}
|
}
|
||||||
|
|
||||||
type NostrEventsRow = NPostgresSchema['nostr_events'] & {
|
type NostrEventsRow = NPostgresSchema['nostr_events'] & {
|
||||||
|
|
@ -55,3 +56,28 @@ interface EventZapRow {
|
||||||
amount_millisats: number;
|
amount_millisats: number;
|
||||||
comment: string;
|
comment: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface PushSubscriptionRow {
|
||||||
|
id: bigint;
|
||||||
|
pubkey: string;
|
||||||
|
endpoint: string;
|
||||||
|
key_p256dh: string;
|
||||||
|
key_auth: string;
|
||||||
|
data: {
|
||||||
|
alerts?: {
|
||||||
|
mention?: boolean;
|
||||||
|
status?: boolean;
|
||||||
|
reblog?: boolean;
|
||||||
|
follow?: boolean;
|
||||||
|
follow_request?: boolean;
|
||||||
|
favourite?: boolean;
|
||||||
|
poll?: boolean;
|
||||||
|
update?: boolean;
|
||||||
|
'admin.sign_up'?: boolean;
|
||||||
|
'admin.report'?: boolean;
|
||||||
|
};
|
||||||
|
policy?: 'all' | 'followed' | 'follower' | 'none';
|
||||||
|
} | null;
|
||||||
|
created_at: Date;
|
||||||
|
updated_at: Date;
|
||||||
|
}
|
||||||
|
|
|
||||||
15
src/types/MastodonPush.ts
Normal file
15
src/types/MastodonPush.ts
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
/**
|
||||||
|
* Mastodon push payload.
|
||||||
|
*
|
||||||
|
* This is the object the server sends to the client (with the Web Push API)
|
||||||
|
* to notify of a new push event.
|
||||||
|
*/
|
||||||
|
export interface MastodonPush {
|
||||||
|
access_token: string;
|
||||||
|
preferred_locale: string;
|
||||||
|
notification_id: string;
|
||||||
|
notification_type: string;
|
||||||
|
icon: string;
|
||||||
|
title: string;
|
||||||
|
body: string;
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue