Spaces:
Running
Running
Download client_log.py from Nrighton233j/Api-cache: direct link, hf CLI and curl.
- Browser
- Download file 892 Bytes
-
https://huggingface.co/spaces/Nrighton233j/Api-cache/resolve/main/client_log.py
- Command line
-
hf download hf://spaces/Nrighton233j/Api-cache/client_log.py
-
curl -L -o client_log.py https://huggingface.co/spaces/Nrighton233j/Api-cache/resolve/main/client_log.py
892 Bytes
| import time | |
| from flask import Blueprint, request, jsonify | |
| client_log_bp = Blueprint("client_log", __name__) | |
| _window = [] | |
| MAX_PER_MINUTE = 60 | |
| def _clip(v, n): | |
| return str(v if v is not None else "")[:n].replace("\n", " | ") | |
| def client_log(): | |
| now = time.time() | |
| _window[:] = [t for t in _window if now - t < 60] | |
| if len(_window) >= MAX_PER_MINUTE: | |
| return jsonify({"ok": False}), 429 | |
| _window.append(now) | |
| d = request.get_json(force=True, silent=True) or {} | |
| print("[client-error] v=%s os=%s/%s screen=%s fatal=%s msg=%s stack=%s" % ( | |
| _clip(d.get("version"), 20), _clip(d.get("os"), 10), _clip(d.get("osVersion"), 10), | |
| _clip(d.get("screen"), 60), _clip(d.get("fatal"), 5), | |
| _clip(d.get("message"), 300), _clip(d.get("stack"), 1200)), flush=True) | |
| return jsonify({"ok": True}) | |