Skip to content

Commit e901051

Browse files
alecsavvyisaacsolo
authored andcommitted
shutoff sol relay for plays (#11125)
1 parent ec65d26 commit e901051

File tree

1 file changed

+6
-65
lines changed
  • packages/discovery-provider/plugins/pedalboard/apps/solana-relay/src/routes/listen

1 file changed

+6
-65
lines changed

packages/discovery-provider/plugins/pedalboard/apps/solana-relay/src/routes/listen/listen.ts

+6-65
Original file line numberDiff line numberDiff line change
@@ -197,69 +197,10 @@ export const listen = async (
197197
res: Response,
198198
next: NextFunction
199199
) => {
200-
let logger
201-
try {
202-
logger = res.locals.logger
203-
204-
// if not prod, just return 200
205-
if (config.environment !== 'prod') {
206-
logger.info('not prod, skipping listen')
207-
res.status(200).json({
208-
solTxSignature: null
209-
})
210-
next()
211-
return
212-
}
213-
214-
// validation
215-
const { userId, timestamp, signature } = recordListenBodySchema.parse(
216-
req.body
217-
)
218-
const { trackId } = recordListenParamsSchema.parse(req.params)
219-
const host = req.hostname
220-
logger = res.locals.logger.child({ userId, trackId, host })
221-
const ip = getIP(req)
222-
223-
// require request came from content
224-
if (!(await validateListenSignature(timestamp, signature))) {
225-
logger.info(
226-
{ userId, trackId, ip, timestamp, signature },
227-
'unauthorized request'
228-
)
229-
res.status(401).json({ message: 'Unauthorized Error' })
230-
next()
231-
return
232-
}
233-
234-
// check rate limit on forwarded IP and track
235-
const allowed = await listenRouteRateLimiter({ ip, trackId, logger })
236-
if (!allowed) {
237-
res.send(429).json({ message: 'Too Many Requests' })
238-
next()
239-
return
240-
}
241-
242-
// record listen after validation
243-
const record = await recordListen({ userId, trackId, logger, ip })
244-
return res.status(200).json(record)
245-
} catch (e: unknown) {
246-
if (e instanceof z.ZodError) {
247-
logger?.error({ error: String(e) }, 'validation error')
248-
return res
249-
.status(400)
250-
.json({ message: 'Validation Error', errors: e.errors })
251-
}
252-
if (e instanceof Error) {
253-
logger?.error(
254-
{ message: e.message, stack: e.stack, name: e.name },
255-
'listen error'
256-
)
257-
} else if (typeof e === 'object' && e !== null) {
258-
logger?.error({ error: JSON.stringify(e) }, 'listen error')
259-
} else {
260-
logger?.error({ error: String(e) }, 'listen error')
261-
}
262-
res.status(500).json({ message: 'Internal Server Error' })
263-
next(e)
264-
}
200+
const logger = res.locals.logger
201+
logger.info('not prod, skipping listen')
202+
res.status(200).json({
203+
solTxSignature: null
204+
})
205+
next()
265206
}

0 commit comments

Comments
 (0)