Skip to content

Commit

Permalink
chore: maby support k-on!
Browse files Browse the repository at this point in the history
  • Loading branch information
Lipraty committed Oct 28, 2023
1 parent 731d782 commit f83a82b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 13 deletions.
2 changes: 2 additions & 0 deletions client/components/tableCode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ const intervalTimer = async () => {
}
onMounted(async () => {
tt = 0 // GC
intervalTimer()
})
onDeactivated(() => {
tt = 0 // GC
cancelAnimationFrame(timer)
})
</script>
Expand Down
14 changes: 9 additions & 5 deletions client/page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}
})
</script>

Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down Expand Up @@ -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.",
Expand Down Expand Up @@ -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"
}
}
2 changes: 1 addition & 1 deletion src/commands.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
14 changes: 10 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const usage = `
为确保安全性,建议如下措施:
- 使用随机字符串来作为存储密码 (salt) ,用于加密令牌以及认证令牌
- 添加 Auth 插件,以保证 WebUI 有限度访问
- 如果部署在公网环境,请添加 Auth 插件,以保证 WebUI 有限度访问
`

export interface Config {
Expand All @@ -36,8 +36,8 @@ export const Config: Schema<Config> = 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('基础配置'),
Expand All @@ -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'),
})
Expand Down

0 comments on commit f83a82b

Please sign in to comment.