🔖 chore: Add sort parameter for chat links to enable sorting in the playground (#225)

* 修改action工作流打包推送docker镜像使用的仓库名称(DOCKER_HUB_REPO/DOCKER_HUB_REPO_EN)、DOCKER HUB用户名(DOCKER_HUB_USERNAME)全部从github仓库环境变量获取

* 增加聊天连接排序参数用于在playground中对聊天内容进行排序

* 🔖 chore:  Add sort parameter for chat links to enable sorting in the playground

---------

Co-authored-by: ZeroDeng <denglin0105@vip.qq.com>
This commit is contained in:
Buer 2024-05-25 14:56:58 +08:00 committed by GitHub
parent 671aa51f42
commit d5d601263b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 38 additions and 18 deletions

View File

@ -9,11 +9,6 @@ on:
paths-ignore: paths-ignore:
- "README.md" - "README.md"
env:
# github.repository as <account>/<repo>
DOCKER_HUB_USERNAME: martialbe
DOCKER_HUB_REPO: one-api-en
jobs: jobs:
build-and-push: build-and-push:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -90,7 +85,7 @@ jobs:
# list of Docker images to use as base name for tags # list of Docker images to use as base name for tags
images: | images: |
ghcr.io/${{ github.repository }}-en ghcr.io/${{ github.repository }}-en
docker.io/${{ env.DOCKER_HUB_USERNAME }}/${{ env.DOCKER_HUB_REPO }} docker.io/${{ env.DOCKER_HUB_USERNAME }}/${{ env.DOCKER_HUB_REPO_EN }}
# generate Docker tags based on the following events/attributes # generate Docker tags based on the following events/attributes
tags: | tags: |
type=raw,value=dev,enable=${{ github.ref == 'refs/heads/main' }} type=raw,value=dev,enable=${{ github.ref == 'refs/heads/main' }}

View File

@ -9,11 +9,6 @@ on:
paths-ignore: paths-ignore:
- "README.md" - "README.md"
env:
# github.repository as <account>/<repo>
DOCKER_HUB_USERNAME: martialbe
DOCKER_HUB_REPO: one-api
jobs: jobs:
build-and-push: build-and-push:
runs-on: ubuntu-latest runs-on: ubuntu-latest

View File

@ -2,21 +2,25 @@ export const CHAT_LINKS = [
{ {
name: 'ChatGPT Next', name: 'ChatGPT Next',
url: 'https://app.nextchat.dev/#/?settings={"key":"{key}","url":"{server}"}', url: 'https://app.nextchat.dev/#/?settings={"key":"{key}","url":"{server}"}',
show: true show: true,
sort: 1
}, },
{ {
name: 'chatgpt-web-midjourney-proxy', name: 'chatgpt-web-midjourney-proxy',
url: 'https://vercel.ddaiai.com/#/?settings={"key":"{key}","url":"{server}"}', url: 'https://vercel.ddaiai.com/#/?settings={"key":"{key}","url":"{server}"}',
show: true show: true,
sort: 2
}, },
{ {
name: 'AMA 问天', name: 'AMA 问天',
url: 'ama://set-api-key?server={server}&key={key}', url: 'ama://set-api-key?server={server}&key={key}',
show: false show: false,
sort: 3
}, },
{ {
name: 'OpenCat', name: 'OpenCat',
url: 'opencat://team/join?domain={server}&token={key}', url: 'opencat://team/join?domain={server}&token={key}',
show: false show: false,
sort: 4
} }
]; ];

View File

@ -254,7 +254,12 @@ export function getChatLinks(filterShow = false) {
if (filterShow) { if (filterShow) {
links = links.filter((link) => link.show); links = links.filter((link) => link.show);
} }
// 对links进行排序sort为空的项排在最后
links.sort((a, b) => {
if (!a?.sort) return 1;
if (!b?.sort) return -1;
return b.sort - a.sort;
});
return links; return links;
} }

View File

@ -18,6 +18,10 @@ function validation(row) {
return 'URL不能为空'; return 'URL不能为空';
} }
if (row.sort != '' && !/^[0-9]\d*$/.test(row.sort)) {
return '排序必须为正整数';
}
return false; return false;
} }
@ -28,7 +32,7 @@ function randomId() {
function EditToolbar({ setRows, setRowModesModel }) { function EditToolbar({ setRows, setRowModesModel }) {
const handleClick = () => { const handleClick = () => {
const id = randomId(); const id = randomId();
setRows((oldRows) => [{ id, name: '', url: '', show: true, isNew: true }, ...oldRows]); setRows((oldRows) => [{ id, name: '', url: '', show: true, sort: 0, isNew: true }, ...oldRows]);
setRowModesModel((oldModel) => ({ setRowModesModel((oldModel) => ({
[id]: { mode: GridRowModes.Edit, fieldToFocus: 'name' }, [id]: { mode: GridRowModes.Edit, fieldToFocus: 'name' },
...oldModel ...oldModel
@ -103,7 +107,13 @@ const ChatLinksDataGrid = ({ links, onChange }) => {
); );
const processRowUpdate = (newRow, oldRows) => { const processRowUpdate = (newRow, oldRows) => {
if (!newRow.isNew && newRow.name === oldRows.name && newRow.url === oldRows.url && newRow.show === oldRows.show) { if (
!newRow.isNew &&
newRow.name === oldRows.name &&
newRow.url === oldRows.url &&
newRow.sort === oldRows.sort &&
newRow.show === oldRows.show
) {
return oldRows; return oldRows;
} }
const updatedRow = { ...newRow, isNew: false }; const updatedRow = { ...newRow, isNew: false };
@ -153,6 +163,16 @@ const ChatLinksDataGrid = ({ links, onChange }) => {
editable: true, editable: true,
hideable: false hideable: false
}, },
{
field: 'sort',
sortable: true,
headerName: '排序',
type: 'number',
flex: 1,
minWidth: 100,
editable: true,
hideable: false
},
{ {
field: 'actions', field: 'actions',
type: 'actions', type: 'actions',

View File

@ -553,6 +553,7 @@ const OperationSetting = () => {
<br /> <br />
opencat {'opencat://team/join?domain={server}&token={key}'} opencat {'opencat://team/join?domain={server}&token={key}'}
<br /> <br />
排序规则值越大越靠前值相同则按照配置顺序
</Alert> </Alert>
<Stack justifyContent="flex-start" alignItems="flex-start" spacing={2}> <Stack justifyContent="flex-start" alignItems="flex-start" spacing={2}>
<ChatLinksDataGrid links={inputs.ChatLinks || '[]'} onChange={handleInputChange} /> <ChatLinksDataGrid links={inputs.ChatLinks || '[]'} onChange={handleInputChange} />