From d5d601263b3b30a28223b5fddd2f58df91b1d970 Mon Sep 17 00:00:00 2001 From: Buer <42402987+MartialBE@users.noreply.github.com> Date: Sat, 25 May 2024 14:56:58 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=96=20chore:=20=20Add=20sort=20paramet?= =?UTF-8?q?er=20for=20chat=20links=20to=20enable=20sorting=20in=20the=20pl?= =?UTF-8?q?ayground=20(#225)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 修改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 --- .github/workflows/docker-image-en.yml | 7 +----- .github/workflows/docker-image.yml | 5 ---- web/src/constants/chatLinks.js | 12 ++++++---- web/src/utils/common.js | 7 +++++- .../Setting/component/ChatLinksDataGrid.js | 24 +++++++++++++++++-- .../Setting/component/OperationSetting.js | 1 + 6 files changed, 38 insertions(+), 18 deletions(-) diff --git a/.github/workflows/docker-image-en.yml b/.github/workflows/docker-image-en.yml index c044e33b..265cdbb1 100644 --- a/.github/workflows/docker-image-en.yml +++ b/.github/workflows/docker-image-en.yml @@ -9,11 +9,6 @@ on: paths-ignore: - "README.md" -env: - # github.repository as / - 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' }} diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 4537bd1b..55556134 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -9,11 +9,6 @@ on: paths-ignore: - "README.md" -env: - # github.repository as / - DOCKER_HUB_USERNAME: martialbe - DOCKER_HUB_REPO: one-api - jobs: build-and-push: runs-on: ubuntu-latest diff --git a/web/src/constants/chatLinks.js b/web/src/constants/chatLinks.js index 88febc77..17191cd9 100644 --- a/web/src/constants/chatLinks.js +++ b/web/src/constants/chatLinks.js @@ -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 } ]; diff --git a/web/src/utils/common.js b/web/src/utils/common.js index 459bb54e..21991e27 100644 --- a/web/src/utils/common.js +++ b/web/src/utils/common.js @@ -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; } diff --git a/web/src/views/Setting/component/ChatLinksDataGrid.js b/web/src/views/Setting/component/ChatLinksDataGrid.js index 4367f87b..52d62201 100644 --- a/web/src/views/Setting/component/ChatLinksDataGrid.js +++ b/web/src/views/Setting/component/ChatLinksDataGrid.js @@ -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', diff --git a/web/src/views/Setting/component/OperationSetting.js b/web/src/views/Setting/component/OperationSetting.js index e4fadfec..045ec24d 100644 --- a/web/src/views/Setting/component/OperationSetting.js +++ b/web/src/views/Setting/component/OperationSetting.js @@ -553,6 +553,7 @@ const OperationSetting = () => {
opencat : {'opencat://team/join?domain={server}&token={key}'}
+ 排序规则:值越大越靠前,值相同则按照配置顺序