Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

specific api filter #72

Merged
merged 2 commits into from
Nov 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/middlewares/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default class Middleware {
* @returns Null if if request is duplicated.
*/
triggerDuplicateFilter = (req: Request, res: Response, next: NextFunction) => {
if (req.body.fid === undefined){
if (req.body.transaction.hash === undefined){
next();
}
const txHash = req.body.transaction.hash;
Expand All @@ -28,4 +28,24 @@ export default class Middleware {
this.cache.set(txHash, "in_progress", 500);
next();
}
/**
* Middleware for AI Network trigger call. It will filter duplicated request triggered by same transaction.
* It will pass request which is not from AI Network trigger.
* You can set filter inside specific api.
* @param {Request} request - Request data
* @param {Res} response - Response data
* @returns Null if if request is duplicated.
*/
triggerFilter = (req: Request, res: Response) => {
if (req.body.fid || req.body.transaction){
res.send("not from trigger");
return;
}
const txHash = req.body.transaction.hash;
if (this.cache.get(txHash) && this.cache.get(txHash) !== "error") {
res.send("duplicated");
return;
}
this.cache.set(txHash, "in_progress", 500);
}
}