From 5e409e92427e54b4d22686623791625aa70fcadb Mon Sep 17 00:00:00 2001
From: KaBankz <20971850+KaBankz@users.noreply.github.com>
Date: Sun, 28 Apr 2024 14:54:35 -0400
Subject: [PATCH] refactor(mangademon): use `base_url` as crate
---
src/rust/en.mangademon/src/helper.rs | 10 ++++++----
src/rust/en.mangademon/src/lib.rs | 12 ++++++------
src/rust/en.mangademon/src/parser.rs | 13 +++++++------
3 files changed, 19 insertions(+), 16 deletions(-)
diff --git a/src/rust/en.mangademon/src/helper.rs b/src/rust/en.mangademon/src/helper.rs
index 521be35b5..652927d1c 100644
--- a/src/rust/en.mangademon/src/helper.rs
+++ b/src/rust/en.mangademon/src/helper.rs
@@ -3,6 +3,8 @@ use aidoku::{
std::{html::Node, String},
};
+use crate::BASE_URL;
+
/// Converts `
` into newlines.
pub fn text_with_newlines(node: Node) -> String {
let html = node.html().read();
@@ -71,13 +73,13 @@ pub fn get_chapter_id(url: &str) -> String {
}
/// Returns full URL of a manga from a manga ID.
-pub fn get_manga_url(manga_id: &String, base_url: &String) -> String {
+pub fn get_manga_url(manga_id: &String) -> String {
// Append the `-VA` suffix to the manga id to get the proper url.
- format!("{}/manga/{}-VA", base_url, manga_id)
+ format!("{}/manga/{}-VA", BASE_URL, manga_id)
}
/// Returns full URL of a chapter from a chapter ID.
-pub fn get_chapter_url(chapter_id: &String, manga_id: &String, base_url: &String) -> String {
+pub fn get_chapter_url(chapter_id: &String, manga_id: &String) -> String {
// Append the `-VA` suffix to the chapter id to get the proper url.
- format!("{}/manga/{}/chapter/{}-VA", base_url, manga_id, chapter_id)
+ format!("{}/manga/{}/chapter/{}-VA", BASE_URL, manga_id, chapter_id)
}
diff --git a/src/rust/en.mangademon/src/lib.rs b/src/rust/en.mangademon/src/lib.rs
index c4d920e4e..85fcba473 100644
--- a/src/rust/en.mangademon/src/lib.rs
+++ b/src/rust/en.mangademon/src/lib.rs
@@ -69,7 +69,7 @@ fn get_manga_list(filters: Vec, page: i32) -> Result {
let html = Request::new(url, HttpMethod::Get).html()?;
- Ok(parse_manga_list(html, String::from(BASE_URL), searching))
+ Ok(parse_manga_list(html, searching))
}
#[get_manga_listing]
@@ -78,12 +78,12 @@ fn get_manga_listing(_listing: Listing, page: i32) -> Result {
let html = Request::new(url, HttpMethod::Get).html()?;
- Ok(parse_manga_list(html, String::from(BASE_URL), false))
+ Ok(parse_manga_list(html, false))
}
#[get_manga_details]
fn get_manga_details(manga_id: String) -> Result {
- let url = get_manga_url(&manga_id, &String::from(BASE_URL));
+ let url = get_manga_url(&manga_id);
let html = Request::new(url.clone(), HttpMethod::Get).html()?;
@@ -92,16 +92,16 @@ fn get_manga_details(manga_id: String) -> Result {
#[get_chapter_list]
fn get_chapter_list(manga_id: String) -> Result> {
- let url = get_manga_url(&manga_id, &String::from(BASE_URL));
+ let url = get_manga_url(&manga_id);
let html = Request::new(url, HttpMethod::Get).html()?;
- Ok(parse_chapter_list(html, String::from(BASE_URL)))
+ Ok(parse_chapter_list(html))
}
#[get_page_list]
fn get_page_list(manga_id: String, chapter_id: String) -> Result> {
- let url = get_chapter_url(&chapter_id, &manga_id, &String::from(BASE_URL));
+ let url = get_chapter_url(&chapter_id, &manga_id);
let html = Request::new(url, HttpMethod::Get).html()?;
diff --git a/src/rust/en.mangademon/src/parser.rs b/src/rust/en.mangademon/src/parser.rs
index bb9091b67..7017cf78c 100644
--- a/src/rust/en.mangademon/src/parser.rs
+++ b/src/rust/en.mangademon/src/parser.rs
@@ -5,8 +5,9 @@ use aidoku::{
};
use crate::helper::*;
+use crate::BASE_URL;
-pub fn parse_manga_list(html: Node, base_url: String, searching: bool) -> MangaPageResult {
+pub fn parse_manga_list(html: Node, searching: bool) -> MangaPageResult {
let mut manga: Vec = Vec::new();
if searching {
@@ -15,8 +16,8 @@ pub fn parse_manga_list(html: Node, base_url: String, searching: bool) -> MangaP
let raw_url = node.attr("href").read();
let id = get_manga_id(&raw_url);
- let url = get_manga_url(&id, &base_url);
- let cover = format!("{}/img/noimg.jpg", base_url);
+ let url = get_manga_url(&id);
+ let cover = format!("{}/img/noimg.jpg", BASE_URL);
let title = String::from(node.text().read().trim());
manga.push(Manga {
@@ -41,7 +42,7 @@ pub fn parse_manga_list(html: Node, base_url: String, searching: bool) -> MangaP
let title = node.attr("title").read();
let id = get_manga_id(&raw_url);
- let url = get_manga_url(&id, &base_url);
+ let url = get_manga_url(&id);
let cover = node.select("img").attr("src").read();
manga.push(Manga {
@@ -140,7 +141,7 @@ pub fn parse_manga_details(html: Node, manga_url: String) -> Manga {
}
}
-pub fn parse_chapter_list(html: Node, base_url: String) -> Vec {
+pub fn parse_chapter_list(html: Node) -> Vec {
let mut chapters: Vec = Vec::new();
for node in html
@@ -153,7 +154,7 @@ pub fn parse_chapter_list(html: Node, base_url: String) -> Vec {
let id = node.attr("data-chapterno").read();
let manga_id = get_manga_id(&raw_url);
- let url = get_chapter_url(&id, &manga_id, &base_url);
+ let url = get_chapter_url(&id, &manga_id);
let chapter = node
.attr("data-chapterno")