From d4573873ab1b70418472efb7a63b7c73bc08e072 Mon Sep 17 00:00:00 2001 From: lanyeeee <1210347077@qq.com> Date: Mon, 18 Nov 2024 06:27:38 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=AB=A0=E8=8A=82?= =?UTF-8?q?=E9=87=8D=E5=90=8D=E5=AF=BC=E8=87=B4=E7=9A=84=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-tauri/src/types/comic.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src-tauri/src/types/comic.rs b/src-tauri/src/types/comic.rs index c8110a4..26ae9a4 100644 --- a/src-tauri/src/types/comic.rs +++ b/src-tauri/src/types/comic.rs @@ -1,3 +1,5 @@ +use std::collections::HashMap; + use crate::config::Config; use crate::responses::{ComicRespData, EpisodeRespData}; use crate::types::AlbumPlus; @@ -153,6 +155,8 @@ pub struct Comic { pub album_plus: AlbumPlus, } impl Comic { + #[allow(clippy::too_many_lines)] + // TODO: 统一用from实现,以减少代码行数 pub fn from(app: &AppHandle, comic: ComicRespData, album_plus: AlbumPlus) -> Self { let comic_title = filename_filter(&comic.title); let mut episode_infos: Vec = comic @@ -198,6 +202,27 @@ impl Comic { Some(episode_info) }) .collect(); + // 解决章节标题重复的问题 + let mut ep_title_count = HashMap::new(); + // 统计章节标题出现的次数 + for ep in &episode_infos { + let Some(count) = ep_title_count.get_mut(&ep.episode_title) else { + ep_title_count.insert(ep.episode_title.clone(), 1); + continue; + }; + *count += 1; + } + // 只保留重复的章节标题 + ep_title_count.retain(|_, v| *v > 1); + // 为重复的章节标题添加序号 + for ep in &mut episode_infos { + let Some(count) = ep_title_count.get_mut(&ep.episode_title) else { + continue; + }; + ep.episode_title = format!("{}-{}", ep.episode_title, count); + *count -= 1; + } + episode_infos.reverse(); let styles2 = comic