Skip to content

Commit

Permalink
Merge pull request #37 from mouxangithub/mdui2
Browse files Browse the repository at this point in the history
将刷新接口合并成一个域名请求,潘多拉自带platform的api,无需单独再配
  • Loading branch information
woodchen-ink authored Jan 4, 2024
2 parents 4c65ee7 + 82af4c8 commit 12885d6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 108 deletions.
52 changes: 9 additions & 43 deletions refresh_see.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<link rel="stylesheet" href="./static/css-1.css" type="text/css" />
<link rel="stylesheet" href="./static/mdui/mdui.css" />
<script src="./static/mdui/mdui.global.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/1.6.3/axios.min.js" integrity="sha512-JWQFV6OCC2o2x8x46YrEeFEQtzoNV++r9im8O8stv91YwHNykzIS2TbvAlFdeH0GVlpnyd79W0ZGmffcRi++Bw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>

<script>
mdui.setColorScheme("#0d2d44");
Expand All @@ -38,17 +37,15 @@
border-radius: 4px;
margin: 8px 0;
margin-top: 20px;
margin-left:20px;
margin-left: 20px;
}
</style>
<mdui-layout>
<mdui-layout-main>
<div class="mdui-main-container">
<div style="display: flex">
<h2 style="flex: 1">查询结果</h2>
<button class="copy-button" onclick="copySess()">
复制sess
</button>
<button class="copy-button" onclick="copySess()">复制sess</button>
<button class="copy-button" onclick="copyTable()">
复制全部内容
</button>
Expand Down Expand Up @@ -92,60 +89,29 @@ <h3>输入 API KEY</h3>
<p>本站不保存 KEY 信息,查询后请自行保存</p>
<mdui-text-field
id="api-key-input"
placeholder="请输入refresh_token,多个请换行"
placeholder="请输入 refresh_token,多个请回车换行"
label="refresh_token"
rows="6"
></mdui-text-field>

<mdui-select
id="refresh-token-api"
id="api-url-select"
icon="airline_stops"
label="刷新token线路"
label="查询线路"
value="https://ai.fakeopen.com"
onchange="toggleCustomUrlInput()"
>
<mdui-menu-item value="https://ai.fakeopen.com"
>[FakeOpen]ai.fakeopen.com</mdui-menu-item
>[FkopenAi]ai.fakeopen.com</mdui-menu-item
>
<mdui-menu-item value="custom">自定义,使用PandoraNext的API</mdui-menu-item>
<mdui-menu-item value="custom">[已前置https]自定义PandoraNext API</mdui-menu-item>
</mdui-select>

<mdui-select
id="api-url-select"
icon="airline_stops"
label="查询Sess线路"
value="https://api.openai.com"
onchange="toggleCustomUrlInput()"
>
<mdui-menu-item value="https://api.openai.com"
>[官网线路]api.openai.com</mdui-menu-item
>
<mdui-menu-item value="https://oapi.czl.net"
>[CZLoapi线路]oapi.czl.net</mdui-menu-item
>
<mdui-menu-item value="https://openai.996.lat"
>[群友CF反代]openai.996.lat</mdui-menu-item
>
<mdui-menu-item
value="https://gateway.ai.cloudflare.com/v1/feedd0aa8abd6875052d86a94f1baf83/test/openai"
>CF Gateway</mdui-menu-item
>
<mdui-menu-item value="custom">[已前置https]自定义</mdui-menu-item>
</mdui-select>

<mdui-text-field
type="text"
id="PandoraNext-url-input"
class="hidden"
label="PandoraNext API地址"
placeholder="输入PandoraNext的API地址和前缀"
></mdui-text-field>

<mdui-text-field
type="text"
id="custom-url-input"
label="自定义查询API"
placeholder="输入自定义API,填域名即可,无需https://"
placeholder="请输入PandoraNext的API地址和前缀"
label="PandoraNext API地址和前缀"
class="hidden"
></mdui-text-field>

Expand Down
96 changes: 31 additions & 65 deletions static/refresh_see.js
Original file line number Diff line number Diff line change
@@ -1,68 +1,61 @@
let serialNumber = 1;

// 线路选择框
function toggleCustomUrlInput() {
const refreshTokenApiElement = document.getElementById("refresh-token-api");
const PandoraNextUrlInput = document.getElementById("PandoraNext-url-input");
if (refreshTokenApiElement.value === "custom") {
PandoraNextUrlInput.classList.remove("hidden");
PandoraNextUrlInput.style.display = "inline-block";
PandoraNextUrlInput.style.marginTop = "5px";
} else {
PandoraNextUrlInput.classList.add("hidden");
PandoraNextUrlInput.style.display = "none";
}
// 获取id为"api-url-select"的元素
const selectElement = document.getElementById("api-url-select");
// 获取id为"custom-url-input"的元素
const customUrlInput = document.getElementById("custom-url-input");

// 如果selectElement的值为"custom"
if (selectElement.value === "custom") {
// 从customUrlInput的classList中移除"hidden"
customUrlInput.classList.remove("hidden");
customUrlInput.style.display = "inline-block";
customUrlInput.style.marginTop = "5px";
} else {
// 给customUrlInput的classList添加"hidden"
customUrlInput.classList.add("hidden");
customUrlInput.style.display = "none";
}
}

