Skip to content

Commit

Permalink
bak
Browse files Browse the repository at this point in the history
  • Loading branch information
timzaak committed Jun 24, 2024
1 parent d90f59e commit 8598ceb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 26 deletions.
34 changes: 17 additions & 17 deletions server/src/domain_storage.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::acme::ACMEManager;
use crate::config::get_host_path_from_domain;
use crate::file_cache::{CacheItem, FileCache};
use anyhow::{anyhow, bail, Context};
use chrono::{DateTime, Utc};
use dashmap::DashMap;
use lazy_static::lazy_static;
use md5::{Digest, Md5};
Expand All @@ -13,11 +15,9 @@ use std::io::{Read, Write};
use std::ops::RangeInclusive;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use chrono::{DateTime, Utc};
use tracing::{debug, info};
use walkdir::{DirEntry, WalkDir};
use warp::fs::sanitize_path;
use crate::acme::ACMEManager;

pub(crate) const URI_REGEX_STR: &str =
"[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+\\.?";
Expand Down Expand Up @@ -198,7 +198,7 @@ impl DomainStorage {
let mut max_version = 0;
let mut uploading_version = None;
if !domain_dir.exists() {
return Ok((None, None))
return Ok((None, None));
}
for version_dir_entry in fs::read_dir(domain_dir)? {
let version_dir_entry = version_dir_entry?;
Expand Down Expand Up @@ -536,18 +536,17 @@ impl DomainStorage {
}
}
pub fn check_if_empty_index(&self, host: &str, path: &str) -> bool {
match self.meta
.get(host) {
Some(v) => {
match v.value() {
DomainMeta::OneWeb { .. } => path.is_empty(),
DomainMeta::MultipleWeb(map) => {
if path.len() > 1 {
map.contains_key(&path[1..])
} else {
map.contains_key(path)
}
}
match self.meta.get(host) {
Some(v) => match v.value() {
DomainMeta::OneWeb { .. } => path.is_empty(),
DomainMeta::MultipleWeb(map) => {
let result = if path.len() > 1 {
map.contains_key(&path[1..])
} else {
map.contains_key(path)
};
debug!("fuck, {},{}, {}", path.len(), path, result);
result
}
},
None => {
Expand Down Expand Up @@ -611,7 +610,9 @@ impl DomainStorage {
"domain:{}, version:{} change to upload status:finish",
domain, version
);
acme_manager.add_new_domain(get_host_path_from_domain(&domain).0).await;
acme_manager
.add_new_domain(get_host_path_from_domain(&domain).0)
.await;
}
} else if uploading_status == UploadingStatus::Uploading {
if self
Expand Down Expand Up @@ -757,7 +758,6 @@ pub struct CertInfo {
pub host: String,
}


#[cfg(test)]
mod test {
use crate::config::Config;
Expand Down
11 changes: 2 additions & 9 deletions tests/tests/common.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use reqwest::header::CACHE_CONTROL;
use reqwest::header::{CACHE_CONTROL, LOCATION};
use reqwest::redirect::Policy;
use reqwest::{ClientBuilder, StatusCode, Url};
use spa_client::api::API;
Expand Down Expand Up @@ -155,18 +155,11 @@ pub async fn assert_redirect_correct(request_prefix: &str, target_prefix: &str)
.unwrap();
let query = [("lang", "rust"), ("browser", "servo"), ("zh", "转义字符")];
let url = Url::parse_with_params(request_prefix, &query).unwrap();
println!("{}", url);
let path = url.path();
let query = url.query().unwrap();
let response = client.get(url.clone()).send().await.unwrap();
assert_eq!(response.status(), StatusCode::MOVED_PERMANENTLY);
assert_eq!(
response
.headers()
.get("location")
.unwrap()
.to_str()
.unwrap(),
response.headers().get(LOCATION).unwrap().to_str().unwrap(),
format!("{target_prefix}?{query}") //format!("{path}/?{query}")
);
}
Expand Down

0 comments on commit 8598ceb

Please sign in to comment.