feat: support config.showHidden
This commit is contained in:
		
							parent
							
								
									3d45f4cf81
								
							
						
					
					
						commit
						4efbf232e4
					
				| @ -1,7 +1,7 @@ | |||||||
| { | { | ||||||
|   "name": "koishi-plugin-market-info", |   "name": "koishi-plugin-market-info", | ||||||
|   "description": "Koishi plugin market information", |   "description": "Koishi plugin market information", | ||||||
|   "version": "1.1.0", |   "version": "1.1.1", | ||||||
|   "main": "lib/index.js", |   "main": "lib/index.js", | ||||||
|   "typings": "lib/index.d.ts", |   "typings": "lib/index.d.ts", | ||||||
|   "files": [ |   "files": [ | ||||||
| @ -43,10 +43,10 @@ | |||||||
|     "koishi": "^4.10.5" |     "koishi": "^4.10.5" | ||||||
|   }, |   }, | ||||||
|   "devDependencies": { |   "devDependencies": { | ||||||
|     "@koishijs/registry": "^4.2.1", |     "@koishijs/registry": "^4.3.2", | ||||||
|     "@types/node": "^17.0.45", |     "@types/node": "^18.11.18", | ||||||
|     "atsc": "^1.2.2", |     "atsc": "^1.2.2", | ||||||
|     "koishi": "^4.10.10", |     "koishi": "^4.11.1", | ||||||
|     "typescript": "^4.9.4" |     "typescript": "^4.9.4" | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  | |||||||
							
								
								
									
										11
									
								
								src/index.ts
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								src/index.ts
									
									
									
									
									
								
							| @ -22,26 +22,29 @@ export const Rule: Schema<Rule> = Schema.object({ | |||||||
| export interface Config { | export interface Config { | ||||||
|   rules: Rule[] |   rules: Rule[] | ||||||
|   interval: number |   interval: number | ||||||
|  |   showHidden: boolean | ||||||
|   showDeletion: boolean |   showDeletion: boolean | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export const Config: Schema<Config> = Schema.object({ | export const Config: Schema<Config> = Schema.object({ | ||||||
|   rules: Schema.array(Rule).description('推送规则。'), |   rules: Schema.array(Rule).description('推送规则。'), | ||||||
|   interval: Schema.number().default(Time.minute * 30).description('轮询间隔 (毫秒)。'), |   interval: Schema.number().default(Time.minute * 30).description('轮询间隔 (毫秒)。'), | ||||||
|  |   showHidden: Schema.boolean().default(false).description('是否显示隐藏的插件。'), | ||||||
|   showDeletion: Schema.boolean().default(false).description('是否显示删除的插件。'), |   showDeletion: Schema.boolean().default(false).description('是否显示删除的插件。'), | ||||||
| }) | }) | ||||||
| 
 | 
 | ||||||
| function makeDict(result: MarketResult) { | export function apply(ctx: Context, config: Config) { | ||||||
|  |   ctx.i18n.define('zh', require('./locales/zh-CN')) | ||||||
|  | 
 | ||||||
|  |   const makeDict = (result: MarketResult) => { | ||||||
|     const dict: Dict<AnalyzedPackage> = {} |     const dict: Dict<AnalyzedPackage> = {} | ||||||
|     for (const object of result.objects) { |     for (const object of result.objects) { | ||||||
|  |       if (object.manifest.hidden && !config.showHidden) continue | ||||||
|       dict[object.shortname] = object |       dict[object.shortname] = object | ||||||
|     } |     } | ||||||
|     return dict |     return dict | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
| export function apply(ctx: Context, config: Config) { |  | ||||||
|   ctx.i18n.define('zh', require('./locales/zh-CN')) |  | ||||||
| 
 |  | ||||||
|   const getMarket = async () => { |   const getMarket = async () => { | ||||||
|     const data = await ctx.http.get<MarketResult>('https://registry.koishi.chat/market.json') |     const data = await ctx.http.get<MarketResult>('https://registry.koishi.chat/market.json') | ||||||
|     return makeDict(data) |     return makeDict(data) | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user