feat: support config.showHidden

This commit is contained in:
Shigma 2023-01-12 00:31:33 +08:00
parent 3d45f4cf81
commit 4efbf232e4
No known key found for this signature in database
GPG Key ID: 414458B84ACF8744
2 changed files with 15 additions and 12 deletions

View File

@ -1,7 +1,7 @@
{
"name": "koishi-plugin-market-info",
"description": "Koishi plugin market information",
"version": "1.1.0",
"version": "1.1.1",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"files": [
@ -43,10 +43,10 @@
"koishi": "^4.10.5"
},
"devDependencies": {
"@koishijs/registry": "^4.2.1",
"@types/node": "^17.0.45",
"@koishijs/registry": "^4.3.2",
"@types/node": "^18.11.18",
"atsc": "^1.2.2",
"koishi": "^4.10.10",
"koishi": "^4.11.1",
"typescript": "^4.9.4"
}
}

View File

@ -22,26 +22,29 @@ export const Rule: Schema<Rule> = Schema.object({
export interface Config {
rules: Rule[]
interval: number
showHidden: boolean
showDeletion: boolean
}
export const Config: Schema<Config> = Schema.object({
rules: Schema.array(Rule).description('推送规则。'),
interval: Schema.number().default(Time.minute * 30).description('轮询间隔 (毫秒)。'),
showHidden: Schema.boolean().default(false).description('是否显示隐藏的插件。'),
showDeletion: Schema.boolean().default(false).description('是否显示删除的插件。'),
})
function makeDict(result: MarketResult) {
const dict: Dict<AnalyzedPackage> = {}
for (const object of result.objects) {
dict[object.shortname] = object
}
return dict
}
export function apply(ctx: Context, config: Config) {
ctx.i18n.define('zh', require('./locales/zh-CN'))
const makeDict = (result: MarketResult) => {
const dict: Dict<AnalyzedPackage> = {}
for (const object of result.objects) {
if (object.manifest.hidden && !config.showHidden) continue
dict[object.shortname] = object
}
return dict
}
const getMarket = async () => {
const data = await ctx.http.get<MarketResult>('https://registry.koishi.chat/market.json')
return makeDict(data)