Commit 8944fb4c authored by nanahira's avatar nanahira

bump

parent 2dd5cc5e
...@@ -2,8 +2,8 @@ import { App } from 'koishi'; ...@@ -2,8 +2,8 @@ import { App } from 'koishi';
import TargetPlugin from '../src'; import TargetPlugin from '../src';
import ConsolePlugin from '@koishijs/plugin-console'; import ConsolePlugin from '@koishijs/plugin-console';
import SandboxPlugin from '@koishijs/plugin-sandbox'; import SandboxPlugin from '@koishijs/plugin-sandbox';
import * as DatabasePlugin from '@koishijs/plugin-database-memory'; import DatabasePlugin from '@koishijs/plugin-database-memory';
import CachePlugin from '@koishijs/plugin-cache-lru'; import CachePlugin from 'koishi-plugin-cache-aragami';
import ExtrasInDev from './extras'; import ExtrasInDev from './extras';
const app = new App({ const app = new App({
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -24,29 +24,30 @@ ...@@ -24,29 +24,30 @@
"nonebot", "nonebot",
"heisi", "heisi",
"required:pics", "required:pics",
"required:cache" "required:cache-aragami"
], ],
"bugs": { "bugs": {
"url": "https://code.mycard.moe/3rdeye/koishi-plugin-picsource-heisi/issues" "url": "https://code.mycard.moe/3rdeye/koishi-plugin-picsource-heisi/issues"
}, },
"homepage": "https://code.mycard.moe/3rdeye/koishi-plugin-picsource-heisi", "homepage": "https://code.mycard.moe/3rdeye/koishi-plugin-picsource-heisi",
"peerDependencies": { "peerDependencies": {
"koishi": "^4.7.5", "koishi": "^4.8.2",
"koishi-plugin-pics": "^9.4.1" "koishi-plugin-cache-aragami": "^1.0.4",
"koishi-plugin-pics": "^10.0.0"
}, },
"dependencies": { "dependencies": {
"koishi-thirdeye": "^10.3.2", "koishi-thirdeye": "^11.0.6",
"schemastery-gen": "^3.1.14" "schemastery-gen": "^3.1.14"
}, },
"devDependencies": { "devDependencies": {
"@koishijs/plugin-cache-lru": "^1.0.0-rc.0", "@koishijs/plugin-console": "^4.1.1",
"@koishijs/plugin-console": "^3.3.2", "@koishijs/plugin-database-memory": "^1.4.1",
"@koishijs/plugin-database-memory": "^1.3.0", "@koishijs/plugin-sandbox": "^2.0.1",
"@koishijs/plugin-sandbox": "^1.1.3",
"@types/jest": "^27.4.0", "@types/jest": "^27.4.0",
"@types/node": "^16.11.11", "@types/node": "^16.11.11",
"@typescript-eslint/eslint-plugin": "^4.33.0", "@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0", "@typescript-eslint/parser": "^4.33.0",
"esbuild-loader": "^2.19.0",
"eslint": "^7.32.0", "eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0", "eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.1", "eslint-plugin-prettier": "^3.4.1",
......
// import 'source-map-support/register'; // import 'source-map-support/register';
import { Quester, Cache, Random } from 'koishi'; import { Quester, Random } from 'koishi';
import { PicSourceHeisiConfig } from './config'; import { PicSourceHeisiConfig } from './config';
import { DefinePlugin, Inject } from 'koishi-thirdeye'; import { DefinePlugin, Inject } from 'koishi-thirdeye';
import { PicSourcePlugin } from 'koishi-plugin-pics'; import { PicSourcePlugin } from 'koishi-plugin-pics';
import AragamiPlugin, { CacheKey } from 'koishi-plugin-cache-aragami';
export * from './config'; export * from './config';
declare module 'koishi' { class HeisiList {
// eslint-disable-next-line @typescript-eslint/no-namespace list: string[];
namespace Cache {
interface Tables { @CacheKey()
heisiList: string[]; identifier() {
} return 'heisi';
}
isAvailable() {
return !!this.list?.length;
} }
} }
...@@ -18,14 +23,13 @@ declare module 'koishi' { ...@@ -18,14 +23,13 @@ declare module 'koishi' {
export default class PicSourceHeisi extends PicSourcePlugin( export default class PicSourceHeisi extends PicSourcePlugin(
PicSourceHeisiConfig, PicSourceHeisiConfig,
) { ) {
@Inject('cache', true) @Inject(true)
private cache: Cache; private aragami: AragamiPlugin;
@Inject(true) @Inject(true)
private http: Quester; private http: Quester;
onApply() { onApply() {
this.cache.table('heisiList', { maxAge: this.config.ttl });
this.getRandomUrl().then(); this.getRandomUrl().then();
} }
...@@ -39,27 +43,27 @@ export default class PicSourceHeisi extends PicSourcePlugin( ...@@ -39,27 +43,27 @@ export default class PicSourceHeisi extends PicSourcePlugin(
} }
async getRandomUrl() { async getRandomUrl() {
let list = await this.cache.get('heisiList', 'list'); let list = await this.aragami.get(HeisiList, 'heisi');
if (!list || !list.length) { if (!list?.isAvailable()) {
await this.fetchPicList(); await this.fetchPicList();
list = await this.cache.get('heisiList', 'list'); list = await this.aragami.get(HeisiList, 'heisi');
} }
if (!list || !list.length) { if (!list?.isAvailable()) {
return; return;
} }
return Random.pick(list); return Random.pick(list.list);
} }
async fetchPicList() { async fetchPicList() {
this.logger.info(`Fetching pic list from ${this.config.endpoint}...`); this.logger.info(`Fetching pic list from ${this.config.endpoint}...`);
try { try {
const content = await this.http.get(this.config.endpoint); const content = await this.http.get<string>(this.config.endpoint);
const urls = content const urls = content
.trim() .trim()
.split('\n') .split('\n')
.map((line) => line.trim()) .map((line) => line.trim())
.filter((line) => line.startsWith('http')); .filter((line) => line.startsWith('http'));
await this.cache.set('heisiList', 'list', urls); await this.aragami.set(HeisiList, { list: urls });
this.logger.info( this.logger.info(
`fetched ${urls.length} pics from ${this.config.endpoint}`, `fetched ${urls.length} pics from ${this.config.endpoint}`,
); );
......
const path = require('path'); const path = require('path');
const packgeInfo = require('./package.json'); const packgeInfo = require('./package.json');
const { ESBuildMinifyPlugin } = require('esbuild-loader');
function externalsFromDep() { function externalsFromDep() {
return Object.fromEntries( return Object.fromEntries(
...@@ -43,4 +44,11 @@ module.exports = { ...@@ -43,4 +44,11 @@ module.exports = {
koishi: 'koishi', koishi: 'koishi',
...(packAll ? {} : externalsFromDep()), ...(packAll ? {} : externalsFromDep()),
}, },
optimization: {
minimizer: [
new ESBuildMinifyPlugin({
keepNames: true,
}),
],
},
}; };
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