koishi-plugin-teach
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -9,3 +9,3 @@ "use strict"; | ||
const path_1 = require("path"); | ||
const fs_extra_1 = require("fs-extra"); | ||
const fs_1 = require("fs"); | ||
const axios_1 = __importDefault(require("axios")); | ||
@@ -32,3 +32,3 @@ const imageRE = /\[CQ:image,file=([^,]+),url=([^\]]+)\]/; | ||
if (imagePath && uploadPath) { | ||
const fileList = fs_extra_1.readdirSync(imagePath); | ||
const fileList = fs_1.readdirSync(imagePath); | ||
let totalCount = fileList.length; | ||
@@ -38,5 +38,5 @@ let totalSize = 0; | ||
const path = path_1.resolve(imagePath, file); | ||
if (!fs_extra_1.existsSync(path)) { | ||
if (!fs_1.existsSync(path)) { | ||
const { data } = await axios_1.default.get(url, { responseType: 'arraybuffer' }); | ||
await fs_extra_1.writeFile(path, data); | ||
await fs_1.promises.writeFile(path, Buffer.from(data)); | ||
totalCount += 1; | ||
@@ -47,3 +47,3 @@ totalSize += data.byteLength; | ||
const statPromise = Promise.all(fileList.map(async (file) => { | ||
const { size } = await fs_extra_1.stat(path_1.resolve(imagePath, file)); | ||
const { size } = await fs_1.promises.stat(path_1.resolve(imagePath, file)); | ||
totalSize += size; | ||
@@ -55,17 +55,15 @@ })); | ||
}; | ||
ctx.on('connect', () => { | ||
ctx.router.get(uploadPath, async (ctx) => { | ||
const { salt, sign, url, file } = ctx.query; | ||
if (!file) | ||
return ctx.body = await getStatus(); | ||
if (uploadKey) { | ||
if (!salt || !sign) | ||
return ctx.status = 400; | ||
const hash = crypto_1.createHmac('sha1', uploadKey).update(file + salt).digest('hex'); | ||
if (hash !== sign) | ||
return ctx.status = 403; | ||
} | ||
await downloadFile(file, url); | ||
return ctx.status = 200; | ||
}); | ||
ctx.router.get(uploadPath, async (ctx) => { | ||
const { salt, sign, url, file } = ctx.query; | ||
if (!file) | ||
return ctx.body = await getStatus(); | ||
if (uploadKey) { | ||
if (!salt || !sign) | ||
return ctx.status = 400; | ||
const hash = crypto_1.createHmac('sha1', uploadKey).update(file + salt).digest('hex'); | ||
if (hash !== sign) | ||
return ctx.status = 403; | ||
} | ||
await downloadFile(file, url); | ||
return ctx.status = 200; | ||
}); | ||
@@ -72,0 +70,0 @@ } |
@@ -18,3 +18,3 @@ import { Context } from 'koishi-core'; | ||
} | ||
export declare function isHours(value: string): boolean; | ||
export declare function isHours(value: string): boolean | "请输入正确的时间。"; | ||
export default function apply(ctx: Context, config: Dialogue.Config): void; |
@@ -6,3 +6,3 @@ "use strict"; | ||
if (!/^\d+(:\d+)?$/.test(value)) | ||
return true; | ||
return '请输入正确的时间。'; | ||
const [_hours, _minutes = '0'] = value.split(':'); | ||
@@ -9,0 +9,0 @@ const hours = +_hours, minutes = +_minutes; |
@@ -113,3 +113,3 @@ "use strict"; | ||
return next(); | ||
const target = Math.random() * Math.max(1, total); | ||
const target = koishi_utils_1.Random.real(Math.max(1, total)); | ||
let pointer = 0; | ||
@@ -116,0 +116,0 @@ for (const _dialogue of dialogues) { |
@@ -236,3 +236,3 @@ "use strict"; | ||
tasks.push(app.getImageServerStatus().then(({ totalSize, totalCount }) => { | ||
return `收录图片 ${totalCount} 张,总体积 ${(totalSize / (1 << 20)).toFixed(1)} MB。`; | ||
return `收录图片 ${totalCount} 张,总体积 ${+(totalSize / (1 << 20)).toFixed(1)} MB。`; | ||
})); | ||
@@ -239,0 +239,0 @@ } |
{ | ||
"name": "koishi-plugin-teach", | ||
"description": "Teach plugin for Koishi", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"main": "dist/index.js", | ||
@@ -41,6 +41,6 @@ "typings": "dist/index.d.ts", | ||
"peerDependencies": { | ||
"koishi-core": "^2.0.2" | ||
"koishi-core": "^2.1.1" | ||
}, | ||
"devDependencies": { | ||
"koishi-plugin-mongo": "^1.0.1", | ||
"koishi-plugin-mongo": "^1.0.2", | ||
"koishi-plugin-mysql": "^2.0.0", | ||
@@ -50,3 +50,4 @@ "koishi-test-utils": "^4.0.0" | ||
"dependencies": { | ||
"koishi-utils": "^3.1.2", | ||
"axios": "^0.20.0", | ||
"koishi-utils": "^3.1.3", | ||
"leven": "^3.1.0", | ||
@@ -53,0 +54,0 @@ "regexpp": "^3.1.0" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
222492
5
2913
+ Addedaxios@^0.20.0
+ Addedaxios@0.20.0(transitive)
+ Addedfollow-redirects@1.15.9(transitive)
Updatedkoishi-utils@^3.1.3