* feat(core): 添加 Bing 搜索推送功能 - 在 errorCode.constant.ts 中添加 Bing 相关的错误代码 - 在 configs.dto.ts 中添加 BingSearchOptionDto 类用于配置 Bing 推送选项 - 在 helper.cron.service.ts 中实现 pushToBingSearch 方法进行 Bing 搜索推送 * feat(core): 添加必应搜索推送配置并优化相关功能 - 在默认配置中添加 bingSearchOptions 项 - 更新 BingSearchOptionDto 类,统一字段命名 - 在 IConfig 接口中添加 bingSearchOptions 字段 - 修改 CronService 中的 pushToBingSearch 方法,适配新配置 * build: 更新下载资源链接 - 将 CDN 下载 URL 从 `https://mirror.ghproxy.com/` 更改为 `https://ghfast.top/` * feat(api-client): 添加 Bing 搜索配置模型 - 新增 BingSearchOptionsModel 类,用于 Bing 搜索的配置选项 - 该模型包括 enable 和 token 两个属性,与 BaiduSearchOptionsModel 类似 * refactor(configs): 统一配置类命名规则 - 将 BingSearchOptionDto 重命名为 BingSearchOptionsDto,与 BaiduSearchOptionsDto 保持一致 - 更新相关引用和配置字段类型 * feat(core): 添加每日凌晨1点执行的 Bing 搜索推送任务 - 在 CronService 类中添加了 pushToBingSearch 方法 - 使用 @CronOnce 装饰器设置任务执行时间为每天凌晨1点 - 任务名称为 'pushToBingSearch' - 方法描述为 '推送到Bing' * chore: 添加.eslintcache到.gitignore - 在.gitignore文件中添加.eslintcache,避免eslint缓存文件被版本控制 * feat(docs): 更新readme * refactor(core): 优化 Bing 站长提交日志输出 - 修改了 Bing 站长提交结果的日志输出格式 - 当提交成功时,输出简短的成功日志 - 当提交失败时,仍输出详细的错误信息 * Update apps/core/src/processors/helper/helper.cron.service.ts Co-authored-by: Innei <tukon479@gmail.com> Signed-off-by: Teror Fox <i@trfox.top> * chore: 删除废弃的服务器部署脚本 * feat(core): 添加 Bing API 域名无效错误码 - 在 ErrorCodeEnum 枚举中添加 BingDomainInvalid 错误码 - 在 ErrorCode 对象中添加对应的错误信息和状态码 * refactor(core): 修复 Bing 推送异常时返回值问题 --------- Signed-off-by: Teror Fox <i@trfox.top> Co-authored-by: Innei <tukon479@gmail.com>
MApi Client
这是一个适用于 MServer v3 的 JS SDK,封装了常用接口请求方法以及返回类型的声明,以快速开发前端应用。
迁移到 v1
不再提供 camelcase-keys 的 re-export,此库不再依赖 camelcase-keys 库,如有需要可自行安装。
- import { camelcaseKeysDeep, camelcaseKeys } from '@mx-space/api-client'
+ import { simpleCamelcaseKeys as camelcaseKeysDeep } from '@mx-space/api-client'
如何使用
此 SDK 框架无关,不捆绑任何一个网络请求库,只需要提供适配器。你需要手动传入符合接口标准的适配器。
此项目提供 axios 和 umi-request 两个适配器。
以 axios 为例。
import {
AggregateController,
CategoryController,
NoteController,
PostController,
allControllers, // ...
createClient,
} from '@mx-space/api-client'
import { axiosAdaptor } from '@mx-space/api-client/adaptors/axios'
const endpoint = 'https://api.innei.dev/v2'
const client = createClient(axiosAdaptor)(endpoint)
// `default` is AxiosInstance
// you can do anything else on this
// interceptor or re-configure
const $axios = axiosAdaptor.default
// re-config (optional)
$axios.defaults.timeout = 10000
// set interceptors (optional)
$axios.interceptors.request.use(
(config) => {
const token = getToken()
if (token) {
config.headers!['Authorization'] = 'bearer ' + getToken()
}
return config
},
(error) => {
if (__DEV__) {
console.log(error.message)
}
return Promise.reject(error)
},
)
// inject controller first.
client.injectControllers([
PostController,
NoteController,
AggregateController,
CategoryController,
])
// or you can inject allControllers
client.injectControllers(allControllers)
// then you can request `post` `note` and `aggregate` controller
client.post.post.getList(page, 10, { year }).then((data) => {
// do anything
})
为什么要手动注入控制器
按需加载,可以减少打包体积 (Tree Shake)
为什么不依赖请求库
可以防止项目中出现两个请求库,减少打包体积
如果不使用 axios,应该如何编写适配器
参考 src/adaptors/axios.ts 和 src/adaptors/umi-request.ts
如何使用 proxy 来访问 sdk 内未包含的请求
如请求 GET /notes/something/other/123456/info,可以使用
client.note.proxy.something.other('123456').info.get()
从 proxy 获取请求地址但不发出
client.note.proxy.something.other('123456').info.toString() // /notes/something/other/123456/info
client.note.proxy.something.other('123456').info.toString(true) // http://localhost:2333/notes/something/other/123456/info