mirror of
https://github.com/minetest/contentdb.git
synced 2025-01-09 14:37:36 +01:00
Check user-agent for crawlers before incrementing counters
This commit is contained in:
parent
9d3ba8991d
commit
74371d3fcb
@ -53,7 +53,7 @@ def list_all():
|
||||
subqueryload(Package.tags))
|
||||
|
||||
ip = request.headers.get("X-Forwarded-For") or request.remote_addr
|
||||
if ip is not None:
|
||||
if ip is not None and not is_user_bot():
|
||||
edited = False
|
||||
for tag in qb.tags:
|
||||
edited = True
|
||||
|
@ -130,7 +130,7 @@ def download_release(package, id):
|
||||
abort(404)
|
||||
|
||||
ip = request.headers.get("X-Forwarded-For") or request.remote_addr
|
||||
if ip is not None:
|
||||
if ip is not None and not is_user_bot():
|
||||
key = make_download_key(ip, release.package)
|
||||
if not has_key(key):
|
||||
set_key(key, "true")
|
||||
|
@ -20,7 +20,7 @@ from flask_user import *
|
||||
from flask_login import login_user, logout_user
|
||||
from .models import *
|
||||
from . import app
|
||||
import random, string, os, imghdr
|
||||
import random, string, os, imghdr, user_agents
|
||||
from urllib.parse import urljoin
|
||||
from werkzeug.datastructures import MultiDict
|
||||
|
||||
@ -64,6 +64,10 @@ def get_int_or_abort(v, default=None):
|
||||
except ValueError:
|
||||
abort(400)
|
||||
|
||||
def is_user_bot():
|
||||
user_agent = user_agents.parse(request.headers.get('User-Agent'))
|
||||
return user_agent.is_bot
|
||||
|
||||
def getExtension(filename):
|
||||
return filename.rsplit(".", 1)[1].lower() if "." in filename else None
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user