const service = axios.create({
withCredentials: true, // 跨域请求时发送Cookie
timeout: 60000, // 请求超时
});

function checkBilling(refreshToken, refUrl, apiUrl) {
function checkBilling(apiKey, apiUrl) {
return new Promise(async (resolve, reject) => {
try {
// 拼接url
var tokenUrl = `${apiUrl}`;
var loginUrl = `${apiUrl}/v1/dashboard/onboarding/login`;
// 使用"/auth/platform/refresh",潘多拉则需要加上/api
if (!apiUrl.startsWith("https://ai.fakeopen.com")) {
tokenUrl += "/api";
}
tokenUrl += "/auth/platform/refresh";

var urlencoded = new URLSearchParams();
urlencoded.append("refresh_token", refreshToken);
const response = await service.post(refUrl, urlencoded, {
urlencoded.append("refresh_token", apiKey);

let response = await fetch(tokenUrl, {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
body: urlencoded,
redirect: "follow",
});
const rdata = response.data;
console.log(`rdata: ${rdata}`);
const rdata = await response.json();
if (rdata && rdata.access_token && rdata.refresh_token) {
// 查询sess
const get_sess = await service.post(
`${apiUrl}/dashboard/onboarding/login`,
{},
{
headers: {
Authorization: "Bearer " + rdata.access_token,
"Content-Type": "application/json",
},
}
);
const getsessdata = get_sess.data;
console.log(`getsessdata: ${getsessdata}`);
const get_sess = await fetch(loginUrl, {
method: "POST", // 设置请求方法为 POST
headers: {
Authorization: "Bearer " + rdata.access_token,
"Content-Type": "application/json",
},
body: JSON.stringify({}), // 此处放置要发送的数据
});
const getsessdata = await get_sess.json();
if (getsessdata && getsessdata.user && getsessdata.user.session) {
resolve({token_info: rdata, ...getsessdata});
resolve({ token_info: rdata, ...getsessdata });
} else {
reject({token_info: rdata, ...getsessdata});
reject(getsessdata);
}
} else {
reject(rdata);
Expand All @@ -76,38 +69,16 @@ function checkBilling(refreshToken, refUrl, apiUrl) {
//查询函数
async function sendRequest() {
let apiKeyInput = document.getElementById("api-key-input");
let refreshTokenApi = document.getElementById("refresh-token-api");
let PandoraNextUrlInput = document.getElementById("PandoraNext-url-input");
let apiUrlSelect = document.getElementById("api-url-select");
let customUrlInput = document.getElementById("custom-url-input");

document
.getElementById("result-table")
.getElementsByTagName("tbody")[0].innerHTML = "";

let refUrl = refreshTokenApi.value;
let apiUrl = apiUrlSelect.value;
if (refUrl === "custom") {
refUrl = PandoraNextUrlInput.value.trim();
if (refUrl) {
refUrl += "/api";
}
}
if (!refUrl) {
mdui.alert({
headline: "无查询线路",
description: "请选择或自定义配置刷新token线路",
confirmText: "OK",
});
return;
}
if (!refUrl.startsWith("http://") && !refUrl.startsWith("https://")) {
refUrl = "https://" + refUrl;
}
if (apiUrlSelect.value === "custom") {
apiUrl = customUrlInput.value.trim();
}
refUrl += "/auth/platform/refresh";
if (!apiUrl) {
mdui.alert({
headline: "无查询线路",
Expand All @@ -119,11 +90,6 @@ async function sendRequest() {
if (!apiUrl.startsWith("http://") && !apiUrl.startsWith("https://")) {
apiUrl = "https://" + apiUrl;
}
if (!apiUrl.startsWith("https://gateway.ai.cloudflare.com")) {
apiUrl += "/v1"; // 如果不是,则添加路径‘/v1’
} else {
apiUrl = apiUrl.replace("/v1", ""); // 如果用户选择的选项是https://gateway.ai.cloudflare.com开头,则删除/v1
}
if (apiUrl && apiUrl.endsWith("/")) {
apiUrl = apiUrl.slice(0, -1); // 去掉末尾的"/"
}
Expand Down Expand Up @@ -160,7 +126,7 @@ async function sendRequest() {
serialNumberCell.textContent = serialNumber;
row.appendChild(serialNumberCell);
try {
let data = await checkBilling(token, refUrl, apiUrl);
let data = await checkBilling(token, apiUrl);
let user = data.user;
let session = user.session;
let token_info = data.token_info;
Expand Down

0 comments on commit 12885d6

Please sign in to comment.