自定义源新增`version`字段,新增`utils.buffer.bufToString`方法

pull/733/head
lyswhut 2021-10-07 12:28:03 +08:00
parent 68518e609d
commit d4240006f1
3 changed files with 16 additions and 3 deletions

9
FAQ.md
View File

@ -344,8 +344,8 @@ send(EVENT_NAMES.inited, {
``` ```
- `@name `:源的名字,建议不要过长,10个字符以内 - `@name `:源的名字,建议不要过长,24个字符以内
- `@description `:源的描述,建议不要过长,20个字符以内,可不填,不填时必须保留 @description - `@description `:源的描述,建议不要过长,36个字符以内,可不填,不填时必须保留 @description
- `@version`:源的版本号,可不填,不填时可以删除 @version - `@version`:源的版本号,可不填,不填时可以删除 @version
- `@author `:脚本作者名字,可不填,不填时可以删除 @author - `@author `:脚本作者名字,可不填,不填时可以删除 @author
- `@homepage `:脚本主页,可不填,不填时可以删除 @homepage - `@homepage `:脚本主页,可不填,不填时可以删除 @homepage
@ -354,6 +354,10 @@ send(EVENT_NAMES.inited, {
应用为脚本暴露的API对象。 应用为脚本暴露的API对象。
#### `window.lx.version`
自定义源API版本API变更时此版本号将会更改新增于v1.14.0之后)
#### `window.lx.EVENT_NAMES` #### `window.lx.EVENT_NAMES`
常量事件名称对象,发送、注册事件时传入事件名时使用,可用值: 常量事件名称对象,发送、注册事件时传入事件名时使用,可用值:
@ -409,6 +413,7 @@ const cancelHttp = window.lx.request(url, options, callback)
应用提供给脚本的工具方法: 应用提供给脚本的工具方法:
- `window.lx.utils.buffer.from`对应Node.js的 `Buffer.from` - `window.lx.utils.buffer.from`对应Node.js的 `Buffer.from`
- `window.lx.utils.buffer.bufToString`Buffer转字符串 `bufToString(buffer, format)``format`对应Node.js `Buffer.toString`的参数v1.14.0之后新增)
- `window.lx.utils.crypto.aesEncrypt`AES加密 `aesEncrypt(buffer, mode, key, iv)` - `window.lx.utils.crypto.aesEncrypt`AES加密 `aesEncrypt(buffer, mode, key, iv)`
- `window.lx.utils.crypto.md5`MD5加密 `md5(str)` - `window.lx.utils.crypto.md5`MD5加密 `md5(str)`
- `window.lx.utils.crypto.randomBytes`:生成随机字符串 `randomBytes(size)` - `window.lx.utils.crypto.randomBytes`:生成随机字符串 `randomBytes(size)`

View File

@ -1,3 +1,7 @@
### 新增
- 自定义源新增`version`字段,新增`utils.buffer.bufToString`方法
### 优化 ### 优化
- 优化列表同步代码逻辑 - 优化列表同步代码逻辑

View File

@ -185,7 +185,7 @@ contextBridge.exposeInMainWorld('lx', {
utils: { utils: {
crypto: { crypto: {
aesEncrypt(buffer, mode, key, iv) { aesEncrypt(buffer, mode, key, iv) {
const cipher = createCipheriv('aes-128-' + mode, key, iv) const cipher = createCipheriv(mode, key, iv)
return Buffer.concat([cipher.update(buffer), cipher.final()]) return Buffer.concat([cipher.update(buffer), cipher.final()])
}, },
rsaEncrypt(buffer, key) { rsaEncrypt(buffer, key) {
@ -203,8 +203,12 @@ contextBridge.exposeInMainWorld('lx', {
from(...args) { from(...args) {
return Buffer.from(...args) return Buffer.from(...args)
}, },
bufToString(buf, format) {
return Buffer.from(buf, 'binary').toString(format)
},
}, },
}, },
version: '1.1.0',
// removeEvent(eventName, handler) { // removeEvent(eventName, handler) {
// if (!eventNames.includes(eventName)) return Promise.reject(new Error('The event is not supported: ' + eventName)) // if (!eventNames.includes(eventName)) return Promise.reject(new Error('The event is not supported: ' + eventName))
// let handlers // let handlers