🔖 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:
- "README.md"
env:
# github.repository as <account>/<repo>
DOCKER_HUB_USERNAME: martialbe
DOCKER_HUB_REPO: one-api-en
jobs:
build-and-push:
runs-on: ubuntu-latest
@ -90,7 +85,7 @@ jobs:
# list of Docker images to use as base name for tags
images: |
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
tags: |
type=raw,value=dev,enable=${{ github.ref == 'refs/heads/main' }}

View File

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

View File

@ -2,21 +2,25 @@ export const CHAT_LINKS = [
{
name: 'ChatGPT Next',
url: 'https://app.nextchat.dev/#/?settings={"key":"{key}","url":"{server}"}',
show: true
show: true,
sort: 1
},
{
name: 'chatgpt-web-midjourney-proxy',
url: 'https://vercel.ddaiai.com/#/?settings={"key":"{key}","url":"{server}"}',
show: true
show: true,
sort: 2
},
{
name: 'AMA 问天',
url: 'ama://set-api-key?server={server}&key={key}',
show: false
show: false,
sort: 3
},
{
name: 'OpenCat',
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) {
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;
}

View File

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

View File

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