diff --git a/Cargo.lock b/Cargo.lock index a922655..64cd504 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1056,7 +1056,7 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "leetcode-cli" -version = "0.4.1" +version = "0.6.2" dependencies = [ "anyhow", "async-trait", diff --git a/Cargo.toml b/Cargo.toml index ec01180..6d41fa7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ path = "src/bin/lc.rs" [package] name = "leetcode-cli" -version = "0.4.1" +version = "0.6.2" authors = ["clearloop "] edition = "2021" description = "Leetcode command-line interface in rust." diff --git a/src/cache/models.rs b/src/cache/models.rs index 12c512e..b066af0 100644 --- a/src/cache/models.rs +++ b/src/cache/models.rs @@ -49,6 +49,14 @@ impl Problem { res + "\n" } + + pub fn get_fid(&self) -> String { + format!("s{:0>4}", self.fid) + } + + pub fn get_slug(&self) -> String { + self.slug.replace("-", "_").to_string() + } } static DONE: &str = " ✔"; diff --git a/src/config/code.rs b/src/config/code.rs index 0384608..b56f438 100644 --- a/src/config/code.rs +++ b/src/config/code.rs @@ -2,11 +2,11 @@ use serde::{Deserialize, Serialize}; fn default_pick() -> String { - "${fid}.${slug}".into() + "${fid}_${slug}".into() } fn default_submission() -> String { - "${fid}.${slug}.${sid}.${ac}".into() + "${fid}_${slug}.${sid}.${ac}".into() } /// Code config @@ -47,8 +47,8 @@ impl Default for Code { comment_leading: "".into(), test: true, lang: "rust".into(), - pick: "${fid}.${slug}".into(), - submission: "${fid}.${slug}.${sid}.${ac}".into(), + pick: "${fid}_${slug}".into(), + submission: "${fid}_${slug}.${sid}.${ac}".into(), } } } diff --git a/src/config/storage.rs b/src/config/storage.rs index 72a01fc..38f2946 100644 --- a/src/config/storage.rs +++ b/src/config/storage.rs @@ -49,11 +49,22 @@ impl Storage { /// get code path pub fn code(&self) -> Result { - let root = &self.root()?; - let p = PathBuf::from(root).join(&self.code); - if !PathBuf::from(&p).exists() { - fs::create_dir(&p)? - } + let home = dirs::home_dir() + .ok_or(Error::NoneError)? + .to_string_lossy() + .to_string(); + let path = self.code.replace('~', &home); + + let p = if !path.starts_with("/") { + let root = &self.root()?; + let abs_path = PathBuf::from(root).join(&path); + if !PathBuf::from(&abs_path).exists() { + fs::create_dir(&abs_path)? + }; + abs_path + } else { + PathBuf::from(path) + }; Ok(p.to_string_lossy().to_string()) } diff --git a/src/config/sys.rs b/src/config/sys.rs index 7c6f77e..5c8f0cf 100644 --- a/src/config/sys.rs +++ b/src/config/sys.rs @@ -33,20 +33,20 @@ pub struct Urls { impl Default for Urls { fn default() -> Self { Self { - base: "https://leetcode.com".into(), - graphql: "https://leetcode.com/graphql".into(), - login: "https://leetcode.com/accounts/login/".into(), + base: "https://leetcode.cn".into(), + graphql: "https://leetcode.cn/graphql".into(), + login: "https://leetcode.cn/accounts/login/".into(), problems: "https://leetcode.com/api/problems/$category/".into(), problem: "https://leetcode.com/problems/$slug/description/".into(), - tag: "https://leetcode.com/tag/$slug/".into(), - test: "https://leetcode.com/problems/$slug/interpret_solution/".into(), - session: "https://leetcode.com/session/".into(), - submit: "https://leetcode.com/problems/$slug/submit/".into(), - submissions: "https://leetcode.com/submissions/detail/$id/".into(), - submission: "https://leetcode.com/submissions/detail/$id/".into(), - verify: "https://leetcode.com/submissions/detail/$id/check/".into(), - favorites: "https://leetcode.com/list/api/questions".into(), - favorite_delete: "https://leetcode.com/list/api/questions/$hash/$id".into(), + tag: "https://leetcode.cn/tag/$slug/".into(), + test: "https://leetcode.cn/problems/$slug/interpret_solution/".into(), + session: "https://leetcode.cn/session/".into(), + submit: "https://leetcode.cn/problems/$slug/submit/".into(), + submissions: "https://leetcode.cn/submissions/detail/$id/".into(), + submission: "https://leetcode.cn/submissions/detail/$id/".into(), + verify: "https://leetcode.cn/submissions/detail/$id/check/".into(), + favorites: "https://leetcode.cn/list/api/questions".into(), + favorite_delete: "https://leetcode.cn/list/api/questions/$hash/$id".into(), } } } diff --git a/src/helper.rs b/src/helper.rs index db1a77e..a1b4d63 100644 --- a/src/helper.rs +++ b/src/helper.rs @@ -195,8 +195,8 @@ mod file { let conf = crate::config::Config::locate()?; let mut path = format!("{}/{}.tests.dat", conf.storage.code()?, conf.code.pick); - path = path.replace("${fid}", &problem.fid.to_string()); - path = path.replace("${slug}", &problem.slug.to_string()); + path = path.replace("${fid}", &problem.get_fid()); + path = path.replace("${slug}", &problem.get_slug()); Ok(path) } @@ -215,8 +215,8 @@ mod file { suffix(&lang)?, ); - path = path.replace("${fid}", &problem.fid.to_string()); - path = path.replace("${slug}", &problem.slug.to_string()); + path = path.replace("${fid}", &problem.get_fid()); + path = path.replace("${slug}", &problem.get_slug()); Ok(path) } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy