Commit 537c6b66 authored by nanahira's avatar nanahira

bump

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