This commit is contained in:
quantulr
2023-11-14 13:00:39 +08:00
parent e0fe8f6a09
commit 008eb15fb1
9 changed files with 134 additions and 3 deletions

3
.env
View File

@ -1,2 +1,3 @@
DATABASE_URL=mysql://root:archlinux0311@localhost:3306/likeadmin DATABASE_URL=mysql://root:archlinux0311@localhost:3306/likeadmin
UPLOAD_PATH=D:/Downloads/upload_path #UPLOAD_PATH=/var/www/uploads/caszl
UPLOAD_PATH="/Volumes/iMac Doc/likeadmin-java"

4
.idea/deployment.xml generated Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="PublishConfigData" serverName="aliyun" remoteFilesAllowedToDisappearOnAutoupload="false" />
</project>

8
.idea/sshConfigs.xml generated Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="SshConfigs">
<configs>
<sshConfig host="47.102.206.10" id="1d7378a3-b681-41f4-845d-dec953996939" keyPath="$USER_HOME$/.ssh/id_ed25519" port="22" nameFormat="DESCRIPTIVE" username="root" useOpenSSHConfig="true" />
</configs>
</component>
</project>

14
.idea/webServers.xml generated Normal file
View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="WebServers">
<option name="servers">
<webServer id="83c35c51-1b39-4180-a58d-1b5506d9948f" name="aliyun">
<fileTransfer rootFolder="/var/www" accessType="SFTP" host="47.102.206.10" port="22" sshConfigId="1d7378a3-b681-41f4-845d-dec953996939" sshConfig="root@47.102.206.10:22 key" keyPair="true">
<advancedOptions>
<advancedOptions dataProtectionLevel="Private" keepAliveTimeout="0" passiveMode="true" shareSSLContext="true" />
</advancedOptions>
</fileTransfer>
</webServer>
</option>
</component>
</project>

99
Cargo.lock generated
View File

@ -337,10 +337,13 @@ dependencies = [
"axum", "axum",
"chrono", "chrono",
"dotenvy", "dotenvy",
"hyper",
"sea-orm", "sea-orm",
"serde", "serde",
"serde_json", "serde_json",
"tokio", "tokio",
"tower",
"tower-http",
] ]
[[package]] [[package]]
@ -713,6 +716,25 @@ version = "0.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0"
[[package]]
name = "h2"
version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "91fc23aa11be92976ef4729127f1a74adf36d8436f7816b185d18df956790833"
dependencies = [
"bytes",
"fnv",
"futures-core",
"futures-sink",
"futures-util",
"http",
"indexmap 1.9.3",
"slab",
"tokio",
"tokio-util",
"tracing",
]
[[package]] [[package]]
name = "hashbrown" name = "hashbrown"
version = "0.12.3" version = "0.12.3"
@ -820,6 +842,12 @@ dependencies = [
"pin-project-lite", "pin-project-lite",
] ]
[[package]]
name = "http-range-header"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "add0ab9360ddbd88cfeb3bd9574a1d85cfdfa14db10b3e21d3700dbc4328758f"
[[package]] [[package]]
name = "httparse" name = "httparse"
version = "1.8.0" version = "1.8.0"
@ -842,6 +870,7 @@ dependencies = [
"futures-channel", "futures-channel",
"futures-core", "futures-core",
"futures-util", "futures-util",
"h2",
"http", "http",
"http-body", "http-body",
"httparse", "httparse",
@ -888,6 +917,16 @@ dependencies = [
"unicode-normalization", "unicode-normalization",
] ]
[[package]]
name = "indexmap"
version = "1.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99"
dependencies = [
"autocfg",
"hashbrown 0.12.3",
]
[[package]] [[package]]
name = "indexmap" name = "indexmap"
version = "2.1.0" version = "2.1.0"
@ -1015,6 +1054,16 @@ version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
[[package]]
name = "mime_guess"
version = "2.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef"
dependencies = [
"mime",
"unicase",
]
[[package]] [[package]]
name = "minimal-lexical" name = "minimal-lexical"
version = "0.2.1" version = "0.2.1"
@ -1905,7 +1954,7 @@ dependencies = [
"futures-util", "futures-util",
"hashlink", "hashlink",
"hex", "hex",
"indexmap", "indexmap 2.1.0",
"log", "log",
"memchr", "memchr",
"native-tls", "native-tls",
@ -2264,6 +2313,20 @@ dependencies = [
"tokio", "tokio",
] ]
[[package]]
name = "tokio-util"
version = "0.7.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15"
dependencies = [
"bytes",
"futures-core",
"futures-sink",
"pin-project-lite",
"tokio",
"tracing",
]
[[package]] [[package]]
name = "toml" name = "toml"
version = "0.5.11" version = "0.5.11"
@ -2289,6 +2352,31 @@ dependencies = [
"tracing", "tracing",
] ]
[[package]]
name = "tower-http"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61c5bb1d698276a2443e5ecfabc1008bf15a36c12e6a7176e7bf089ea9131140"
dependencies = [
"bitflags 2.4.1",
"bytes",
"futures-core",
"futures-util",
"http",
"http-body",
"http-range-header",
"httpdate",
"mime",
"mime_guess",
"percent-encoding",
"pin-project-lite",
"tokio",
"tokio-util",
"tower-layer",
"tower-service",
"tracing",
]
[[package]] [[package]]
name = "tower-layer" name = "tower-layer"
version = "0.3.2" version = "0.3.2"
@ -2345,6 +2433,15 @@ version = "1.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825"
[[package]]
name = "unicase"
version = "2.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89"
dependencies = [
"version_check",
]
[[package]] [[package]]
name = "unicode-bidi" name = "unicode-bidi"
version = "0.3.13" version = "0.3.13"

