| 1 | from helpers.api import ApiHandler, Input, Output, Request, Response |
| 2 | |
| 3 | |
| 4 | from helpers.file_browser import FileBrowser |
| 5 | from helpers import files, runtime, extension |
| 6 | from api import get_work_dir_files |
| 7 | |
| 8 | |
| 9 | class DeleteWorkDirFile(ApiHandler): |
| 10 | async def process(self, input: Input, request: Request) -> Output: |
| 11 | try: |
| 12 | file_path = input.get("path", "") |
| 13 | if not file_path.startswith("/"): |
| 14 | file_path = f"/{file_path}" |
| 15 | |
| 16 | current_path = input.get("currentPath", "") |
| 17 | |
| 18 | # browser = FileBrowser() |
| 19 | res = await runtime.call_development_function(delete_file, file_path) |
| 20 | |
| 21 | if res: |
| 22 | await extension.call_extensions_async( |
| 23 | "workdir_file_mutation_after", |
| 24 | agent=None, |
| 25 | data={ |
| 26 | "action": "delete", |
| 27 | "path": file_path, |
| 28 | "paths": [file_path], |
| 29 | "current_path": current_path, |
| 30 | }, |
| 31 | ) |
| 32 | # Get updated file list |
| 33 | # result = browser.get_files(current_path) |
| 34 | result = await runtime.call_development_function(get_work_dir_files.get_files, current_path) |
| 35 | return {"data": result} |
| 36 | else: |
| 37 | return {"error": "File not found or could not be deleted"} |
| 38 | except Exception as e: |
| 39 | return {"error": str(e)} |
| 40 | |
| 41 | |
| 42 | async def delete_file(file_path: str): |
| 43 | browser = FileBrowser() |
| 44 | return browser.delete_file(file_path) |