Skip to content

Commit

Permalink
added protectedEndpoint caching logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Egge21M committed Feb 3, 2025
1 parent 7f52505 commit 7b855a0
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/model/MintInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,23 @@ import { GetInfoResponse, MPPMethod, SwapMethod, WebSocketSupport } from './type

export class MintInfo {
private readonly _mintInfo: GetInfoResponse;
private readonly _protectedEnpoints?: Array<{ method: 'GET' | 'POST'; regex: RegExp }>;
private readonly _protectedEnpoints?: {
cache: {
[url: string]: boolean;
};
apiReturn: Array<{ method: 'GET' | 'POST'; regex: RegExp; cachedValue?: boolean }>;
};

constructor(info: GetInfoResponse) {
this._mintInfo = info;
if (info.nuts[22]) {
this._protectedEnpoints = info.nuts[22].protected_endpoints.map((o) => ({
method: o.method,
regex: new RegExp(o.path)
}));
this._protectedEnpoints = {
cache: {},
apiReturn: info.nuts[22].protected_endpoints.map((o) => ({
method: o.method,
regex: new RegExp(o.path)
}))
};
}
}

Expand Down Expand Up @@ -49,7 +57,12 @@ export class MintInfo {
if (!this._protectedEnpoints) {
return false;
}
return this._protectedEnpoints.some((e) => e.regex.test(path));
if (typeof this._protectedEnpoints.cache[path] === 'boolean') {
return this._protectedEnpoints.cache[path];
}
const isProtectedEndpoint = this._protectedEnpoints.apiReturn.some((e) => e.regex.test(path));
this._protectedEnpoints.cache[path] = isProtectedEndpoint;
return isProtectedEndpoint;
}

private checkGenericNut(num: 7 | 8 | 9 | 10 | 11 | 12 | 14) {
Expand Down

0 comments on commit 7b855a0

Please sign in to comment.