@@ -85,6 +85,44 @@ async def process_directory(cls, req: ProcessDirectoryRequest):
8585 suffix = raw_suffix
8686 overwrite = req .overwrite
8787
88+ if produces_file :
89+ if not overwrite and not suffix :
90+ raise HTTPException (400 , detail = "Suffix is required when not overwriting files" )
91+ else :
92+ overwrite = False
93+ suffix = None
94+ payload = {
95+ "path" : req .path ,
96+ "processor_type" : req .processor_type ,
97+ "config" : req .config ,
98+ "overwrite" : overwrite ,
99+ "max_depth" : req .max_depth ,
100+ "suffix" : suffix ,
101+ }
102+ task = await task_queue_service .add_task ("process_directory_scan" , payload )
103+ return {"task_id" : task .id }
104+
105+ @classmethod
106+ async def scan_directory (cls , req : ProcessDirectoryRequest ):
107+ if req .max_depth is not None and req .max_depth < 0 :
108+ raise HTTPException (400 , detail = "max_depth must be >= 0" )
109+
110+ is_dir = await VirtualFSService .path_is_directory (req .path )
111+ if not is_dir :
112+ raise HTTPException (400 , detail = "Path must be a directory" )
113+
114+ schema = get_config_schema (req .processor_type )
115+ _processor = get (req .processor_type )
116+ if not schema or not _processor :
117+ raise HTTPException (404 , detail = "Processor not found" )
118+
119+ produces_file = bool (schema .get ("produces_file" ))
120+ raw_suffix = req .suffix if req .suffix is not None else None
121+ if raw_suffix is not None and raw_suffix .strip () == "" :
122+ raw_suffix = None
123+ suffix = raw_suffix
124+ overwrite = req .overwrite
125+
88126 if produces_file :
89127 if not overwrite and not suffix :
90128 raise HTTPException (400 , detail = "Suffix is required when not overwriting files" )
@@ -133,7 +171,7 @@ def apply_suffix(path_str: str, suffix_str: str) -> str:
133171 new_name = f"{ name } { suffix_str } "
134172 return str (path_obj .with_name (new_name ))
135173
136- scheduled_tasks : List [ str ] = []
174+ scheduled_count = 0
137175 stack : List [Tuple [str , int ]] = [(rel , 0 )]
138176 page_size = 200
139177
@@ -161,7 +199,7 @@ def apply_suffix(path_str: str, suffix_str: str) -> str:
161199 save_to = None
162200 if produces_file and not overwrite and suffix :
163201 save_to = apply_suffix (absolute_path , suffix )
164- task = await task_queue_service .add_task (
202+ await task_queue_service .add_task (
165203 "process_file" ,
166204 {
167205 "path" : absolute_path ,
@@ -171,16 +209,13 @@ def apply_suffix(path_str: str, suffix_str: str) -> str:
171209 "overwrite" : overwrite ,
172210 },
173211 )
174- scheduled_tasks . append ( task . id )
212+ scheduled_count += 1
175213
176214 if total is None or page * page_size >= total :
177215 break
178216 page += 1
179217
180- return {
181- "task_ids" : scheduled_tasks ,
182- "scheduled" : len (scheduled_tasks ),
183- }
218+ return {"scheduled" : scheduled_count }
184219
185220 @classmethod
186221 async def get_source (cls , processor_type : str ):
0 commit comments