luojunhui 2 days ago
parent
commit
9833ffef98
2 changed files with 51 additions and 26 deletions
  1. 48 23
      applications/service/get_cover.py
  2. 3 3
      applications/utils/get_cover.py

+ 48 - 23
applications/service/get_cover.py

@@ -21,23 +21,17 @@ class GetCoverService(Response):
             case _:
                 return None
 
-    async def get_cover(self, content_id: str):
-        channel_info = await fetch_channel_info(self.pool, content_id)
-        channel_content_id = channel_info[0]["channel_content_id"]
-        channel_type = channel_info[0]["channel"]
-        match channel_type:
-            case 5:
-                fetch_response = await fetch_aigc_cover(self.pool, channel_content_id)
-                if fetch_response:
-                    image_oss = fetch_response[0]["oss_object_key"]
-                    cover = await self.montage_cover(image_oss, "aigc_db_pool")
-                else:
+    async def fetch_cover_info(self, pool_name, channel_content_id: str):
+        match pool_name:
+            case "aigc_db_pool":
+                fetch_response, sql_error = await fetch_aigc_cover(
+                    self.pool, channel_content_id
+                )
+                if sql_error:
                     return self.error_response(
-                        error_code="402",
-                        error_message="can't find cover in aigc system",
+                        error_code="111",
+                        error_message="sql_error!!\n{}".format(sql_error),
                     )
-            case 6:
-                fetch_response = await fetch_aigc_cover(self.pool, channel_content_id)
                 if fetch_response:
                     image_oss = fetch_response[0]["oss_object_key"]
                     cover = await self.montage_cover(image_oss, "aigc_db_pool")
@@ -46,10 +40,15 @@ class GetCoverService(Response):
                         error_code="402",
                         error_message="can't find cover in aigc system",
                     )
-            case 10:
-                fetch_response = await fetch_long_video_cover(
+            case "long_video_db_pool":
+                fetch_response, sql_error = await fetch_long_video_cover(
                     self.pool, channel_content_id
                 )
+                if sql_error:
+                    return self.error_response(
+                        error_code="111",
+                        error_message="sql_error!!\n{}".format(sql_error),
+                    )
                 if fetch_response:
                     image_oss = fetch_response[1]["image_path"]
                     cover = await self.montage_cover(image_oss, "long_video_db_pool")
@@ -61,14 +60,40 @@ class GetCoverService(Response):
             case _:
                 return self.error_response(
                     error_code="403",
-                    error_message="channel_type is not supported",
+                    error_message="pool_name is not supported",
                 )
 
-        return self.success_response(
-            data={
-                "cover": cover,
-            }
-        )
+        return self.success_response(data={"cover": cover})
+
+    async def get_cover(self, content_id: str):
+        channel_info, sql_error = await fetch_channel_info(self.pool, content_id)
+        if sql_error:
+            return self.error_response(
+                error_code="111",
+                error_message="sql_error!!\n{}".format(sql_error),
+            )
+        if not channel_info:
+            return self.error_response(
+                error_code="402",
+                error_message="can't find content info in aigc system",
+            )
+
+        channel_content_id = channel_info[0]["channel_content_id"]
+        channel_type = channel_info[0]["channel"]
+        match channel_type:
+            case 5:
+                return await self.fetch_cover_info("aigc_db_pool", channel_content_id)
+            case 6:
+                return await self.fetch_cover_info("aigc_db_pool", channel_content_id)
+            case 10:
+                return await self.fetch_cover_info(
+                    "long_video_db_pool", channel_content_id
+                )
+            case _:
+                return self.error_response(
+                    error_code="403",
+                    error_message="channel_type is not supported",
+                )
 
     async def deal(self):
         content_id = self.params.get("content_id")

+ 3 - 3
applications/utils/get_cover.py

@@ -9,7 +9,7 @@ async def fetch_channel_info(pools, content_id):
         from produce_plan_exe_record t1 join crawler_content t2 on t1.channel_content_id = t2.channel_content_id
         where plan_exe_id = '{content_id}';
     """
-    fetch_response, error = await pools.async_fetch(
+    fetch_response = await pools.async_fetch(
         query=fetch_query, db_name="aigc_db_pool", cursor_type=DictCursor
     )
     return fetch_response
@@ -24,7 +24,7 @@ async def fetch_aigc_cover(pools, channel_content_id):
         from crawler_content_image
         where channel_content_id = '{channel_content_id}' and image_type = 2;
     """
-    fetch_response, error = await pools.async_fetch(
+    fetch_response = await pools.async_fetch(
         query=fetch_query, db_name="aigc_db_pool", cursor_type=DictCursor
     )
     return fetch_response
@@ -39,7 +39,7 @@ async def fetch_long_video_cover(pools, channel_content_id):
         from video_cover_snapshots
         where video_id = '{channel_content_id}';
     """
-    fetch_response, error = await pools.async_fetch(
+    fetch_response = await pools.async_fetch(
         query=fetch_query, db_name="long_video_db_pool", cursor_type=DictCursor
     )
     return fetch_response