|
|
@ -4,7 +4,6 @@ import json |
|
|
|
import os |
|
|
|
from frappe.utils import cstr |
|
|
|
from smart_service.apis.app_user_login import input_validation |
|
|
|
from smart_service.apis.master_api import custom_rate_limit |
|
|
|
current_db_name = frappe.conf.get("db_name") |
|
|
|
|
|
|
|
site_name = cstr(frappe.local.site) |
|
|
@ -12,6 +11,23 @@ base_url = os.path.expanduser( |
|
|
|
"~") + "/frappe-bench/sites/" + site_name + "/public" |
|
|
|
|
|
|
|
|
|
|
|
def custom_rate_limit(limit, seconds): |
|
|
|
ip_based = True |
|
|
|
ip = frappe.local.request_ip if ip_based is True else None |
|
|
|
identity = None |
|
|
|
|
|
|
|
identity = ip |
|
|
|
cache_key = f"rl:{frappe.form_dict.cmd}:{identity}" |
|
|
|
value = frappe.cache().get(cache_key) or 0 |
|
|
|
if not value: |
|
|
|
frappe.cache().setex(cache_key, seconds, 0) |
|
|
|
|
|
|
|
value = frappe.cache().incrby(cache_key, 1) |
|
|
|
if value > limit: |
|
|
|
frappe.local.response["http_status_code"] = 429 |
|
|
|
return "You hit the rate limit because of too many requests. Please try after sometime." |
|
|
|
return 1 |
|
|
|
|
|
|
|
@frappe.whitelist() |
|
|
|
def get_technical_manual(args=None): |
|
|
|
rate_res = custom_rate_limit(limit=5, seconds=15) |
|
|
|