Skip to content

Commit

Permalink
fix: 🧵CI
Browse files Browse the repository at this point in the history
  • Loading branch information
LycasLdt committed May 11, 2024
1 parent c7dbaef commit edb6e82
Show file tree
Hide file tree
Showing 5 changed files with 185 additions and 9 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
uses: dtolnay/rust-toolchain@stable
with:
toolchain: nightly
target: ${{ matrix.target }}
- name: Cache rust
uses: Swatinem/rust-cache@v2

Expand Down
148 changes: 148 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ scraper = "0.19"
# Decoding
base64 = "0.22"
md-5 = "0.11.0-pre.3"
rsa = "0.10.0-pre.1"
rand = "0.8"
chrono = "0.4"
base16ct = { version = "0.2", features = ["alloc"] }
aes = "0.8"
Expand Down
23 changes: 21 additions & 2 deletions src/downloads/clipcc.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use super::{Download, DownloadAssetServer, DownloadContext, DownloadDescriptor};
use crate::utils::{decode::decode_cbc_aes, get_next_data};
use anyhow::Result;
use base64::{engine::general_purpose::STANDARD, Engine};
use chrono::Utc;
use rsa::{pkcs8::DecodePublicKey, Pkcs1v15Encrypt, RsaPublicKey};

const CLIPCC_SB3_URL: &str = "https://api.codingclip.com/v1/project/publicJson";
const CLIPCC_SB3_URL: &str = "https://api.codingclip.com/v1/project/download";
const CLIPCC_PROJECT_URL: &str = "https://codingclip.com/project/";
// clipccyydsclipccyydsclipccyydscc
const CLIPCC_AES_KEY: [u8; 32] = [
Expand All @@ -15,6 +18,14 @@ const CLIPCC_AES_IV: [u8; 16] = [
];
// ·-M8q -> {"ta
const CLIPCC_SOURCE_PREFIX: [u8; 5] = [221, 45, 77, 56, 113];
const CLIPCC_PUBLIC_KEY: &str =
r#"-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCzOaIJxii0ItmbVx1/lWTJxGht
M/sPHGRyX/n4u7XFy89C+BPweyhowXMVvoN8aJivSrUC8wwn3/fDbq3PLF8Wm+37
fmZw7JJssyEsow4x/TE6N9b0Hq8mYwLXHSAWWBHL0uzQeRtxfa9ZQsvpkGW/VoBJ
CP/tf54FNKZWpN+VZwIDAQAB
-----END PUBLIC KEY-----
"#;

#[derive(serde::Deserialize)]
struct ClipccData {
Expand Down Expand Up @@ -58,8 +69,16 @@ impl Download for ClipccDownload {
let data = get_next_data(&res)?;
let json = serde_json::from_str::<ClipccData>(&data)?.props.page_props;

let timestamp = Utc::now().timestamp_millis().to_string();
let asset_id = ["public", &timestamp, &context.id].join("|");

let mut rng = rand::thread_rng();
let public_key = RsaPublicKey::from_public_key_pem(&CLIPCC_PUBLIC_KEY)?;
let keys = public_key.encrypt(&mut rng, Pkcs1v15Encrypt, asset_id.as_bytes())?;
let keys = STANDARD.encode(keys);

let project_url =
crate::utils::Url::parse_with_params(CLIPCC_SB3_URL, &[("id", context.id.clone())])?;
crate::utils::Url::parse_with_params(CLIPCC_SB3_URL, &[("keys", keys)])?;

context.set_info(project_url, json.project.name, vec![json.project.user_name]);
Ok(())
Expand Down
20 changes: 13 additions & 7 deletions src/utils/sb3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ pub struct Sb3Target {
pub struct Sb3Asset {
#[serde(skip)]
pub kind: Sb3AssetKind,
pub name: String,
pub md5ext: String,
}

Expand Down Expand Up @@ -68,25 +67,32 @@ impl Sb3Reader {
}
}

pub struct Sb3Writer<W: Write + Seek>(pub ZipWriter<W>);
pub struct Sb3Writer<W: Write + Seek> {
inner: ZipWriter<W>,
assets: Vec<String>
}
impl<W: Write + Seek> Sb3Writer<W> {
pub fn new(writer: W) -> Self {
let inner = ZipWriter::new(writer);
Sb3Writer(inner)
Sb3Writer { inner, assets: Vec::new() }
}

pub fn set_project_json<C: AsRef<[u8]>>(&mut self, json: C) -> Result<&mut Self> {
self.add_asset("project.json", json.as_ref())?;
Ok(self)
}
pub fn add_asset(&mut self, name: &str, buf: &[u8]) -> Result<&mut Self> {
let inner = &mut self.0;
inner.start_file(name, SimpleFileOptions::default())?;
inner.write_all(buf)?;
let inner = &mut self.inner;
if !self.assets.contains(&name.to_owned()) {
inner.start_file(name, SimpleFileOptions::default())?;
inner.write_all(buf)?;

self.assets.push(name.to_owned())
}

Ok(self)
}
pub fn finish(&mut self) -> Result<W> {
Ok(self.0.finish()?)
Ok(self.inner.finish()?)
}
}

0 comments on commit edb6e82

Please sign in to comment.