Skip to content

Commit

Permalink
use direct functions
Browse files Browse the repository at this point in the history
  • Loading branch information
gurgunday committed Nov 16, 2024
1 parent 7b2e46d commit 592694f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const fp = require('fastify-plugin')
const ms = require('@lukeed/ms')
const { parse, format } = require('@lukeed/ms')

const LocalStore = require('./store/LocalStore')
const RedisStore = require('./store/RedisStore')
Expand Down Expand Up @@ -75,7 +75,7 @@ async function fastifyRateLimit (fastify, settings) {
if (Number.isFinite(settings.timeWindow) && settings.timeWindow >= 0) {
globalParams.timeWindow = Math.trunc(settings.timeWindow)
} else if (typeof settings.timeWindow === 'string') {
globalParams.timeWindow = ms.parse(settings.timeWindow)
globalParams.timeWindow = parse(settings.timeWindow)
} else if (
typeof settings.timeWindow === 'function'
) {
Expand Down Expand Up @@ -162,7 +162,7 @@ function mergeParams (...params) {
if (Number.isFinite(result.timeWindow) && result.timeWindow >= 0) {
result.timeWindow = Math.trunc(result.timeWindow)
} else if (typeof result.timeWindow === 'string') {
result.timeWindow = ms.parse(result.timeWindow)
result.timeWindow = parse(result.timeWindow)
} else if (typeof result.timeWindow !== 'function') {
result.timeWindow = defaultTimeWindow
}
Expand Down Expand Up @@ -271,7 +271,7 @@ function rateLimitRequestHandler (pluginComponent, params) {
ban: false,
max,
ttl,
after: ms.format(ttlInSeconds * 1000, true)
after: format(ttlInSeconds * 1000, true)
}

if (params.ban !== -1 && current - max > params.ban) {
Expand Down

0 comments on commit 592694f

Please sign in to comment.