add: api for rate control
This commit is contained in:
14
api/path.py
14
api/path.py
@@ -1,4 +1,6 @@
|
||||
from flask import Blueprint, request, jsonify
|
||||
|
||||
import api
|
||||
from api import require_auth
|
||||
from db import get_db
|
||||
from db.models.Markdown import Markdown
|
||||
@@ -10,14 +12,14 @@ logger = logging.getLogger(__name__)
|
||||
path_bp = Blueprint('path', __name__, url_prefix='/api/path')
|
||||
|
||||
@path_bp.route('/', methods=['GET'])
|
||||
@limiter.limit('5 per minute')
|
||||
@limiter.limit(api.get_rate_limit)
|
||||
def get_root_paths():
|
||||
with get_db() as session:
|
||||
paths = session.query(Path).filter(Path.parent_id == 1)
|
||||
return jsonify([pth.to_dict() for pth in paths]), 200
|
||||
|
||||
@path_bp.route('/<int:path_id>', methods=['GET'])
|
||||
@limiter.limit('5 per minute')
|
||||
@limiter.limit(api.get_rate_limit)
|
||||
def get_path(path_id):
|
||||
with get_db() as session:
|
||||
path = session.query(Path).get(path_id)
|
||||
@@ -26,14 +28,14 @@ def get_path(path_id):
|
||||
return jsonify(path.to_dict()), 200
|
||||
|
||||
@path_bp.route('/parent/<int:parent_id>', methods=['GET'])
|
||||
@limiter.limit('5 per minute')
|
||||
@limiter.limit(api.get_rate_limit)
|
||||
def get_path_by_parent(parent_id):
|
||||
with get_db() as session:
|
||||
paths = session.query(Path).filter(Path.parent_id == parent_id).all()
|
||||
return jsonify([pth.to_dict() for pth in paths]), 200
|
||||
|
||||
@path_bp.route('/', methods=['POST'])
|
||||
@limiter.limit('60 per minute')
|
||||
@limiter.limit(api.get_rate_limit)
|
||||
@require_auth(roles=['admin', 'creator'])
|
||||
def create_path():
|
||||
data = request.json
|
||||
@@ -50,7 +52,7 @@ def create_path():
|
||||
return jsonify(new_path.to_dict()), 201
|
||||
|
||||
@path_bp.route('/<int:path_id>', methods=['PUT'])
|
||||
@limiter.limit('30 per minute')
|
||||
@limiter.limit(api.get_rate_limit)
|
||||
@require_auth(roles=['admin'])
|
||||
def update_path(path_id):
|
||||
data = request.json
|
||||
@@ -68,7 +70,7 @@ def update_path(path_id):
|
||||
return jsonify(path.to_dict()), 200
|
||||
|
||||
@path_bp.route('/<int:path_id>', methods=['DELETE'])
|
||||
@limiter.limit('60 per minute')
|
||||
@limiter.limit(api.get_rate_limit)
|
||||
@require_auth(roles=['admin'])
|
||||
def delete_path(path_id):
|
||||
with get_db() as session:
|
||||
|
||||
Reference in New Issue
Block a user