diff --git a/client/components/tableCode.vue b/client/components/tableCode.vue index 47567ed..9f00dc2 100644 --- a/client/components/tableCode.vue +++ b/client/components/tableCode.vue @@ -57,10 +57,12 @@ const intervalTimer = async () => { } onMounted(async () => { + tt = 0 // GC intervalTimer() }) onDeactivated(() => { + tt = 0 // GC cancelAnimationFrame(timer) }) diff --git a/client/page.vue b/client/page.vue index cdb95ee..35dcf55 100644 --- a/client/page.vue +++ b/client/page.vue @@ -62,11 +62,15 @@ const sender = (activity: any, id?: number, data?) => { } send('otp/alive').then(data => { - loading.value = false - alive.value = data - send('otp/list').then(data => { - tokenTable.value = data - }) + if (process.env.KOISHI_ENV === 'browser') { + alive.value = true + } else { + loading.value = false + alive.value = data + send('otp/list').then(data => { + tokenTable.value = data + }) + } }) diff --git a/package.json b/package.json index e2acf6f..a0c6a9a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "koishi-plugin-otp", "description": "one time password", - "version": "0.2.0", + "version": "1.0.0", "main": "lib/index.js", "typings": "lib/index.d.ts", "author": { @@ -31,6 +31,7 @@ "pub": "yakumo publish" }, "koishi": { + "browser": true, "description": { "zh": "2FA(OTP) 可以用于二步认证的验证码服务,目前支持 TOTP、HOTP 算法。", "en": "2FA(OTP) can be used for two-step verification of verification code service, currently supports TOTP, HOTP algorithm.", @@ -71,7 +72,7 @@ "yakumo-version": "^0.3.4" }, "peerDependencies": { - "koishi": "^4.12.1", - "@koishijs/plugin-console": "^5.11.0" + "koishi": "^4.15.3", + "@koishijs/plugin-console": "^5.17.1" } } diff --git a/src/commands.tsx b/src/commands.tsx index 1b65f0f..29e37aa 100644 --- a/src/commands.tsx +++ b/src/commands.tsx @@ -21,7 +21,7 @@ declare module 'koishi' { const otpMethods = [OTPMethod.TOTP, OTPMethod.HOTP] -export const using = ['database', 'otp'] +export const inject = ['database', 'otp'] export function apply(ctx: Context, options: Config) { ctx.model.extend('otp', { id: 'unsigned', diff --git a/src/index.ts b/src/index.ts index 2ec03ec..8244677 100644 --- a/src/index.ts +++ b/src/index.ts @@ -15,7 +15,7 @@ export const usage = ` 为确保安全性,建议如下措施: - 使用随机字符串来作为存储密码 (salt) ,用于加密令牌以及认证令牌 -- 添加 Auth 插件,以保证 WebUI 有限度访问 +- 如果部署在公网环境,请添加 Auth 插件,以保证 WebUI 有限度访问 ` export interface Config { @@ -36,8 +36,8 @@ export const Config: Schema = Schema.intersect([ 'uuid', 'random', 'timestamp']).default('uuid').description('令牌生成方式'), - salt: Schema.string().role('secret').description('存储密码(为保证账户安全性,请尽量使用复杂密码)').required(), - qrcode: Schema.boolean().default(false).description('[⚠ 实验性]是否使用二维码识别(需要 qrcode 服务)'), + salt: Schema.string().role('secret').description('存储密码(为保证账户安全性,请尽量使用复杂密码)').required().hidden(process.env.KOISHI_ENV === 'browser'), + qrcode: Schema.boolean().default(false).description('[⚠ 实验性]是否使用二维码识别(需要 qrcode 服务)').hidden(process.env.KOISHI_ENV === 'browser'), manager: Schema.boolean().default(false).description('允许在 WebUI 中管理令牌'), command: Schema.boolean().default(true).description('允许使用命令管理令牌'), }).description('基础配置'), @@ -64,7 +64,13 @@ export function apply(ctx: Context, opt: Config) { ctx.i18n.define('en-US', enGB) if (opt.manager) ctx.using(['console'], (ctx) => { - ctx.console.addEntry({ + ctx.console.addEntry(process.env.KOISHI_BASE ? [ + process.env.KOISHI_BASE + '/dist/index.js', + process.env.KOISHI_BASE + '/dist/style.css', + ] : process.env.KOISHI_ENV === 'browser' ? [ + // @ts-ignore + import.meta.url.replace(/\/src\/[^/]+$/, '/client/index.ts'), + ] : { dev: resolve(__dirname, '../client/index.ts'), prod: resolve(__dirname, '../dist'), })