Skip to content
This repository has been archived by the owner on Apr 8, 2024. It is now read-only.

Commit

Permalink
新增获取refresh_token,1000额度
Browse files Browse the repository at this point in the history
  • Loading branch information
Yanyutin753 committed Dec 23, 2023
1 parent 60bf273 commit 0066daf
Show file tree
Hide file tree
Showing 62 changed files with 514 additions and 125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.*;

import java.util.List;
Expand All @@ -35,9 +34,12 @@ public class apiController {
*/
private static String previousIPAddress = "";
public String deploy = "default";

private systemService systemService;

@Value("${deployPosition}")
private String deployPosition;

private apiService apiService;
/**
* 部署方法
Expand Down Expand Up @@ -95,11 +97,10 @@ public Result selectToken(@RequestParam("name") String name) {
public Result addToken(@RequestBody token token) {
try {
String res = apiService.addToken(token);
if (res.length() > 300) {
if (res.contains("成功")) {
return Result.success(res);
} else if (res.length() == 0) {
return Result.success("添加成功,已装填你的token");
} else {
}
else {
return Result.error(res);
}
} catch (Exception e) {
Expand Down Expand Up @@ -227,20 +228,22 @@ public Result openContainer() {
@GetMapping("/reload")
public Result reloadContainer() {
try {
String externalIP = previousIPAddress;
systemSetting systemSetting = systemService.selectSetting();
String baseUrlWithoutPath;
systemSetting systemSetting = systemService.selectSettingUrl();
String bingUrl = systemSetting.getBing();
String[] parts = bingUrl.split(":");
String baseUrlWithoutPath = "http://" + externalIP + ":" + parts[1] + "/" + systemSetting.getProxy_api_prefix();
if (systemSetting.getAutoToken_url().equals("default")) {
baseUrlWithoutPath = "http://127.0.0.1" + ":" + parts[1] + "/" + systemSetting.getProxy_api_prefix() + reloadUrl;
} else {
baseUrlWithoutPath = systemSetting.getAutoToken_url() + reloadUrl;
}
if (parts.length != 2) {
return Result.error("bind填写有误,无法提取port");
}
log.info("重载的PandoraNext服务Url:" + baseUrlWithoutPath);

String reloadCommand = "curl -i -X POST " + baseUrlWithoutPath + reloadUrl;
String reloadCommand = "curl -i -X POST " + baseUrlWithoutPath;
log.info("重载命令:" + reloadCommand);
// 执行重载进程的命令
Process reloadProcess = executeCommand(reloadCommand);
log.info("重载命令:" + reloadCommand);
// 等待重载进程完成
try {
int exitCode = reloadProcess.waitFor();
Expand Down Expand Up @@ -402,29 +405,30 @@ public Result getPandoraLimit() {
}

/**
* 该功能目前已弃用
* pandoara_Ip要是填写的是default
* 每隔60分钟刷新一次ip,若地址发生变化并重新验证
* 如不是则放回:"Ip将采用用户设置:"+pandoara_Ip
*/
@Scheduled(fixedRate = 3600000)
public void autoCheckIp() {
if (!pandoara_Ip.equals("default")) {
if (previousIPAddress != pandoara_Ip) {
previousIPAddress = pandoara_Ip;
}
log.info("Ip将采用用户设置:" + pandoara_Ip);
return;
}
String currentIPAddress = apiService.getIp();
if (currentIPAddress == "失败") {
log.info("获取IP失败!");
return;
}
if (!currentIPAddress.equals(previousIPAddress)) {
log.info("IP地址已变化,新的IP地址是:" + currentIPAddress);
previousIPAddress = currentIPAddress;
} else {
log.info("IP地址未发生变化。");
}
}
// @Scheduled(fixedRate = 3600000)
// public void autoCheckIp() {
// if (!pandoara_Ip.equals("default")) {
// if (previousIPAddress != pandoara_Ip) {
// previousIPAddress = pandoara_Ip;
// }
// log.info("Ip将采用用户设置:" + pandoara_Ip);
// return;
// }
// String currentIPAddress = apiService.getIp();
// if (currentIPAddress == "失败") {
// log.info("获取IP失败!");
// return;
// }
// if (!currentIPAddress.equals(previousIPAddress)) {
// log.info("IP地址已变化,新的IP地址是:" + currentIPAddress);
// previousIPAddress = currentIPAddress;
// } else {
// log.info("IP地址未发生变化。");
// }
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ public void toUpdateToken() {
log.info(Result.error("自动检查更新access_token,share_token和pool_token失败").toString());
}

/**
* 一键检查所有session或者refresh_token
* 失效变黄
* 并更新所有access_token和share_token
* 重新组成pool_token
* @return
*/
@GetMapping("updateAllToken")
public Result toUpdateAllToken() {
try {
Expand Down Expand Up @@ -79,7 +86,7 @@ public Result toUpdateToken(@RequestBody token token) {
} catch (Exception e) {
e.printStackTrace();
}
return Result.error("生成access_token和share_token失败,请请确保填写token为session_token!");
return Result.error("生成access_token和share_token失败,请请确保填写token为session或refresh_token!");
}

/**
Expand All @@ -94,11 +101,11 @@ public Result toUpdateSessionToken(@RequestBody token token) {
try {
token resToken = apiService.updateSession(token);
if (resToken != null) {
return Result.success("更新session成功");
return Result.success("刷新成功!");
}
} catch (Exception e) {
e.printStackTrace();
}
return Result.error("刷新session_token失败,请尝重新刷新!");
return Result.error("刷新失败,请尝重新刷新或检查proxy的url填写是否正确!");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public Result login(@RequestBody systemSetting setting) {

/**
* 验证是否登录成功
*
* @return 没登陆成功否则返回"NOT_LOGIN"
*/
@PostMapping("/loginToken")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public Result changePoolToken(@RequestBody poolToken poolToken) {
} catch (Exception e) {
e.printStackTrace();
}
return Result.error("修改失败!");
return Result.error("更换失败!");
}

@GetMapping("selectPoolToken")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,15 @@ public class token {
private String access_token;

/**
* token session_token获取的时间
* token session_token或者refresh_token获取的时间
*/
private String updateTime;

/**
* token 是否使用refresh_token
*/
private boolean useRefreshToken;

/**
* token 检查session是否过期
*/
Expand Down
Loading

0 comments on commit 0066daf

Please sign in to comment.