Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions common/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ func RedisDel(key string) error {
return RDB.Del(ctx, key).Err()
}

func RedisHDelObj(key string) error {
func RedisDelKey(key string) error {
if DebugEnabled {
SysLog(fmt.Sprintf("Redis HDEL: key=%s", key))
SysLog(fmt.Sprintf("Redis DEL Key: key=%s", key))
}
ctx := context.Background()
return RDB.HDel(ctx, key).Err()
return RDB.Del(ctx, key).Err()
}

func RedisHSetObj(key string, obj interface{}, expiration time.Duration) error {
Expand Down
41 changes: 41 additions & 0 deletions controller/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,3 +623,44 @@ func BatchSetChannelTag(c *gin.Context) {
})
return
}

func GetTagModels(c *gin.Context) {
tag := c.Query("tag")
if tag == "" {
c.JSON(http.StatusBadRequest, gin.H{
"success": false,
"message": "tag不能为空",
})
return
}

channels, err := model.GetChannelsByTag(tag, false) // Assuming false for idSort is fine here
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{
"success": false,
"message": err.Error(),
})
return
}

var longestModels string
maxLength := 0

// Find the longest models string among all channels with the given tag
for _, channel := range channels {
if channel.Models != "" {
currentModels := strings.Split(channel.Models, ",")
if len(currentModels) > maxLength {
maxLength = len(currentModels)
longestModels = channel.Models
}
}
}

c.JSON(http.StatusOK, gin.H{
"success": true,
"message": "",
"data": longestModels,
})
return
}
2 changes: 1 addition & 1 deletion model/token_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func cacheSetToken(token Token) error {

func cacheDeleteToken(key string) error {
key = common.GenerateHMAC(key)
err := common.RedisHDelObj(fmt.Sprintf("token:%s", key))
err := common.RedisDelKey(fmt.Sprintf("token:%s", key))
if err != nil {
return err
}
Expand Down
5 changes: 3 additions & 2 deletions model/user_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package model
import (
"encoding/json"
"fmt"
"github.com/gin-gonic/gin"
"one-api/common"
"one-api/constant"
"time"

"github.com/gin-gonic/gin"

"github.com/bytedance/gopkg/util/gopool"
)

Expand Down Expand Up @@ -57,7 +58,7 @@ func invalidateUserCache(userId int) error {
if !common.RedisEnabled {
return nil
}
return common.RedisHDelObj(getUserCacheKey(userId))
return common.RedisDelKey(getUserCacheKey(userId))
}

// updateUserCache updates all user cache fields using hash
Expand Down
1 change: 1 addition & 0 deletions router/api-router.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ func SetApiRouter(router *gin.Engine) {
channelRoute.GET("/fetch_models/:id", controller.FetchUpstreamModels)
channelRoute.POST("/fetch_models", controller.FetchModels)
channelRoute.POST("/batch/tag", controller.BatchSetChannelTag)
channelRoute.GET("/tag/models", controller.GetTagModels)
}
tokenRoute := apiRouter.Group("/token")
tokenRoute.Use(middleware.UserAuth())
Expand Down
3 changes: 2 additions & 1 deletion web/src/components/table/MjLogsTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ const LogsTable = () => {
percent={text ? parseInt(text.replace('%', '')) : 0}
showInfo={true}
aria-label='drawing progress'
style={{ minWidth: '200px' }}
style={{ minWidth: '160px' }}
/>
}
</div>
Expand All @@ -483,6 +483,7 @@ const LogsTable = () => {
setModalImageUrl(text);
setIsModalOpenurl(true);
}}
className="!rounded-full"
>
{t('查看图片')}
</Button>
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/table/TaskLogsTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ const LogsTable = () => {
percent={text ? parseInt(text.replace('%', '')) : 0}
showInfo={true}
aria-label='task progress'
style={{ minWidth: '200px' }}
style={{ minWidth: '160px' }}
/>
)
}
Expand Down
1 change: 1 addition & 0 deletions web/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import { BrowserRouter } from 'react-router-dom';
import '@douyinfe/semi-ui/dist/css/semi.css';
import { UserProvider } from './context/User';
import 'react-toastify/dist/ReactToastify.css';
import { StatusProvider } from './context/Status';
Expand Down
26 changes: 25 additions & 1 deletion web/src/pages/Channel/EditTagModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,33 @@ const EditTagModal = (props) => {
}, [originModelOptions, inputs.models]);

useEffect(() => {
const fetchTagModels = async () => {
if (!tag) return;
setLoading(true);
try {
const res = await API.get(`/api/channel/tag/models?tag=${tag}`);
if (res?.data?.success) {
const models = res.data.data ? res.data.data.split(',') : [];
setInputs((inputs) => ({ ...inputs, models: models }));
} else {
showError(res.data.message);
}
} catch (error) {
showError(error.message);
} finally {
setLoading(false);
}
};

setInputs({
...originInputs,
tag: tag,
new_tag: tag,
});
fetchModels().then();
fetchGroups().then();
}, [visible]);
fetchTagModels().then(); // Call the new function
}, [visible, tag]); // Add tag to dependency array

const addCustomModels = () => {
if (customModel.trim() === '') return;
Expand Down Expand Up @@ -347,6 +366,11 @@ const EditTagModal = (props) => {
<div className="space-y-4">
<div>
<Text strong className="block mb-2">{t('模型')}</Text>
<Banner
type="info"
description={t('当前模型列表为该标签下所有渠道模型列表最长的一个,并非所有渠道的并集,请注意可能导致某些渠道模型丢失。')}
className="!rounded-lg mb-4"
/>
<Select
placeholder={t('请选择该渠道所支持的模型,留空则不更改')}
name='models'
Expand Down
12 changes: 9 additions & 3 deletions web/src/pages/Token/EditToken.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,15 @@ const EditToken = (props) => {
let successCount = 0; // 记录成功创建的令牌数量
for (let i = 0; i < tokenCount; i++) {
let localInputs = { ...inputs };
if (i !== 0) {
// 如果用户想要创建多个令牌,则给每个令牌一个序号后缀
localInputs.name = `${inputs.name}-${generateRandomSuffix()}`;

// 检查用户是否填写了令牌名称
const baseName = inputs.name.trim() === '' ? 'default' : inputs.name;

if (i !== 0 || inputs.name.trim() === '') {
// 如果创建多个令牌(i !== 0)或者用户没有填写名称,则添加随机后缀
localInputs.name = `${baseName}-${generateRandomSuffix()}`;
} else {
localInputs.name = baseName;
}
localInputs.remain_quota = parseInt(localInputs.remain_quota);

Expand Down