feat:新增 Bark 推送开关控制

This commit is contained in:
besscroft
2023-07-12 16:10:25 +08:00
parent 4853fc21c7
commit b884de0dd8
7 changed files with 38 additions and 3 deletions

View File

@@ -46,6 +46,9 @@ public interface CacheConstants {
/** barkId */
String BARK_ID = "system:barkId";
/** bark 推送状态 */
String BACK_STATUS = "system:backStatus";
/** 统计信息 */
String STATISTICS = "system:statistics";

View File

@@ -20,7 +20,7 @@ public class OpenApiConfiguration {
return new OpenAPI()
.info(new Info().title("DiyFile")
.description("一款好看的在线文件列表程序")
.version("v0.5.3")
.version("v0.6.0")
.license(new License().name("MIT license").url("https://github.com/besscroft/diyfile/blob/main/LICENSE")))
.externalDocs(new ExternalDocumentation()
.description("DiyFile 文档")

View File

@@ -89,4 +89,12 @@ public class SystemConfigController {
return AjaxResult.success(MessageConstants.SUCCESS, barkId);
}
@GetMapping("/getBarkStatus")
@SaCheckRole(value = { RoleConstants.PLATFORM_SUPER_ADMIN, RoleConstants.PLATFORM_ADMIN }, mode = SaMode.OR)
@Operation(summary = "获取 Bark 推送状态")
public AjaxResult getBarkStatus() {
Integer barkStatus = systemConfigService.getBarkStatus();
return AjaxResult.success(MessageConstants.SUCCESS, barkStatus);
}
}

View File

@@ -1,9 +1,12 @@
package com.besscroft.diyfile.message.impl;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.besscroft.diyfile.message.PushService;
import com.besscroft.diyfile.service.SystemConfigService;
import com.ejlchina.okhttps.OkHttps;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@@ -16,10 +19,17 @@ import java.util.Objects;
*/
@Slf4j
@Service
@RequiredArgsConstructor
public class PushServiceImpl implements PushService {
private final SystemConfigService systemConfigService;
@Override
public String pushBark(String sendKey, String message) {
Integer barkStatus = systemConfigService.getBarkStatus();
if (0 == barkStatus) {
return "";
}
String url = "https://api.day.app" +
"/" +
sendKey +

View File

@@ -52,6 +52,12 @@ public interface SystemConfigService extends IService<SystemConfig> {
*/
String getBarkId();
/**
* 获取 Bark 推送状态
* @return Bark 推送状态
*/
Integer getBarkStatus();
/**
* 获取统计信息
* @return 统计信息

View File

@@ -1,6 +1,7 @@
package com.besscroft.diyfile.service.impl;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.besscroft.diyfile.common.constant.CacheConstants;
import com.besscroft.diyfile.common.constant.SystemConstants;
@@ -78,7 +79,8 @@ public class SystemConfigServiceImpl extends ServiceImpl<SystemConfigMapper, Sys
CacheConstants.SITE_TITLE,
CacheConstants.SITE_CONFIG,
CacheConstants.SITE_BEIAN,
CacheConstants.BARK_ID
CacheConstants.BARK_ID,
CacheConstants.BACK_STATUS
}, allEntries = true)
public void updateConfig(String configKey, String configValue) {
long userId = StpUtil.getLoginIdAsLong();
@@ -91,6 +93,12 @@ public class SystemConfigServiceImpl extends ServiceImpl<SystemConfigMapper, Sys
return this.baseMapper.queryByConfigKey("barkId").getConfigValue();
}
@Override
@Cacheable(value = CacheConstants.BACK_STATUS, unless = "#result == null")
public Integer getBarkStatus() {
return StrUtil.equals(this.baseMapper.queryByConfigKey("barkStatus").getConfigValue(), "1") ? 1 : 0;
}
@Override
@Cacheable(value = CacheConstants.STATISTICS, unless = "#result == null")
public Map<String, Object> getTotalInfo() {

View File

@@ -17,7 +17,7 @@
<packaging>pom</packaging>
<properties>
<revision>0.5.3</revision>
<revision>0.6.0</revision>
<java.version>17</java.version>
<maven.compiler.release>17</maven.compiler.release>
<maven.compiler.source>${java.version}</maven.compiler.source>