3232from utils .logger import logger
3333
3434
35+ def _normalize_file_path (file_path : str ) -> str :
36+ """
37+ Normalize file path to ensure cross-service compatibility.
38+ Converts various absolute path formats to relative paths.
39+
40+ Args:
41+ file_path: The file path to normalize
42+
43+ Returns:
44+ The normalized relative path
45+ """
46+ if not file_path or file_path .strip () == "" :
47+ return ""
48+
49+ # Convert various absolute path formats to relative paths
50+ if file_path .startswith (UPLOAD_FOLDER + "/" ):
51+ return file_path .replace (UPLOAD_FOLDER + "/" , "" )
52+ elif file_path .startswith ("/app/upload_files/" ):
53+ # For backward compatibility with existing Docker paths
54+ return file_path .replace ("/app/upload_files/" , "" )
55+ elif file_path .startswith ("/upload_files/" ):
56+ # Handle paths starting with /upload_files/
57+ return file_path [len ("/upload_files/" ) :]
58+
59+ return file_path
60+
61+
62+ def _get_cert_config (body : TaskCreateReq ) -> Tuple [str , str ]:
63+ """
64+ Get and normalize certificate configuration from the request body.
65+
66+ Args:
67+ body: The task creation request body
68+
69+ Returns:
70+ A tuple of (cert_file, key_file) normalized paths
71+ """
72+ cert_file = ""
73+ key_file = ""
74+
75+ if body .cert_config :
76+ cert_file = body .cert_config .cert_file or ""
77+ key_file = body .cert_config .key_file or ""
78+ else :
79+ # Try to get certificate configuration from upload service
80+ from service .upload_service import get_task_cert_config
81+
82+ cert_config = get_task_cert_config (body .temp_task_id )
83+ cert_file = cert_config .get ("cert_file" , "" )
84+ key_file = cert_config .get ("key_file" , "" )
85+
86+ # Normalize paths
87+ cert_file = _normalize_file_path (cert_file )
88+ key_file = _normalize_file_path (key_file )
89+
90+ return cert_file , key_file
91+
92+
3593async def get_tasks_svc (
3694 request : Request ,
3795 page : int = Query (1 , ge = 1 , alias = "page" ),
@@ -251,35 +309,7 @@ async def create_task_svc(request: Request, body: TaskCreateReq):
251309 task_id = str (uuid .uuid4 ())
252310 logger .info (f"Creating task '{ body .name } ' with ID: { task_id } " )
253311
254- cert_file = ""
255- key_file = ""
256- if body .cert_config :
257- cert_file = body .cert_config .cert_file or ""
258- key_file = body .cert_config .key_file or ""
259- else :
260- # Try to get certificate configuration from upload service
261- from service .upload_service import get_task_cert_config
262-
263- cert_config = get_task_cert_config (body .temp_task_id )
264- cert_file = cert_config .get ("cert_file" , "" )
265- key_file = cert_config .get ("key_file" , "" )
266-
267- # Convert absolute paths to relative paths for cross-service compatibility
268- if cert_file :
269- # Convert backend upload path to relative path that st_engine can access
270- if cert_file .startswith (UPLOAD_FOLDER + "/" ):
271- cert_file = cert_file .replace (UPLOAD_FOLDER + "/" , "" )
272- elif cert_file .startswith ("/app/upload_files/" ):
273- # For backward compatibility with existing Docker paths
274- cert_file = cert_file .replace ("/app/upload_files/" , "" )
275-
276- if key_file :
277- # Convert backend upload path to relative path that st_engine can access
278- if key_file .startswith (UPLOAD_FOLDER + "/" ):
279- key_file = key_file .replace (UPLOAD_FOLDER + "/" , "" )
280- elif key_file .startswith ("/app/upload_files/" ):
281- # For backward compatibility with existing Docker paths
282- key_file = key_file .replace ("/app/upload_files/" , "" )
312+ cert_file , key_file = _get_cert_config (body )
283313
284314 # Convert headers from a list of objects to a dictionary, then to a JSON string.
285315 headers = {
@@ -297,6 +327,16 @@ async def create_task_svc(request: Request, body: TaskCreateReq):
297327 }
298328 cookies_json = json .dumps (cookies )
299329
330+ # Normalize test_data path to ensure cross-service compatibility
331+ test_data = body .test_data or ""
332+ if (
333+ test_data
334+ and not test_data .strip ().lower () in ("" , "default" )
335+ and not test_data .strip ().startswith ("{" )
336+ ):
337+ # If test_data is a file path, convert it to relative path
338+ test_data = _normalize_file_path (test_data )
339+
300340 db = request .state .db
301341 try :
302342 # Convert field_mapping to JSON string if provided
@@ -325,7 +365,7 @@ async def create_task_svc(request: Request, body: TaskCreateReq):
325365 api_path = body .api_path ,
326366 request_payload = body .request_payload ,
327367 field_mapping = field_mapping_json ,
328- test_data = body . test_data ,
368+ test_data = test_data ,
329369 )
330370
331371 db .add (new_task )
0 commit comments