Skip to content

Commit 439a81f

Browse files
committed
refactor!(napi): use EngineId instead of our enum
* Supported executor.list() to get all available engines * Engine is no longer present
1 parent 7b83e1e commit 439a81f

6 files changed

Lines changed: 13 additions & 44 deletions

File tree

napi/demo/demo.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ async function main() {
66
UNM.enableLogging(UNM.LoggingType.ConsoleEnv);
77
const executor = new UNM.Executor();
88

9+
console.log(`Enabled engines: ${executor.list().join(", ")}`);
910
const searchResult = await executor.search(
10-
Object.values(UNM.Engine),
11+
executor.list(),
1112
{
1213
id: "12345",
1314
name: "青花瓷",

napi/index.d.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,6 @@
33

44
/* auto-generated by NAPI-RS */
55

6-
export const enum Engine {
7-
Bilibili = 0,
8-
Kugou = 1,
9-
Migu = 2,
10-
PyNCM = 3,
11-
YtDl = 4,
12-
Kuwo = 5
13-
}
146
/** [napi-rs] The metadata of the artist of a song. */
157
export interface Artist {
168
/** The identifier of this artist. */
@@ -91,6 +83,7 @@ export function enableLogging(logType: LoggingType): void
9183
export type JsExecutor = Executor
9284
export class Executor {
9385
constructor()
94-
search(engines: Array<Engine>, song: Song, ctx: Context): Promise<SongSearchInformation>
86+
list(): Array<string>
87+
search(engines: Array<string>, song: Song, ctx: Context): Promise<SongSearchInformation>
9588
retrieve(song: SongSearchInformation, ctx: Context): Promise<RetrievedSongInfo>
9689
}

napi/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,8 @@ if (!nativeBinding) {
236236
throw new Error(`Failed to load native binding`)
237237
}
238238

239-
const { Engine, Executor, LoggingType, enableLogging } = nativeBinding
239+
const { Executor, LoggingType, enableLogging } = nativeBinding
240240

241-
module.exports.Engine = Engine
242241
module.exports.Executor = Executor
243242
module.exports.LoggingType = LoggingType
244243
module.exports.enableLogging = enableLogging

napi/src/engines.rs

Lines changed: 0 additions & 25 deletions
This file was deleted.

napi/src/executor.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ use napi_derive::napi;
44
use std::{borrow::Cow, sync::Arc};
55
use unm_engine::executor::Executor;
66

7-
use crate::{
8-
engines::Engine,
9-
types::{Context, RetrievedSongInfo, Song, SongSearchInformation},
10-
};
7+
use crate::types::{Context, RetrievedSongInfo, Song, SongSearchInformation};
118

129
#[napi(js_name = "Executor")]
1310
pub struct JsExecutor {
@@ -21,16 +18,21 @@ impl JsExecutor {
2118
Self::default()
2219
}
2320

21+
#[napi]
22+
pub fn list(&self) -> Vec<&str> {
23+
self.executor.list()
24+
}
25+
2426
#[napi]
2527
pub async fn search(
2628
&self,
27-
engines: Vec<Engine>,
29+
engines: Vec<String>,
2830
song: Song,
2931
ctx: Context,
3032
) -> Result<SongSearchInformation> {
3133
let engines = engines
3234
.into_iter()
33-
.map(|engine| engine.as_str().into())
35+
.map(|engine| engine.into())
3436
.collect::<Vec<Cow<'static, str>>>();
3537

3638
self

napi/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
pub mod engines;
21
pub mod executor;
32
pub mod types;
43

0 commit comments

Comments
 (0)