update, and allow non-mount data

This commit is contained in:
q
2025-10-17 11:29:29 +03:00
parent fb5ce59582
commit 6bb6941287
7 changed files with 84 additions and 56 deletions

View File

@@ -20,6 +20,7 @@ from utils.files import (
db_add_download,
db_delete_file,
db_get_file,
db_get_last_maintenance,
db_get_name,
db_maintenance,
db_store_file,
@@ -28,6 +29,7 @@ from utils.files import (
file_full_url,
file_list,
file_list_simple,
get_db,
invalidate_upload_token,
new_upload_token,
validate_upload_token,
@@ -43,16 +45,17 @@ from werkzeug.utils import secure_filename
logging.basicConfig(
level=logging.INFO,
format=f"[%(asctime)s] [%(levelname)s] %(message)s",
format="[%(asctime)s] [%(levelname)s] %(message)s",
)
__VERSION__ = "20250328.0"
__VERSION__ = "20251017.0"
app = Flask(__name__)
app.config.from_object(__name__)
app.config.from_prefixed_env()
app.debug = True
app.secret_key = app.config["APP_SECRET_KEY"]
app.wsgi_app = ReverseProxied(app.wsgi_app)
app.config["KEY_LENGTH"] = int(app.config["KEY_LENGTH"])
@app.before_request
@@ -70,14 +73,24 @@ def log_the_status_code(response):
@app.route("/")
def index():
"""Returns Index"""
return render_template(
"index.html"
)
return render_template("index.html")
@app.route('/health.html', methods=["GET",]) # fmt: skip
@app.route('/health', methods=["GET",]) # fmt: skip
def health():
return f"OK {request.url}", 200
try:
get_db()
except Exception:
return "DB Error", 500
try:
last_maintenance = db_get_last_maintenance()
if time.time() > last_maintenance + 86400: # Daily
return f"OK, {db_maintenance()}, {request.url}", 200
except Exception:
return "DB Maintenance error", 500
return f"OK, {request.url}", 200
@app.route("/upload", methods=["PUT", "POST"])
@@ -144,7 +157,7 @@ def upload():
return "IP list contains unknown characters"
while True:
token = random_token()
token = random_token(app.config["KEY_LENGTH"])
folder = os.path.join(app.config["DATAFOLDER"], token)
if not os.path.exists(folder):
break
@@ -196,6 +209,7 @@ def upload_token():
token = new_upload_token(expires)
return token, 200
@app.route("/details/<token>", methods=["GET"])
@app.route("/details/<token>/<name>", methods=["GET"])
def details(token, name=None):
@@ -211,7 +225,10 @@ def details(token, name=None):
if secret != app.config["ACCESS_TOKEN"]:
return "Error", 401
if name is None:
name = db_get_name(token)[0]
try:
name = db_get_name(token)[0]
except TypeError:
return "No such file", 404
details = file_details(token, name)
if details["allowed_ip"] is not None:
if not is_ip_allowed(
@@ -223,7 +240,7 @@ def details(token, name=None):
@app.route("/delete/<token>", methods=["GET"])
@app.route("/delete/<token>/<name>", methods=["GET"])
def delete_file(token,name=None):
def delete_file(token, name=None):
"""
Delete a file from the system
"""