mirror of
				https://github.com/songquanpeng/one-api.git
				synced 2025-11-04 15:53:42 +08:00 
			
		
		
		
	feat: able to copy scheme of ama, opencat & chatgpt next web (#343)
* Token Adds Option to Quickly Copy AMA and OpenCat URL Scheme * feat: add ChatGPT Next Web --------- Co-authored-by: JustSong <songquanpeng@foxmail.com>
This commit is contained in:
		@@ -1,11 +1,17 @@
 | 
			
		||||
import React, { useEffect, useState } from 'react';
 | 
			
		||||
import { Button, Form, Label, Modal, Pagination, Popup, Table } from 'semantic-ui-react';
 | 
			
		||||
import { Button, Dropdown, Form, Label, Pagination, Popup, Table } from 'semantic-ui-react';
 | 
			
		||||
import { Link } from 'react-router-dom';
 | 
			
		||||
import { API, copy, showError, showSuccess, showWarning, timestamp2string } from '../helpers';
 | 
			
		||||
 | 
			
		||||
import { ITEMS_PER_PAGE } from '../constants';
 | 
			
		||||
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) {
 | 
			
		||||
  return (
 | 
			
		||||
    <>
 | 
			
		||||
@@ -68,7 +74,40 @@ const TokensTable = () => {
 | 
			
		||||
  const refresh = async () => {
 | 
			
		||||
    setLoading(true);
 | 
			
		||||
    await loadTokens(activePage - 1);
 | 
			
		||||
  }
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  const onCopy = async (type, key) => {
 | 
			
		||||
    let status = localStorage.getItem('status');
 | 
			
		||||
    let serverAddress = '';
 | 
			
		||||
    if (status) {
 | 
			
		||||
      status = JSON.parse(status);
 | 
			
		||||
      serverAddress = status.server_address;
 | 
			
		||||
    }
 | 
			
		||||
    if (serverAddress === '') {
 | 
			
		||||
      serverAddress = window.location.origin;
 | 
			
		||||
    }
 | 
			
		||||
    let encodedServerAddress = encodeURIComponent(serverAddress);
 | 
			
		||||
    let url;
 | 
			
		||||
    switch (type) {
 | 
			
		||||
      case 'ama':
 | 
			
		||||
        url = `ama://set-api-key?server=${encodedServerAddress}&key=sk-${key}`;
 | 
			
		||||
        break;
 | 
			
		||||
      case 'opencat':
 | 
			
		||||
        url = `opencat://team/join?domain=${encodedServerAddress}&token=sk-${key}`;
 | 
			
		||||
        break;
 | 
			
		||||
      case 'next':
 | 
			
		||||
        url = `https://chatgpt1.nextweb.fun/#/?settings=%7B%22key%22:%22sk-${key}%22,%22url%22:%22${serverAddress}%22%7D`;
 | 
			
		||||
        break;
 | 
			
		||||
      default:
 | 
			
		||||
        url = `sk-${key}`;
 | 
			
		||||
    }
 | 
			
		||||
    if (await copy(url)) {
 | 
			
		||||
      showSuccess('已复制到剪贴板!');
 | 
			
		||||
    } else {
 | 
			
		||||
      showWarning('无法复制到剪贴板,请手动复制,已将令牌填入搜索框。');
 | 
			
		||||
      setSearchKeyword(url);
 | 
			
		||||
    }
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  useEffect(() => {
 | 
			
		||||
    loadTokens(0)
 | 
			
		||||
@@ -235,21 +274,28 @@ const TokensTable = () => {
 | 
			
		||||
                  <Table.Cell>{token.expired_time === -1 ? '永不过期' : renderTimestamp(token.expired_time)}</Table.Cell>
 | 
			
		||||
                  <Table.Cell>
 | 
			
		||||
                    <div>
 | 
			
		||||
                      <Button
 | 
			
		||||
                        size={'small'}
 | 
			
		||||
                        positive
 | 
			
		||||
                        onClick={async () => {
 | 
			
		||||
                          let key = "sk-" + token.key;
 | 
			
		||||
                          if (await copy(key)) {
 | 
			
		||||
                            showSuccess('已复制到剪贴板!');
 | 
			
		||||
                          } else {
 | 
			
		||||
                            showWarning('无法复制到剪贴板,请手动复制,已将令牌填入搜索框。');
 | 
			
		||||
                            setSearchKeyword(key);
 | 
			
		||||
                      <Button.Group color='green' size={'small'}>
 | 
			
		||||
                        <Button
 | 
			
		||||
                          size={'small'}
 | 
			
		||||
                          positive
 | 
			
		||||
                          onClick={async () => {
 | 
			
		||||
                            await onCopy('', token.key);
 | 
			
		||||
                          }
 | 
			
		||||
                        }}
 | 
			
		||||
                      >
 | 
			
		||||
                        复制
 | 
			
		||||
                      </Button>
 | 
			
		||||
                          }
 | 
			
		||||
                        >
 | 
			
		||||
                          复制
 | 
			
		||||
                        </Button>
 | 
			
		||||
                        <Dropdown
 | 
			
		||||
                          className='button icon'
 | 
			
		||||
                          floating
 | 
			
		||||
                          options={COPY_OPTIONS}
 | 
			
		||||
                          onChange={async (e, { value } = {}) => {
 | 
			
		||||
                            await onCopy(value, token.key);
 | 
			
		||||
                          }}
 | 
			
		||||
                          trigger={<></>}
 | 
			
		||||
                        />
 | 
			
		||||
                      </Button.Group>
 | 
			
		||||
                      {' '}
 | 
			
		||||
                      <Popup
 | 
			
		||||
                        trigger={
 | 
			
		||||
                          <Button size='small' negative>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user