mirror of
https://github.com/Xevion/v1.xevion.dev.git
synced 2025-12-07 09:16:56 -06:00
add initial flask rate limiting
This commit is contained in:
@@ -5,6 +5,7 @@ from config import Config
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
from flask_migrate import Migrate
|
||||
from flask_login import LoginManager
|
||||
from flask_limiter import Limiter
|
||||
|
||||
# App & App config setup
|
||||
app = Flask(__name__)
|
||||
@@ -14,6 +15,7 @@ login = LoginManager(app)
|
||||
login.login_view = 'login'
|
||||
db = SQLAlchemy(app)
|
||||
migrate = Migrate(app, db)
|
||||
limiter = Limiter(app, default_limits=["10 per minute"])
|
||||
|
||||
from app import models
|
||||
from app import routes, simple_routes, hidden, dashboard
|
||||
|
||||
14
app/sound.py
14
app/sound.py
@@ -1,6 +1,6 @@
|
||||
from app import app, db
|
||||
from app.sound_models import YouTubeAudio, SoundcloudAudio
|
||||
from flask import Response, send_file, redirect, url_for, render_template
|
||||
from flask import Response, send_file, redirect, url_for, render_template, request
|
||||
from multiprocessing import Value
|
||||
from mutagen.mp3 import MP3
|
||||
import os
|
||||
@@ -23,8 +23,20 @@ def get_youtube(mediaid):
|
||||
db.session.commit()
|
||||
return audio
|
||||
|
||||
def downloadLimiter():
|
||||
service = request.args.get('service')
|
||||
mediaid = request.args.get('mediaid')
|
||||
if service == 'youtube':
|
||||
if YouTubeAudio.query.get(mediaid) is not None:
|
||||
return '5 per minute'
|
||||
else:
|
||||
return '1 per 30 seconds'
|
||||
else:
|
||||
return '10 per minute'
|
||||
|
||||
# Streams back the specified media back to the client
|
||||
@app.route('/stream/<service>/<mediaid>')
|
||||
@limiter.limit(downloadLimiter)
|
||||
def stream(service, mediaid):
|
||||
if service == 'youtube':
|
||||
audio = get_youtube(mediaid)
|
||||
|
||||
Reference in New Issue
Block a user