Commit 537c6b66 authored by nanahira's avatar nanahira

bump

parent 1e8fb420
......@@ -27,7 +27,7 @@ app.plugin(ExtrasInDev);
// Target plugin
app.plugin(TargetPlugin, {
sources: [{ name: 'ygopro', isDefault: true, path: './dev/test-pics' }],
instances: [{ name: 'ygopro', isDefault: true, path: './dev/test-pics' }],
});
app.start();
......@@ -36,8 +36,8 @@
"ws": "^8.3.0"
},
"peerDependencies": {
"koishi": "^4.6.0",
"koishi-plugin-pics": "^9.0.0"
"koishi": "^4.6.1",
"koishi-plugin-pics": "^9.0.3"
}
},
"node_modules/@ampproject/remapping": {
......@@ -1070,15 +1070,15 @@
}
},
"node_modules/@koishijs/core": {
"version": "4.6.0",
"resolved": "https://registry.npmjs.org/@koishijs/core/-/core-4.6.0.tgz",
"integrity": "sha512-m+K2h/Oqmpcw39dQhJ/D9MBmwnWNUf9uFqymJ94+nP4CR7rcM1DTWNiaMGshGUqNu+s4q0ildoEDlQrE4hVuWA==",
"version": "4.6.1",
"resolved": "https://registry.npmjs.org/@koishijs/core/-/core-4.6.1.tgz",
"integrity": "sha512-2HzdUi76YSLFZYpPXcmEwwVyHQLPF8BL0GJR6PuCYdOYfHykzwA5NmqOGx29EyeuYzs8sS6yr25IQktxMYqsdg==",
"peer": true,
"dependencies": {
"@koishijs/utils": "^5.4.0",
"cosmotype": "^1.0.3",
"@koishijs/utils": "^5.4.1",
"cosmotype": "^1.0.6",
"fastest-levenshtein": "^1.0.12",
"ns-require": "^1.1.0"
"ns-require": "^1.1.2"
},
"engines": {
"node": ">=12.0.0"
......@@ -1139,15 +1139,15 @@
"peer": true
},
"node_modules/@koishijs/utils": {
"version": "5.4.0",
"resolved": "https://registry.npmjs.org/@koishijs/utils/-/utils-5.4.0.tgz",
"integrity": "sha512-w5SHArw032cXVtxp5nXkc5jzP6Fn3LrF7FQTanPnOgmjGv/AIOAKfJ6bqaOUsSg+ttcK3iO8xs65W6XsNz3g7g==",
"version": "5.4.1",
"resolved": "https://registry.npmjs.org/@koishijs/utils/-/utils-5.4.1.tgz",
"integrity": "sha512-M3L9KqtdTyCzQK1LxTtp7QCucc75IA2vRwnYJA1gXMAxPC3SoEjUVmsk/oNFBSknmfADdViI5mFJtUXMCpJW1g==",
"peer": true,
"dependencies": {
"@koishijs/segment": "^1.1.1",
"cosmokit": "^1.1.1",
"reggol": "^1.0.1",
"schemastery": "^3.3.2",
"cosmokit": "^1.1.2",
"reggol": "^1.0.2",
"schemastery": "^3.3.3",
"supports-color": "^8.1.1"
}
},
......@@ -2608,18 +2608,18 @@
"peer": true
},
"node_modules/cosmokit": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/cosmokit/-/cosmokit-1.1.1.tgz",
"integrity": "sha512-+f8x9pFGIc7I6HTObS90dq2K5YsI4U3Me4l9OminU9woVtF9Sv3CAHb5vKbFZ93XpTFctAQ6qAVSGjkGvGI9iw=="
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/cosmokit/-/cosmokit-1.1.2.tgz",
"integrity": "sha512-cSNrcyxZ3GT+tjSlUzWIzMiK7Wndq1Nm/2tlRhT65RXltSIcH5zaHdmnz1TnIhLuOViaO9qfSdnRPzxNkxMv0g=="
},
"node_modules/cosmotype": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/cosmotype/-/cosmotype-1.0.3.tgz",
"integrity": "sha512-JykvyDjyjaDjycm8CcK8GD4Xt6/Glu4pJU9uJ5lsDuE5B5bdmAykiTPMHfs+Is8QUsNaDKpsHfxtxCUBDPYgdw==",
"version": "1.0.9",
"resolved": "https://registry.npmjs.org/cosmotype/-/cosmotype-1.0.9.tgz",
"integrity": "sha512-ot2m5LYBj9UNFvYpQNQ28hWYDG4GWmym094us2HNn6qgYzvALmjs4FxEVBsjA+VBnIf3ykuMGRYcex5cqZTvJQ==",
"peer": true,
"dependencies": {
"cosmokit": "^1.1.1",
"ns-require": "^1.1.0"
"cosmokit": "^1.1.2",
"ns-require": "^1.1.2"
}
},
"node_modules/cosmotype-decorators": {
......@@ -5235,14 +5235,14 @@
}
},
"node_modules/koishi": {
"version": "4.6.0",
"resolved": "https://registry.npmjs.org/koishi/-/koishi-4.6.0.tgz",
"integrity": "sha512-QhjFWTGhrFnYfpVg4dNNxgHER38zSij3nyM/RB3YrLTM4VwImVk5unpgg0QryViwWxSYM4zJ0YUoys4A9jgG6A==",
"version": "4.6.1",
"resolved": "https://registry.npmjs.org/koishi/-/koishi-4.6.1.tgz",
"integrity": "sha512-9NtcXrIKLN8AG9zEf3GzweSiHQubew0AWfjaci0grIxy760T77D8iLVsDbVhzmGSnc26WOR2q3CMFdRmE2igVA==",
"peer": true,
"dependencies": {
"@koa/router": "^10.1.1",
"@koishijs/core": "^4.6.0",
"@koishijs/utils": "^5.4.0",
"@koishijs/core": "^4.6.1",
"@koishijs/utils": "^5.4.1",
"@types/koa": "*",
"@types/koa__router": "*",
"@types/ws": "^8.5.3",
......@@ -5275,16 +5275,16 @@
}
},
"node_modules/koishi-plugin-pics": {
"version": "9.0.0",
"resolved": "https://registry.npmjs.org/koishi-plugin-pics/-/koishi-plugin-pics-9.0.0.tgz",
"integrity": "sha512-oRbgqbTs2sZvER5+i6OeD6TYR4ttSC3BfQjXuGq5em1Itt9KPLkQ6ZXcZPYMdidFQokFDfBvCu8abA6IDZBLjQ==",
"version": "9.0.3",
"resolved": "https://registry.npmjs.org/koishi-plugin-pics/-/koishi-plugin-pics-9.0.3.tgz",
"integrity": "sha512-ZXzRJnGwg1W7dNRdmcaRyYFiGDFuOPq8qLh/Qer0Bk/dHVTW9tYZcdViXfA5TSe7sxluoB2koTRB8JvwPTnhVA==",
"peer": true,
"dependencies": {
"koishi-thirdeye": "^10.0.0",
"koishi-thirdeye": "^10.0.5",
"lodash": "^4.17.21"
},
"peerDependencies": {
"koishi": "^4.6.0"
"koishi": "^4.6.1"
}
},
"node_modules/koishi-thirdeye": {
......@@ -5607,9 +5607,9 @@
}
},
"node_modules/ns-require": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/ns-require/-/ns-require-1.1.0.tgz",
"integrity": "sha512-Iw349zwWNgkGZjYJtruf+BXUe8YHOiMZE0iUNffvpt/A1yTSabTnpBMQ0zNl65G1LhpzwCo1KMCqjmJF0z8O6g==",
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/ns-require/-/ns-require-1.1.2.tgz",
"integrity": "sha512-GUF6I1hWDsGx1cA9FW27KIRAlkMel2UZagR39dVNPAPBgwWK1Ez0XB96WEz2OFcwHsCORI9h75dEZueHqZ/1pA==",
"peer": true
},
"node_modules/nwsapi": {
......@@ -6310,12 +6310,12 @@
}
},
"node_modules/reggol": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/reggol/-/reggol-1.0.1.tgz",
"integrity": "sha512-ZMOp3rZG6YQFVp/DC+BgFZaXSQcxHDayCmo7cL/kGujsSEoUzee0VJq1KCe9sgNt0qsM6JzkuSlj/+5SmmoO7Q==",
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/reggol/-/reggol-1.0.2.tgz",
"integrity": "sha512-BP7gx5nUBntWChG4x/yf7xLdpxy1R5PMtF/LJlOsz+XkWtip4YVNkQp2Flmio9hXSc2UxrwUyP0WrQ1M/FFWXw==",
"peer": true,
"dependencies": {
"cosmokit": "^1.1.0",
"cosmokit": "^1.1.2",
"supports-color": "^8.1.1"
}
},
......@@ -6491,12 +6491,12 @@
}
},
"node_modules/schemastery": {
"version": "3.3.2",
"resolved": "https://registry.npmjs.org/schemastery/-/schemastery-3.3.2.tgz",
"integrity": "sha512-Z1C850OPtNEBs+D4QBPdC+Wu1t6Fn1BrOJILRHs2b+I/u61hUKP2vIPMAXFLvmmONnwqAW8ksPdCD6Zz9n8zhg==",
"version": "3.3.3",
"resolved": "https://registry.npmjs.org/schemastery/-/schemastery-3.3.3.tgz",
"integrity": "sha512-DwRsse6C+Qao90P/Bz+4G3gmAjM3he/VgHk3TykmEWv3KFqvwmqEn61SF3BPaTPP0L77a5Kc6q4+KQvdN1bBqA==",
"peer": true,
"dependencies": {
"cosmokit": "^1.1.0"
"cosmokit": "^1.1.2"
}
},
"node_modules/schemastery-gen": {
......@@ -8611,15 +8611,15 @@
}
},
"@koishijs/core": {
"version": "4.6.0",
"resolved": "https://registry.npmjs.org/@koishijs/core/-/core-4.6.0.tgz",
"integrity": "sha512-m+K2h/Oqmpcw39dQhJ/D9MBmwnWNUf9uFqymJ94+nP4CR7rcM1DTWNiaMGshGUqNu+s4q0ildoEDlQrE4hVuWA==",
"version": "4.6.1",
"resolved": "https://registry.npmjs.org/@koishijs/core/-/core-4.6.1.tgz",
"integrity": "sha512-2HzdUi76YSLFZYpPXcmEwwVyHQLPF8BL0GJR6PuCYdOYfHykzwA5NmqOGx29EyeuYzs8sS6yr25IQktxMYqsdg==",
"peer": true,
"requires": {
"@koishijs/utils": "^5.4.0",
"cosmotype": "^1.0.3",
"@koishijs/utils": "^5.4.1",
"cosmotype": "^1.0.6",
"fastest-levenshtein": "^1.0.12",
"ns-require": "^1.1.0"
"ns-require": "^1.1.2"
}
},
"@koishijs/plugin-cache-lru": {
......@@ -8665,15 +8665,15 @@
"peer": true
},
"@koishijs/utils": {
"version": "5.4.0",
"resolved": "https://registry.npmjs.org/@koishijs/utils/-/utils-5.4.0.tgz",
"integrity": "sha512-w5SHArw032cXVtxp5nXkc5jzP6Fn3LrF7FQTanPnOgmjGv/AIOAKfJ6bqaOUsSg+ttcK3iO8xs65W6XsNz3g7g==",
"version": "5.4.1",
"resolved": "https://registry.npmjs.org/@koishijs/utils/-/utils-5.4.1.tgz",
"integrity": "sha512-M3L9KqtdTyCzQK1LxTtp7QCucc75IA2vRwnYJA1gXMAxPC3SoEjUVmsk/oNFBSknmfADdViI5mFJtUXMCpJW1g==",
"peer": true,
"requires": {
"@koishijs/segment": "^1.1.1",
"cosmokit": "^1.1.1",
"reggol": "^1.0.1",
"schemastery": "^3.3.2",
"cosmokit": "^1.1.2",
"reggol": "^1.0.2",
"schemastery": "^3.3.3",
"supports-color": "^8.1.1"
},
"dependencies": {
......@@ -9873,18 +9873,18 @@
"peer": true
},
"cosmokit": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/cosmokit/-/cosmokit-1.1.1.tgz",
"integrity": "sha512-+f8x9pFGIc7I6HTObS90dq2K5YsI4U3Me4l9OminU9woVtF9Sv3CAHb5vKbFZ93XpTFctAQ6qAVSGjkGvGI9iw=="
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/cosmokit/-/cosmokit-1.1.2.tgz",
"integrity": "sha512-cSNrcyxZ3GT+tjSlUzWIzMiK7Wndq1Nm/2tlRhT65RXltSIcH5zaHdmnz1TnIhLuOViaO9qfSdnRPzxNkxMv0g=="
},
"cosmotype": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/cosmotype/-/cosmotype-1.0.3.tgz",
"integrity": "sha512-JykvyDjyjaDjycm8CcK8GD4Xt6/Glu4pJU9uJ5lsDuE5B5bdmAykiTPMHfs+Is8QUsNaDKpsHfxtxCUBDPYgdw==",
"version": "1.0.9",
"resolved": "https://registry.npmjs.org/cosmotype/-/cosmotype-1.0.9.tgz",
"integrity": "sha512-ot2m5LYBj9UNFvYpQNQ28hWYDG4GWmym094us2HNn6qgYzvALmjs4FxEVBsjA+VBnIf3ykuMGRYcex5cqZTvJQ==",
"peer": true,
"requires": {
"cosmokit": "^1.1.1",
"ns-require": "^1.1.0"
"cosmokit": "^1.1.2",
"ns-require": "^1.1.2"
}
},
"cosmotype-decorators": {
......@@ -11842,14 +11842,14 @@
}
},
"koishi": {
"version": "4.6.0",
"resolved": "https://registry.npmjs.org/koishi/-/koishi-4.6.0.tgz",
"integrity": "sha512-QhjFWTGhrFnYfpVg4dNNxgHER38zSij3nyM/RB3YrLTM4VwImVk5unpgg0QryViwWxSYM4zJ0YUoys4A9jgG6A==",
"version": "4.6.1",
"resolved": "https://registry.npmjs.org/koishi/-/koishi-4.6.1.tgz",
"integrity": "sha512-9NtcXrIKLN8AG9zEf3GzweSiHQubew0AWfjaci0grIxy760T77D8iLVsDbVhzmGSnc26WOR2q3CMFdRmE2igVA==",
"peer": true,
"requires": {
"@koa/router": "^10.1.1",
"@koishijs/core": "^4.6.0",
"@koishijs/utils": "^5.4.0",
"@koishijs/core": "^4.6.1",
"@koishijs/utils": "^5.4.1",
"@types/koa": "*",
"@types/koa__router": "*",
"@types/ws": "^8.5.3",
......@@ -11876,12 +11876,12 @@
}
},
"koishi-plugin-pics": {
"version": "9.0.0",
"resolved": "https://registry.npmjs.org/koishi-plugin-pics/-/koishi-plugin-pics-9.0.0.tgz",
"integrity": "sha512-oRbgqbTs2sZvER5+i6OeD6TYR4ttSC3BfQjXuGq5em1Itt9KPLkQ6ZXcZPYMdidFQokFDfBvCu8abA6IDZBLjQ==",
"version": "9.0.3",
"resolved": "https://registry.npmjs.org/koishi-plugin-pics/-/koishi-plugin-pics-9.0.3.tgz",
"integrity": "sha512-ZXzRJnGwg1W7dNRdmcaRyYFiGDFuOPq8qLh/Qer0Bk/dHVTW9tYZcdViXfA5TSe7sxluoB2koTRB8JvwPTnhVA==",
"peer": true,
"requires": {
"koishi-thirdeye": "^10.0.0",
"koishi-thirdeye": "^10.0.5",
"lodash": "^4.17.21"
}
},
......@@ -12140,9 +12140,9 @@
}
},
"ns-require": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/ns-require/-/ns-require-1.1.0.tgz",
"integrity": "sha512-Iw349zwWNgkGZjYJtruf+BXUe8YHOiMZE0iUNffvpt/A1yTSabTnpBMQ0zNl65G1LhpzwCo1KMCqjmJF0z8O6g==",
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/ns-require/-/ns-require-1.1.2.tgz",
"integrity": "sha512-GUF6I1hWDsGx1cA9FW27KIRAlkMel2UZagR39dVNPAPBgwWK1Ez0XB96WEz2OFcwHsCORI9h75dEZueHqZ/1pA==",
"peer": true
},
"nwsapi": {
......@@ -12659,12 +12659,12 @@
"dev": true
},
"reggol": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/reggol/-/reggol-1.0.1.tgz",
"integrity": "sha512-ZMOp3rZG6YQFVp/DC+BgFZaXSQcxHDayCmo7cL/kGujsSEoUzee0VJq1KCe9sgNt0qsM6JzkuSlj/+5SmmoO7Q==",
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/reggol/-/reggol-1.0.2.tgz",
"integrity": "sha512-BP7gx5nUBntWChG4x/yf7xLdpxy1R5PMtF/LJlOsz+XkWtip4YVNkQp2Flmio9hXSc2UxrwUyP0WrQ1M/FFWXw==",
"peer": true,
"requires": {
"cosmokit": "^1.1.0",
"cosmokit": "^1.1.2",
"supports-color": "^8.1.1"
},
"dependencies": {
......@@ -12783,12 +12783,12 @@
}
},
"schemastery": {
"version": "3.3.2",
"resolved": "https://registry.npmjs.org/schemastery/-/schemastery-3.3.2.tgz",
"integrity": "sha512-Z1C850OPtNEBs+D4QBPdC+Wu1t6Fn1BrOJILRHs2b+I/u61hUKP2vIPMAXFLvmmONnwqAW8ksPdCD6Zz9n8zhg==",
"version": "3.3.3",
"resolved": "https://registry.npmjs.org/schemastery/-/schemastery-3.3.3.tgz",
"integrity": "sha512-DwRsse6C+Qao90P/Bz+4G3gmAjM3he/VgHk3TykmEWv3KFqvwmqEn61SF3BPaTPP0L77a5Kc6q4+KQvdN1bBqA==",
"peer": true,
"requires": {
"cosmokit": "^1.1.0"
"cosmokit": "^1.1.2"
}
},
"schemastery-gen": {
......
......@@ -32,8 +32,8 @@
"read-dir-deep": "^7.0.1"
},
"peerDependencies": {
"koishi": "^4.6.0",
"koishi-plugin-pics": "^9.0.0"
"koishi": "^4.6.1",
"koishi-plugin-pics": "^9.0.3"
},
"devDependencies": {
"@koishijs/plugin-cache-lru": "^1.0.0-rc.0",
......
import { PicResult, PicSource } from 'koishi-plugin-pics';
import { Context, Random } from 'koishi';
import path from 'path';
import { readDirDeep } from 'read-dir-deep';
import fs from 'fs';
import { LocalSourceConfig } from './config';
export class LocalSource extends PicSource {
constructor(ctx: Context, private config: LocalSourceConfig) {
super(ctx);
config.applyTo(this);
}
async randomPic(picTags: string[]): Promise<PicResult> {
const absolutePath = path.resolve(process.cwd(), this.config.path);
const files = (
await readDirDeep(absolutePath, {
absolute: true,
patterns: this.config.patterns,
gitignore: false,
ignore: this.config.exclude,
})
).filter((f) => picTags.every((t) => f.includes(t)));
if (!files.length) {
return null;
}
const filename = Random.pick(files);
const fileBase64 = (await fs.promises.readFile(filename)).toString(
'base64',
);
return {
url: `base64://${fileBase64}`,
description: this.config.displayFilename
? path.basename(filename)
: undefined,
};
}
}
// import 'source-map-support/register';
import { PicSourceConfig, PicSourceInfo } from 'koishi-plugin-pics';
import { Context } from 'koishi';
import { LocalSource } from './LocalSource';
import { PicSourceConfig } from 'koishi-plugin-pics';
import { DefineSchema, RegisterSchema } from 'schemastery-gen';
export interface LocalSourceConfigLike extends PicSourceInfo {
path: string;
patterns?: string[];
exclude?: string[];
displayFilename?: boolean;
}
@RegisterSchema()
export class LocalSourceConfig
extends PicSourceConfig
implements LocalSourceConfigLike
{
constructor(config: LocalSourceConfigLike) {
export class LocalSourceConfig extends PicSourceConfig {
constructor(config: Partial<LocalSourceConfig>) {
super(config);
}
@DefineSchema({ description: '目录路径', required: true })
......@@ -43,27 +31,4 @@ export class LocalSourceConfig
exclude: string[];
@DefineSchema({ description: '是否显示文件名', default: true })
displayFilename: boolean;
registerInstance(ctx: Context) {
const instance = new LocalSource(ctx, this);
ctx
.logger('picsource-localfs')
.info(`Registered localfs pic source ${instance.name}.`);
ctx.pics.addSource(instance, ctx);
}
}
export interface PicSourceLocalFSPluginConfigLike {
sources: LocalSourceConfigLike[];
}
export class PicSourceLocalFSPluginConfig
implements PicSourceLocalFSPluginConfigLike
{
@DefineSchema({
description: '目录定义',
type: LocalSourceConfig,
required: true,
})
sources: LocalSourceConfig[];
}
// import 'source-map-support/register';
import { Random } from 'koishi';
import {
PicSourceLocalFSPluginConfig,
PicSourceLocalFSPluginConfigLike,
} from './config';
import {
BasePlugin,
DefinePlugin,
LifecycleEvents,
UsingService,
} from 'koishi-thirdeye';
DefineMultiSourcePlugin,
PicResult,
PicSourcePlugin,
} from 'koishi-plugin-pics';
import { DefinePlugin } from 'koishi-thirdeye';
import path from 'path';
import { readDirDeep } from 'read-dir-deep';
import { LocalSourceConfig } from './config';
import fs from 'fs';
@UsingService('pics')
@DefinePlugin({
name: 'picsource-localfs',
schema: PicSourceLocalFSPluginConfig,
})
export default class PicSourceLocal
extends BasePlugin<
PicSourceLocalFSPluginConfig,
PicSourceLocalFSPluginConfigLike
>
implements LifecycleEvents
{
onApply() {
this.config.sources.forEach((s) => s.registerInstance(this.ctx));
@DefinePlugin({ name: 'picsource-local', schema: LocalSourceConfig })
export class LocalSource extends PicSourcePlugin<LocalSourceConfig> {
async randomPic(picTags: string[]): Promise<PicResult> {
const absolutePath = path.resolve(process.cwd(), this.config.path);
const files = (
await readDirDeep(absolutePath, {
absolute: true,
patterns: this.config.patterns,
gitignore: false,
ignore: this.config.exclude,
})
).filter((f) => picTags.every((t) => f.includes(t)));
if (!files.length) {
return null;
}
const filename = Random.pick(files);
const fileBase64 = (await fs.promises.readFile(filename)).toString(
'base64',
);
return {
url: `base64://${fileBase64}`,
description: this.config.displayFilename
? path.basename(filename)
: undefined,
};
}
}
export default class LocalSourcePlugin extends DefineMultiSourcePlugin(
LocalSource,
LocalSourceConfig,
) {}
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