feat: Android APP V1 - Experimental Alpha
This commit is contained in:
58
server/src/routes/device-tokens.ts
Normal file
58
server/src/routes/device-tokens.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import { Router } from 'express';
|
||||
import {
|
||||
dispatchPushToUser,
|
||||
listDeviceTokensForUser,
|
||||
upsertDeviceToken
|
||||
} from '../services/push-dispatch.service';
|
||||
|
||||
export interface DeviceTokenRecord {
|
||||
userId: string;
|
||||
platform: 'ios' | 'android';
|
||||
token: string;
|
||||
updatedAt: number;
|
||||
}
|
||||
|
||||
const router = Router();
|
||||
|
||||
router.post('/', async (req, res) => {
|
||||
const { userId, platform, token } = req.body as Partial<DeviceTokenRecord>;
|
||||
|
||||
if (!userId || !token || (platform !== 'ios' && platform !== 'android')) {
|
||||
return res.status(400).json({ error: 'Missing or invalid userId/platform/token' });
|
||||
}
|
||||
|
||||
await upsertDeviceToken({ userId, platform, token });
|
||||
|
||||
res.status(201).json({ ok: true });
|
||||
});
|
||||
|
||||
router.get('/:userId', async (req, res) => {
|
||||
const records = await listDeviceTokensForUser(req.params.userId);
|
||||
|
||||
res.json({
|
||||
tokens: records.map((record) => ({
|
||||
userId: record.userId,
|
||||
platform: record.platform,
|
||||
token: record.token,
|
||||
updatedAt: record.updatedAt
|
||||
}))
|
||||
});
|
||||
});
|
||||
|
||||
router.post('/:userId/dispatch', async (req, res) => {
|
||||
const { title, body, data } = req.body as {
|
||||
title?: string;
|
||||
body?: string;
|
||||
data?: Record<string, string>;
|
||||
};
|
||||
|
||||
if (!title || !body) {
|
||||
return res.status(400).json({ error: 'Missing title/body' });
|
||||
}
|
||||
|
||||
await dispatchPushToUser(req.params.userId, { title, body, data });
|
||||
|
||||
res.json({ ok: true });
|
||||
});
|
||||
|
||||
export default router;
|
||||
@@ -5,6 +5,7 @@ import linkMetadataRouter from './link-metadata';
|
||||
import gamesRouter from './games';
|
||||
import proxyRouter from './proxy';
|
||||
import usersRouter from './users';
|
||||
import deviceTokensRouter from './device-tokens';
|
||||
import serversRouter from './servers';
|
||||
import pluginSupportRouter from './plugin-support';
|
||||
import openApiDocsRouter from './openapi-docs';
|
||||
@@ -18,6 +19,7 @@ export function registerRoutes(app: Express): void {
|
||||
app.use('/api/games', gamesRouter);
|
||||
app.use('/api', proxyRouter);
|
||||
app.use('/api/users', usersRouter);
|
||||
app.use('/api/users/device-tokens', deviceTokensRouter);
|
||||
app.use('/api', openApiDocsRouter);
|
||||
app.use('/api/servers', pluginSupportRouter);
|
||||
app.use('/api/servers', serversRouter);
|
||||
|
||||
Reference in New Issue
Block a user