feat: add ChatGPT Next Web
This commit is contained in:
parent
8a887cbfee
commit
f685891110
@ -1,11 +1,17 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import { Button, Form, Label, Modal, Pagination, Popup, Table, Dropdown } from 'semantic-ui-react';
|
import { Button, Dropdown, Form, Label, Pagination, Popup, Table } from 'semantic-ui-react';
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
import { API, copy, showError, showSuccess, showWarning, timestamp2string } from '../helpers';
|
import { API, copy, showError, showSuccess, showWarning, timestamp2string } from '../helpers';
|
||||||
|
|
||||||
import { ITEMS_PER_PAGE } from '../constants';
|
import { ITEMS_PER_PAGE } from '../constants';
|
||||||
import { renderQuota } from '../helpers/render';
|
import { renderQuota } from '../helpers/render';
|
||||||
|
|
||||||
|
const COPY_OPTIONS = [
|
||||||
|
{ key: 'next', text: 'ChatGPT Next Web', value: 'next' },
|
||||||
|
{ key: 'ama', text: 'AMA 问天', value: 'ama' },
|
||||||
|
{ key: 'opencat', text: 'OpenCat', value: 'opencat' },
|
||||||
|
];
|
||||||
|
|
||||||
function renderTimestamp(timestamp) {
|
function renderTimestamp(timestamp) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@ -68,25 +74,32 @@ const TokensTable = () => {
|
|||||||
const refresh = async () => {
|
const refresh = async () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
await loadTokens(activePage - 1);
|
await loadTokens(activePage - 1);
|
||||||
}
|
};
|
||||||
|
|
||||||
const onCopy = async (type,key)=>{
|
const onCopy = async (type, key) => {
|
||||||
let status = localStorage.getItem('status');
|
let status = localStorage.getItem('status');
|
||||||
let server_address="";
|
let serverAddress = '';
|
||||||
if (status) {
|
if (status) {
|
||||||
status = JSON.parse(status);
|
status = JSON.parse(status);
|
||||||
server_address = encodeURIComponent(status.server_address)
|
serverAddress = status.server_address;
|
||||||
}
|
}
|
||||||
|
if (serverAddress === '') {
|
||||||
|
serverAddress = window.location.origin;
|
||||||
|
}
|
||||||
|
let encodedServerAddress = encodeURIComponent(serverAddress);
|
||||||
let url;
|
let url;
|
||||||
switch (type){
|
switch (type) {
|
||||||
case 'ama':
|
case 'ama':
|
||||||
url=`ama://set-api-key?server=${server_address}&key=sk-${key}`
|
url = `ama://set-api-key?server=${encodedServerAddress}&key=sk-${key}`;
|
||||||
break;
|
break;
|
||||||
case 'opencat':
|
case 'opencat':
|
||||||
url=`opencat://team/join?domain=${server_address}&token=sk-${key}`
|
url = `opencat://team/join?domain=${encodedServerAddress}&token=sk-${key}`;
|
||||||
break
|
break;
|
||||||
|
case 'next':
|
||||||
|
url = `https://chatgpt1.nextweb.fun/#/?settings=%7B%22key%22:%22sk-${key}%22,%22url%22:%22${serverAddress}%22%7D`;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
url=`sk-${key}`
|
url = `sk-${key}`;
|
||||||
}
|
}
|
||||||
if (await copy(url)) {
|
if (await copy(url)) {
|
||||||
showSuccess('已复制到剪贴板!');
|
showSuccess('已复制到剪贴板!');
|
||||||
@ -94,7 +107,7 @@ const TokensTable = () => {
|
|||||||
showWarning('无法复制到剪贴板,请手动复制,已将令牌填入搜索框。');
|
showWarning('无法复制到剪贴板,请手动复制,已将令牌填入搜索框。');
|
||||||
setSearchKeyword(url);
|
setSearchKeyword(url);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
loadTokens(0)
|
loadTokens(0)
|
||||||
@ -173,11 +186,6 @@ const TokensTable = () => {
|
|||||||
setTokens(sortedTokens);
|
setTokens(sortedTokens);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
};
|
};
|
||||||
const copy_actions = [
|
|
||||||
{ key: 'ama', text: 'AMA 问天', value: 'ama' },
|
|
||||||
{ key: 'opencat', text: 'OpenCat', value: 'opencat' },
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@ -266,12 +274,12 @@ const TokensTable = () => {
|
|||||||
<Table.Cell>{token.expired_time === -1 ? '永不过期' : renderTimestamp(token.expired_time)}</Table.Cell>
|
<Table.Cell>{token.expired_time === -1 ? '永不过期' : renderTimestamp(token.expired_time)}</Table.Cell>
|
||||||
<Table.Cell>
|
<Table.Cell>
|
||||||
<div>
|
<div>
|
||||||
<Button.Group color='green' size={'small'} >
|
<Button.Group color='green' size={'small'}>
|
||||||
<Button
|
<Button
|
||||||
size={'small'}
|
size={'small'}
|
||||||
positive
|
positive
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
await onCopy('', token.key)
|
await onCopy('', token.key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
@ -280,9 +288,9 @@ const TokensTable = () => {
|
|||||||
<Dropdown
|
<Dropdown
|
||||||
className='button icon'
|
className='button icon'
|
||||||
floating
|
floating
|
||||||
options={copy_actions}
|
options={COPY_OPTIONS}
|
||||||
onChange={async (e,{value}={})=>{
|
onChange={async (e, { value } = {}) => {
|
||||||
await onCopy(value, token.key)
|
await onCopy(value, token.key);
|
||||||
}}
|
}}
|
||||||
trigger={<></>}
|
trigger={<></>}
|
||||||
/>
|
/>
|
||||||
|
Loading…
Reference in New Issue
Block a user