From 66b114ed0b9612740275dd11e09e3173b614aba7 Mon Sep 17 00:00:00 2001 From: userA Date: Mon, 23 Oct 2023 22:38:44 +0800 Subject: [PATCH 1/6] =?UTF-8?q?LabelManage=E6=8F=92=E4=BB=B6=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=20=E6=9C=AA=E6=B3=A8=E5=86=8C=E7=9A=84=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E4=B8=8D=E4=BC=9A=E5=9C=A8=E5=89=8D=E7=AB=AF=E6=98=BE?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/api/LabelManagerPluginApi.java | 44 ++++++ .../org/example/api/OpenAPIPluginApi.java | 4 + .../core/label/LabelManagerPlugin.java | 26 ++-- .../java/org/example/pojo/VideoLabel.java | 1 + .../java/org/example/aop/PluginAspect.java | 2 +- .../example/bean}/section/VideoSection.java | 2 +- .../plugin/PluginNotRegisterException.java | 10 ++ .../example/controller/AccountController.java | 37 ++++- .../exception/GlobalExceptionHandler.java | 5 +- .../org/example/service/AccountService.java | 3 + .../service/impl/AccountServiceImpl.java | 9 ++ .../auto/video/title/GptTitleGenerator.java | 4 +- .../core/section/VideoSectionWorkShop.java | 3 +- config/chopperBotConfig.json | 2 +- console-ui/src/api/account/labelApi.ts | 26 ++++ .../src/components/navigation/MainMenu.vue | 25 +++- console-ui/src/configs/menus/apps.menu.ts | 61 +++++---- console-ui/src/locales/en.ts | 2 +- console-ui/src/locales/zhHans.ts | 3 +- console-ui/src/router/apps.routes.ts | 14 ++ console-ui/src/utils/request.ts | 50 +++---- console-ui/src/utils/validate.ts | 5 + .../hot/live_follow/pages/LiveFollowPage.vue | 2 - .../src/views/app/label/LabelManageView.vue | 126 ++++++++++++++++++ .../src/views/app/label/LabelManagerStore.ts | 48 +++++++ console-ui/src/views/app/label/LabelTypes.ts | 5 + .../src/views/setting/plugin/pluginStore.ts | 16 ++- 27 files changed, 449 insertions(+), 86 deletions(-) create mode 100644 chopperbot-account/src/main/java/org/example/api/LabelManagerPluginApi.java rename {chopperbot-section/src/main/java/org/example/core => chopperbot-common/src/main/java/org/example/bean}/section/VideoSection.java (95%) create mode 100644 console-ui/src/api/account/labelApi.ts create mode 100644 console-ui/src/views/app/label/LabelManageView.vue create mode 100644 console-ui/src/views/app/label/LabelManagerStore.ts create mode 100644 console-ui/src/views/app/label/LabelTypes.ts diff --git a/chopperbot-account/src/main/java/org/example/api/LabelManagerPluginApi.java b/chopperbot-account/src/main/java/org/example/api/LabelManagerPluginApi.java new file mode 100644 index 0000000..0b5484b --- /dev/null +++ b/chopperbot-account/src/main/java/org/example/api/LabelManagerPluginApi.java @@ -0,0 +1,44 @@ +package org.example.api; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import org.example.core.label.LabelManagerPlugin; +import org.example.pojo.VideoLabel; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +/** + * @author Genius + * @date 2023/10/23 17:22 + **/ +@Component +public class LabelManagerPluginApi { + @Resource + LabelManagerPlugin plugin; + + public List labelList(){ + return plugin.getMapper().selectList(new QueryWrapper<>()); + } + + public VideoLabel addLabel(VideoLabel label){ + try { + label.setLabelId(UUID.randomUUID().toString()); + if (plugin.getMapper().insert(label)>0) { + return label; + } + }catch (Exception e){ + } + return null; + } + + public boolean deleteLabel(String label){ + return plugin.getMapper().deleteByMap(Map.of("label",label))>0; + } + + public boolean updateLabel(VideoLabel label){ + return plugin.getMapper().update(label,new QueryWrapper().eq("label_id",label.getLabelId()))>0; + } +} diff --git a/chopperbot-account/src/main/java/org/example/api/OpenAPIPluginApi.java b/chopperbot-account/src/main/java/org/example/api/OpenAPIPluginApi.java index 9136e15..b1175dd 100644 --- a/chopperbot-account/src/main/java/org/example/api/OpenAPIPluginApi.java +++ b/chopperbot-account/src/main/java/org/example/api/OpenAPIPluginApi.java @@ -8,6 +8,7 @@ import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.util.List; +import java.util.Map; /** * @Date 2023/10/12 @@ -22,6 +23,9 @@ public class OpenAPIPluginApi { return plugin.getMapper().update(newKey, new QueryWrapper().eq("function", newKey.getFunction())) == 1; } + public boolean deleteKey(String function){ + return plugin.getMapper().deleteByMap(Map.of("function",function))==1; + } public boolean addKey(GPTKey key){ return plugin.getMapper().insert(key)==1; } diff --git a/chopperbot-account/src/main/java/org/example/core/label/LabelManagerPlugin.java b/chopperbot-account/src/main/java/org/example/core/label/LabelManagerPlugin.java index 6ccdd6e..80088ce 100644 --- a/chopperbot-account/src/main/java/org/example/core/label/LabelManagerPlugin.java +++ b/chopperbot-account/src/main/java/org/example/core/label/LabelManagerPlugin.java @@ -1,6 +1,7 @@ package org.example.core.label; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import lombok.Data; import org.example.mapper.LabelMapper; import org.example.plugin.SpringBootPlugin; import org.example.pojo.VideoLabel; @@ -11,6 +12,7 @@ import javax.annotation.Resource; import java.awt.*; import java.util.List; import java.util.Map; +import java.util.UUID; import java.util.stream.Collectors; /** @@ -18,6 +20,7 @@ import java.util.stream.Collectors; * @date 2023/10/23 00:10 **/ @Component +@Data public class LabelManagerPlugin extends SpringBootPlugin { @Resource @@ -31,32 +34,19 @@ public class LabelManagerPlugin extends SpringBootPlugin { @Override @SQLInit(table = "video_label",tableSQL = "CREATE TABLE \"video_label\" (\n" + "\t\"id\"\tINTEGER NOT NULL,\n" + + "\t\"label_id\"\tTEXT NOT NULL UNIQUE,\n" + "\t\"label\"\tTEXT NOT NULL UNIQUE,\n" + "\tPRIMARY KEY(\"id\" AUTOINCREMENT)\n" + ")",mapper = LabelMapper.class) public List sqlInit() { - return List.of(new VideoLabel(null,"搞笑"), - new VideoLabel(null,"破防"),new VideoLabel(null,"泪目"), - new VideoLabel(null,"精彩操作")); + return List.of(new VideoLabel(null, UUID.randomUUID().toString(),"搞笑"), + new VideoLabel(null, UUID.randomUUID().toString(),"破防"), + new VideoLabel(null, UUID.randomUUID().toString(),"泪目"), + new VideoLabel(null, UUID.randomUUID().toString(),"精彩操作")); } public List labelStrList(){ return mapper.selectList(new QueryWrapper<>()).stream().map(VideoLabel::getLabel).collect(Collectors.toList()); } - public List labelList(){ - return mapper.selectList(new QueryWrapper<>()); - } - - public boolean addLabel(VideoLabel label){ - return mapper.insert(label)>0; - } - - public boolean deleteLabel(String label){ - return mapper.deleteByMap(Map.of("label",label))>0; - } - - public boolean updateLabel(VideoLabel label){ - return mapper.update(label,new QueryWrapper().eq("id",label.getId()))>0; - } } diff --git a/chopperbot-account/src/main/java/org/example/pojo/VideoLabel.java b/chopperbot-account/src/main/java/org/example/pojo/VideoLabel.java index 9142e96..fca4f6e 100644 --- a/chopperbot-account/src/main/java/org/example/pojo/VideoLabel.java +++ b/chopperbot-account/src/main/java/org/example/pojo/VideoLabel.java @@ -15,5 +15,6 @@ import lombok.NoArgsConstructor; @NoArgsConstructor public class VideoLabel { private Integer id; + private String labelId; private String label; } diff --git a/chopperbot-common/src/main/java/org/example/aop/PluginAspect.java b/chopperbot-common/src/main/java/org/example/aop/PluginAspect.java index af57ea4..77e789d 100644 --- a/chopperbot-common/src/main/java/org/example/aop/PluginAspect.java +++ b/chopperbot-common/src/main/java/org/example/aop/PluginAspect.java @@ -35,7 +35,7 @@ public class PluginAspect { for (String plugin : annotation.needPlugin()) { if(!InitPluginRegister.isRegister(plugin)){ - throw new PluginNotRegisterException(); + throw new PluginNotRegisterException(annotation.needPlugin()); } } } diff --git a/chopperbot-section/src/main/java/org/example/core/section/VideoSection.java b/chopperbot-common/src/main/java/org/example/bean/section/VideoSection.java similarity index 95% rename from chopperbot-section/src/main/java/org/example/core/section/VideoSection.java rename to chopperbot-common/src/main/java/org/example/bean/section/VideoSection.java index d112e83..7d46e1d 100644 --- a/chopperbot-section/src/main/java/org/example/core/section/VideoSection.java +++ b/chopperbot-common/src/main/java/org/example/bean/section/VideoSection.java @@ -1,4 +1,4 @@ -package org.example.core.section; +package org.example.bean.section; import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; diff --git a/chopperbot-common/src/main/java/org/example/exception/plugin/PluginNotRegisterException.java b/chopperbot-common/src/main/java/org/example/exception/plugin/PluginNotRegisterException.java index f36f9d9..5e80fa2 100644 --- a/chopperbot-common/src/main/java/org/example/exception/plugin/PluginNotRegisterException.java +++ b/chopperbot-common/src/main/java/org/example/exception/plugin/PluginNotRegisterException.java @@ -2,14 +2,24 @@ package org.example.exception.plugin; import org.example.exception.Impl.ResultCode; +import java.util.Arrays; +import java.util.stream.Collectors; + /** * @author Genius * @date 2023/08/02 16:59 **/ public class PluginNotRegisterException extends PluginException{ + private String pluginName[]; public PluginNotRegisterException() { super("Error! Plugin Not Register!"); resultCode = ResultCode.PLUGIN_NOT_REGISTER; } + + public PluginNotRegisterException(String...pluginName) { + super(String.format("Error! %s Plugin Not Register!",Arrays.stream(pluginName).collect(Collectors.toList()).toString())); + resultCode = ResultCode.PLUGIN_NOT_REGISTER; + this.pluginName = pluginName; + } } diff --git a/chopperbot-console/src/main/java/org/example/controller/AccountController.java b/chopperbot-console/src/main/java/org/example/controller/AccountController.java index e214af1..6238ddd 100644 --- a/chopperbot-console/src/main/java/org/example/controller/AccountController.java +++ b/chopperbot-console/src/main/java/org/example/controller/AccountController.java @@ -1,9 +1,11 @@ package org.example.controller; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import org.example.pojo.Account; import org.example.pojo.AccountVO; import org.example.pojo.GPTKey; +import org.example.pojo.VideoLabel; import org.example.service.AccountService; import org.example.util.Result; import org.springframework.web.bind.annotation.*; @@ -47,11 +49,16 @@ public class AccountController { return Result.success(); } - @GetMapping(value = "/gpt/key") + @GetMapping(value = "/gpt/keys") public Result getGPT(){ return Result.success(Map.of("list",accountService.chatGptPlugin().getKeys())); } + @GetMapping(value = "/gpt/delete") + public Result deleteGPT(@RequestParam String function){ + return Result.success(Map.of("success",accountService.chatGptPlugin().deleteKey(function))); + } + @PostMapping(value = "/gpt/add") public Result addGPT(@RequestBody GPTKey key){ boolean b = accountService.chatGptPlugin().addKey(key); @@ -63,4 +70,32 @@ public class AccountController { boolean b = accountService.chatGptPlugin().changeKey(key); return Result.success(Map.of("success",b)); } + + @GetMapping(value = "/gpt/functions") + public Result getFunctions(){ + return Result.success(Map.of("list",accountService.chatGptPlugin().functions())); + } + + @GetMapping(value = "/label/list") + public Result labelList(){ + return Result.success(Map.of("list",accountService.labelManagerPlugin().labelList())); + } + + @PostMapping(value = "/label/add") + public Result addLabel(@RequestBody VideoLabel label){ + if (accountService.labelManagerPlugin().addLabel(label)==null) { + return Result.error("添加失败"); + } + return Result.success(Map.of("data",label)); + } + + @GetMapping(value = "/label/delete") + public Result deleteLabel(@RequestParam String label){ + return Result.success(Map.of("success",accountService.labelManagerPlugin().deleteLabel(label))); + } + + @PostMapping(value = "/label/update") + public Result updateLabel(@RequestBody VideoLabel label){ + return Result.success(Map.of("success",accountService.labelManagerPlugin().updateLabel(label))); + } } diff --git a/chopperbot-console/src/main/java/org/example/exception/GlobalExceptionHandler.java b/chopperbot-console/src/main/java/org/example/exception/GlobalExceptionHandler.java index 7dd8870..00e466a 100644 --- a/chopperbot-console/src/main/java/org/example/exception/GlobalExceptionHandler.java +++ b/chopperbot-console/src/main/java/org/example/exception/GlobalExceptionHandler.java @@ -7,6 +7,7 @@ import org.example.exception.plugin.PluginException; import org.example.exception.plugin.PluginNotRegisterException; import org.example.log.ChopperLogFactory; import org.example.log.LoggerType; +import org.example.util.ExceptionUtil; import org.example.util.Result; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -32,10 +33,10 @@ public class GlobalExceptionHandler { @ExceptionHandler(PluginException.class) public Result handlerPluginException(HttpServletRequest request,PluginException ex){ - logger.error("Handle Exception Request Url:{},Exception:{}", request.getRequestURL(), ex); + logger.error("Handle Exception Request Url:{},Exception:{}", request.getRequestURL(), ExceptionUtil.getCause(ex)); if(ex instanceof PluginNotRegisterException){ PluginNotRegisterException exception = (PluginNotRegisterException) ex; - return Result.error(exception.getResultCode()); + return Result.error(exception.getResultCode(),ExceptionUtil.getCause(ex)); }else if(ex instanceof PluginDependOnException){ PluginDependOnException exception = (PluginDependOnException) ex; String msg = "[%s] plugin depend on [%s]!"; diff --git a/chopperbot-console/src/main/java/org/example/service/AccountService.java b/chopperbot-console/src/main/java/org/example/service/AccountService.java index 4ea0e82..14487ed 100644 --- a/chopperbot-console/src/main/java/org/example/service/AccountService.java +++ b/chopperbot-console/src/main/java/org/example/service/AccountService.java @@ -3,6 +3,7 @@ package org.example.service; import org.example.api.AccountApi; +import org.example.api.LabelManagerPluginApi; import org.example.api.OpenAPIPluginApi; /** @@ -15,4 +16,6 @@ public interface AccountService { AccountApi accountPlugin(); OpenAPIPluginApi chatGptPlugin(); + + LabelManagerPluginApi labelManagerPlugin(); } diff --git a/chopperbot-console/src/main/java/org/example/service/impl/AccountServiceImpl.java b/chopperbot-console/src/main/java/org/example/service/impl/AccountServiceImpl.java index b9ce879..0056fac 100644 --- a/chopperbot-console/src/main/java/org/example/service/impl/AccountServiceImpl.java +++ b/chopperbot-console/src/main/java/org/example/service/impl/AccountServiceImpl.java @@ -2,6 +2,7 @@ package org.example.service.impl; import org.example.api.AccountApi; +import org.example.api.LabelManagerPluginApi; import org.example.api.OpenAPIPluginApi; import org.example.service.AccountService; @@ -22,6 +23,9 @@ public class AccountServiceImpl implements AccountService { @Resource OpenAPIPluginApi openAPIPluginApi; + @Resource + LabelManagerPluginApi labelManagerPluginApi; + @Override public AccountApi accountPlugin() { return accountApi; @@ -31,4 +35,9 @@ public class AccountServiceImpl implements AccountService { public OpenAPIPluginApi chatGptPlugin() { return openAPIPluginApi; } + + @Override + public LabelManagerPluginApi labelManagerPlugin() { + return labelManagerPluginApi; + } } diff --git a/chopperbot-section-work/src/main/java/org/example/core/auto/video/title/GptTitleGenerator.java b/chopperbot-section-work/src/main/java/org/example/core/auto/video/title/GptTitleGenerator.java index e60f886..b1181d2 100644 --- a/chopperbot-section-work/src/main/java/org/example/core/auto/video/title/GptTitleGenerator.java +++ b/chopperbot-section-work/src/main/java/org/example/core/auto/video/title/GptTitleGenerator.java @@ -22,7 +22,7 @@ import java.util.List; public class GptTitleGenerator implements TitleGenerator{ @Resource - TitleSchemeMapper titleSchemeMapper; + TitleSchemeMapper mapper; private List schemeList; public GptTitleGenerator() { @@ -46,7 +46,7 @@ public class GptTitleGenerator implements TitleGenerator{ throw PluginDependOnException.MissingFatherPlugin(PluginName.CHAT_GPT,""); } try { - schemeList = titleSchemeMapper.selectList(new QueryWrapper<>()); + schemeList = mapper.selectList(new QueryWrapper<>()); }catch (Exception e){ throw new RuntimeException("读取title_scheme表失败"); } diff --git a/chopperbot-section/src/main/java/org/example/core/section/VideoSectionWorkShop.java b/chopperbot-section/src/main/java/org/example/core/section/VideoSectionWorkShop.java index bb73e40..48f6e33 100644 --- a/chopperbot-section/src/main/java/org/example/core/section/VideoSectionWorkShop.java +++ b/chopperbot-section/src/main/java/org/example/core/section/VideoSectionWorkShop.java @@ -1,8 +1,7 @@ package org.example.core.section; -import org.apache.coyote.Request; import org.example.bean.Live; -import org.example.cache.FileCache; +import org.example.bean.section.VideoSection; import org.example.constpool.ConstPool; import org.example.constpool.FileNameBuilder; import org.example.constpool.GlobalFileCache; diff --git a/config/chopperBotConfig.json b/config/chopperBotConfig.json index 56d3827..f2e1eb2 100644 --- a/config/chopperBotConfig.json +++ b/config/chopperBotConfig.json @@ -38,5 +38,5 @@ "OpenAPI":true } }, - "updateTime":"2023-10-23 15:10:01" + "updateTime":"2023-10-23 22:36:56" } \ No newline at end of file diff --git a/console-ui/src/api/account/labelApi.ts b/console-ui/src/api/account/labelApi.ts new file mode 100644 index 0000000..50d6007 --- /dev/null +++ b/console-ui/src/api/account/labelApi.ts @@ -0,0 +1,26 @@ +import request from "@/utils/request"; +import { Label } from "@/views/app/label/LabelTypes"; +export function list() { + return request({ + url: "/account/label/list/", + method: "get", + }); +} + +export function add(label: string) { + return request.post("/account/label/add/", { label: label }); +} + +export function remove(label: string) { + return request({ + url: "/account/label/delete/", + method: "get", + params: { + label: label, + }, + }); +} + +export function update(Label: Label) { + return request.post("/account/label/update/", Label); +} diff --git a/console-ui/src/components/navigation/MainMenu.vue b/console-ui/src/components/navigation/MainMenu.vue index 74634ed..caa6db6 100644 --- a/console-ui/src/components/navigation/MainMenu.vue +++ b/console-ui/src/components/navigation/MainMenu.vue @@ -1,7 +1,8 @@