feat: support config.showHidden
This commit is contained in:
		
							parent
							
								
									3d45f4cf81
								
							
						
					
					
						commit
						4efbf232e4
					
				| @ -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" | ||||
|   } | ||||
| } | ||||
|  | ||||
							
								
								
									
										19
									
								
								src/index.ts
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								src/index.ts
									
									
									
									
									
								
							| @ -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) | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user