major server manager overhaul
This commit is contained in:
@@ -35,13 +35,54 @@ class SambaManager:
|
||||
"name": f.filename,
|
||||
"is_directory": f.isDirectory,
|
||||
"size": f.file_size,
|
||||
"path": full_item_path
|
||||
"path": full_item_path,
|
||||
"last_modified": f.last_write_time
|
||||
})
|
||||
return items
|
||||
except Exception as e:
|
||||
logger.error(f"Error listing path '{current_dir_path}' on share '{self.share_name}': {e}", exc_info=True)
|
||||
return []
|
||||
|
||||
def search_files(self, query, start_path="/"):
|
||||
"""
|
||||
Recursively searches for files matching query (partial, case-insensitive).
|
||||
"""
|
||||
matches = []
|
||||
try:
|
||||
stack = [start_path]
|
||||
while stack:
|
||||
current_path = stack.pop()
|
||||
try:
|
||||
files = self.conn.listPath(self.share_name, current_path)
|
||||
except Exception:
|
||||
continue # Skip unreadable dirs
|
||||
|
||||
for f in files:
|
||||
if f.filename in ['.', '..']: continue
|
||||
|
||||
normalized_current_path = current_path
|
||||
if normalized_current_path != '/' and not normalized_current_path.endswith('/'):
|
||||
normalized_current_path += '/'
|
||||
|
||||
full_item_path = f"{normalized_current_path}{f.filename}".replace("\\", "/")
|
||||
|
||||
if query.lower() in f.filename.lower():
|
||||
matches.append({
|
||||
"name": f.filename,
|
||||
"is_directory": f.isDirectory,
|
||||
"size": f.file_size,
|
||||
"path": full_item_path,
|
||||
"last_modified": f.last_write_time
|
||||
})
|
||||
|
||||
if f.isDirectory:
|
||||
stack.append(full_item_path)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error searching path '{start_path}': {e}")
|
||||
|
||||
return matches
|
||||
|
||||
|
||||
def delete_file(self, path):
|
||||
try:
|
||||
@@ -63,6 +104,8 @@ class SambaManager:
|
||||
self.conn.retrieveFile(self.share_name, path, file_obj)
|
||||
return {"success": True}
|
||||
except Exception as e:
|
||||
if "Scan canceled by user" in str(e):
|
||||
raise e
|
||||
return {"error": str(e)}
|
||||
|
||||
def download_file_range(self, path, file_obj, offset, max_length):
|
||||
|
||||
Reference in New Issue
Block a user