Commit d6118002 authored by nanahira's avatar nanahira

bump

parent c476b097
......@@ -26,6 +26,23 @@ app.plugin(DatabasePlugin);
app.plugin(ExtrasInDev);
// Target plugin
app.plugin(TargetPlugin, {} as any);
app.plugin(TargetPlugin, {
instances: [
{
name: 'yande',
weight: 1,
endpoint: 'https://yande.re/post.json',
pageLimit: 200,
isDefault: true,
},
{
name: 'konachan',
weight: 1,
endpoint: 'https://konachan.com/post.json',
pageLimit: 200,
isDefault: true,
},
],
});
app.start();
This diff is collapsed.
......@@ -28,8 +28,8 @@
},
"homepage": "https://code.mycard.moe/3rdeye/koishi-plugin-picsource-yande",
"peerDependencies": {
"koishi": "^4.6.0",
"koishi-plugin-pics": "^9.0.0"
"koishi": "^4.6.1",
"koishi-plugin-pics": "^9.0.3"
},
"dependencies": {
"koishi-thirdeye": "^10.0.5"
......
......@@ -3,7 +3,7 @@ import { DefineSchema, RegisterSchema } from 'koishi-thirdeye';
import { PicSourceConfig } from 'koishi-plugin-pics';
@RegisterSchema()
export class InstanceConfig extends PicSourceConfig {
export class PicSourceYandePluginConfig extends PicSourceConfig {
@DefineSchema({
description:
'网站 post.json 的地址。如果使用 Konachan 则可以使用 `https://konachan.com/post.json` 。',
......@@ -18,22 +18,3 @@ export class InstanceConfig extends PicSourceConfig {
@DefineSchema({ description: '使用原始图而不是 sample 图。', default: true })
useOriginal: boolean;
}
@RegisterSchema()
export class PicSourceYandePluginConfig {
constructor(config: PicSourceYandePluginConfigLike) {}
@DefineSchema({
description: '实例列表。',
type: InstanceConfig,
default: [
{ name: 'yande', url: 'https://yande.re/post.json' },
{ name: 'konachan', url: 'https://konachan.com/post.json' },
],
})
instances: InstanceConfig[];
}
export interface PicSourceYandePluginConfigLike {
instances: Partial<InstanceConfig>[];
}
// import 'source-map-support/register';
import { InstanceConfig, PicSourceYandePluginConfig, PicSourceYandePluginConfigLike } from './config';
import {
DefinePlugin,
BasePlugin,
Inject,
LifecycleEvents,
} from 'koishi-thirdeye';
import PicsContainer, { PicSource } from 'koishi-plugin-pics';
import { Context, Random } from 'koishi';
import { PicSourceYandePluginConfig } from './config';
import { DefinePlugin, Inject } from 'koishi-thirdeye';
import { DefineMultiSourcePlugin, PicSourcePlugin } from 'koishi-plugin-pics';
import { Random, Quester } from 'koishi';
import { PicInfo } from './def';
export * from './config';
export class PicSourceInstance extends PicSource {
constructor(ctx: Context, private config: InstanceConfig) {
super(ctx);
config.applyTo(this);
}
@DefinePlugin({ name: 'picsource-yande', schema: PicSourceYandePluginConfig })
export class PicSourceYande extends PicSourcePlugin<PicSourceYandePluginConfig> {
@Inject(true)
private http: Quester;
private page = 1;
private nextPage() {
......@@ -30,7 +24,7 @@ export class PicSourceInstance extends PicSource {
async randomPic(picTags: string[]) {
const page = this.nextPage();
const data = await this.ctx.http.get<PicInfo[]>(this.config.endpoint, {
const data = await this.http.get<PicInfo[]>(this.config.endpoint, {
params: {
tags: picTags.length ? picTags.join('+') : undefined,
limit: 1000,
......@@ -61,17 +55,7 @@ export class PicSourceInstance extends PicSource {
}
}
@DefinePlugin({ name: 'picsource-yande', schema: PicSourceYandePluginConfig })
export default class PicSourceYandePlugin
extends BasePlugin<PicSourceYandePluginConfig, PicSourceYandePluginConfigLike>
implements LifecycleEvents
{
@Inject(true)
private pics: PicsContainer;
onApply() {
for (const instanceConfig of this.config.instances) {
this.pics.addSource(new PicSourceInstance(this.ctx, instanceConfig));
}
}
}
export default class PicSourceYandePlugin extends DefineMultiSourcePlugin(
PicSourceYande,
PicSourceYandePluginConfig,
) {}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment