浏览代码

Merge branch 'dev' of github.com:allanpk716/ChineseSubFinder into dev

allan716 2 年之前
父节点
当前提交
9c6583cb05

+ 5 - 2
frontend/src/composables/use-event-bus.js

@@ -6,9 +6,12 @@ import eventBus from 'vue3-eventbus';
 import { onBeforeUnmount } from 'vue';
 
 const useEventBus = (eventName, fn) => {
-  eventBus.on(eventName, fn);
+  const eventBusFn = (...args) => {
+    fn(...args);
+  };
+  eventBus.on(eventName, eventBusFn);
   onBeforeUnmount(() => {
-    eventBus.off(eventName, fn);
+    eventBus.off(eventName, eventBusFn);
   });
 };
 

+ 24 - 10
frontend/src/pages/library/BtnIgnoreVideo.vue

@@ -43,12 +43,16 @@ const isSkipped = ref(null);
 
 const getIsSkipped = async () => {
   const [res] = await LibraryApi.getSkipInfo({
-    video_type: props.videoType,
-    physical_video_file_full_path: props.path,
-    is_bluray: false,
-    is_skip: true,
+    video_skip_infos: [
+      {
+        video_type: props.videoType,
+        physical_video_file_full_path: props.path,
+        is_bluray: false,
+        is_skip: true,
+      },
+    ],
   });
-  isSkipped.value = res.is_skip;
+  isSkipped.value = res.is_skips?.[0];
 };
 
 const skip = async () => {
@@ -59,10 +63,14 @@ const skip = async () => {
     persistent: true,
   }).onOk(async () => {
     const [res] = await LibraryApi.setSkipInfo({
-      video_type: props.videoType,
-      physical_video_file_full_path: props.path,
-      is_bluray: false,
-      is_skip: !isSkipped.value,
+      video_skip_infos: [
+        {
+          video_type: props.videoType,
+          physical_video_file_full_path: props.path,
+          is_bluray: false,
+          is_skip: !isSkipped.value,
+        },
+      ],
     });
     if (res) {
       SystemMessage.success('操作成功');
@@ -71,7 +79,13 @@ const skip = async () => {
   });
 };
 
-useEventBus(`refresh-skip-status-${props.path}`, getIsSkipped);
+useEventBus(`refresh-skip-status-${props.path}`, (flag) => {
+  if (flag !== undefined) {
+    isSkipped.value = flag;
+  } else {
+    getIsSkipped();
+  }
+});
 
 onMounted(() => {
   getIsSkipped();

+ 23 - 14
frontend/src/pages/library/tvs/DialogTVDetail.vue

@@ -256,27 +256,36 @@ const skipAll = async (isSkip) => {
     cancel: true,
     persistent: true,
   }).onOk(async () => {
-    const promises = selection.value.map(async (item) => {
-      const [, err] = await LibraryApi.setSkipInfo({
+    const [, err] = await LibraryApi.setSkipInfo({
+      video_skip_infos: selection.value.map((item) => ({
         video_type: VIDEO_TYPE_TV,
         physical_video_file_full_path: item.video_f_path,
         is_bluray: false,
         is_skip: isSkip,
-      });
-      if (err !== null) {
-        return Promise.reject(err);
-      }
-      eventBus.emit(`refresh-skip-status-${item.video_f_path}`);
-      return Promise.resolve();
+      })),
     });
+    if (err !== null) {
+      SystemMessage.error(err.message);
+      return;
+    }
+    const [res, err2] = await LibraryApi.getSkipInfo({
+      video_skip_infos: selection.value.map((item) => ({
+        video_type: VIDEO_TYPE_TV,
+        physical_video_file_full_path: item.video_f_path,
+        is_bluray: false,
+        is_skip: true,
+      })),
+    });
+    if (err2 !== null) {
+      SystemMessage.error(err2.message);
+      return;
+    }
 
-    const result = await Promise.allSettled(promises);
-
-    const successCount = result.filter((item) => item.status === 'fulfilled').length;
-    const errorCount = result.filter((item) => item.status === 'rejected').length;
+    selection.value.forEach((item, index) => {
+      eventBus.emit(`refresh-skip-status-${item.video_f_path}`, res.is_skips[index]);
+    });
 
-    const msg = `成功${isSkip ? '锁定' : '解锁'} ${successCount} 个视频${errorCount ? `,失败 ${errorCount} 个` : ''}`;
-    SystemMessage.success(msg);
+    SystemMessage.success('操作成功');
   });
 };
 

+ 0 - 13
frontend/src/pages/library/tvs/ListItemTV.vue

@@ -37,7 +37,6 @@ import { computed, onMounted, ref, watch } from 'vue';
 import DialogTVDetail from 'pages/library/tvs/DialogTVDetail';
 import LibraryApi from 'src/api/LibraryApi';
 import { getUrl, subtitleUploadList } from 'pages/library/use-library';
-import { VIDEO_TYPE_TV } from 'src/constants/SettingConstants';
 
 const props = defineProps({
   data: Object,
@@ -45,7 +44,6 @@ const props = defineProps({
 
 const posterInfo = ref(null);
 const detailInfo = ref(null);
-const isSkipped = ref(null);
 
 const getPosterInfo = async () => {
   const [res] = await LibraryApi.getTvPoster({
@@ -65,16 +63,6 @@ const getDetailInfo = async () => {
   detailInfo.value = res;
 };
 
-const getIsSkipped = async () => {
-  const [res] = await LibraryApi.getSkipInfo({
-    video_type: VIDEO_TYPE_TV,
-    physical_video_file_full_path: props.data.video_f_path,
-    is_bluray: false,
-    is_skip: true,
-  });
-  isSkipped.value = res.is_skip;
-};
-
 const hasSubtitleVideoCount = computed(
   () => detailInfo.value?.one_video_info.filter((e) => e.sub_f_path_list.length > 0).length
 );
@@ -91,7 +79,6 @@ watch(subtitleUploadList, (val, oldValue) => {
 
 onMounted(() => {
   getPosterInfo();
-  getIsSkipped();
   getDetailInfo();
 });
 </script>

+ 8 - 9
frontend/src/pages/library/tvs/index.vue

@@ -91,14 +91,6 @@ const toggleSelection = (item) => {
   }
 };
 
-const lockVideo = async (item, lock) =>
-  LibraryApi.setSkipInfo({
-    video_type: VIDEO_TYPE_TV,
-    physical_video_file_full_path: item.video_f_path,
-    is_bluray: false,
-    is_skip: lock,
-  });
-
 const lockTv = async (item, lock) => {
   const [tvInfo] = await LibraryApi.getTvDetail({
     name: item.name,
@@ -106,7 +98,14 @@ const lockTv = async (item, lock) => {
     root_dir_path: item.root_dir_path,
   });
 
-  return Promise.allSettled(tvInfo.one_video_info.map((e) => lockVideo(e, lock)));
+  return LibraryApi.setSkipInfo({
+    video_skip_infos: tvInfo.one_video_info.map((e) => ({
+      video_type: VIDEO_TYPE_TV,
+      physical_video_file_full_path: e.video_f_path,
+      is_bluray: false,
+      is_skip: lock,
+    })),
+  });
 };
 
 const setLock = async (flag) => {