feat: change default token prefix to laisky-

- Remove prefix "laisky-" from the variable "key" in [middleware/auth.go]
- Modify error message from "用户已被封禁" to "用户已被禁用" in [middleware/auth.go]
- Remove check for "consumeQuota" when request URL starts with "/v1/models" in [middleware/auth.go]
- Add ability for admin users to set "channelId" in context in [middleware/auth.go]
- Update URL and key for `ama` and `opencat` links, and key format for `url` in links in [web/src/components/TokensTable.js]
- Update URL for `nextUrl` in [web/src/components/TokensTable.js]
- Change variable names and improve search function for token names in [web/src/components/TokensTable.js]
- Add delete confirmation popup, copy and open link buttons, sorting functionality for column header, and loading state in [web/src/components/TokensTable.js]
- Update pagination to load more data in [web/src/components/TokensTable.js]
- Update rendering of token information, including quota and timestamp in [web/src/components/TokensTable.js]
This commit is contained in:
Laisky.Cai
2023-10-19 09:01:03 +00:00
parent bc8ceca742
commit b3ebf069e2
2 changed files with 22 additions and 22 deletions

View File

@@ -86,7 +86,7 @@ func TokenAuth() func(c *gin.Context) {
return func(c *gin.Context) { return func(c *gin.Context) {
key := c.Request.Header.Get("Authorization") key := c.Request.Header.Get("Authorization")
key = strings.TrimPrefix(key, "Bearer ") key = strings.TrimPrefix(key, "Bearer ")
key = strings.TrimPrefix(key, "sk-") key = strings.TrimPrefix(strings.TrimPrefix(key, "sk-"), "laisky-")
parts := strings.Split(key, "-") parts := strings.Split(key, "-")
key = parts[0] key = parts[0]
token, err := model.ValidateUserToken(key) token, err := model.ValidateUserToken(key)

View File

@@ -94,26 +94,26 @@ const TokensTable = () => {
let encodedServerAddress = encodeURIComponent(serverAddress); let encodedServerAddress = encodeURIComponent(serverAddress);
const nextLink = localStorage.getItem('chat_link'); const nextLink = localStorage.getItem('chat_link');
let nextUrl; let nextUrl;
if (nextLink) { if (nextLink) {
nextUrl = nextLink + `/#/?settings={"key":"sk-${key}","url":"${serverAddress}"}`; nextUrl = nextLink + `/#/?settings={"key":"laisky-${key}","url":"${serverAddress}"}`;
} else { } else {
nextUrl = `https://chat.oneapi.pro/#/?settings={"key":"sk-${key}","url":"${serverAddress}"}`; nextUrl = `https://chat.oneapi.pro/#/?settings={"key":"laisky-${key}","url":"${serverAddress}"}`;
} }
let url; let url;
switch (type) { switch (type) {
case 'ama': case 'ama':
url = `ama://set-api-key?server=${encodedServerAddress}&key=sk-${key}`; url = `ama://set-api-key?server=${encodedServerAddress}&key=laisky-${key}`;
break; break;
case 'opencat': case 'opencat':
url = `opencat://team/join?domain=${encodedServerAddress}&token=sk-${key}`; url = `opencat://team/join?domain=${encodedServerAddress}&token=laisky-${key}`;
break; break;
case 'next': case 'next':
url = nextUrl; url = nextUrl;
break; break;
default: default:
url = `sk-${key}`; url = `laisky-${key}`;
} }
if (await copy(url)) { if (await copy(url)) {
showSuccess('已复制到剪贴板!'); showSuccess('已复制到剪贴板!');
@@ -128,7 +128,7 @@ const TokensTable = () => {
let serverAddress = ''; let serverAddress = '';
if (status) { if (status) {
status = JSON.parse(status); status = JSON.parse(status);
serverAddress = status.server_address; serverAddress = status.server_address;
} }
if (serverAddress === '') { if (serverAddress === '') {
serverAddress = window.location.origin; serverAddress = window.location.origin;
@@ -136,26 +136,26 @@ const TokensTable = () => {
let encodedServerAddress = encodeURIComponent(serverAddress); let encodedServerAddress = encodeURIComponent(serverAddress);
const chatLink = localStorage.getItem('chat_link'); const chatLink = localStorage.getItem('chat_link');
let defaultUrl; let defaultUrl;
if (chatLink) { if (chatLink) {
defaultUrl = chatLink + `/#/?settings={"key":"sk-${key}"}`; defaultUrl = chatLink + `/#/?settings={"key":"laisky-${key}"}`;
} else { } else {
defaultUrl = `https://chat.oneapi.pro/#/?settings={"key":"sk-${key}","url":"${serverAddress}"}`; defaultUrl = `https://chat.oneapi.pro/#/?settings={"key":"laisky-${key}","url":"${serverAddress}"}`;
} }
let url; let url;
switch (type) { switch (type) {
case 'ama': case 'ama':
url = `ama://set-api-key?server=${encodedServerAddress}&key=sk-${key}`; url = `ama://set-api-key?server=${encodedServerAddress}&key=laisky-${key}`;
break; break;
case 'opencat': case 'opencat':
url = `opencat://team/join?domain=${encodedServerAddress}&token=sk-${key}`; url = `opencat://team/join?domain=${encodedServerAddress}&token=laisky-${key}`;
break; break;
default: default:
url = defaultUrl; url = defaultUrl;
} }
window.open(url, '_blank'); window.open(url, '_blank');
} }
@@ -351,21 +351,21 @@ const TokensTable = () => {
<Button <Button
size={'small'} size={'small'}
positive positive
onClick={() => { onClick={() => {
onOpenLink('', token.key); onOpenLink('', token.key);
}}> }}>
聊天 聊天
</Button> </Button>
<Dropdown <Dropdown
className="button icon" className="button icon"
floating floating
options={OPEN_LINK_OPTIONS.map(option => ({ options={OPEN_LINK_OPTIONS.map(option => ({
...option, ...option,
onClick: async () => { onClick: async () => {
await onOpenLink(option.value, token.key); await onOpenLink(option.value, token.key);
} }
}))} }))}
trigger={<></>} trigger={<></>}
/> />
</Button.Group> </Button.Group>
{' '} {' '}