@@ -31,13 +31,8 @@ def __init__(self, wifi_ssid, wifi_password, port=80, timeout=20, doc_root="/www
3131 self .doc_root = doc_root
3232 self .function_routes = []
3333 self .log_level = log_level
34- # wifi client in station mode so we can connect to an access point
3534 self .wlan_sta = network .WLAN (network .STA_IF )
3635 self .wlan_ap = network .WLAN (network .AP_IF )
37- # activate the interface
38- #self.wlan.active(True)
39- # connect to the access point with the ssid and password
40- #self.wlan.connect(self.wifi_ssid, self.wifi_password)
4136 self .html = """<!DOCTYPE html>
4237 <html>
4338 <head> <title>GurgleApps.com Webserver</title> </head>
@@ -46,27 +41,11 @@ def __init__(self, wifi_ssid, wifi_password, port=80, timeout=20, doc_root="/www
4641 </body>
4742 </html>
4843 """
49- # counter = self.timeout
50- # while counter > 0:
51- # if self.wlan_sta.status() < 0 or self.wlan_sta.status() >= 3:
52- # break
53- # counter -= 1
54- # print('waiting for connection...')
55- # time.sleep(1)
56-
57- # if self.wlan.status() != 3:
58- # if self.wlan_sta.isconnected() == False:
59- # raise RuntimeError('network connection failed')
60- # else:
61- # print('connected')
62- # status = self.wlan_sta.ifconfig()
63- # print('ip = ' + status[0])
6444 if self .connect_wifi (self .wifi_ssid , self .wifi_password ):
6545 print ('point your browser to http://' , self .ip_address )
6646 else :
6747 raise RuntimeError ('network connection failed' )
6848 self .server_running = False
69- # self.ip_address = status[0]
7049
7150
7251 def connect_wifi (self , ssid , password ):
@@ -97,8 +76,6 @@ def connect_wifi(self, ssid, password):
9776
9877 def start_access_point (self , ssid , password = None ):
9978 #def connect_access_point(self, ssid, password=None, ip='192.168.1.1', subnet='255.255.255.0', gateway='192.168.1.1', dns='8.8.8.8'):
100- # Deactivate Wi-Fi mode
101- # self.wlan_sta.active(False)
10279 # Set the IP configuration for the AP mode
10380 #self.wlan_ap.ifconfig((ip, subnet, gateway, dns))
10481 self .ap_ssid = ssid
@@ -412,18 +389,21 @@ def blink_element(element, pin, duration=0.27):
412389
413390 def list_files_and_folders (self , path ):
414391 entries = uos .ilistdir (path )
392+ path = path .replace (self .doc_root , '' )
393+ # remove all leading slashes
394+ path = path .lstrip ('/' )
415395 files_and_folders = []
416396 # print("list_files_and_folders: "+path)
417397 # print("list_files_and_folders: "+self.doc_root)
418398 if path != self .doc_root and path != self .doc_root + '/' :
419- files_and_folders .append ({"name" : ".." , "type" : "directory" })
399+ files_and_folders .append ({"name" : ".." , "type" : "directory" , "path" : path + "/.." })
420400 for entry in entries :
421401 name = entry [0 ]
422402 mode = entry [1 ]
423403 if mode & 0o170000 == 0o040000 : # Check if it's a directory
424- files_and_folders .append ({"name" : name , "type" : "directory" })
404+ files_and_folders .append ({"name" : name , "type" : "directory" , "path" : path + "/" + name })
425405 elif mode & 0o170000 == 0o100000 : # Check if it's a file
426- files_and_folders .append ({"name" : name , "type" : "file" })
406+ files_and_folders .append ({"name" : name , "type" : "file" , "path" : path + "/" + name })
427407 return files_and_folders
428408
429409 def generate_root_page_html (self , files_and_folders ):
@@ -465,7 +445,7 @@ def generate_root_page_html(self, files_and_folders):
465445 icon = folder_icon_svg if file_or_folder ['type' ] == 'directory' else file_icon_svg
466446 text_class = 'text-blue-500' if file_or_folder ['type' ] == 'directory' else 'text-blue-600'
467447 bg_class = "" if index % 2 == 1 else "bg-gray-50"
468- yield f"<li class='border-t border-gray-300 py-1.5 { bg_class } '><a href='/ { file_or_folder ['name ' ]} ' class='flex items-center font-semibold { text_class } hover:text-blue-700'>{ icon } <p class='ml-2'>{ file_or_folder ['name' ]} </p></a></li>"
448+ yield f"<li class='border-t border-gray-300 py-1.5 { bg_class } '><a href='{ file_or_folder ['path ' ]} ' class='flex items-center font-semibold { text_class } hover:text-blue-700'>{ icon } <p class='ml-2'>{ file_or_folder ['name' ]} </p></a></li>"
469449 yield "</ul>"
470450 # Closing tags for the body and container div
471451 yield """
0 commit comments