1
0
mirror of https://github.com/sasjs/server.git synced 2026-01-06 14:10:06 +00:00

chore: move secondsToHms to @sasjs/utils

This commit is contained in:
2023-03-29 20:10:55 +05:00
parent a1e255e0c7
commit bd3aff9a7b
6 changed files with 96 additions and 37 deletions

View File

@@ -1,7 +1,7 @@
import path from 'path'
import express from 'express'
import { Request, Route, Tags, Post, Body, Get, Example } from 'tsoa'
import { readFile } from '@sasjs/utils'
import { readFile, convertSecondsToHms } from '@sasjs/utils'
import User from '../model/User'
import Client from '../model/Client'
@@ -10,8 +10,7 @@ import {
generateAuthCode,
RateLimiter,
AuthProviderType,
LDAPClient,
secondsToHms
LDAPClient
} from '../utils'
import { InfoJWT } from '../types'
import { AuthController } from './auth'
@@ -111,7 +110,9 @@ const login = async (
if (retrySecs > 0) {
throw {
code: 429,
message: `Too Many Requests! Retry after ${secondsToHms(retrySecs)}`
message: `Too Many Requests! Retry after ${convertSecondsToHms(
retrySecs
)}`
}
}
}

View File

@@ -1,5 +1,6 @@
import { RequestHandler } from 'express'
import { RateLimiter, secondsToHms } from '../utils'
import { convertSecondsToHms } from '@sasjs/utils'
import { RateLimiter } from '../utils'
export const bruteForceProtection: RequestHandler = async (req, res, next) => {
const ip = req.ip
@@ -12,7 +13,7 @@ export const bruteForceProtection: RequestHandler = async (req, res, next) => {
if (retrySecs > 0) {
res
.status(429)
.send(`Too Many Requests! Retry after ${secondsToHms(retrySecs)}`)
.send(`Too Many Requests! Retry after ${convertSecondsToHms(retrySecs)}`)
return
}

View File

@@ -24,7 +24,6 @@ export * from './parseLogToArray'
export * from './rateLimiter'
export * from './removeTokensInDB'
export * from './saveTokensInDB'
export * from './secondsToHms'
export * from './seedDB'
export * from './setProcessVariables'
export * from './setupFolders'

View File

@@ -1,10 +0,0 @@
export const secondsToHms = (seconds: number) => {
const h = Math.floor(seconds / 3600)
const m = Math.floor((seconds % 3600) / 60)
const s = Math.floor((seconds % 3600) % 60)
const hDisplay = h > 0 ? h + (h == 1 ? ' hour, ' : ' hours, ') : ''
const mDisplay = m > 0 ? m + (m == 1 ? ' minute, ' : ' minutes, ') : ''
const sDisplay = s > 0 ? s + (s == 1 ? ' second' : ' seconds') : ''
return hDisplay + mDisplay + sDisplay
}