From 77d942d9bb4c79c01f292109d249f0d09d9d420a Mon Sep 17 00:00:00 2001 From: ocueye Date: Thu, 21 Nov 2024 15:32:52 +0000 Subject: [PATCH] added qrcode --- README.md | 2 +- dockerfile | 2 +- htt.conf | 4 +-- start.py | 47 +++++++++++++++++++++++--- webpage/index.html | 81 +++++++++++++++++++++++---------------------- webpage/upload.html | 14 +++++++- 6 files changed, 101 insertions(+), 49 deletions(-) diff --git a/README.md b/README.md index d257758..ad6ac6d 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ I made it because all of the options eather have ads, only work on the lan, or c (This is desined to be run on linux) ### linux -to run this program, make a venv virtual enviroment and run `pip install cherrypy` and then run `start.py`. +to run this program, make a venv virtual enviroment and run `pip install cherrypy qrcode pillow` and then run `start.py`. ### docker just clone this repo diff --git a/dockerfile b/dockerfile index a65861f..ad53f62 100644 --- a/dockerfile +++ b/dockerfile @@ -5,7 +5,7 @@ FROM python:3.12.3-slim WORKDIR /app # Install any needed packages specified in requirements.txt -RUN pip install cherrypy +RUN pip install cherrypy pillow qrcode # Copy the rest of your application code into the container at /app COPY . . diff --git a/htt.conf b/htt.conf index f3e43f1..2573a27 100644 --- a/htt.conf +++ b/htt.conf @@ -1,5 +1,5 @@ [DEFAULT] cleartime = 10 -domain = localhost:8170 +domain = https://vscode.carsonmayn.com/proxy/8170 port = 8170 -filesizemb = 200 \ No newline at end of file +filesizemb = 100 \ No newline at end of file diff --git a/start.py b/start.py index bf29f3a..f620703 100644 --- a/start.py +++ b/start.py @@ -4,6 +4,8 @@ import cherrypy import time import shutil import configparser +import qrcode +from io import BytesIO config = configparser.ConfigParser() config.read('htt.conf') @@ -11,7 +13,9 @@ domain = str(config['DEFAULT']['domain']) MAINTENANCE_INTERVAL_MINUTES = float(config['DEFAULT']['cleartime']) port = int(config['DEFAULT']['port']) maxfilesize = int(config['DEFAULT']['filesizemb']) +maxsizemb = str(maxfilesize) maxfilesize = maxfilesize * 10 * 1024 * 1024 + def popup(mesage,link="",file="popup.html"): out = load(file) out = out.replace("",str(mesage)) @@ -20,8 +24,13 @@ def popup(mesage,link="",file="popup.html"): def load(file): path = os.path.dirname(os.path.realpath(sys.argv[0])) + + with open(f"{path}/webpage/{file}") as f: - return f.read() + out = f.read() + if file == "index.html": + out = out.replace("!MAXFILESIZEHERE!",str(maxsizemb)) + return out def clear_cache(): @@ -72,9 +81,9 @@ class FileUploadApp: file_size = 0 file.file.seek(0, os.SEEK_END) # Seek to the end of the file file_size = file.file.tell() # Get the current position (file size) - file.file.seek(0) + file.file.seek(0) # if file_size > maxfilesize: - return popup(f"This file is to large, max size is is {maxfilesize}") + return popup(f"This file is to large, max size is is {maxfilesize / 10,485,760}mb") # Find the lowest unused number as the identifier existing_ids = set(int(folder) for folder in os.listdir(self.upload_dir) if folder.isdigit()) @@ -110,13 +119,43 @@ class FileUploadApp: raise FileNotFoundError("No files found for this code.") file_path = os.path.join(download_path, files[0]) - absolute_file_path = os.path.abspath(file_path) # Convert to absolute path + absolute_file_path = os.path.abspath(file_path) # Serve the file as a downloadable attachment return cherrypy.lib.static.serve_file(absolute_file_path, "application/octet-stream", "attachment") except Exception as e: return popup(f"An error occurred: {str(e)}") + @cherrypy.expose + def qrcode(self, link=None): + if not link: + raise cherrypy.HTTPError(400, "Bad Request: No link provided.") + elif not domain in link: + raise cherrypy.HTTPError(400, "Bad Request: No link provided.") + + # Generate the QR Code + qr = qrcode.QRCode( + version=1, + error_correction=qrcode.constants.ERROR_CORRECT_L, + box_size=10, + border=4, + ) + qr.add_data(link) + qr.make(fit=True) + + # Create an image for the QR Code + img = qr.make_image(fill_color="black", back_color="white") + buffered = BytesIO() + img.save(buffered, format="PNG") + buffered.seek(0) + + # Serve the image as PNG + cherrypy.response.headers['Content-Type'] = 'image/png' + return buffered.read() + + + + if __name__ == "__main__": config = { diff --git a/webpage/index.html b/webpage/index.html index e7fd9cf..08c6d32 100644 --- a/webpage/index.html +++ b/webpage/index.html @@ -1,11 +1,9 @@ + Here To There - - - - + - - File Upload - - - -
-

Here To There

-

A simple file transfer website

+ +
+

Here To There

+

A simple file transfer website

+
+
+
+

Upload a File

+
+ +

+ + +
-
-
-

Upload a File

-
- -

- -
-
-

-
-

Retrieve a File

-
- -
-
- -
-
+

+
+

Retrieve a File

+
+ +

+ +
- +
- + \ No newline at end of file diff --git a/webpage/upload.html b/webpage/upload.html index 81ca0f6..9a3b1e8 100644 --- a/webpage/upload.html +++ b/webpage/upload.html @@ -42,6 +42,7 @@ background-color: rgb(52, 52, 52); border: none; color: rgb(222, 222, 222); + transition: all .3s; } @@ -61,6 +62,10 @@ padding: 20px; } + button:hover { + transition: all .3s; + + } @@ -97,12 +102,19 @@
+

The qr code:

+
+ QR Code +

Or use the link:

- Home +
+
+
+
Home