added qrcode
This commit is contained in:
parent
e97bf818b3
commit
77d942d9bb
@ -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
|
||||
|
||||
|
@ -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 . .
|
||||
|
||||
|
4
htt.conf
4
htt.conf
@ -1,5 +1,5 @@
|
||||
[DEFAULT]
|
||||
cleartime = 10
|
||||
domain = localhost:8170
|
||||
domain = https://vscode.carsonmayn.com/proxy/8170
|
||||
port = 8170
|
||||
filesizemb = 200
|
||||
filesizemb = 100
|
47
start.py
47
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("<popuphere>",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 = {
|
||||
|
@ -1,11 +1,9 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>Here To There</title>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;700&display=swap" rel="stylesheet">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<style>
|
||||
.title,
|
||||
.main {
|
||||
@ -22,17 +20,12 @@
|
||||
display: flex;
|
||||
}
|
||||
|
||||
|
||||
body {
|
||||
font-family: 'Montserrat', sans-serif;
|
||||
background: hsla(198, 100%, 50%, 1);
|
||||
|
||||
background: linear-gradient(90deg, hsla(198, 100%, 50%, 1) 0%, hsla(188, 92%, 49%, 1) 48%, hsla(201, 100%, 49%, 1) 97%);
|
||||
|
||||
background: -moz-linear-gradient(90deg, hsla(198, 100%, 50%, 1) 0%, hsla(188, 92%, 49%, 1) 48%, hsla(201, 100%, 49%, 1) 97%);
|
||||
|
||||
background: -webkit-linear-gradient(90deg, hsla(198, 100%, 50%, 1) 0%, hsla(188, 92%, 49%, 1) 48%, hsla(201, 100%, 49%, 1) 97%);
|
||||
|
||||
filter: progid: DXImageTransform.Microsoft.gradient(startColorstr="#00B2FF", endColorstr="#0AD2F1", GradientType=1);
|
||||
}
|
||||
|
||||
@ -55,17 +48,11 @@
|
||||
background-color: rgb(79, 79, 79);
|
||||
border: none;
|
||||
color: rgb(222, 222, 222);
|
||||
|
||||
|
||||
}
|
||||
</style>
|
||||
<html>
|
||||
</head>
|
||||
|
||||
<head>
|
||||
<title>File Upload</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<body>
|
||||
<div class="title">
|
||||
<h1>Here To There</h1>
|
||||
<h2>A simple file transfer website</h2>
|
||||
@ -73,10 +60,11 @@
|
||||
<div class="main">
|
||||
<div class="upload">
|
||||
<h2>Upload a File</h2>
|
||||
<form action="upload" method="post" enctype="multipart/form-data">
|
||||
<input type="file" name="file" />
|
||||
<form action="upload" method="post" enctype="multipart/form-data" id="uploadForm">
|
||||
<input type="file" name="file" id="fileInput" />
|
||||
<br><br>
|
||||
<input type="submit" value="Upload" />
|
||||
<input type="submit" value="Upload" id="submitButton" />
|
||||
<p id="error" style="color: red; display: none;">File size must be below !MAXFILESIZEHERE! MB.</p>
|
||||
</form>
|
||||
</div>
|
||||
<br><br>
|
||||
@ -84,15 +72,28 @@
|
||||
<h2>Retrieve a File</h2>
|
||||
<form action="download" method="get">
|
||||
<input type="text" name="code" placeholder="Enter the code for the file" />
|
||||
<br>
|
||||
<br>
|
||||
<br><br>
|
||||
<button type="submit">Retrieve</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
<script>
|
||||
document.getElementById('uploadForm').addEventListener('submit', function (event) {
|
||||
const fileInput = document.getElementById('fileInput');
|
||||
const errorText = document.getElementById('error');
|
||||
|
||||
if (fileInput.files.length > 0) {
|
||||
const fileSize = fileInput.files[0].size / 1024 / 1024; // Convert to MB
|
||||
if (fileSize > !MAXFILESIZEHERE!) {
|
||||
errorText.style.display = 'block'; // Show error message
|
||||
event.preventDefault(); // Prevent form submission
|
||||
return;
|
||||
}
|
||||
}
|
||||
errorText.style.display = 'none'; // Hide error message
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</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;
|
||||
|
||||
}
|
||||
</style>
|
||||
<html>
|
||||
|
||||
@ -97,12 +102,19 @@
|
||||
<popuphere>
|
||||
</div>
|
||||
<button onclick="copycode()">Copy Code</button>
|
||||
<h2>The qr code:</h2>
|
||||
<div class="code">
|
||||
<img src="https://vscode.carsonmayn.com/proxy/8170/qrcode?link=<linkhere>" alt="QR Code" style="border-radius: 20px;">
|
||||
</div>
|
||||
<h2>Or use the link:</h2>
|
||||
<div class="code" id="link">
|
||||
<linkhere>
|
||||
</div>
|
||||
<button onclick="copylink()">Copy Link</button>
|
||||
<a class="button" href="/">Home</a>
|
||||
<br>
|
||||
<br>
|
||||
<br>
|
||||
<br> <a class="button" href="/">Home</a>
|
||||
</div>
|
||||
<br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br><br> <br> <br> <br> <br> <br><br> <br> <br> <br>
|
||||
</body>
|
||||
|
Loading…
x
Reference in New Issue
Block a user