From 31377338c465b1eb081e39d2502f5a9e663d0fe9 Mon Sep 17 00:00:00 2001 From: Operacon Date: Sun, 3 Oct 2021 22:24:50 +0800 Subject: [PATCH 1/2] add bhpan upload on linux server --- judger/src/fs/net.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/judger/src/fs/net.rs b/judger/src/fs/net.rs index 61d36f99..aad006e7 100644 --- a/judger/src/fs/net.rs +++ b/judger/src/fs/net.rs @@ -108,6 +108,36 @@ pub async fn git_clone(dir: &Path, options: GitCloneOptions) -> std::io::Result< tokio::fs::create_dir_all(dir).await?; + if &options.revision == "bhpan" { + let bytes = &options.repo.as_bytes(); + + // cut 'https://bhpan.buaa.edu.cn/link/' + let mut fid = &options.repo[35..]; + + for (i, &item) in bytes.iter().enumerate() { + if item == b'#'{ + // cut 'https://bhpan.buaa.edu.cn/#/link/', if so + fid = &options.repo[37..]; + break; + } + } + + if cfg!(windows) { + // TODO: write command for windows + } + else if cfg!(macos) { + // TODO: write command for macos + } + else { + do_command!(dir, [&("x=`curl --location --request POST 'https://bhpan.buaa.edu.cn/api/v1/link/osdownload' --header 'Content-Type: application/json' --data-raw '{\"link\":\"".to_string() + + fid + + "\",\"reqhost\":\"bhpan.buaa.edu.cn\",\"usehttps\": true}'`&&x=`echo ${x%\\\"]*}`&&x=`echo ${x#*,\\\"}`&&curl --location --request GET $x --output code.zip" + ),]); + do_command!(dir, ["unzip", "code.zip"]); + } + Ok(()) + } + do_command!(dir, ["git", "init"]); do_command!(dir, ["git", "remote", "add", "origin", &options.repo]); do_command!( From 1ab3396f3dc168969239c49f6dfc0bdc1d05e768 Mon Sep 17 00:00:00 2001 From: Operacon Date: Sun, 3 Oct 2021 22:48:51 +0800 Subject: [PATCH 2/2] fix do_command add entry sh --- judger/src/fs/net.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/judger/src/fs/net.rs b/judger/src/fs/net.rs index aad006e7..0bd3f57b 100644 --- a/judger/src/fs/net.rs +++ b/judger/src/fs/net.rs @@ -129,10 +129,10 @@ pub async fn git_clone(dir: &Path, options: GitCloneOptions) -> std::io::Result< // TODO: write command for macos } else { - do_command!(dir, [&("x=`curl --location --request POST 'https://bhpan.buaa.edu.cn/api/v1/link/osdownload' --header 'Content-Type: application/json' --data-raw '{\"link\":\"".to_string() + do_command!(dir, ["sh", &("x=`curl --location --request POST 'https://bhpan.buaa.edu.cn/api/v1/link/osdownload' --header 'Content-Type: application/json' --data-raw '{\"link\":\"".to_string() + fid + "\",\"reqhost\":\"bhpan.buaa.edu.cn\",\"usehttps\": true}'`&&x=`echo ${x%\\\"]*}`&&x=`echo ${x#*,\\\"}`&&curl --location --request GET $x --output code.zip" - ),]); + )]); do_command!(dir, ["unzip", "code.zip"]); } Ok(())