From 1d710f844b65d9bfdf986a71a3b924cd70598a41 Mon Sep 17 00:00:00 2001
From: Bin <bin.zheng@slooong.com>
Date: 星期三, 17 十二月 2025 10:31:28 +0800
Subject: [PATCH] 添加导出日期,查看图片问题

---
 label_studio/data_export/api.py    |   10 ++++++++++
 label_studio/data_export/mixins.py |   42 +++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 51 insertions(+), 1 deletions(-)

diff --git a/label_studio/data_export/api.py b/label_studio/data_export/api.py
index 0bd4832..13f1c2a 100644
--- a/label_studio/data_export/api.py
+++ b/label_studio/data_export/api.py
@@ -208,6 +208,14 @@
         download_resources = query_serializer.validated_data['download_resources']
         interpolate_key_frames = query_serializer.validated_data['interpolate_key_frames']
 
+        # 调试日志: API 层参数
+        logger.info(f'[Export API Debug] ========== Export Request Received ==========')
+        logger.info(f'[Export API Debug] Project ID: {project.id}')
+        logger.info(f'[Export API Debug] export_type: {export_type}')
+        logger.info(f'[Export API Debug] download_resources: {download_resources}')
+        logger.info(f'[Export API Debug] only_finished: {only_finished}')
+        logger.info(f'[Export API Debug] Request GET params: {dict(request.GET)}')
+
         tasks_ids = request.GET.getlist('ids[]')
 
         logger.debug('Get tasks')
@@ -219,6 +227,8 @@
             query = query.filter(annotations__isnull=False).distinct()
 
         task_ids = query.values_list('id', flat=True)
+        
+        logger.info(f'[Export API Debug] Total tasks to export: {len(task_ids)}')
 
         logger.debug('Serialize tasks for export')
         tasks = []
diff --git a/label_studio/data_export/mixins.py b/label_studio/data_export/mixins.py
index d41e521..d251861 100644
--- a/label_studio/data_export/mixins.py
+++ b/label_studio/data_export/mixins.py
@@ -349,10 +349,27 @@
             out_dir = pathlib.Path(tmp_dir) / OUT
             out_dir.mkdir(mode=0o700, parents=True, exist_ok=True)
 
+            upload_dir = os.path.join(settings.MEDIA_ROOT, settings.UPLOAD_DIR)
+            
+            # 调试日志:打印关键参数
+            logger.info(f'[COCO Export Debug] ========== Export Started ==========')
+            logger.info(f'[COCO Export Debug] Project ID: {self.project.id}')
+            logger.info(f'[COCO Export Debug] Export format: {to_format}')
+            logger.info(f'[COCO Export Debug] download_resources: {download_resources}')
+            logger.info(f'[COCO Export Debug] hostname: {hostname}')
+            logger.info(f'[COCO Export Debug] upload_dir: {upload_dir}')
+            logger.info(f'[COCO Export Debug] upload_dir exists: {os.path.exists(upload_dir)}')
+            if os.path.exists(upload_dir):
+                logger.info(f'[COCO Export Debug] upload_dir contents: {os.listdir(upload_dir)}')
+            logger.info(f'[COCO Export Debug] tmp_dir: {tmp_dir}')
+            logger.info(f'[COCO Export Debug] out_dir: {out_dir}')
+            logger.info(f'[COCO Export Debug] settings.MEDIA_ROOT: {settings.MEDIA_ROOT}')
+            logger.info(f'[COCO Export Debug] settings.UPLOAD_DIR: {settings.UPLOAD_DIR}')
+
             converter = Converter(
                 config=self.project.get_parsed_config(),
                 project_dir=None,
-                upload_dir=os.path.join(settings.MEDIA_ROOT, settings.UPLOAD_DIR),
+                upload_dir=upload_dir,
                 download_resources=download_resources,
                 # for downloading resource we need access to the API
                 access_token=self.project.organization.created_by.auth_token.key,
@@ -361,24 +378,47 @@
             input_name = pathlib.Path(self.file.name).name
             input_file_path = pathlib.Path(tmp_dir) / input_name
 
+            logger.info(f'[COCO Export Debug] input_name: {input_name}')
+            logger.info(f'[COCO Export Debug] input_file_path: {input_file_path}')
+
             with open(input_file_path, 'wb') as file_:
                 file_.write(self.file.open().read())
 
+            logger.info(f'[COCO Export Debug] Starting converter.convert...')
             converter.convert(input_file_path, out_dir, to_format, is_dir=False)
+            logger.info(f'[COCO Export Debug] Converter.convert completed')
 
             files = get_all_files_from_dir(out_dir)
             dirs = get_all_dirs_from_dir(out_dir)
 
+            logger.info(f'[COCO Export Debug] Output files: {files}')
+            logger.info(f'[COCO Export Debug] Output dirs: {dirs}')
+            
+            # 检查是否有 images 目录
+            images_dir = out_dir / 'images'
+            if images_dir.exists():
+                image_files = list(images_dir.glob('*'))
+                logger.info(f'[COCO Export Debug] images/ directory exists with {len(image_files)} files')
+                logger.info(f'[COCO Export Debug] Image files: {[f.name for f in image_files]}')
+            else:
+                logger.warning(f'[COCO Export Debug] images/ directory does NOT exist')
+
             if len(files) == 0 and len(dirs) == 0:
+                logger.error(f'[COCO Export Debug] No files or dirs in output')
                 return None
             elif len(files) == 1 and len(dirs) == 0:
                 output_file = files[0]
                 filename = pathlib.Path(input_name).stem + pathlib.Path(output_file).suffix
+                logger.info(f'[COCO Export Debug] Single file output: {output_file}')
             else:
+                logger.info(f'[COCO Export Debug] Creating zip archive...')
                 shutil.make_archive(out_dir, 'zip', out_dir)
                 output_file = pathlib.Path(tmp_dir) / (str(out_dir.stem) + '.zip')
                 filename = pathlib.Path(input_name).stem + '.zip'
+                logger.info(f'[COCO Export Debug] Zip archive created: {output_file}')
 
+            logger.info(f'[COCO Export Debug] ========== Export Completed ==========')
+            
             # TODO(jo): can we avoid the `f.read()` here?
             with open(output_file, mode='rb') as f:
                 return File(

--
Gitblit v1.9.3