From eea21cea1e2f4a742bad77ef280d7255b5218f1d Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Mon, 1 Jul 2024 11:37:19 +1000 Subject: [PATCH] fix: Don't show loader to google crawler --- requirements.txt | 3 +- server.py | 50 ++++++++++------------- templates/assets/js/hacker-podcast.min.js | 2 +- templates/index.html | 2 +- 4 files changed, 25 insertions(+), 32 deletions(-) diff --git a/requirements.txt b/requirements.txt index ae5530b..107a7d2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,4 +5,5 @@ gunicorn requests cloudflare qrcode -ansi2html \ No newline at end of file +ansi2html +cachetools \ No newline at end of file diff --git a/server.py b/server.py index e9c7662..63759d5 100644 --- a/server.py +++ b/server.py @@ -9,13 +9,13 @@ import datetime import qrcode import re from ansi2html import Ansi2HTMLConverter +from functools import cache app = Flask(__name__) CORS(app) dotenv.load_dotenv() -address = '' handshake_scripts = '' restricted = ['ascii'] @@ -30,11 +30,12 @@ if os.path.isfile('data/sites.json'): projects = [] projectsUpdated = 0 - -def getAddress(): - global address - if address == '': - address = 'hs1qv3uu4amv87g7p7h49xez2pmzwjf92am0wzpnh4' +@cache +def getAddress(coin:str) -> str: + address = '' + if os.path.isfile('.well-known/wallets/' + coin.upper()): + with open('.well-known/wallets/' + coin.upper()) as file: + address = file.read() return address #Assets routes @@ -110,20 +111,6 @@ def removeTrailingSlash(): @app.route('/.well-known/wallets/') def wallet(path): - # If HNS, redirect to HNS wallet - if path == "HNS": - # Get from 100.66.107.77:8080 then return result - # Check for cookie - if request.cookies.get('HNS'): - return make_response(request.cookies.get('HNS'), 200, {'Content-Type': 'text/plain'}) - - address = getAddress() - # Set cookie - resp = make_response(address, 200, {'Content-Type': 'text/plain'}) - # Cookie should last 1 week - resp.set_cookie('HNS', address, max_age=604800) - return resp - if path[0] == ".": return send_from_directory('.well-known/wallets', path, mimetype='application/json') elif os.path.isfile('.well-known/wallets/' + path): @@ -181,15 +168,16 @@ def index(): loaded = True - # Check if cookie is set - if not request.cookies.get('loaded') and not loaded: - # Set cookie - resp = make_response(render_template('loading.html'), 200, {'Content-Type': 'text/html'}) - resp.set_cookie('loaded', 'true', max_age=604800) - return resp + # Check if crawler + if request.user_agent.browser != 'Googlebot' and request.user_agent.browser != 'Bingbot': + # Check if cookie is set + if not request.cookies.get('loaded') and not loaded: + # Set cookie + resp = make_response(render_template('loading.html'), 200, {'Content-Type': 'text/html'}) + resp.set_cookie('loaded', 'true', max_age=604800) + return resp - global address global handshake_scripts global projects global projectsUpdated @@ -257,10 +245,14 @@ def index(): if request.host == "localhost:5000" or request.host == "127.0.0.1:5000" or os.getenv('dev') == "true" or request.host == "test.nathan.woodburn.au": handshake_scripts = "" - address = getAddress() + HNSaddress = getAddress("HNS") + SOLaddress = getAddress("SOL") + BTCaddress = getAddress("BTC") + ETHaddress = getAddress("ETH") # Set cookie resp = make_response(render_template('index.html', handshake_scripts=handshake_scripts, - HNS=address, repo=repo, + HNS=HNSaddress, SOL=SOLaddress, BTC=BTCaddress, + ETH=ETHaddress, repo=repo, repo_description=repo_description, custom=custom,sites=sites,projects=projects), 200, {'Content-Type': 'text/html'}) resp.set_cookie('loaded', 'true', max_age=604800) diff --git a/templates/assets/js/hacker-podcast.min.js b/templates/assets/js/hacker-podcast.min.js index 4add074..8d868ae 100644 --- a/templates/assets/js/hacker-podcast.min.js +++ b/templates/assets/js/hacker-podcast.min.js @@ -1 +1 @@ -const letters="ABCDEFGHIJKLMNOPQRSTUVWXYZ/.?!@#$%^&*()_+";let interval=null,interval2=null,interval3=null;document.querySelector(".copyright").onmouseover=t=>{let e=0,l="Copyright © Nathan Woodburn 2023";clearInterval(interval2),interval2=setInterval((()=>{t.target.innerText=t.target.innerText.split("").map(((t,r)=>r=l.length&&clearInterval(interval2),e+=1/3}),10)}; \ No newline at end of file +const letters="ABCDEFGHIJKLMNOPQRSTUVWXYZ/.?!@#$%^&*()_+";let interval=null,interval2=null,interval3=null;document.querySelector(".copyright").onmouseover=t=>{let e=0,l="Copyright © Nathan.Woodburn/ 2024";clearInterval(interval2),interval2=setInterval((()=>{t.target.innerText=t.target.innerText.split("").map(((t,r)=>r=l.length&&clearInterval(interval2),e+=1/3}),10)}; \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index 797bc2a..bf848fa 100644 --- a/templates/index.html +++ b/templates/index.html @@ -163,7 +163,7 @@ Check them out here!   Github
  •   Stripe
  • -

    HNS:
    nathan.woodburn{{HNS}}
    BTC:
    bc1qhs94zzcw64qnwq4hvk056rwxwvgrkd7tq7d4xw
    SOL:
    woodburn.solAJsPEEe6S7XSiVcdZKbeV8GRp1QuhFUsG8mLrqL4XgiU
    ETH:
    woodburn.au0x6cB4B39bEc23a921C9a20D061Bf17d4640B0d39eOTHER OPTIONS

    +

    HNS:
    nathan.woodburn{{HNS}}
    BTC:
    {{BTC}}
    SOL:
    woodburn.sol{{SOL}}
    ETH:
    woodburn.au{{ETH}}OTHER OPTIONS