sigyllly commited on
Commit
d9c2e0e
·
verified ·
1 Parent(s): b4dd6fc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -48
app.py CHANGED
@@ -1,49 +1,42 @@
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()
 
1
  import os
2
+ from cheroot import wsgi
3
+ from wsgidav.wsgidav_app import WsgiDAVApp
4
+ from wsgidav.fs_dav_provider import FilesystemProvider
5
+
6
+ # Create the files directory and sample.txt
7
+ files_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "files")
8
+ if not os.path.exists(files_dir):
9
+ os.makedirs(files_dir)
10
+
11
+ # Create a sample.txt file
12
+ with open(os.path.join(files_dir, "sample.txt"), "w") as f:
13
+ f.write("This is a sample file for the WebDAV server.")
14
+
15
+ print(f"Created 'files' directory with sample.txt at {files_dir}")
16
+
17
+ # Configuration
18
+ config = {
19
+ "provider_mapping": {
20
+ "/": FilesystemProvider(files_dir)
21
+ },
22
+ "http_authenticator": {
23
+ "domain_controller": None,
24
+ },
25
+ "simple_dc": {"user_mapping": {"*": True}}, # No authentication
26
+ "verbose": 1,
27
+ }
28
+
29
+ # Create the WSGI application
30
+ app = WsgiDAVApp(config)
31
+
32
+ # Create and start the server
33
+ server_addr = "0.0.0.0"
34
+ server_port = 7860
35
+ server = wsgi.Server((server_addr, server_port), app)
36
+
37
+ print(f"Starting WebDAV server at http://{server_addr}:{server_port}")
38
+ try:
39
+ server.start()
40
+ except KeyboardInterrupt:
41
+ print("Stopping server...")
42
+ server.stop()