From ab84dea51821b4610dfdd0a4631a640f36eadf3f Mon Sep 17 00:00:00 2001 From: Andrew Date: Sat, 10 Jan 2026 20:07:23 +0900 Subject: [PATCH] show location of user --- app.py | 26 ++++++++++++++- static/script.js | 15 +-------- templates/upload.html | 75 +++++++++++++++++++++++++++++++++++++------ 3 files changed, 92 insertions(+), 24 deletions(-) diff --git a/app.py b/app.py index a053b61..7767e0f 100644 --- a/app.py +++ b/app.py @@ -5,7 +5,8 @@ from flask import ( request, url_for, send_from_directory, - flash + flash, + jsonify ) from utils import redirect, dbload, dbsave, udbload, udbsave from werkzeug.exceptions import RequestEntityTooLarge @@ -15,6 +16,7 @@ import os import random import threading import time +import requests import logging import logging.handlers @@ -32,6 +34,28 @@ logging.getLogger('werkzeug').addHandler(handler) app.logger.setLevel(logging.WARNING) app.logger.addHandler(handler) +@app.route('/get-location') +def get_location(): + # Get IP (handling Docker/Proxy headers) + user_ip = request.headers.get('X-Forwarded-For', request.remote_addr) + if user_ip and ',' in user_ip: + user_ip = user_ip.split(',')[0].strip() + + # Localhost testing fix + if user_ip in ['127.0.0.1', 'localhost', '::1']: + user_ip = '8.8.8.8' + + try: + # Use a fast, reliable API + response = requests.get(f'http://ip-api.com/json/{user_ip}', timeout=5) + return jsonify(response.json()) + except: + return jsonify({"status": "fail"}), 500 + +@app.route('/ping') +def ping(): + return jsonify({"status": "ok"}) + @app.route('/') def index(): return redirect(url_for('upload')) diff --git a/static/script.js b/static/script.js index caef571..acfd8cc 100644 --- a/static/script.js +++ b/static/script.js @@ -1,17 +1,4 @@ -if (localStorage.getItem("loaded")) { - document.getElementById("mirrorLogo").className = "fa-solid fa-circle-dot fa-2xs"; - document.getElementById("mirrorText").textContent = "drive.fybe.dev"; - document.getElementById("mirrorLogo").style.color = "#47cc00"; -} else { - setTimeout(() => { - document.getElementById("mirrorLogo").style.color = "#47cc00"; - document.getElementById("mirrorText").textContent = "drive.fybe.dev"; - setTimeout(() => { - document.getElementById("mirrorLogo").className = "fa-solid fa-circle-dot fa-2xs"; - localStorage.setItem("loaded", true); - }, 3000); - }, 3000); -} + document.addEventListener('DOMContentLoaded', function() { const form = document.getElementById('uploadForm'); diff --git a/templates/upload.html b/templates/upload.html index 0a092c1..6495773 100644 --- a/templates/upload.html +++ b/templates/upload.html @@ -41,18 +41,18 @@ {% if loggedIn %}

ADrive File Sharing {{ username }}

{% else %} -

ADrive File Sharing Guest

+

ADrive File Sharing Guest

{% endif %} - - + - Finding Nearby Mirror Ping: CONNECTINGms - - - --> + + - Location Not Found + Locating... ..ms @@ -63,7 +63,7 @@
- @@ -177,6 +177,63 @@ })(); + + +