View File

@ -9,7 +9,10 @@ edition = "2021"
axum = "0.6.20" axum = "0.6.20"
chrono = "0.4.31" chrono = "0.4.31"
dotenvy = "0.15.7" dotenvy = "0.15.7"
hyper = { version = "0.14.27", features = ["full"] }
sea-orm = { version = "0.12.4", features = ["sqlx-mysql", "runtime-tokio-native-tls", "macros"] } sea-orm = { version = "0.12.4", features = ["sqlx-mysql", "runtime-tokio-native-tls", "macros"] }
serde = { version = "1.0.192", features = ["derive"] } serde = { version = "1.0.192", features = ["derive"] }
serde_json = "1.0.108" serde_json = "1.0.108"
tokio = { version = "1.34.0", features = ["full"] } tokio = { version = "1.34.0", features = ["full"] }
tower = "0.4.13"
tower-http = { version = "0.4.4", features = ["fs"] }

View File

@ -18,10 +18,11 @@ use std::sync::Arc;
async fn main() { async fn main() {
dotenvy::dotenv().ok(); dotenvy::dotenv().ok();
let db_url = env::var("DATABASE_URL").expect(".env 文件中没有设置 DATABASE_URL"); let db_url = env::var("DATABASE_URL").expect(".env 文件中没有设置 DATABASE_URL");
let upload_path = env::var("UPLOAD_PATH").expect(".env 文件中没有设置 UPLOAD_PATH");
let db_conn = Database::connect(&db_url).await.expect("数据库链接失败"); let db_conn = Database::connect(&db_url).await.expect("数据库链接失败");
let app_state = AppState { db_conn }; let app_state = AppState { db_conn, upload_path };
let app = routes::create_routes(Arc::new(app_state)); let app = routes::create_routes(Arc::new(app_state));
Server::bind(&"0.0.0.0:3000".parse().unwrap()) Server::bind(&"0.0.0.0:3000".parse().unwrap())

View File

@ -3,12 +3,14 @@ use crate::state::app::AppState;
use axum::routing::{get, IntoMakeService}; use axum::routing::{get, IntoMakeService};
use axum::{Router, ServiceExt}; use axum::{Router, ServiceExt};
use std::sync::Arc; use std::sync::Arc;
use tower_http::services::ServeDir;
pub fn create_routes(app_state: Arc<AppState>) -> IntoMakeService<Router> { pub fn create_routes(app_state: Arc<AppState>) -> IntoMakeService<Router> {
Router::new() Router::new()
.nest( .nest(
"/api", "/api",
Router::new() Router::new()
.nest_service("/uploads",ServeDir::new(&app_state.upload_path))
.nest("/article", Router::new().route("/list", get(article_list))) .nest("/article", Router::new().route("/list", get(article_list)))
.nest( .nest(
"/pc", "/pc",

View File

@ -2,4 +2,5 @@ use sea_orm::DatabaseConnection;
pub struct AppState { pub struct AppState {
pub db_conn: DatabaseConnection, pub db_conn: DatabaseConnection,
pub upload_path: String,
} }