mirror of
https://github.com/fullstack-cash/bch-api.git
synced 2026-09-22 01:02:05 -07:00
Refactored for four tiers
This commit is contained in:
@@ -321,28 +321,28 @@ class RateLimits {
|
||||
const apiLevel = jwtInfo.apiLevel
|
||||
const resource = jwtInfo.resource
|
||||
|
||||
const level20Routes = ["insight", "bitcore", "blockbook"]
|
||||
const level30Routes = ["slp"]
|
||||
const level30Routes = ["insight", "bitcore", "blockbook"]
|
||||
const level40Routes = ["slp"]
|
||||
|
||||
// console.log(`apiLevel: ${apiLevel}`)
|
||||
|
||||
// Only evaluate if user is using a JWT token.
|
||||
if (jwtInfo.id) {
|
||||
// SLP indexer routes
|
||||
if (level30Routes.includes(resource)) {
|
||||
if (apiLevel >= 30) retVal = 1
|
||||
if (level40Routes.includes(resource)) {
|
||||
if (apiLevel >= 40) retVal = 1
|
||||
// else if (apiLevel >= 10) retVal = 10
|
||||
else retVal = 10
|
||||
}
|
||||
|
||||
// Normal indexer routes
|
||||
else if (level20Routes.includes(resource)) {
|
||||
if (apiLevel >= 20) retVal = 1
|
||||
else if (level30Routes.includes(resource)) {
|
||||
if (apiLevel >= 30) retVal = 1
|
||||
else retVal = 10
|
||||
}
|
||||
|
||||
// Full node tier
|
||||
else if (apiLevel >= 10) {
|
||||
else if (apiLevel >= 20) {
|
||||
retVal = 1
|
||||
}
|
||||
|
||||
|
||||
+40
-7
@@ -303,7 +303,7 @@ describe("#route-ratelimits & jwt-auth", () => {
|
||||
assert.equal(result, 10)
|
||||
})
|
||||
|
||||
it("should return 1 point for indexer tier requesting full node access", () => {
|
||||
it("should return 1 point for full node tier requesting full node access", () => {
|
||||
const jwtInfo = {
|
||||
apiLevel: 20,
|
||||
resource: "blockchain",
|
||||
@@ -314,7 +314,7 @@ describe("#route-ratelimits & jwt-auth", () => {
|
||||
assert.equal(result, 1)
|
||||
})
|
||||
|
||||
it("should return 1 points for indexer tier requesting indexer access", () => {
|
||||
it("should return 10 points for full-node tier requesting indexer access", () => {
|
||||
const jwtInfo = {
|
||||
apiLevel: 20,
|
||||
resource: "blockbook",
|
||||
@@ -322,10 +322,10 @@ describe("#route-ratelimits & jwt-auth", () => {
|
||||
}
|
||||
|
||||
const result = rateLimits.calcPoints(jwtInfo)
|
||||
assert.equal(result, 1)
|
||||
assert.equal(result, 10)
|
||||
})
|
||||
|
||||
it("should return 10 points for indexer tier requesting SLPDB access", () => {
|
||||
it("should return 10 points for full node tier requesting SLPDB access", () => {
|
||||
const jwtInfo = {
|
||||
apiLevel: 20,
|
||||
resource: "slp",
|
||||
@@ -336,7 +336,7 @@ describe("#route-ratelimits & jwt-auth", () => {
|
||||
assert.equal(result, 10)
|
||||
})
|
||||
|
||||
it("should return 1 point for SLP tier requesting full node access", () => {
|
||||
it("should return 1 point for indexer tier requesting full node access", () => {
|
||||
const jwtInfo = {
|
||||
apiLevel: 30,
|
||||
resource: "blockchain",
|
||||
@@ -347,7 +347,7 @@ describe("#route-ratelimits & jwt-auth", () => {
|
||||
assert.equal(result, 1)
|
||||
})
|
||||
|
||||
it("should return 1 points for SLP tier requesting indexer access", () => {
|
||||
it("should return 1 points for indexer tier requesting indexer access", () => {
|
||||
const jwtInfo = {
|
||||
apiLevel: 30,
|
||||
resource: "blockbook",
|
||||
@@ -358,13 +358,46 @@ describe("#route-ratelimits & jwt-auth", () => {
|
||||
assert.equal(result, 1)
|
||||
})
|
||||
|
||||
it("should return 1 points for SLP tier requesting SLPDB access", () => {
|
||||
it("should return 10 points for indexer tier requesting SLPDB access", () => {
|
||||
const jwtInfo = {
|
||||
apiLevel: 30,
|
||||
resource: "slp",
|
||||
id: "5e3a0415eb29a962da2708b4"
|
||||
}
|
||||
|
||||
const result = rateLimits.calcPoints(jwtInfo)
|
||||
assert.equal(result, 10)
|
||||
})
|
||||
|
||||
it("should return 1 point for SLP tier requesting full node access", () => {
|
||||
const jwtInfo = {
|
||||
apiLevel: 40,
|
||||
resource: "blockchain",
|
||||
id: "5e3a0415eb29a962da2708b4"
|
||||
}
|
||||
|
||||
const result = rateLimits.calcPoints(jwtInfo)
|
||||
assert.equal(result, 1)
|
||||
})
|
||||
|
||||
it("should return 1 points for SLP tier requesting indexer access", () => {
|
||||
const jwtInfo = {
|
||||
apiLevel: 40,
|
||||
resource: "blockbook",
|
||||
id: "5e3a0415eb29a962da2708b4"
|
||||
}
|
||||
|
||||
const result = rateLimits.calcPoints(jwtInfo)
|
||||
assert.equal(result, 1)
|
||||
})
|
||||
|
||||
it("should return 1 points for SLP tier requesting SLPDB access", () => {
|
||||
const jwtInfo = {
|
||||
apiLevel: 40,
|
||||
resource: "slp",
|
||||
id: "5e3a0415eb29a962da2708b4"
|
||||
}
|
||||
|
||||
const result = rateLimits.calcPoints(jwtInfo)
|
||||
assert.equal(result, 1)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user