| 1 | from helpers.api import ApiHandler, Request, Response |
| 2 | |
| 3 | from helpers import file_tree, files |
| 4 | |
| 5 | |
| 6 | class SettingsWorkdirFileStructure(ApiHandler): |
| 7 | async def process(self, input: dict, request: Request) -> dict | Response: |
| 8 | workdir_path = input.get("workdir_path", "") |
| 9 | workdir_path = files.get_abs_path_development(workdir_path) |
| 10 | if not workdir_path: |
| 11 | raise Exception("workdir_path is required") |
| 12 | |
| 13 | tree = str( |
| 14 | file_tree.file_tree( |
| 15 | workdir_path, |
| 16 | max_depth=int(input.get("workdir_max_depth", 0) or 0), |
| 17 | max_files=int(input.get("workdir_max_files", 0) or 0), |
| 18 | max_folders=int(input.get("workdir_max_folders", 0) or 0), |
| 19 | max_lines=int(input.get("workdir_max_lines", 0) or 0), |
| 20 | ignore=input.get("workdir_gitignore", "") or "", |
| 21 | output_mode=file_tree.OUTPUT_MODE_STRING, |
| 22 | ) |
| 23 | ) |
| 24 | |
| 25 | if "\n" not in tree: |
| 26 | tree += "\n # Empty" |
| 27 | |
| 28 | return {"data": tree} |
| 29 | |
| 30 | @classmethod |
| 31 | def get_methods(cls) -> list[str]: |
| 32 | return ["POST"] |