Spaces:
Sleeping
Sleeping
import hashlib | |
import time | |
from flask import Flask, render_template, request, jsonify | |
app = Flask(__name__) | |
current_text = "" | |
logs = [] | |
def get_ip_hash(ip): | |
return hashlib.sha256(ip.encode()).hexdigest()[:8] | |
def log_text(ip, text): | |
timestamp = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()) | |
ip_hash = get_ip_hash(ip) | |
logs.append([timestamp, ip_hash, text]) | |
def index(): | |
return render_template('index.html') | |
def viewport(): | |
return render_template('viewport.html') | |
def ctrl(): | |
global current_text | |
if request.method == 'POST': | |
new_text = request.form['text'] | |
if new_text != current_text: # Check for duplicate content | |
current_text = new_text | |
log_text(request.remote_addr, current_text) | |
return '', 204 | |
return render_template('ctrl.html') | |
def get_text(): | |
global current_text | |
return jsonify({'text': current_text}) | |
def log(): | |
return render_template('log.html', log_data=logs) | |
if __name__ == '__main__': | |
app.run(debug=True, host="0.0.0.0") | |