Skip to content

Commit

Permalink
fix(copymanga): search not working (#664)
Browse files Browse the repository at this point in the history
* fix: update searching url

* chore: bump version

* refactor: rewrite enum `Url`

* fix: remove unsed constant `DOMAIN`

* fix: not to panic!

* refactor: extract duplicate code to function

* refactor: replace `let-else` with `ok_or_else`
  • Loading branch information
aphronyx authored May 19, 2024
1 parent 80ee9cc commit c0775da
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 112 deletions.
107 changes: 70 additions & 37 deletions src/rust/zh.copymanga/Cargo.lock

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

1 change: 1 addition & 0 deletions src/rust/zh.copymanga/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ cbc = "0.1.2"
chinese-number = { version = "0.7.7", default-features = false, features = ["chinese-to-number"] }
hex = { version = "0.4.3", default-features = false, features = ["alloc"] }
regex = { version = "1.10.3", default-features = false, features = ["unicode"] }
strum_macros = "0.26.2"
uuid = { version = "1.4.1", default-features = false }
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": 5,
"version": 6,
"url": "https://copymanga.site",
"urls": [
"https://copymanga.site",
Expand Down
24 changes: 16 additions & 8 deletions src/rust/zh.copymanga/src/decryptor.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
use crate::helper::to_aidoku_error;
use aes::{
cipher::{block_padding::Pkcs7, BlockDecryptMut, KeyIvInit},
Aes128,
};
use aidoku::std::String;
use aidoku::{error::Result, std::String};
use core::marker::Sized;

type Aes128CbcDec = cbc::Decryptor<Aes128>;

const KEY: &[u8] = b"xxxmanga.woo.key";

pub trait EncryptedString {
fn decrypt(self) -> String;
fn decrypt(self) -> Result<Self>
where
Self: Sized;
}

impl EncryptedString for String {
fn decrypt(self) -> String {
fn decrypt(self) -> Result<Self> {
let encrypted_data = self.as_bytes();
let iv = &encrypted_data[..16];
let mut ciphertext =
hex::decode(&encrypted_data[16..]).expect("Failed to hex-decode ciphertext.");
let iv = encrypted_data
.get(..16)
.ok_or_else(|| to_aidoku_error("Failed to get `iv` from `encrypted_data`"))?;
let hex_ciphertext = encrypted_data.get(16..).ok_or_else(|| {
to_aidoku_error("Failed to get `hex_ciphertext` from `encrypted_data`")
})?;
let mut ciphertext = hex::decode(hex_ciphertext).map_err(to_aidoku_error)?;

let plaintext = Aes128CbcDec::new(KEY.into(), iv.into())
.decrypt_padded_mut::<Pkcs7>(&mut ciphertext)
.expect("Failed to decrypt chapter list");
String::from_utf8_lossy(plaintext).into()
.map_err(to_aidoku_error)?;
Ok(Self::from_utf8_lossy(plaintext).into())
}
}
23 changes: 23 additions & 0 deletions src/rust/zh.copymanga/src/helper/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use aidoku::{
error::{AidokuError, AidokuErrorKind, Result},
prelude::println,
};
use core::fmt::Display;
use regex::Regex as OriginalRegex;

pub struct Regex;

impl Regex {
#[allow(clippy::new_ret_no_self)]
pub fn new<S: AsRef<str>>(pat: S) -> Result<OriginalRegex> {
OriginalRegex::new(pat.as_ref()).map_err(to_aidoku_error)
}
}

pub fn to_aidoku_error<E: Display>(err: E) -> AidokuError {
println!("{err}");

AidokuError {
reason: AidokuErrorKind::Unimplemented,
}
}
Loading

0 comments on commit c0775da

Please sign in to comment.