biliob/src/main/java/com/yutou/bilibili/Controllers/SystemConfigController.java
zlzw b178010f8f 新版改版:
模块化各个功能
改为okhttp网络请求
改为sqlite作为存储
预设QQ机器人API
2024-06-15 15:53:48 +08:00

134 lines
4.3 KiB
Java

package com.yutou.bilibili.Controllers;
import com.alibaba.fastjson2.JSONObject;
import com.yutou.bilibili.BiliBili.Datas.AppData;
import com.yutou.bilibili.QQBot.QQBotManager;
import com.yutou.bilibili.Services.ISystemConfigService;
import com.yutou.bilibili.Tools.Config;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
@Controller
public class SystemConfigController {
@Resource
ISystemConfigService configService;
@RequestMapping("/system/get/config.do")
@ResponseBody
public JSONObject getRegUser() {
JSONObject json = new JSONObject();
JSONObject data = new JSONObject();
String reg = configService.getConfig(Config.USER_REG);
String bLive = configService.getConfig(Config.BILI_LIVE_FLAG);
if (reg == null) {
reg = "0";
}
if (bLive == null) {
bLive = "0";
}
data.put(Config.USER_REG, reg);
data.put(Config.BILI_LIVE_FLAG, bLive);
json.put("code", 0);
json.put("data", data);
return json;
}
@RequestMapping("/system/set/config.do")
@ResponseBody
public JSONObject setConfig(String key, String value) {
configService.setConfig(key, value);
JSONObject json = new JSONObject();
json.put("code", 0);
json.put("msg", "ok");
return json;
}
@RequestMapping("/system/public/reg.do")
@ResponseBody
public JSONObject getRegModel() {
JSONObject json = new JSONObject();
JSONObject data = new JSONObject();
String reg = configService.getConfig(Config.USER_REG);
boolean model = false;
if (reg == null) {
reg = "0";
}
if (reg.equals("1")) {
model = true;
}
data.put(Config.USER_REG, model);
json.put("code", 0);
json.put("data", data);
return json;
}
@ResponseBody
@RequestMapping("/system/set/ffmpeg.do")
public JSONObject setFFmpeg(String ffmpeg) throws UnsupportedEncodingException {
ffmpeg = URLDecoder.decode(ffmpeg, "UTF-8");
configService.setConfig(Config.SYSTEM_VIDEO_FFMPEG, ffmpeg);
AppData.FFMPEG = ffmpeg;
JSONObject json = new JSONObject();
json.put("code", 0);
json.put("msg", "ok");
return json;
}
@ResponseBody
@RequestMapping("/system/get/ffmpeg.do")
public JSONObject getFFmpeg() {
JSONObject json = new JSONObject();
JSONObject data = new JSONObject();
String reg = configService.getConfig(Config.SYSTEM_VIDEO_FFMPEG);
data.put(Config.SYSTEM_VIDEO_FFMPEG, reg);
json.put("code", 0);
json.put("data", data);
return json;
}
@ResponseBody
@RequestMapping("/system/set/savelive.do")
public JSONObject setSaveLive(String model) throws UnsupportedEncodingException {
JSONObject json = new JSONObject();
if (StringUtils.isEmpty(configService.getConfig(Config.SYSTEM_VIDEO_FFMPEG))) {
json.put("code", 404);
json.put("msg", "请先设置FFmpeg路径");
return json;
}
model = URLDecoder.decode(model, "UTF-8");
configService.setConfig(Config.SYSTEM_VIDEO_SAVE_MODEL, model);
AppData.LIVE_SAVE_FFMPEG = model.equals("ffmpeg");
json.put("code", 0);
json.put("msg", "ok");
return json;
}
@ResponseBody
@RequestMapping("/system/get/savelive.do")
public JSONObject getSaveLiveModel() {
JSONObject json = new JSONObject();
JSONObject data = new JSONObject();
String reg = configService.getConfig(Config.SYSTEM_VIDEO_SAVE_MODEL);
System.out.println(reg);
data.put(Config.SYSTEM_VIDEO_SAVE_MODEL, (!StringUtils.isEmpty(reg) && reg.equals("ffmpeg")));
json.put("code", 0);
json.put("data", data);
return json;
}
@ResponseBody
@RequestMapping("/system/qq/login.do")
public JSONObject loginQQ() {
JSONObject json = new JSONObject();
json.put("code", 0);
json.put("msg", "ok");
return json;
}
}