Skip to content

Commit 7b194ea

Browse files
committed
feat: 重命名为 ncm-api-rs,添加发版工作流,更新 README
- crate 名称从 ncm-api 改为 ncm-api-rs - 添加 release.yml 多平台编译发布工作流 - 添加 publish.yml crates.io 发布工作流 - README 新增安装方式、预编译下载说明及新接口文档
1 parent 41010e6 commit 7b194ea

11 files changed

Lines changed: 187 additions & 18 deletions

File tree

.github/workflows/publish.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Publish to crates.io
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
env:
9+
CARGO_TERM_COLOR: always
10+
11+
jobs:
12+
publish:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- name: Install Rust toolchain
19+
run: rustup toolchain install stable --profile minimal
20+
21+
- name: Verify version matches tag
22+
run: |
23+
CARGO_VERSION=$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/')
24+
TAG_VERSION="${GITHUB_REF_NAME#v}"
25+
if [ "$CARGO_VERSION" != "$TAG_VERSION" ]; then
26+
echo "::error::Cargo.toml version ($CARGO_VERSION) does not match tag ($TAG_VERSION)"
27+
exit 1
28+
fi
29+
30+
- name: Publish to crates.io
31+
run: cargo publish
32+
env:
33+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

.github/workflows/release.yml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
permissions:
9+
contents: write
10+
11+
env:
12+
CARGO_TERM_COLOR: always
13+
BINARY_NAME: ncm-server
14+
15+
jobs:
16+
build:
17+
strategy:
18+
matrix:
19+
include:
20+
- target: x86_64-unknown-linux-gnu
21+
os: ubuntu-latest
22+
archive: tar.gz
23+
- target: aarch64-unknown-linux-gnu
24+
os: ubuntu-latest
25+
archive: tar.gz
26+
- target: x86_64-apple-darwin
27+
os: macos-latest
28+
archive: tar.gz
29+
- target: aarch64-apple-darwin
30+
os: macos-latest
31+
archive: tar.gz
32+
- target: x86_64-pc-windows-msvc
33+
os: windows-latest
34+
archive: zip
35+
36+
runs-on: ${{ matrix.os }}
37+
38+
steps:
39+
- uses: actions/checkout@v4
40+
41+
- name: Install Rust toolchain
42+
run: |
43+
rustup toolchain install stable --profile minimal
44+
rustup target add ${{ matrix.target }}
45+
46+
- name: Install cross-compilation tools (Linux aarch64)
47+
if: matrix.target == 'aarch64-unknown-linux-gnu'
48+
run: |
49+
sudo apt-get update
50+
sudo apt-get install -y gcc-aarch64-linux-gnu
51+
echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
52+
53+
- name: Build
54+
run: cargo build --release --features server --target ${{ matrix.target }}
55+
56+
- name: Package (Unix)
57+
if: matrix.archive == 'tar.gz'
58+
run: |
59+
cd target/${{ matrix.target }}/release
60+
tar czf ../../../${{ env.BINARY_NAME }}-${{ github.ref_name }}-${{ matrix.target }}.tar.gz ${{ env.BINARY_NAME }}
61+
62+
- name: Package (Windows)
63+
if: matrix.archive == 'zip'
64+
shell: pwsh
65+
run: |
66+
Compress-Archive -Path "target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}.exe" -DestinationPath "${{ env.BINARY_NAME }}-${{ github.ref_name }}-${{ matrix.target }}.zip"
67+
68+
- name: Upload artifact
69+
uses: actions/upload-artifact@v4
70+
with:
71+
name: ${{ matrix.target }}
72+
path: ${{ env.BINARY_NAME }}-${{ github.ref_name }}-${{ matrix.target }}.*
73+
74+
release:
75+
needs: build
76+
runs-on: ubuntu-latest
77+
78+
steps:
79+
- uses: actions/checkout@v4
80+
81+
- name: Download all artifacts
82+
uses: actions/download-artifact@v4
83+
with:
84+
path: artifacts
85+
merge-multiple: true
86+
87+
- name: Create GitHub Release
88+
uses: softprops/action-gh-release@v2
89+
with:
90+
generate_release_notes: true
91+
files: artifacts/*

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "ncm-api"
2+
name = "ncm-api-rs"
33
version = "0.1.0"
44
edition = "2021"
55
description = "Netease Cloud Music API Rust SDK"

README.md

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
**网易云音乐 API Rust 原生实现**
66

77
[![Rust](https://img.shields.io/badge/Rust-1.70+-orange?logo=rust)](https://www.rust-lang.org/)
8+
[![Crates.io](https://img.shields.io/crates/v/ncm-api-rs.svg)](https://crates.io/crates/ncm-api-rs)
9+
[![GitHub Release](https://img.shields.io/github/v/release/imsyy/ncm-api-rs)](https://github.com/imsyy/ncm-api-rs/releases)
810
[![License](https://img.shields.io/badge/license-WTFPL-brightgreen.svg)](LICENSE)
911
[![Tokio](https://img.shields.io/badge/async-tokio-blue?logo=rust)](https://tokio.rs/)
1012

@@ -37,26 +39,56 @@
3739

3840
### 安装
3941

40-
`Cargo.toml` 中添加依赖:
42+
#### 作为 Rust 库依赖
4143

4244
```toml
4345
[dependencies]
44-
ncm-api = { git = "https://github.com/imsyy/ncm-api-rs.git" }
46+
ncm-api-rs = "0.1"
4547
tokio = { version = "1", features = ["full"] }
4648
```
4749

48-
或使用本地路径(开发时)
50+
或从 Git 安装最新版
4951

5052
```toml
5153
[dependencies]
52-
ncm-api = { path = "../rust-sdk" }
54+
ncm-api-rs = { git = "https://github.com/imsyy/ncm-api-rs.git" }
5355
tokio = { version = "1", features = ["full"] }
5456
```
5557

58+
#### 安装 HTTP 服务器
59+
60+
通过 cargo 安装:
61+
62+
```bash
63+
cargo install ncm-api-rs --features server
64+
```
65+
66+
或从 [GitHub Releases](https://github.com/imsyy/ncm-api-rs/releases) 下载预编译二进制文件,支持以下平台:
67+
68+
| 平台 | 架构 | 文件 |
69+
|------|------|------|
70+
| Linux | x64 | `ncm-server-vX.X.X-x86_64-unknown-linux-gnu.tar.gz` |
71+
| Linux | ARM64 | `ncm-server-vX.X.X-aarch64-unknown-linux-gnu.tar.gz` |
72+
| macOS | x64 | `ncm-server-vX.X.X-x86_64-apple-darwin.tar.gz` |
73+
| macOS | Apple Silicon | `ncm-server-vX.X.X-aarch64-apple-darwin.tar.gz` |
74+
| Windows | x64 | `ncm-server-vX.X.X-x86_64-pc-windows-msvc.zip` |
75+
76+
下载后解压即可运行:
77+
78+
```bash
79+
# Linux / macOS
80+
tar xzf ncm-server-*.tar.gz
81+
./ncm-server
82+
83+
# Windows
84+
# 解压 zip 后双击 ncm-server.exe 或在终端运行
85+
ncm-server.exe
86+
```
87+
5688
### 基础使用
5789

5890
```rust
59-
use ncm_api::{create_client, Query};
91+
use ncm_api_rs::{create_client, Query};
6092

6193
#[tokio::main]
6294
async fn main() {
@@ -93,7 +125,7 @@ async fn main() {
93125
### 带 Cookie 使用(登录后的接口)
94126

95127
```rust
96-
use ncm_api::{create_client, Query};
128+
use ncm_api_rs::{create_client, Query};
97129

98130
#[tokio::main]
99131
async fn main() {
@@ -226,11 +258,14 @@ cargo build --release --features server --bin ncm-server
226258
|--------|------|--------|
227259
| `NCM_HOST` | 监听地址 | `0.0.0.0` |
228260
| `NCM_PORT` | 监听端口 | `3000` |
229-
| `CORS_ALLOW_ORIGIN` | CORS 允许的 Origin | `*`(允许所有) |
261+
| `CORS_ALLOW_ORIGIN` | CORS 允许的 Origin,支持逗号分隔多个源 | `*`(允许所有) |
230262

231263
```bash
232264
# 示例:自定义端口和 CORS
233265
NCM_HOST=127.0.0.1 NCM_PORT=8080 CORS_ALLOW_ORIGIN=http://localhost:5173 cargo run --features server --bin ncm-server
266+
267+
# 示例:允许多个源
268+
CORS_ALLOW_ORIGIN=https://a.com,https://b.com cargo run --features server --bin ncm-server
234269
```
235270

236271
### 前端调用示例
@@ -275,7 +310,7 @@ const res = await axios.get('/user/playlist', {
275310
如果你已有 Axum 项目,可以直接集成路由:
276311

277312
```rust
278-
use ncm_api::{create_client, server::{build_app, build_app_with_config, ServerConfig}};
313+
use ncm_api_rs::{create_client, server::{build_app, build_app_with_config, ServerConfig}};
279314

280315
// 方式一:快速构建
281316
let app = build_app(create_client(None));
@@ -391,6 +426,7 @@ axum::serve(listener, app).await?;
391426
| `lyric` | 歌词 |
392427
| `lyric_new` | 逐字歌词 |
393428
| `like` | 喜欢音乐 |
429+
| `song_like` | 喜欢歌曲(新版) |
394430
| `likelist` | 喜欢的音乐列表 |
395431
| `song_like_check` | 歌曲是否喜爱 |
396432
| `scrobble` | 听歌打卡 |
@@ -423,6 +459,7 @@ axum::serve(listener, app).await?;
423459
| `search_hot` | 热搜列表(简略) |
424460
| `search_hot_detail` | 热搜列表(详细) |
425461
| `search_suggest` | 搜索建议 |
462+
| `search_suggest_pc` | 搜索建议(PC端) |
426463
| `search_multimatch` | 搜索多重匹配 |
427464
| `search_match` | 搜索匹配 |
428465

@@ -480,6 +517,8 @@ axum::serve(listener, app).await?;
480517
| `comment_hot` | 热门评论 |
481518
| `comment_like` | 点赞评论 |
482519
| `comment_new` | 新版评论 |
520+
| `comment_reply` | 回复评论 |
521+
| `comment_delete` | 删除评论 |
483522
| `comment_hug_list` | 抱一抱列表 |
484523
| `comment_info_list` | 评论统计 |
485524
| `hug_comment` | 抱一抱评论 |
@@ -596,6 +635,11 @@ axum::serve(listener, app).await?;
596635
| `dj_toplist_newcomer` | 电台新人榜 |
597636
| `dj_toplist_pay` | 付费电台榜 |
598637
| `dj_toplist_popular` | 电台热门榜 |
638+
| `dj_difm_all_style_channel` | DIFM电台 - 分类 |
639+
| `dj_difm_channel_subscribe` | DIFM电台 - 收藏频道 |
640+
| `dj_difm_channel_unsubscribe` | DIFM电台 - 取消收藏频道 |
641+
| `dj_difm_playing_tracks_list` | DIFM电台 - 播放列表 |
642+
| `dj_difm_subscribe_channels_get` | DIFM电台 - 收藏列表 |
599643
| `dj_paygift` | 付费精品 |
600644
| `dj_today_perfered` | 今日优选 |
601645
| `dj_radio_top` | 电台排行 |
@@ -788,6 +832,7 @@ axum::serve(listener, app).await?;
788832
| `voice_lyric` | 音频歌词 |
789833
| `voicelist_list` | 声音列表 |
790834
| `voicelist_detail` | 声音列表详情 |
835+
| `voicelist_my_created` | 我创建的播客声音 |
791836
| `voicelist_search` | 搜索声音列表 |
792837
| `voicelist_list_search` | 搜索声音 |
793838
| `voicelist_trans` | 声音转换 |

examples/basic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/// 使用示例:搜索歌曲并获取播放链接
22
///
33
/// 运行: cargo run --example basic
4-
use ncm_api::{create_client, Query};
4+
use ncm_api_rs::{create_client, Query};
55

66
#[tokio::main]
77
async fn main() {

examples/search_test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/// 搜索测试 - 打印原始响应查看数据
22
///
33
/// 运行: cargo run --example search_test
4-
use ncm_api::{create_client, Query};
4+
use ncm_api_rs::{create_client, Query};
55

66
#[tokio::main]
77
async fn main() {
@@ -64,7 +64,7 @@ async fn main() {
6464
Err(e) => {
6565
eprintln!("❌ 搜索失败: {}", e);
6666
// 如果是 API 错误,尝试打印详细信息
67-
if let ncm_api::NcmError::Api { code, msg } = &e {
67+
if let ncm_api_rs::NcmError::Api { code, msg } = &e {
6868
eprintln!(" code={}, msg={}", code, msg);
6969
}
7070
}

src/bin/server.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use ncm_api::server::{start_server, ServerConfig};
1+
use ncm_api_rs::server::{start_server, ServerConfig};
22

33
#[tokio::main]
44
async fn main() {
@@ -7,7 +7,7 @@ async fn main() {
77
tracing_subscriber::fmt()
88
.with_env_filter(
99
tracing_subscriber::EnvFilter::try_from_default_env()
10-
.unwrap_or_else(|_| "ncm_api=info".into()),
10+
.unwrap_or_else(|_| "ncm_api_rs=info".into()),
1111
)
1212
.init();
1313

tests/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/// Error 类型测试
2-
use ncm_api::NcmError;
2+
use ncm_api_rs::NcmError;
33

44
#[test]
55
fn test_error_from_api_auth() {

tests/integration.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/// 集成测试 - 验证关键接口能正常请求网易云 API
22
///
33
/// 注意:这些测试会发起真实网络请求,CI 环境中可能需要跳过
4-
use ncm_api::{create_client, Query};
4+
use ncm_api_rs::{create_client, Query};
55

66
#[tokio::test]
77
async fn test_banner() {

0 commit comments

Comments
 (0)