first commit
This commit is contained in:
commit
a9234f82b7
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
/.venv
|
116
start.py
Normal file
116
start.py
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import cherrypy
|
||||||
|
import time
|
||||||
|
import shutil
|
||||||
|
|
||||||
|
def popup(mesage):
|
||||||
|
out = load("popup.html")
|
||||||
|
return out.replace("<popuphere>",mesage)
|
||||||
|
|
||||||
|
def load(file):
|
||||||
|
path = os.path.dirname(os.path.realpath(sys.argv[0]))
|
||||||
|
with open(f"{path}/webpage/{file}") as f:
|
||||||
|
return f.read()
|
||||||
|
# Maximum time in minutes before a file is removed
|
||||||
|
MAINTENANCE_INTERVAL_MINUTES = 1
|
||||||
|
|
||||||
|
|
||||||
|
def clear_cache():
|
||||||
|
"""
|
||||||
|
Deletes files in the 'uploads' directory that have not been modified
|
||||||
|
within the last MAINTENANCE_INTERVAL_MINUTES.
|
||||||
|
"""
|
||||||
|
upload_dir = os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), "uploads")
|
||||||
|
print(upload_dir)
|
||||||
|
if not os.path.exists(upload_dir):
|
||||||
|
print("notfound")
|
||||||
|
return # If the directory doesn't exist, nothing to clean.
|
||||||
|
|
||||||
|
for file in os.listdir(upload_dir):
|
||||||
|
print(file)
|
||||||
|
item_path = os.path.join(upload_dir, file)
|
||||||
|
last_mod_time = os.path.getmtime(item_path)
|
||||||
|
time_diff_minutes = (time.time() - last_mod_time) / 60
|
||||||
|
|
||||||
|
if time_diff_minutes >= MAINTENANCE_INTERVAL_MINUTES:
|
||||||
|
try:
|
||||||
|
shutil.rmtree(item_path)
|
||||||
|
print(f"Deleted {item_path}")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error deleting {item_path}: {e}")
|
||||||
|
else:
|
||||||
|
print(f"File {file} is {time_diff_minutes:.2f} minutes old, not deleting.")
|
||||||
|
|
||||||
|
|
||||||
|
class FileUploadApp:
|
||||||
|
upload_dir = "uploads/" # Directory to save uploaded files
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
# Ensure the upload directory exists
|
||||||
|
if not os.path.exists(self.upload_dir):
|
||||||
|
os.makedirs(self.upload_dir)
|
||||||
|
|
||||||
|
@cherrypy.expose
|
||||||
|
def index(self):
|
||||||
|
# HTML form for file upload and file retrieval
|
||||||
|
return load("index.html")
|
||||||
|
|
||||||
|
@cherrypy.expose
|
||||||
|
def upload(self, file):
|
||||||
|
clear_cache()
|
||||||
|
try:
|
||||||
|
# Find the lowest unused number as the identifier
|
||||||
|
existing_ids = set(int(folder) for folder in os.listdir(self.upload_dir) if folder.isdigit())
|
||||||
|
ident = 1 # Start checking from 1
|
||||||
|
while ident in existing_ids:
|
||||||
|
ident += 1
|
||||||
|
|
||||||
|
# Create the directory for the new upload
|
||||||
|
upload_path = os.path.join(self.upload_dir, str(ident))
|
||||||
|
os.makedirs(upload_path)
|
||||||
|
file_path = os.path.join(upload_path, file.filename)
|
||||||
|
|
||||||
|
# Save the file to the upload directory
|
||||||
|
with open(file_path, "wb") as f:
|
||||||
|
while chunk := file.file.read(8192):
|
||||||
|
f.write(chunk)
|
||||||
|
|
||||||
|
return popup(f"File '{file.filename}' uploaded successfully! Your code is {ident}.")
|
||||||
|
except Exception as e:
|
||||||
|
return popup(f"An error occurred during upload: {str(e)}")
|
||||||
|
|
||||||
|
@cherrypy.expose
|
||||||
|
def download(self, code):
|
||||||
|
try:
|
||||||
|
# Check if the directory for the code exists
|
||||||
|
download_path = os.path.join(self.upload_dir, code)
|
||||||
|
if not os.path.exists(download_path) or not os.path.isdir(download_path):
|
||||||
|
raise FileNotFoundError("Invalid code or file not found.")
|
||||||
|
|
||||||
|
# Get the first file in the directory
|
||||||
|
files = os.listdir(download_path)
|
||||||
|
if not files:
|
||||||
|
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
|
||||||
|
|
||||||
|
# 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)}")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
config = {
|
||||||
|
"/": {
|
||||||
|
"tools.staticdir.root": os.path.abspath(os.getcwd())
|
||||||
|
},
|
||||||
|
"/uploads": {
|
||||||
|
"tools.staticdir.on": True,
|
||||||
|
"tools.staticdir.dir": os.path.abspath("uploads"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cherrypy.quickstart(FileUploadApp(), "/", config)
|
5
uploads/1/Submission+2.html
Normal file
5
uploads/1/Submission+2.html
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"><base href = "https://mcnhs.schoology.com/"></head><body><p dir="ltr"><span style="font-family: 'Times New Roman',serif; color: black;">Virtual insanity is a song about monsters and the monster is humans desire to innovate. And relates to my theme as this innovation causes humanity to be isolated from each other.</span></p>
|
||||||
|
<p><span style="font-family: 'Times New Roman',serif; color: black;"> </span></p>
|
||||||
|
<p><span style="font-family: 'Times New Roman',serif; color: black;">This is shown to us in the quote “and now every mother can chose the color of her child, that’s not nature’s way” and”</span> And now there is no sound, for we all live underground”<span style="font-family: 'Times New Roman',serif; color: black;">. The first quote shows that the Monster is humans desire to innovate by telling us that we are messing with things that can have massive consequences for nature and therefore ourselves. the next quote proves that as when he says that they live underground. He is referring to how technology is isolating us from others. It could also have the more literal meaning of how an incident involving technology forced humanity underground. </span></p>
|
||||||
|
<p><span style="font-family: 'Times New Roman',serif; color: black;"> </span></p>
|
||||||
|
<p><span style="font-family: 'Times New Roman',serif; color: black;">The second quote I have to prove this is “Always seem to be governed by this love we have For useless twisting of our new technology “This quote talks about how we get caught up in making more technology that we fail to take into account other important things like social issues, poverty, and the environment. This means the technology is a monster as it distracts us from fixing other important issues. This relates to my theme as this means technology isolates us from important issues.</span></p></body></html>
|
87
webpage/index.html
Normal file
87
webpage/index.html
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<title>index.html</title>
|
||||||
|
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;700&display=swap" rel="stylesheet">
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<style>
|
||||||
|
.title {
|
||||||
|
background-color: #ff0000;
|
||||||
|
color: white;
|
||||||
|
padding: 20px;
|
||||||
|
margin: 20px;
|
||||||
|
border-radius: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.main {
|
||||||
|
display: flex;
|
||||||
|
background-color: gray;
|
||||||
|
padding: 20px;
|
||||||
|
margin: 20px;
|
||||||
|
border-radius: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
font-family: 'Montserrat', sans-serif;
|
||||||
|
background-color: rgb(37, 37, 37);
|
||||||
|
}
|
||||||
|
|
||||||
|
.upload,
|
||||||
|
.download {
|
||||||
|
color: white;
|
||||||
|
border-radius: 20px;
|
||||||
|
background-color: #ff0000;
|
||||||
|
margin: 20px;
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
input,
|
||||||
|
button {
|
||||||
|
padding: 10px;
|
||||||
|
margin: 10px;
|
||||||
|
border-radius: 20px;
|
||||||
|
background-color: rgb(52, 52, 52);
|
||||||
|
border: none;
|
||||||
|
color: rgb(222, 222, 222);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<title>File Upload</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div class="title">
|
||||||
|
<h1>Here to there</h1>
|
||||||
|
<h2>A simple file transfer webserver</h2>
|
||||||
|
</div>
|
||||||
|
<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" />
|
||||||
|
<br><br>
|
||||||
|
<input type="submit" value="Upload" />
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<br><br>
|
||||||
|
<div class="download">
|
||||||
|
<h2>Retrieve a File</h2>
|
||||||
|
<form action="download" method="get">
|
||||||
|
<p>id:</p>
|
||||||
|
<input type="text" name="code" placeholder="Enter file code" />
|
||||||
|
<button type="submit">Retrieve</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
64
webpage/popup.html
Normal file
64
webpage/popup.html
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<title>info</title>
|
||||||
|
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;700&display=swap" rel="stylesheet">
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
display: flex;
|
||||||
|
font-family: 'Montserrat', sans-serif;
|
||||||
|
background-color: rgb(37, 37, 37);
|
||||||
|
}
|
||||||
|
|
||||||
|
.popup {
|
||||||
|
color: white;
|
||||||
|
border-radius: 20px;
|
||||||
|
background-color: #ff0000;
|
||||||
|
margin: 20px;
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
input,
|
||||||
|
button {
|
||||||
|
padding: 10px;
|
||||||
|
margin: 10px;
|
||||||
|
border-radius: 20px;
|
||||||
|
background-color: rgb(52, 52, 52);
|
||||||
|
border: none;
|
||||||
|
color: rgb(222, 222, 222);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
.button {
|
||||||
|
text-decoration: none;
|
||||||
|
padding: 10px;
|
||||||
|
border-radius: 20px;
|
||||||
|
background-color: rgb(0, 0, 0);
|
||||||
|
color: aliceblue;
|
||||||
|
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<title>File Upload</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div class="popup">
|
||||||
|
<h2>
|
||||||
|
<popuphere>
|
||||||
|
</h2>
|
||||||
|
<a class="button" href="/">Home</a>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
Loading…
x
Reference in New Issue
Block a user