Token Adds Option to Quickly Copy AMA and OpenCat URL Scheme
This commit is contained in:
parent
30a7f1a1c7
commit
b1c1d69ee2
@ -1,5 +1,5 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { Button, Form, Label, Modal, Pagination, Popup, Table } from 'semantic-ui-react';
|
||||
import { Button, Form, Label, Modal, Pagination, Popup, Table, Dropdown } from 'semantic-ui-react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { API, copy, showError, showSuccess, showWarning, timestamp2string } from '../helpers';
|
||||
|
||||
@ -70,6 +70,32 @@ const TokensTable = () => {
|
||||
await loadTokens(activePage - 1);
|
||||
}
|
||||
|
||||
const onCopy = async (type,key)=>{
|
||||
let status = localStorage.getItem('status');
|
||||
let server_address="";
|
||||
if (status) {
|
||||
status = JSON.parse(status);
|
||||
server_address = encodeURIComponent(status.server_address)
|
||||
}
|
||||
let url;
|
||||
switch (type){
|
||||
case 'ama':
|
||||
url=`ama://set-api-key?server=${server_address}&key=sk-${key}`
|
||||
break;
|
||||
case 'opencat':
|
||||
url=`opencat://team/join?domain=${server_address}&token=sk-${key}`
|
||||
break
|
||||
default:
|
||||
url=`sk-${key}`
|
||||
}
|
||||
if (await copy(url)) {
|
||||
showSuccess('已复制到剪贴板!');
|
||||
} else {
|
||||
showWarning('无法复制到剪贴板,请手动复制,已将令牌填入搜索框。');
|
||||
setSearchKeyword(url);
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
loadTokens(0)
|
||||
.then()
|
||||
@ -147,6 +173,11 @@ const TokensTable = () => {
|
||||
setTokens(sortedTokens);
|
||||
setLoading(false);
|
||||
};
|
||||
const copy_actions = [
|
||||
{ key: 'ama', text: 'AMA 问天', value: 'ama' },
|
||||
{ key: 'opencat', text: 'OpenCat', value: 'opencat' },
|
||||
]
|
||||
|
||||
|
||||
return (
|
||||
<>
|
||||
@ -235,21 +266,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>
|
||||
<Button.Group color='green' size={'small'} >
|
||||
<Button
|
||||
size={'small'}
|
||||
positive
|
||||
onClick={async () => {
|
||||
await onCopy('', token.key)
|
||||
}
|
||||
}
|
||||
>
|
||||
复制
|
||||
</Button>
|
||||
<Dropdown
|
||||
className='button icon'
|
||||
floating
|
||||
options={copy_actions}
|
||||
onChange={async (e,{value}={})=>{
|
||||
await onCopy(value, token.key)
|
||||
}}
|
||||
trigger={<></>}
|
||||
/>
|
||||
</Button.Group>
|
||||
{' '}
|
||||
<Popup
|
||||
trigger={
|
||||
<Button size='small' negative>
|
||||
|
Loading…
Reference in New Issue
Block a user