Skip to content

Commit a863db9

Browse files
Merge pull request #158 from NodeSeekDev/dev
Dev
2 parents 8f6c219 + 13c738e commit a863db9

8 files changed

Lines changed: 746 additions & 55 deletions

File tree

.github/workflows/release.yml.bak

Lines changed: 621 additions & 0 deletions
Large diffs are not rendered by default.

Cargo.lock

Lines changed: 22 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ members = [
2020
resolver = "2"
2121

2222
[workspace.package]
23-
version = "0.5.10"
23+
version = "0.5.11"
2424
license = "AGPL-3"
2525
edition = "2024"
2626
repository = "https://github.com/NodeSeekDev/NodeGet"
@@ -63,6 +63,7 @@ tower = { version = "0.5.3", default-features = false }
6363
axum-server = { version = "0.8.0", features = ["tls-rustls-no-provider"] }
6464
dhat = { version = "0.3.3"}
6565
arc-swap = { version = "1.9", default-features = false }
66+
portable-atomic = { version = "1.13.1", default-features = false, features = ["fallback"] }
6667

6768
# Internal crates
6869
ng-core = { path = "crates/ng-core" }

Cross.toml

Lines changed: 61 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,61 @@
1-
[target.arm-unknown-linux-gnueabi]
2-
rustflags = ["-C", "link-arg=-latomic"]
3-
4-
[target.arm-unknown-linux-gnueabihf]
5-
rustflags = ["-C", "link-arg=-latomic"]
6-
7-
[target.armv7-unknown-linux-gnueabi]
8-
rustflags = ["-C", "link-arg=-latomic"]
9-
10-
[target.armv7-unknown-linux-gnueabihf]
11-
rustflags = ["-C", "link-arg=-latomic"]
12-
13-
[target.armv7-unknown-linux-musleabi]
14-
rustflags = ["-C", "link-arg=-latomic"]
15-
16-
[target.armv7-unknown-linux-musleabihf]
17-
rustflags = ["-C", "link-arg=-latomic"]
1+
## Android
2+
#[target.x86_64-linux-android]
3+
#build-std = true
4+
#
5+
#[target.i686-linux-android]
6+
#build-std = true
7+
#
8+
#[target.aarch64-linux-android]
9+
#build-std = true
10+
#
11+
#[target.arm-linux-androideabi]
12+
#build-std = true
13+
#
14+
#[target.armv7-linux-androideabi]
15+
#build-std = true
16+
#
17+
#[target.thumbv7neon-linux-androideabi]
18+
#build-std = true
19+
#
20+
## ARM 老款 (tier 3):无预编译 std,必须从源码构建
21+
#[target.armv5te-unknown-linux-gnueabi]
22+
#build-std = true
23+
#
24+
#[target.armv5te-unknown-linux-musleabi]
25+
#build-std = true
26+
#
27+
## 极老 x86 (tier 3)
28+
#[target.i586-unknown-linux-gnu]
29+
#build-std = true
30+
#
31+
#[target.i586-unknown-linux-musl]
32+
#build-std = true
33+
#
34+
## 32 位 PowerPC (tier 3)
35+
#[target.powerpc-unknown-linux-gnu]
36+
#build-std = true
37+
#
38+
## MIPS 系列 (tier 3):无预编译 std,必须从源码构建
39+
#[target.mips-unknown-linux-gnu]
40+
#build-std = true
41+
#
42+
#[target.mips-unknown-linux-musl]
43+
#build-std = true
44+
#
45+
#[target.mipsel-unknown-linux-gnu]
46+
#build-std = true
47+
#
48+
#[target.mipsel-unknown-linux-musl]
49+
#build-std = true
50+
#
51+
#[target.mips64-unknown-linux-gnuabi64]
52+
#build-std = true
53+
#
54+
#[target.mips64-unknown-linux-muslabi64]
55+
#build-std = true
56+
#
57+
#[target.mips64el-unknown-linux-gnuabi64]
58+
#build-std = true
59+
#
60+
#[target.mips64el-unknown-linux-muslabi64]
61+
#build-std = true

crates/ng-core/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ uuid = { workspace = true }
1414
rand = { workspace = true }
1515
tracing = { workspace = true }
1616

17+
# 32 位平台兼容:portable-atomic 在不支持原生 64 位原子操作的平台提供回退实现
18+
portable-atomic = { workspace = true }
19+
1720
# for-server / for-agent feature dependencies
1821
libc = { version = "0.2.175", default-features = false, optional = true }
1922

crates/ng-core/src/utils/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rand::distr::Alphanumeric;
88
use rand::{RngExt, rng};
99
use serde::Deserialize;
1010
use serde::Serialize;
11-
use std::sync::atomic::{AtomicI64, Ordering};
11+
use portable_atomic::{AtomicI64, Ordering};
1212

1313
#[cfg(feature = "for-server")]
1414
pub mod error_message;

crates/ng-crontab/src/rpc/crontab/mod.rs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,22 @@ mod set_enable;
2222

2323
/// 校验 crontab 名称合法性。
2424
///
25-
/// 只允许字母、数字、下划线、短横线。禁止路径分隔符及控制字符。
25+
/// 允许 Unicode 字母、数字、下划线、短横线(支持中文等多语言命名)。
26+
/// 禁止路径分隔符、控制字符及可能造成问题的特殊符号。
2627
fn validate_name(name: &str) -> anyhow::Result<()> {
2728
if name.is_empty() {
2829
return Err(ng_core::error::NodegetError::InvalidInput("name cannot be empty".to_owned()).into());
2930
}
30-
if name.len() > 128 {
31+
if name.chars().count() > 128 {
3132
return Err(ng_core::error::NodegetError::InvalidInput("name too long (max 128 chars)".to_owned()).into());
3233
}
33-
let valid = name
34-
.chars()
35-
.all(|c| c.is_ascii_alphanumeric() || c == '_' || c == '-');
34+
let valid = name.chars().all(|c| {
35+
// 允许:Unicode 字母/数字(含中文)、下划线、短横线
36+
c.is_alphanumeric() || c == '_' || c == '-'
37+
});
3638
if !valid {
3739
return Err(ng_core::error::NodegetError::InvalidInput(
38-
"name contains invalid characters (only [A-Za-z0-9_-] are allowed)".to_owned(),
40+
"name contains invalid characters (alphanumeric, underscore, hyphen allowed)".to_owned(),
3941
)
4042
.into());
4143
}
@@ -208,6 +210,16 @@ mod tests {
208210
assert!(validate_name(&name).is_ok());
209211
}
210212

213+
#[test]
214+
fn validate_name_accepts_chinese() {
215+
assert!(validate_name("电信ping").is_ok());
216+
}
217+
218+
#[test]
219+
fn validate_name_accepts_mixed_chinese_ascii() {
220+
assert!(validate_name("定时任务_1").is_ok());
221+
}
222+
211223
// ── validate_name: empty ──────────────────────────────────────
212224

213225
#[test]
@@ -259,8 +271,9 @@ mod tests {
259271
}
260272

261273
#[test]
262-
fn validate_name_rejects_unicode() {
263-
assert!(validate_name("定时任务").is_err());
274+
fn validate_name_rejects_unicode_symbols() {
275+
// Unicode 符号(非字母数字)仍应被拒绝
276+
assert!(validate_name("任务❌").is_err());
264277
}
265278

266279
#[test]

crates/ng-token/src/super_token.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use crate::hash_to_bytes;
2727
/// - 错误:数据库插入失败(通常因 ID=1 唯一约束冲突)
2828
async fn insert_new_super_token(
2929
db: &sea_orm::DatabaseConnection,
30-
) -> anyhow::Result<(String, String)> {
30+
) -> Result<(String, String), sea_orm::DbErr> {
3131
let token_key = generate_random_string(16);
3232
let token_secret = generate_random_string(32);
3333
let full_token = format!("{token_key}:{token_secret}");
@@ -50,12 +50,7 @@ async fn insert_new_super_token(
5050
password_hash: Set(Some(password_hash)),
5151
};
5252

53-
token::Entity::insert(super_token_model)
54-
.exec(db)
55-
.await
56-
.map_err(|e| {
57-
NodegetError::DatabaseError(format!("Failed to initialize super token: {e}"))
58-
})?;
53+
token::Entity::insert(super_token_model).exec(db).await?;
5954

6055
debug!(target: "token", "Super token inserted into database");
6156
Ok((full_token, raw_password))
@@ -82,15 +77,22 @@ pub async fn generate_super_token() -> anyhow::Result<Option<(String, String)>>
8277
}
8378
Ok(Some(result))
8479
}
85-
Err(e) => {
86-
// 判断是否为唯一约束冲突(SQLite 和 PostgreSQL 的错误消息不同)
87-
let error_msg = format!("{e}");
88-
if error_msg.contains("UNIQUE constraint failed") || error_msg.contains("duplicate key")
89-
{
80+
Err(db_err) => {
81+
// 使用 SeaORM 的 sql_err() 精确判断唯一约束冲突,
82+
// 不依赖错误消息字符串(PostgreSQL 中文 locale 下消息不含 "duplicate key")
83+
let is_unique_violation = matches!(
84+
db_err.sql_err(),
85+
Some(sea_orm::SqlErr::UniqueConstraintViolation(_))
86+
);
87+
88+
if is_unique_violation {
9089
debug!(target: "token", "Super token already exists, skipping generation");
9190
Ok(None)
9291
} else {
93-
Err(e)
92+
Err(NodegetError::DatabaseError(format!(
93+
"Failed to initialize super token: {db_err}"
94+
))
95+
.into())
9496
}
9597
}
9698
}

0 commit comments

Comments
 (0)