Skip to content

Commit e99c613

Browse files
committed
support 2024
1 parent 13f726d commit e99c613

File tree

13 files changed

+95
-109
lines changed

13 files changed

+95
-109
lines changed

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ members = [
99

1010
[workspace.package]
1111
authors = ["timzaak <[email protected]>"]
12-
edition = "2021"
12+
edition = "2024"
1313
version = "3.0.0"
1414

1515
[workspace.dependencies]
1616
anyhow = { version = "1.0" }
1717
bytes = "1"
1818
chrono = { version = "0.4" }
19-
clap = { version = "4.5"}
19+
clap = { version = "4.5" }
2020
console = "0.16"
2121
dashmap = "6.1"
2222
delay_timer = "0.11.6"
@@ -32,15 +32,15 @@ md-5 = "0.10"
3232
percent-encoding = "2.1"
3333
regex = "1.10"
3434
reqwest = { version = "0.12", default-features = false }
35-
serde = { version = "1.0"}
35+
serde = { version = "1.0" }
3636
serde_json = "1.0"
3737
serde_repr = "0.1"
3838
tokio = { version = "1.0" }
3939
toml = { version = "0.9.8" }
4040
toml_edit = "0.23.7"
4141
tracing = "0.1.21"
4242
tracing-core = "0.1.32"
43-
tracing-subscriber = { version = "0.3"}
43+
tracing-subscriber = { version = "0.3" }
4444
walkdir = "2.5"
4545
salvo = "0.85.0"
4646
dunce = "1"

client/src/api.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use entity::request::{
55
GetDomainOption, UpdateUploadingStatusOption,
66
};
77
use entity::storage::{CertInfo, DomainInfo, ShortMetaData, UploadDomainPosition};
8-
use reqwest::{header, multipart, StatusCode};
8+
use reqwest::{StatusCode, header, multipart};
99
use std::borrow::Cow;
1010
use std::path::PathBuf;
1111

@@ -207,8 +207,8 @@ impl API {
207207
}
208208
#[cfg(test)]
209209
mod test {
210-
use crate::api::API;
211210
use crate::LOCAL_HOST;
211+
use crate::api::API;
212212
use entity::request::UpdateUploadingStatusOption;
213213
use entity::storage::UploadingStatus;
214214

client/src/config.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,18 @@ pub(crate) mod test {
7272
use std::env;
7373

7474
pub(crate) fn init_env() {
75-
env::set_var("SPA_SERVER_ADDRESS", "http://127.0.0.1:9000");
76-
env::set_var("SPA_SERVER_AUTH_TOKEN", "token");
77-
env::set_var("SPA_UPLOAD_PARALLEL", "4");
75+
unsafe {
76+
env::set_var("SPA_SERVER_ADDRESS", "http://127.0.0.1:9000");
77+
env::set_var("SPA_SERVER_AUTH_TOKEN", "token");
78+
env::set_var("SPA_UPLOAD_PARALLEL", "4");
79+
}
7880
}
7981
fn remove_env() {
80-
env::remove_var("SPA_SERVER_ADDRESS");
81-
env::remove_var("SPA_SERVER_AUTH_TOKEN");
82-
env::remove_var("SPA_UPLOAD_PARALLEL");
82+
unsafe {
83+
env::remove_var("SPA_SERVER_ADDRESS");
84+
env::remove_var("SPA_SERVER_AUTH_TOKEN");
85+
env::remove_var("SPA_UPLOAD_PARALLEL");
86+
}
8387
}
8488

8589
pub(crate) fn default_local_config() -> anyhow::Result<Config> {

client/src/lib.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,16 @@ const LOCAL_HOST: &str = "local.fornetcode.com";
7070

7171
#[cfg(test)]
7272
mod test {
73-
use crate::{run_with_commands, CliCommand, LOCAL_HOST};
73+
use crate::{CliCommand, LOCAL_HOST, run_with_commands};
7474
use clap::Parser;
7575
use std::env;
7676

7777
fn init_config() {
78-
env::set_var("SPA_SERVER_ADDRESS", "http://127.0.0.1:9000");
79-
env::set_var("SPA_SERVER_AUTH_TOKEN", "token");
80-
env::set_var("SPA_UPLOAD_PARALLEL", "4");
78+
unsafe {
79+
env::set_var("SPA_SERVER_ADDRESS", "http://127.0.0.1:9000");
80+
env::set_var("SPA_SERVER_AUTH_TOKEN", "token");
81+
env::set_var("SPA_UPLOAD_PARALLEL", "4");
82+
}
8183
}
8284

8385
#[ignore]

client/src/upload_files.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use crate::{success, API};
1+
use crate::{API, success};
22
use anyhow::anyhow;
33
use console::style;
44
use entity::request::UpdateUploadingStatusOption;
55
use entity::storage::{GetDomainPositionStatus, ShortMetaData, UploadingStatus};
6-
use futures::future::Either;
76
use futures::StreamExt;
7+
use futures::future::Either;
88
use if_chain::if_chain;
99
use md5::{Digest, Md5};
1010
use std::borrow::Cow;
@@ -13,8 +13,8 @@ use std::fs;
1313
use std::fs::File;
1414
use std::io::Read;
1515
use std::path::{Path, PathBuf};
16-
use std::sync::atomic::{AtomicU64, Ordering};
1716
use std::sync::Arc;
17+
use std::sync::atomic::{AtomicU64, Ordering};
1818
use std::time::Duration;
1919
use tracing::warn;
2020
use walkdir::WalkDir;
@@ -32,7 +32,9 @@ pub async fn upload_files(
3232
return Err(anyhow!("{:?} is not a directory", path));
3333
}
3434
let version = get_upload_version(&api, &domain, version).await?;
35-
println!("begin to fetch server file metadata with md5, you may need to wait if there are large number of files.");
35+
println!(
36+
"begin to fetch server file metadata with md5, you may need to wait if there are large number of files."
37+
);
3638
let server_metadata = api.get_file_metadata(&domain, version).await?;
3739
if !server_metadata.is_empty() {
3840
println!(
@@ -122,15 +124,15 @@ pub async fn upload_files(
122124
let process_count = Arc::new(AtomicU64::new(1));
123125
let upload_result = futures::stream::iter(uploading_files.into_iter().map(|(key, path)| {
124126
let key: Cow<'static, str> = key.into();
125-
let r = retry_upload(
127+
128+
retry_upload(
126129
api.as_ref(),
127130
domain.clone(),
128131
str_version.clone(),
129132
key,
130133
path,
131134
process_count.clone(),
132-
);
133-
r
135+
)
134136
}))
135137
.buffer_unordered(parallel as usize)
136138
.map(|result| match result {

server/src/admin_server.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::config::{get_host_path_from_domain, AdminConfig};
1+
use crate::config::{AdminConfig, get_host_path_from_domain};
22
use crate::domain_storage::DomainStorage;
33
use delay_timer::prelude::*;
44
use salvo::prelude::*;
@@ -128,16 +128,16 @@ pub mod service {
128128
let option = req.parse_queries::<GetDomainOption>();
129129
match storage.get_domain_info() {
130130
Ok(domain_info) => {
131-
if let Ok(option) = option {
132-
if let Some(domain) = option.domain {
133-
if let Some(data) = domain_info.iter().find(|x| x.domain == domain) {
134-
res.render(Json(&[data]));
135-
} else {
136-
let data: Vec<&DomainInfo> = Vec::new();
137-
res.render(Json(data));
138-
}
139-
return;
131+
if let Ok(option) = option
132+
&& let Some(domain) = option.domain
133+
{
134+
if let Some(data) = domain_info.iter().find(|x| x.domain == domain) {
135+
res.render(Json(&[data]));
136+
} else {
137+
let data: Vec<&DomainInfo> = Vec::new();
138+
res.render(Json(data));
140139
}
140+
return;
141141
}
142142
res.render(Json(domain_info));
143143
}

server/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use anyhow::{bail, Context};
1+
use anyhow::{Context, bail};
22
use duration_str::deserialize_duration;
33
use headers::{HeaderValue, Origin};
44
use serde::{Deserialize, Deserializer};

server/src/domain_storage.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::config::get_host_path_from_domain;
22
use crate::file_cache::{CacheItem, FileCache};
3-
use anyhow::{anyhow, bail, Context};
3+
use anyhow::{Context, anyhow, bail};
44
use dashmap::DashMap;
55
use entity::storage::{
66
DomainInfo, GetDomainPositionStatus, ShortMetaData, UploadDomainPosition, UploadingStatus,
@@ -103,16 +103,16 @@ impl DomainStorage {
103103
}
104104
let path_buf = sub_dir.join(version.to_string());
105105
match domain_version.get_mut(domain_dir_name) {
106-
Some(mut domain_meta) => {
107-
match domain_meta.value_mut() {
108-
DomainMeta::MultipleWeb(ref mut map) => {
109-
map.insert(sub_path.clone(), (path_buf, version));
110-
}
111-
DomainMeta::OneWeb(..) => {
112-
panic!("init failure, {sub_dir:?} should be multiple web");
113-
}
106+
Some(mut domain_meta) => match domain_meta.value_mut() {
107+
DomainMeta::MultipleWeb(map) => {
108+
map.insert(sub_path.clone(), (path_buf, version));
114109
}
115-
}
110+
DomainMeta::OneWeb(..) => {
111+
panic!(
112+
"init failure, {sub_dir:?} should be multiple web"
113+
);
114+
}
115+
},
116116
None => {
117117
let map = DashMap::new();
118118
map.insert(sub_path.clone(), (path_buf, version));
@@ -833,7 +833,9 @@ mod test {
833833
fn test_domain_storage_get_domain_info() {
834834
//TODO: fix config path
835835
let path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../test/config.test.conf");
836-
env::set_var("SPA_CONFIG", path.display().to_string());
836+
unsafe {
837+
env::set_var("SPA_CONFIG", path.display().to_string());
838+
}
837839
let mut config = Config::load().unwrap();
838840
config.file_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
839841
.join("../tests/web/data")

server/src/file_cache.rs

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -98,26 +98,25 @@ impl FileCache {
9898
.into_iter()
9999
.filter_map(|x| x.ok())
100100
.filter_map(|entry| {
101-
if let Ok(metadata) = entry.metadata() {
102-
if metadata.is_file() {
103-
if let Ok(key) = entry.path().strip_prefix(&parent) {
104-
let key = key
105-
.components()
106-
.map(|c| c.as_os_str().to_string_lossy())
107-
.collect::<Vec<_>>()
108-
.join("/");
109-
let key = sub_path
110-
.map(|sub_path| format!("{sub_path}/{key}"))
111-
.unwrap_or(key);
112-
return Some((
113-
key,
114-
Arc::new(CacheItem {
115-
data: entry.path().to_path_buf(),
116-
version,
117-
}),
118-
));
119-
}
120-
}
101+
if let Ok(metadata) = entry.metadata()
102+
&& metadata.is_file()
103+
&& let Ok(key) = entry.path().strip_prefix(&parent)
104+
{
105+
let key = key
106+
.components()
107+
.map(|c| c.as_os_str().to_string_lossy())
108+
.collect::<Vec<_>>()
109+
.join("/");
110+
let key = sub_path
111+
.map(|sub_path| format!("{sub_path}/{key}"))
112+
.unwrap_or(key);
113+
return Some((
114+
key,
115+
Arc::new(CacheItem {
116+
data: entry.path().to_path_buf(),
117+
version,
118+
}),
119+
));
121120
}
122121
None
123122
})

server/src/service.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::config::{extract_origin, Config};
1+
use crate::config::{Config, extract_origin};
22
use headers::HeaderValue;
33
use hyper::StatusCode;
44
use salvo::Response;

0 commit comments

Comments
 (0)