Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(copymanga): browse view not loading #852

Merged
merged 5 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 29 additions & 29 deletions src/rust/zh.copymanga/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/rust/zh.copymanga/res/source.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"id": "zh.copymanga",
"lang": "zh",
"name": "拷貝漫畫",
"version": 9,
"version": 10,
"urls": [
"https://copymanga.tv",
"https://www.copymanga.tv",
Expand Down
45 changes: 23 additions & 22 deletions src/rust/zh.copymanga/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ mod url;

use aidoku::{
error::Result,
helpers::substring::Substring,
prelude::{
format, get_chapter_list, get_manga_details, get_manga_list, get_page_list, handle_url,
},
Expand All @@ -17,7 +16,8 @@ use aidoku::{
use alloc::string::ToString;
use decryptor::EncryptedString;
use parser::{Element, JsonObj, JsonString, MangaListResponse, NodeArrValue, Part, UuidString};
use url::{Url, CHAPTER_PATH, MANGA_PATH};
use url::Url;
use uuid::Uuid;

#[get_manga_list]
fn get_manga_list(filters: Vec<Filter>, page: i32) -> Result<MangaPageResult> {
Expand Down Expand Up @@ -205,33 +205,34 @@ fn get_page_list(manga_id: String, chapter_id: String) -> Result<Vec<Page>> {

#[handle_url]
fn handle_url(url: String) -> Result<DeepLink> {
let Some(path) = url.substring_after(MANGA_PATH) else {
return Ok(DeepLink::default());
};
let parts = url.split('/').skip(3).collect::<Vec<_>>();
let (manga_id, chapter_id) = match parts[..] {
["comic", manga_id] | ["h5", "details", "comic", manga_id] => (manga_id, None),

let Some(chapter_id) = path.substring_after(CHAPTER_PATH) else {
let manga = get_manga_details(path.to_string())?;
["comic", manga_id, "chapter", chapter_id]
| ["h5", "comicContent", manga_id, chapter_id] => (manga_id, Some(chapter_id)),

return Ok(DeepLink {
manga: Some(manga),
chapter: None,
});
};
let chapter = Chapter {
id: chapter_id.to_string(),
..Default::default()
_ => return Ok(DeepLink::default()),
};

let Some(manga_id) = path.substring_before(CHAPTER_PATH) else {
return Ok(DeepLink {
manga: None,
chapter: Some(chapter),
if !manga_id
.chars()
.all(|c| c.is_ascii_lowercase() || c.is_ascii_digit())
{
return Ok(DeepLink::default());
}

let manga = get_manga_details(manga_id.into())?;

let chapter = chapter_id
.filter(|id| id.parse::<Uuid>().is_ok())
.map(|id| Chapter {
id: id.into(),
..Default::default()
});
};
let manga = get_manga_details(manga_id.to_string())?;

Ok(DeepLink {
manga: Some(manga),
chapter: Some(chapter),
chapter,
})
}
3 changes: 3 additions & 0 deletions src/rust/zh.copymanga/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@ impl MangaListResponse for Node {
.map(|(index, str)| {
if index % 2 == 0 {
str.replace('\'', "\"")
} else if !str.contains('\'') {
format!(r"\{str}\")
} else {
str.to_string()
}
})
.collect::<Vec<_>>()
.join("\"")
.replace(r#""\"#, r#"\""#)
.json()?
.as_array()?
.get_manga_list()?;
Expand Down
7 changes: 2 additions & 5 deletions src/rust/zh.copymanga/src/url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,6 @@ impl Display for Search {
}
}

pub const MANGA_PATH: &str = "/comic/";
pub const CHAPTER_PATH: &str = "/chapter/";

const GENRES: [&str; 61] = [
"",
"aiqing",
Expand Down Expand Up @@ -329,7 +326,7 @@ const REGIONS: [Region; 4] = [Region::All, Region::Japan, Region::Korea, Region:
/// The number of manga that a single response contains.
const LIMIT: i32 = 20;

impl<'a> Url<'a> {
impl Url<'_> {
pub fn get_html(self) -> Result<Node> {
Request::get(self.to_string()).html()
}
Expand All @@ -339,7 +336,7 @@ impl<'a> Url<'a> {
}
}

impl<'a> From<(Vec<Filter>, i32)> for Url<'a> {
impl From<(Vec<Filter>, i32)> for Url<'_> {
fn from((filters, page): (Vec<Filter>, i32)) -> Self {
let mut genre_index = 0;
let mut region = Region::All;
Expand Down
Loading