lx-source-type 2.0.0 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/define.d.ts +4 -4
  2. package/package.json +3 -2
  3. package/type.d.ts +166 -0
package/define.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { LX } from "./type"
2
-
3
- declare global {
4
- var lx: LX.API
1
+ import type { LX } from "./type"
2
+
3
+ declare global {
4
+ var lx: LX.API
5
5
  }
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "lx-source-type",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "type": "module",
5
5
  "author": "Ceale",
6
6
  "license": "MIT",
7
+ "repository": "https://github.com/Ceale/lx-source-type.git",
7
8
  "exports": {
8
9
  ".": {
9
10
  "types": "./type.d.ts"
@@ -14,7 +15,7 @@
14
15
  },
15
16
  "files": [
16
17
  "README.md",
17
- "index.d.ts",
18
+ "type.d.ts",
18
19
  "define.d.ts"
19
20
  ],
20
21
  "peerDependencies": {
package/type.d.ts ADDED
@@ -0,0 +1,166 @@
1
+ import type { WithImplicitCoercion } from "node:buffer"
2
+ import type Zlib from "node:zlib"
3
+
4
+ /**
5
+ * LX Music 自定义源 API 类型定义
6
+ */
7
+ export declare namespace LX {
8
+ export type Quality = "128k" | "320k" | "flac" | "flac24bit"
9
+ export type NetAction = "musicUrl" | "lyric" | "pic"
10
+ export type SupportPlatform = "kw" | "kg" | "tx" | "wy" | "mg" | "local"
11
+
12
+ export interface MusicInfo {
13
+ name: string
14
+ singer: string
15
+ interval: string
16
+
17
+ source: SupportPlatform
18
+ songmid: string
19
+
20
+ img: string
21
+ albumName: string
22
+
23
+ /** 仅限酷狗 */
24
+ hash?: string
25
+ /** 仅限咪咕 */
26
+ copyrightId?: string
27
+
28
+ [key: string]: any
29
+ }
30
+
31
+ export interface LyricResult {
32
+ lyric: string
33
+ tlyric?: string | null
34
+ rlyric?: string | null
35
+ lxlyric?: string | null
36
+ }
37
+
38
+ export interface RequestOptions {
39
+ /** 默认为 Get */
40
+ method?: string
41
+ headers?: Record<string, string>
42
+ body?: any
43
+ form?: Record<string, any>
44
+ formData?: Record<string, any>
45
+ timeout?: number
46
+ }
47
+
48
+ export interface RequestResponse {
49
+ statusCode: number
50
+ statusMessage: string
51
+ headers: Record<string, string | string[] | undefined>
52
+ bytes?: number,
53
+ raw?: Uint8Array,
54
+ body: any
55
+ }
56
+
57
+ export interface SourceInfo {
58
+ name: string
59
+ type: "music"
60
+ actions: NetAction[]
61
+ qualitys: Quality[]
62
+ }
63
+
64
+ export interface InitedPayload {
65
+ sources: Partial<Record<SupportPlatform, SourceInfo>>
66
+ openDevTools?: boolean
67
+ }
68
+
69
+ export interface UpdateAlertPayload {
70
+ log: string
71
+ updateUrl?: string
72
+ }
73
+
74
+ export interface Provider {
75
+ (params: ProviderParams): Promise<ProviderResult>
76
+ }
77
+
78
+ export interface ProviderParams {
79
+ source: SupportPlatform
80
+ action: NetAction
81
+ info: {
82
+ type?: Quality | null
83
+ musicInfo: MusicInfo
84
+ }
85
+ }
86
+
87
+ export type ProviderResult = string | {
88
+ lyric: string,
89
+ tlyric: string | null
90
+ rlyric: string | null
91
+ lxlyric: string | null
92
+ }
93
+
94
+ export interface EVENT_NAMES {
95
+ inited: "inited"
96
+ request: "request"
97
+ updateAlert: "updateAlert"
98
+ }
99
+
100
+ export interface Utils {
101
+ buffer: {
102
+ from: typeof Buffer.from
103
+ bufToString(buffer: WithImplicitCoercion<ArrayLike<number> | string>, format: BufferEncoding): string
104
+ }
105
+ crypto: {
106
+ aesEncrypt(buffer: BinaryLike, mode: string, key: string, iv: string): Buffer
107
+ rsaEncrypt(buffer: any, key: string): Buffer
108
+ randomBytes(size: number): Uint8Array
109
+ /** 返回 hex 字符串 */
110
+ md5(str: string): string
111
+ }
112
+ zlib: {
113
+ inflate(buffer: Zlib.InputType): Promise<NonSharedBuffer>
114
+ deflate(buffer: Zlib.InputType): Promise<NonSharedBuffer>
115
+ }
116
+ }
117
+
118
+ /** 当前脚本信息 */
119
+ export interface ScriptInfo {
120
+ name: string
121
+ description: string
122
+ version: string
123
+ author: string
124
+ homepage: string
125
+ rawScript: string
126
+ }
127
+
128
+ export interface RequestCallback {
129
+ (err: null, resp: RequestResponse | null, body: any): void
130
+ }
131
+
132
+ export interface OnEvent {
133
+ (eventName: EVENT_NAMES["request"], handler: Provider): Promise<void>
134
+ }
135
+
136
+ export interface SendEvent {
137
+ (eventName: EVENT_NAMES["inited"], data: InitedPayload): Promise<void>
138
+ (eventName: EVENT_NAMES["updateAlert"], data: UpdateAlertPayload): Promise<void>
139
+ }
140
+
141
+ export interface Request {
142
+ (
143
+ url: string,
144
+ options: RequestOptions,
145
+ callback: RequestCallback
146
+ ): () => void
147
+ }
148
+
149
+ export interface API {
150
+ /** API 版本号 */
151
+ version: "2.0.0"
152
+ /** 运行环境 */
153
+ env: "desktop" | "mobile"
154
+ currentScriptInfo: ScriptInfo
155
+ /** 常量事件名 */
156
+ EVENT_NAMES: EVENT_NAMES
157
+ /** 注册事件监听 */
158
+ on: OnEvent
159
+ /** 发送事件 */
160
+ send: SendEvent
161
+ /** HTTP 请求方法 */
162
+ request: Request
163
+ /** 工具方法 */
164
+ utils: Utils
165
+ }
166
+ }