This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// !Important: DO NOT IMPLEMENT THIS ON large scale app | |
// this is an implementation for token bucket algorithm | |
const tokenBuckets = new Map(); | |
const RATE_LIMIT = 3; | |
const INTERVAL = 3 * 60 * 1000; | |
export function allowRequest(userId: string) { | |
const now = Date.now(); | |
if (!tokenBuckets.has(userId)) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sharp from "sharp"; | |
// example rate limiter for getting images | |
import RateLimiter_Middleware from "@/lib/rate-limiter.middleware"; | |
function generateUniqueFilename() { | |
const timestamp = new Date().toISOString().replace(/[:.-]/g, "_"); | |
const randomString = Math.random().toString(36).substring(2, 8); | |
return `${timestamp}_${randomString}.webp`; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var validateEmail = (email)=> { | |
var re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/; | |
return re.test(email) | |
}; | |
var validateNumber = (number) =>{ | |
var re = /(^(\+88|0088)?(01){1}[3456789]{1}(\d){8})$/; | |
return re.test(number); | |
}; |