mirror of
https://github.com/xtr-dev/rondevu-server.git
synced 2025-12-14 04:43:24 +00:00
refactor: Unify polling endpoint and remove AUTH_SECRET
BREAKING CHANGES: - Renamed /offers/poll to /poll (generic polling endpoint) - Removed /offers/answered endpoint (use /poll instead) - Removed AUTH_SECRET environment variable (Ed25519 auth only) - Updated auth message format from 'pollOffers' to 'poll'
This commit is contained in:
36
src/app.ts
36
src/app.ts
@@ -507,43 +507,11 @@ export function createApp(storage: Storage, config: Config) {
|
||||
});
|
||||
|
||||
/**
|
||||
* GET /offers/answered
|
||||
* Get all answered offers for the authenticated peer (efficient batch polling)
|
||||
*/
|
||||
app.get('/offers/answered', authMiddleware, async (c) => {
|
||||
try {
|
||||
const username = getAuthenticatedUsername(c);
|
||||
const since = c.req.query('since');
|
||||
const sinceTimestamp = since ? parseInt(since, 10) : 0;
|
||||
|
||||
const offers = await storage.getAnsweredOffers(username);
|
||||
|
||||
// Filter by timestamp if provided
|
||||
const filteredOffers = since
|
||||
? offers.filter(offer => offer.answeredAt && offer.answeredAt > sinceTimestamp)
|
||||
: offers;
|
||||
|
||||
return c.json({
|
||||
offers: filteredOffers.map(offer => ({
|
||||
offerId: offer.id,
|
||||
serviceId: offer.serviceId,
|
||||
answererId: offer.answererUsername,
|
||||
sdp: offer.answerSdp,
|
||||
answeredAt: offer.answeredAt
|
||||
}))
|
||||
}, 200);
|
||||
} catch (err) {
|
||||
console.error('Error getting answered offers:', err);
|
||||
return c.json({ error: 'Internal server error' }, 500);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* GET /offers/poll
|
||||
* GET /poll
|
||||
* Combined efficient polling endpoint for answers and ICE candidates
|
||||
* Returns all answered offers and ICE candidates for all peer's offers since timestamp
|
||||
*/
|
||||
app.get('/offers/poll', authMiddleware, async (c) => {
|
||||
app.get('/poll', authMiddleware, async (c) => {
|
||||
try {
|
||||
const username = getAuthenticatedUsername(c);
|
||||
const since = c.req.query('since');
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { createApp } from './app.ts';
|
||||
import { D1Storage } from './storage/d1.ts';
|
||||
import { generateSecretKey } from './crypto.ts';
|
||||
import { Config } from './config.ts';
|
||||
|
||||
/**
|
||||
@@ -8,7 +7,6 @@ import { Config } from './config.ts';
|
||||
*/
|
||||
export interface Env {
|
||||
DB: D1Database;
|
||||
AUTH_SECRET?: string;
|
||||
OFFER_DEFAULT_TTL?: string;
|
||||
OFFER_MAX_TTL?: string;
|
||||
OFFER_MIN_TTL?: string;
|
||||
@@ -25,9 +23,6 @@ export default {
|
||||
// Initialize D1 storage
|
||||
const storage = new D1Storage(env.DB);
|
||||
|
||||
// Generate or use provided auth secret
|
||||
const authSecret = env.AUTH_SECRET || generateSecretKey();
|
||||
|
||||
// Build config from environment
|
||||
const config: Config = {
|
||||
port: 0, // Not used in Workers
|
||||
|
||||
Reference in New Issue
Block a user