GPT Key API和web接口

This commit is contained in:
userA
2023-10-16 00:46:20 +08:00
parent 9810c882f6
commit d0f2a60f5d
3 changed files with 26 additions and 3 deletions

4
.idea/compiler.xml generated
View File

@@ -38,7 +38,7 @@
</component>
<component name="JavacSettings">
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
<module name="ChopperBot" options="-parameters" />
<module name="ChopperBot" options="" />
<module name="chopperbot-account" options="-parameters" />
<module name="chopperbot-barrage" options="-parameters" />
<module name="chopperbot-common" options="-parameters" />
@@ -53,4 +53,4 @@
<module name="chopperbot-test" options="-parameters" />
</option>
</component>
</project>
</project>

View File

@@ -36,7 +36,10 @@ public class GPTApi {
}
public boolean addKey(GPTKey key){
return mapper.insert(key)==1;
if (mapper.selectCount(new QueryWrapper<GPTKey>())==0) {
return mapper.insert(key)==1;
}
return false;
}
public GPTKey getKey(){

View File

@@ -1,14 +1,17 @@
package org.example.controller;
import org.apache.tools.ant.taskdefs.Get;
import org.example.core.pojo.Account;
import org.example.core.pojo.AccountVO;
import org.example.pojo.GPTKey;
import org.example.service.AccountService;
import org.example.util.Result;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
/**
* @Description
@@ -44,4 +47,21 @@ public class AccountController {
accountService.edit(account);
return Result.success();
}
@GetMapping(value = "/gpt/key")
public Result getGPT(){
return Result.success(Map.of("key",accountService.chatGptPlugin().getKey()));
}
@PostMapping(value = "/gpt/add")
public Result addGPT(@RequestBody GPTKey key){
boolean b = accountService.chatGptPlugin().addKey(key);
return Result.success(Map.of("success",b));
}
@PostMapping(value="/gpt/update")
public Result updateGPT(@RequestBody GPTKey key){
boolean b = accountService.chatGptPlugin().changeKey(key);
return Result.success(Map.of("success",b));
}
}