Fix D1 storage: Insert service_id when creating offers

The createOffers function was not inserting the service_id column even
though it was passed in the CreateOfferRequest. This caused all offers
to have NULL service_id, making getOffersForService return empty results.

Fixed:
- Added service_id to INSERT statement in createOffers
- Added serviceId to created offer objects
- Added serviceId to rowToOffer mapping

This resolves the 'No available offers' error when trying to connect
to a published service.
This commit is contained in:
2025-12-10 18:52:11 +01:00
parent 9088abe305
commit b282bf6470

View File

@@ -115,13 +115,14 @@ export class D1Storage implements Storage {
const now = Date.now();
await this.db.prepare(`
INSERT INTO offers (id, peer_id, sdp, created_at, expires_at, last_seen, secret)
VALUES (?, ?, ?, ?, ?, ?, ?)
`).bind(id, offer.peerId, offer.sdp, now, offer.expiresAt, now, offer.secret || null).run();
INSERT INTO offers (id, peer_id, service_id, sdp, created_at, expires_at, last_seen, secret)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
`).bind(id, offer.peerId, offer.serviceId || null, offer.sdp, now, offer.expiresAt, now, offer.secret || null).run();
created.push({
id,
peerId: offer.peerId,
serviceId: offer.serviceId,
sdp: offer.sdp,
createdAt: now,
expiresAt: offer.expiresAt,
@@ -565,6 +566,7 @@ export class D1Storage implements Storage {
return {
id: row.id,
peerId: row.peer_id,
serviceId: row.service_id || undefined,
sdp: row.sdp,
createdAt: row.created_at,
expiresAt: row.expires_at,