Skip to content

Commit

Permalink
Merge pull request #73 from ainize-team/release/1.0.2
Browse files Browse the repository at this point in the history
Upgrade version to 1.0.2
  • Loading branch information
akastercomcom authored Nov 3, 2023
2 parents 342db0d + dbb5fbd commit f1d7869
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ainize-team/ainize-sdk",
"version": "1.0.1",
"version": "1.0.2",
"main": "dist/ainize.js",
"types": "dist/ainize.d.ts",
"scripts": {
Expand Down
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);
}
}

0 comments on commit f1d7869

Please sign in to comment.