mirror of
https://github.com/FJurmanovic/sugarr.git
synced 2026-11-11 07:41:08 +00:00
Add Health/Recommendations/Request/Webhook controllers
This commit is contained in:
25
src/app/controllers/WebhookController.ts
Normal file
25
src/app/controllers/WebhookController.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import type { FastifyInstance, FastifyReply, FastifyRequest } from 'fastify';
|
||||
import { Controller } from '../../core/server/Controller';
|
||||
import type { PromptService } from '../../core/langfuse/PromptService';
|
||||
|
||||
interface InvalidateBody {
|
||||
promptName?: string;
|
||||
}
|
||||
|
||||
export class WebhookController extends Controller {
|
||||
constructor(private readonly promptService: PromptService) {
|
||||
super();
|
||||
}
|
||||
|
||||
register(app: FastifyInstance): void {
|
||||
app.post('/webhooks/langfuse/invalidate', (request, reply) =>
|
||||
this.handle(request as FastifyRequest<{ Body: InvalidateBody }>, reply)
|
||||
);
|
||||
}
|
||||
|
||||
private async handle(request: FastifyRequest<{ Body: InvalidateBody }>, reply: FastifyReply) {
|
||||
const promptName = request.body?.promptName;
|
||||
this.promptService.invalidate(promptName);
|
||||
reply.send({ invalidated: true, promptName: promptName ?? 'all' });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user