2525
2626
2727@router .get ("" , response_model = models .Directory )
28- def get_files (
29- context : t .Optional [Context ] = Depends (get_context ),
30- settings : Settings = Depends (get_settings ),
31- ) -> models .Directory :
28+ async def get_files (settings : Settings = Depends (get_settings )) -> models .Directory :
3229 """Get all project files."""
33- return _get_directory (
34- path = settings .project_path ,
35- settings = settings ,
36- context = context ,
37- )
30+ return await _get_directory (settings .project_path , settings )
3831
3932
4033@router .get ("/{path:path}" , response_model = models .File )
@@ -54,21 +47,26 @@ def get_file(
5447@router .post ("/{path:path}" , response_model = t .Optional [models .File ])
5548async def write_file (
5649 response : Response ,
50+ path : str = Depends (validate_path ),
5751 content : str = Body ("" , embed = True ),
5852 new_path : t .Optional [str ] = Body (None , embed = True ),
59- path : str = Depends (validate_path ),
6053 settings : Settings = Depends (get_settings ),
61- context : Context = Depends (get_context ),
54+ context : t . Optional [ Context ] = Depends (get_context ),
6255) -> t .Optional [models .File ]:
6356 """Create, update, or rename a file."""
6457 path_or_new_path = path
6558 if new_path :
66- path_or_new_path = validate_path (new_path , context )
59+ path_or_new_path = await validate_path (new_path , settings )
6760 replace_file (settings .project_path / path , settings .project_path / path_or_new_path )
6861 else :
6962 full_path = settings .project_path / path
70- config = context .config_for_path (Path (path_or_new_path ))
71- if config .ui .format_on_save and content and Path (path_or_new_path ).suffix == ".sql" :
63+ config = context .config_for_path (Path (path_or_new_path )) if context else None
64+ if (
65+ config
66+ and config .ui .format_on_save
67+ and content
68+ and Path (path_or_new_path ).suffix == ".sql"
69+ ):
7270 format_file_status = models .FormatFileStatus (
7371 status = models .Status .INIT , path = path_or_new_path
7472 )
@@ -120,11 +118,8 @@ async def delete_file(
120118 )
121119
122120
123- def _get_directory (
124- path : str | Path ,
125- settings : Settings ,
126- context : t .Optional [Context ] = None ,
127- ) -> models .Directory :
121+ async def _get_directory (path : str | Path , settings : Settings ) -> models .Directory :
122+ context = await get_context (settings )
128123 ignore_patterns = context .config .ignore_patterns if context else c .IGNORE_PATTERNS
129124
130125 def walk_path (
0 commit comments