Upload files to "/"

This commit is contained in:
Arnas 2026-10-03 21:40:12 +00:00
commit d0377a130c
2 changed files with 56 additions and 0 deletions

4
Dockerfile Normal file
View file

@ -0,0 +1,4 @@
FROM python:3.12-alpine
COPY app.py /app.py
EXPOSE 8080
CMD ["python", "-u", "/app.py"]

52
app.py Normal file
View file

@ -0,0 +1,52 @@
import textwrap
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
from urllib.parse import unquote
COW = r""" \ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
"""
def cowsay(text, width=40):
lines = textwrap.wrap(text, width) or [""]
w = max(len(line) for line in lines)
out = [" " + "_" * (w + 2)]
if len(lines) == 1:
out.append(f"< {lines[0]} >")
else:
for i, line in enumerate(lines):
line = line.ljust(w)
if i == 0:
out.append(f"/ {line} \\")
elif i == len(lines) - 1:
out.append(f"\\ {line} /")
else:
out.append(f"| {line} |")
out.append(" " + "-" * (w + 2))
return "\n".join(out) + "\n" + COW
class Handler(BaseHTTPRequestHandler):
def do_GET(self):
path = self.path.split("?", 1)[0].lstrip("/")
if path == "favicon.ico":
self.send_response(404)
self.end_headers()
return
# "+" and "_" become spaces, then %xx decoding (so %2B still gives a literal +)
text = unquote(path.replace("+", " ").replace("_", " "))[:500] or "moo"
body = cowsay(text).encode()
self.send_response(200)
self.send_header("Content-Type", "text/plain; charset=utf-8")
self.send_header("Content-Length", str(len(body)))
self.end_headers()
self.wfile.write(body)
def log_message(self, *args):
pass
ThreadingHTTPServer(("0.0.0.0", 8080), Handler).serve_forever()