From b394aea469195fd81c1166890943602fda2109c7 Mon Sep 17 00:00:00 2001 From: Gianluca Olivito Date: Thu, 9 Jan 2025 17:05:20 +0100 Subject: [PATCH] Adapt path handling --- ...ceCode-NAS-Olivito_Gianluca_CDS205_HS24.py | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/SourceCode-NAS-Olivito_Gianluca_CDS205_HS24.py b/SourceCode-NAS-Olivito_Gianluca_CDS205_HS24.py index 449a0b6..3649b66 100644 --- a/SourceCode-NAS-Olivito_Gianluca_CDS205_HS24.py +++ b/SourceCode-NAS-Olivito_Gianluca_CDS205_HS24.py @@ -1,19 +1,25 @@ # Import libraries import http.server import socketserver +import os -# Define port and path tho external drive directory -PORT = 8000 -DIRECTORY = "/mnt/mydisk" +# Define port and path to external drive directory +port = 8000 +directory = "/media/gianluca/Elements" class MyHandler(http.server.SimpleHTTPRequestHandler): def translatePath(self, path): - # Modifizieren des Standardverhaltens von SimpleHTTPRequestHandler + + # Modify default behavior of SimpleHTTPRequestHandler path = super().translate_path(path) - return path if path.startswith(DIRECTORY) else DIRECTORY + path + + # Ensure correct path handling by joining directories + if not path.startswith(directory): + path = os.path.join(directory, path.lstrip("/")) + return path handler = MyHandler -httpd = socketserver.TCPServer(("", PORT), handler) +httpd = socketserver.TCPServer(("", port), handler) -print(f"Serving on port {PORT}") -httpd.serve_forever() \ No newline at end of file +print(f"Serving on port {port}") +httpd.serve_forever()