From b19fce5b4a26c23b00e1b3b30c6be7ca2ea8458d Mon Sep 17 00:00:00 2001 From: Andrew K Date: Thu, 8 Jan 2026 23:20:55 +0900 Subject: [PATCH 1/3] clean up unrequired import sys --- app.py | 1 - 1 file changed, 1 deletion(-) diff --git a/app.py b/app.py index fb91eef..b1ffb4f 100644 --- a/app.py +++ b/app.py @@ -11,7 +11,6 @@ from utils import redirect, dbload, dbsave, udbload, udbsave from werkzeug.exceptions import RequestEntityTooLarge from werkzeug.utils import secure_filename -import sys import os import random import threading From 2be9e518057f0bcaf52865d4db164f44c9abc4d4 Mon Sep 17 00:00:00 2001 From: Andrew K Date: Thu, 8 Jan 2026 23:23:45 +0900 Subject: [PATCH 2/3] clean up code with increased readability --- app.py | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index b1ffb4f..d75183d 100644 --- a/app.py +++ b/app.py @@ -38,32 +38,51 @@ def index(): @app.route('/dashboard') def dashboard(): + # Load Databases + db = dbload() + udb = udbload() + + # Check if user is a guest if session.get('loggedIn', False) == False: flash('You must be signed in to view the dashboard!', 'error') return redirect(url_for('upload')) - db = dbload() - udb = udbload() + + # Get user quota, usage, and files username = session.get('username') userfiles = [] quota_usage_gb = 0 + if not username: flash('An error occurred. Please sign in again.', 'error') session['loggedIn'] = False session.pop('username', None) return redirect(url_for('upload')) + for file in db['files']: if db['files'][file].get('owner') == username: db['files'][file]['file'] = file db['files'][file]['code'] = file.split('_')[-1] userfiles.append(db['files'][file]) + for userfile in userfiles: usf_mb = userfile['size_megabytes'] if usf_mb: quota_usage_gb += usf_mb / 1024 + quota_usage_gb = round(quota_usage_gb, 1) - return render_template('dashboard.html', files=userfiles, username=username, quota_gb=udb[[user['username'] for user in udb].index(username)]['quota_gb'], quota_usage=quota_usage_gb) + + # Render template with variables + return render_template( + 'dashboard.html', + files=userfiles, + username=username, + quota_gb=udb[[user['username'] for user in udb].index(username)]['quota_gb'], + quota_usage=quota_usage_gb + ) + @app.route('/logout') def logout(): + # Sign out user and redirect to upload page session['loggedIn'] = False session.pop('username', None) flash('Successfully signed out!', 'info') @@ -71,43 +90,53 @@ def logout(): @app.route('/login', methods=['GET', 'POST']) def login(): + # Load User Database (UDB) udb = udbload() if request.method == 'GET': return render_template('login.html') if request.method == 'POST': + # Get data from form username = request.form.get('username') password = request.form.get('password') + # Check if user exists and password matches, log them in for user in udb: if user['username'] == username and user['password'] == password: session['loggedIn'] = True session['username'] = username flash('Successfully signed in!', 'info') return redirect(url_for('upload')) + + # If still here, login failed flash('Invalid username or password!', 'error') return redirect(url_for('login')) @app.route('/register', methods=['GET', 'POST']) def register(): + # Load User Database (UDB) udb = udbload() if request.method == 'GET': return render_template('register.html') if request.method == 'POST': + # Get data from form username = request.form.get('username') password = request.form.get('password') + # Check if username is already taken for user in udb: if user['username'] == username: flash('Username already taken!', 'error') return redirect(url_for('register')) + # Create new user with default quota of 3GB udb.append({ 'username': username, 'password': password, 'quota_gb': 3 }) + udbsave(udb) flash('Successfully registered! You can now sign in.', 'info') return redirect(url_for('login')) From cc12b95c987f26df5c0d1fef1471c4576a109cca Mon Sep 17 00:00:00 2001 From: Andrew K Date: Fri, 9 Jan 2026 13:30:36 +0900 Subject: [PATCH 3/3] use bootstrap style alerts, progress bars --- static/script.js | 23 +++++++-- static/styles.css | 7 ++- templates/upload.html | 105 ++++++++++++++++++++++++++++-------------- 3 files changed, 93 insertions(+), 42 deletions(-) diff --git a/static/script.js b/static/script.js index 8ed8f96..caef571 100644 --- a/static/script.js +++ b/static/script.js @@ -19,6 +19,7 @@ document.addEventListener('DOMContentLoaded', function() { const fileInput = document.getElementById('fileUpload'); const progress = document.getElementById('uploadProgress'); + const progressContainer = document.getElementById('uploadProgressContainer'); const progressText = document.getElementById('uploadProgressText'); const uploadBtn = document.getElementById('uploadBtn'); @@ -42,8 +43,10 @@ document.addEventListener('DOMContentLoaded', function() { if (ev.lengthComputable) { const percent = Math.round((ev.loaded / ev.total) * 100); if (progress) { - progress.style.display = 'block'; - progress.value = percent; + if (progressContainer) progressContainer.style.display = 'block'; + progress.style.width = percent + '%'; + progress.setAttribute('aria-valuenow', percent); + progress.textContent = percent + '%'; } if (progressText) { progressText.style.display = 'block'; @@ -76,13 +79,18 @@ document.addEventListener('DOMContentLoaded', function() { } catch (e) { window.location.href = '/upload'; return; - } finally { + } finally { if (uploadBtn) { uploadBtn.disabled = false; uploadBtn.classList.remove('yellowBtn'); uploadBtn.value = 'Upload'; } - if (progress) { progress.style.display = 'none'; progress.value = 0; } + if (progress) { + if (progressContainer) progressContainer.style.display = 'none'; + progress.style.width = '0%'; + progress.setAttribute('aria-valuenow', 0); + progress.textContent = '0%'; + } if (progressText) { progressText.style.display = 'none'; progressText.textContent = '0%'; } // clear file input and reusable checkbox after successful upload if (fileInput) fileInput.value = ''; @@ -110,7 +118,12 @@ document.addEventListener('DOMContentLoaded', function() { uploadBtn.value = 'Upload'; } if (fileInput) fileInput.value = ''; - if (progress) { progress.style.display = 'none'; progress.value = 0; } + if (progress) { + if (progressContainer) progressContainer.style.display = 'none'; + progress.style.width = '0%'; + progress.setAttribute('aria-valuenow', 0); + progress.textContent = '0%'; + } if (progressText) progressText.style.display = 'none'; }); diff --git a/static/styles.css b/static/styles.css index 93ec7d3..6efaaf4 100644 --- a/static/styles.css +++ b/static/styles.css @@ -35,14 +35,15 @@ body,html { display: flex; flex-direction: column; align-items: flex-start; - width: 50%; + width: 80%; border: 1px solid rgb(40, 40, 40); padding-bottom: 40px; + padding: 50px; } .form-section { padding: 15px 0 0 15px; - width: 50%; + width: 100%; color: var(--light); flex-shrink: 0; } @@ -116,6 +117,8 @@ button[type='button']:hover, display: flex; flex-direction: column; gap: 15px; + padding: 10px; + } .flashes li { list-style-type: none; diff --git a/templates/upload.html b/templates/upload.html index a1cee0e..acc780d 100644 --- a/templates/upload.html +++ b/templates/upload.html @@ -1,5 +1,6 @@ + @@ -7,58 +8,87 @@ ADrive Share + +
{% with messages = get_flashed_messages(with_categories=true) %} {% if messages %} -
    - {% for category, message in messages %} - -
  • {{ message }}
  • - {% endfor %} -
+
    + {% for category, message in messages %} + + {% if category == 'message' %} + {% set category = 'primary' %} + {% endif %} + {% if category == 'error' %} + {% set category = 'danger' %} + {% endif %} + {% if category == 'info' %} + {% set category = 'info' %} + {% endif %} + {% if category == 'warning' %} + {% set category = 'warning' %} + {% endif %} +
  • {{ message }}
  • + {% endfor %} +
{% endif %} {% endwith %}
{% if loggedIn %} -

You are currently logged in as {{ username }}.

+

ADrive File Sharing {{ username }}

{% else %} -

You are currently not logged in.

+

ADrive File Sharing Guest

{% endif %} - - Finding Nearby Mirror + + Finding Nearby Mirror - + Location Not Found - + - - -
- - Reusable? + + +
+
+ + +
- + - +
- +
{% if not loggedIn %} - -
-

Signing in is not required. You can at any time register and sign in to manage your existing codes for free. You can manage up to 1GB of files.

+ +

+

Signing in is not required. You can at any time + register and sign in to manage your existing codes for free. You can manage up to 1GB of files.

{% else %} - - + + {% endif %}
@@ -69,7 +99,7 @@ + - \ No newline at end of file + + +