From 3b6e2be7fe044d032e4d00ace4d7b0768f38fe38 Mon Sep 17 00:00:00 2001 From: zhaojun1998 Date: Mon, 1 Feb 2021 23:14:29 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E6=96=B0=E5=A2=9E=20debug=20?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F,=20=E5=8F=AF=E8=AE=BF=E9=97=AE=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93=E6=8E=A7=E5=88=B6=E5=8F=B0=E5=92=8C=E9=87=8D?= =?UTF-8?q?=E7=BD=AE=E5=AF=86=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/admin/DebugController.java | 31 +++++++++ ...itional-spring-configuration-metadata.json | 5 ++ src/main/resources/application.yml | 65 ++++++++++--------- 3 files changed, 69 insertions(+), 32 deletions(-) create mode 100644 src/main/java/im/zhaojun/zfile/controller/admin/DebugController.java diff --git a/src/main/java/im/zhaojun/zfile/controller/admin/DebugController.java b/src/main/java/im/zhaojun/zfile/controller/admin/DebugController.java new file mode 100644 index 0000000..9bf854a --- /dev/null +++ b/src/main/java/im/zhaojun/zfile/controller/admin/DebugController.java @@ -0,0 +1,31 @@ +package im.zhaojun.zfile.controller.admin; + + +import im.zhaojun.zfile.model.support.ResultBean; +import im.zhaojun.zfile.service.SystemConfigService; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; + +import javax.annotation.Resource; + +@Controller +public class DebugController { + + @Value("${zfile.debug}") + private Boolean debug; + + @Resource + private SystemConfigService systemConfigService; + + @GetMapping("/debug/resetPwd") + public ResultBean resetPwd() { + if (debug) { + systemConfigService.updateUsernameAndPwd("admin", "123456"); + return ResultBean.success(); + } else { + return ResultBean.error("未开启 DEBUG 模式,不允许进行此操作。"); + } + } + +} \ No newline at end of file diff --git a/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/src/main/resources/META-INF/additional-spring-configuration-metadata.json index 580f180..249732c 100644 --- a/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -86,6 +86,11 @@ "name": "zfile.tmp.path", "type": "java.lang.String", "description": "临时文件路径." + }, + { + "name": "zfile.debug", + "type": "java.lang.Boolean", + "description": "是否开启 debug 模式." } ] } \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index a6f9c5d..57f5e9b 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,3 +1,34 @@ +zfile: + debug: false + log: + path: ${user.home}/.zfile/logs + db: + path: ${user.home}/.zfile/db/zfile + tmp: + path: ${user.home}/.zfile/tmp + cache: + auto-refresh: + interval: 1 + timeout: 1800 + constant: + readme: readme.md + password: password.txt + preview: + audio: + maxFileSizeMb: 5 + text: + maxFileSizeKb: 512 + onedrive: + clientId: 09939809-c617-43c8-a220-a93c1513c5d4 + clientSecret: _l:zI-_yrW75lV8M61K@z.I2K@B/On6Q + redirectUri: https://zfile.jun6.net/onedrive/callback + scope: offline_access User.Read Files.ReadWrite.All + onedrive-china: + clientId: 4a72d927-1907-488d-9eb2-1b465c53c1c5 + clientSecret: Y9CEA=82da5n-y_]KAWAgLH3?R9xf7Uw + redirectUri: https://zfile.jun6.net/onedrive/china-callback + scope: offline_access User.Read Files.ReadWrite.All + server: port: 8080 servlet: @@ -13,7 +44,7 @@ spring: settings: web-allow-others: true path: /h2-console - enabled: false + enabled: ${zfile.debug} datasource: # 初始化数据导入 data: classpath*:db/data.sql @@ -47,34 +78,4 @@ spring: chain: gzipped: true profiles: - active: prod - -zfile: - log: - path: ${user.home}/.zfile/logs - db: - path: ${user.home}/.zfile/db/zfile - tmp: - path: ${user.home}/.zfile/tmp - cache: - auto-refresh: - interval: 1 - timeout: 1800 - constant: - readme: readme.md - password: password.txt - preview: - audio: - maxFileSizeMb: 5 - text: - maxFileSizeKb: 512 - onedrive: - clientId: 09939809-c617-43c8-a220-a93c1513c5d4 - clientSecret: _l:zI-_yrW75lV8M61K@z.I2K@B/On6Q - redirectUri: https://zfile.jun6.net/onedrive/callback - scope: offline_access User.Read Files.ReadWrite.All - onedrive-china: - clientId: 4a72d927-1907-488d-9eb2-1b465c53c1c5 - clientSecret: Y9CEA=82da5n-y_]KAWAgLH3?R9xf7Uw - redirectUri: https://zfile.jun6.net/onedrive/china-callback - scope: offline_access User.Read Files.ReadWrite.All \ No newline at end of file + active: prod \ No newline at end of file