Update app.py
Browse files
app.py
CHANGED
|
@@ -1,45 +1,49 @@
|
|
| 1 |
-
from wsgidav.wsgidav_app import WsgiDAVApp
|
| 2 |
-
from wsgidav.fs_dav_provider import FilesystemProvider
|
| 3 |
-
from cheroot.wsgi import Server as WSGIServer
|
| 4 |
import os
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
#
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
#
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
#
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
#
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
+
from wsgidav.server.server_thread import WsgiDAVApp
|
| 3 |
+
from wsgidav.dav_provider import DAVProvider
|
| 4 |
+
from wsgidav.request import Request
|
| 5 |
+
from wsgidav.response import Response
|
| 6 |
+
|
| 7 |
+
# Create a folder named 'files' and add a 'sample.txt' file if not already present
|
| 8 |
+
directory = 'files'
|
| 9 |
+
file_name = os.path.join(directory, 'sample.txt')
|
| 10 |
+
|
| 11 |
+
# Create the directory and file if they do not exist
|
| 12 |
+
if not os.path.exists(directory):
|
| 13 |
+
os.makedirs(directory)
|
| 14 |
+
|
| 15 |
+
if not os.path.exists(file_name):
|
| 16 |
+
with open(file_name, 'w') as f:
|
| 17 |
+
f.write("This is a sample text file.")
|
| 18 |
+
|
| 19 |
+
# WebDAV Provider Class
|
| 20 |
+
class MyDAVProvider(DAVProvider):
|
| 21 |
+
def __init__(self, base_path):
|
| 22 |
+
super().__init__(base_path)
|
| 23 |
+
|
| 24 |
+
# WebDAV App Configuration
|
| 25 |
+
def start_webdav_server():
|
| 26 |
+
# The base folder that the WebDAV server will expose
|
| 27 |
+
base_path = os.path.abspath(directory)
|
| 28 |
+
|
| 29 |
+
# Set up the WebDAV provider (which provides file management)
|
| 30 |
+
provider = MyDAVProvider(base_path)
|
| 31 |
+
|
| 32 |
+
# Server settings (no authentication required)
|
| 33 |
+
config = {
|
| 34 |
+
"host": "0.0.0.0", # Listen on all interfaces
|
| 35 |
+
"port": 7860, # Port number
|
| 36 |
+
"provider": provider, # File system provider
|
| 37 |
+
"authenticator": None, # Disable authentication
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
# Create the WSGI WebDAV app
|
| 41 |
+
app = WsgiDAVApp(config)
|
| 42 |
+
|
| 43 |
+
print(f"Starting WebDAV server on http://0.0.0.0:7860/")
|
| 44 |
+
|
| 45 |
+
# Start the WebDAV server
|
| 46 |
+
app.run()
|
| 47 |
+
|
| 48 |
+
if __name__ == "__main__":
|
| 49 |
+
start_webdav_server()
|