mirror of
https://github.com/linux-do/new-api.git
synced 2025-09-24 02:46:37 +08:00
更新渠道管理
This commit is contained in:
parent
6a2ebf7578
commit
7dc8b0ea93
@ -292,7 +292,7 @@ func UpdateChannelBalance(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func updateAllChannelsBalance() error {
|
func updateAllChannelsBalance() error {
|
||||||
channels, err := model.GetAllChannels(0, 0, true)
|
channels, err := model.GetAllChannels(0, 0, true, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -163,7 +163,7 @@ func testAllChannels(notify bool) error {
|
|||||||
}
|
}
|
||||||
testAllChannelsRunning = true
|
testAllChannelsRunning = true
|
||||||
testAllChannelsLock.Unlock()
|
testAllChannelsLock.Unlock()
|
||||||
channels, err := model.GetAllChannels(0, 0, true)
|
channels, err := model.GetAllChannels(0, 0, true, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,8 @@ func GetAllChannels(c *gin.Context) {
|
|||||||
if pageSize < 0 {
|
if pageSize < 0 {
|
||||||
pageSize = common.ItemsPerPage
|
pageSize = common.ItemsPerPage
|
||||||
}
|
}
|
||||||
channels, err := model.GetAllChannels(p*pageSize, pageSize, false)
|
idSort, _ := strconv.ParseBool(c.Query("id_sort"))
|
||||||
|
channels, err := model.GetAllChannels(p*pageSize, pageSize, false, idSort)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"success": false,
|
"success": false,
|
||||||
@ -36,7 +37,9 @@ func GetAllChannels(c *gin.Context) {
|
|||||||
|
|
||||||
func SearchChannels(c *gin.Context) {
|
func SearchChannels(c *gin.Context) {
|
||||||
keyword := c.Query("keyword")
|
keyword := c.Query("keyword")
|
||||||
channels, err := model.SearchChannels(keyword)
|
group := c.Query("group")
|
||||||
|
//idSort, _ := strconv.ParseBool(c.Query("id_sort"))
|
||||||
|
channels, err := model.SearchChannels(keyword, group)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"success": false,
|
"success": false,
|
||||||
|
@ -28,23 +28,35 @@ type Channel struct {
|
|||||||
AutoBan *int `json:"auto_ban" gorm:"default:1"`
|
AutoBan *int `json:"auto_ban" gorm:"default:1"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetAllChannels(startIdx int, num int, selectAll bool) ([]*Channel, error) {
|
func GetAllChannels(startIdx int, num int, selectAll bool, idSort bool) ([]*Channel, error) {
|
||||||
var channels []*Channel
|
var channels []*Channel
|
||||||
var err error
|
var err error
|
||||||
|
order := "priority desc"
|
||||||
|
if idSort {
|
||||||
|
order = "id desc"
|
||||||
|
}
|
||||||
if selectAll {
|
if selectAll {
|
||||||
err = DB.Order("priority desc").Find(&channels).Error
|
err = DB.Order(order).Find(&channels).Error
|
||||||
} else {
|
} else {
|
||||||
err = DB.Order("priority desc").Limit(num).Offset(startIdx).Omit("key").Find(&channels).Error
|
err = DB.Order(order).Limit(num).Offset(startIdx).Omit("key").Find(&channels).Error
|
||||||
}
|
}
|
||||||
return channels, err
|
return channels, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func SearchChannels(keyword string) (channels []*Channel, err error) {
|
func SearchChannels(keyword string, group string) (channels []*Channel, err error) {
|
||||||
keyCol := "`key`"
|
keyCol := "`key`"
|
||||||
if common.UsingPostgreSQL {
|
if common.UsingPostgreSQL {
|
||||||
keyCol = `"key"`
|
keyCol = `"key"`
|
||||||
}
|
}
|
||||||
err = DB.Omit("key").Where("id = ? or name LIKE ? or "+keyCol+" = ?", common.String2Int(keyword), keyword+"%", keyword).Find(&channels).Error
|
if group != "" {
|
||||||
|
groupCol := "`group`"
|
||||||
|
if common.UsingPostgreSQL {
|
||||||
|
groupCol = `"group"`
|
||||||
|
}
|
||||||
|
err = DB.Omit("key").Where("(id = ? or name LIKE ? or "+keyCol+" = ?) and "+groupCol+" LIKE ?", common.String2Int(keyword), keyword+"%", keyword, "%"+group+"%").Find(&channels).Error
|
||||||
|
} else {
|
||||||
|
err = DB.Omit("key").Where("id = ? or name LIKE ? or "+keyCol+" = ?", common.String2Int(keyword), keyword+"%", keyword).Find(&channels).Error
|
||||||
|
}
|
||||||
return channels, err
|
return channels, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -164,11 +164,24 @@ const RedemptionsTable = () => {
|
|||||||
setShowEdit(false);
|
setShowEdit(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
const setCount = (data) => {
|
// const setCount = (data) => {
|
||||||
if (data.length >= (activePage) * ITEMS_PER_PAGE) {
|
// if (data.length >= (activePage) * ITEMS_PER_PAGE) {
|
||||||
setTokenCount(data.length + 1);
|
// setTokenCount(data.length + 1);
|
||||||
|
// } else {
|
||||||
|
// setTokenCount(data.length);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
const setRedemptionFormat = (redeptions) => {
|
||||||
|
for (let i = 0; i < redeptions.length; i++) {
|
||||||
|
redeptions[i].key = '' + redeptions[i].id;
|
||||||
|
}
|
||||||
|
// data.key = '' + data.id
|
||||||
|
setRedemptions(redeptions);
|
||||||
|
if (redeptions.length >= (activePage) * ITEMS_PER_PAGE) {
|
||||||
|
setTokenCount(redeptions.length + 1);
|
||||||
} else {
|
} else {
|
||||||
setTokenCount(data.length);
|
setTokenCount(redeptions.length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,13 +190,11 @@ const RedemptionsTable = () => {
|
|||||||
const {success, message, data} = res.data;
|
const {success, message, data} = res.data;
|
||||||
if (success) {
|
if (success) {
|
||||||
if (startIdx === 0) {
|
if (startIdx === 0) {
|
||||||
setRedemptions(data);
|
setRedemptionFormat(data);
|
||||||
setCount(data);
|
|
||||||
} else {
|
} else {
|
||||||
let newRedemptions = redemptions;
|
let newRedemptions = redemptions;
|
||||||
newRedemptions.push(...data);
|
newRedemptions.push(...data);
|
||||||
setRedemptions(newRedemptions);
|
setRedemptionFormat(newRedemptions);
|
||||||
setCount(newRedemptions);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
showError(message);
|
showError(message);
|
||||||
|
@ -1,26 +1,16 @@
|
|||||||
export const CHANNEL_OPTIONS = [
|
export const CHANNEL_OPTIONS = [
|
||||||
{ key: 1, text: 'OpenAI', value: 1, color: 'green' },
|
{ key: 1, text: 'OpenAI', value: 1, color: 'green', label: 'OpenAI' },
|
||||||
{ key: 99, text: 'Midjourney-Proxy', value: 99, color: 'green' },
|
{ key: 24, text: 'Midjourney Proxy', value: 24, color: 'light-blue', label: 'Midjourney Proxy' },
|
||||||
{ key: 14, text: 'Anthropic Claude', value: 14, color: 'black' },
|
{ key: 14, text: 'Anthropic Claude', value: 14, color: 'black', label: 'Anthropic Claude' },
|
||||||
{ key: 3, text: 'Azure OpenAI', value: 3, color: 'olive' },
|
{ key: 3, text: 'Azure OpenAI', value: 3, color: 'olive', label: 'Azure OpenAI' },
|
||||||
{ key: 11, text: 'Google PaLM2', value: 11, color: 'orange' },
|
{ key: 11, text: 'Google PaLM2', value: 11, color: 'orange', label: 'Google PaLM2' },
|
||||||
{ key: 15, text: '百度文心千帆', value: 15, color: 'blue' },
|
{ key: 15, text: '百度文心千帆', value: 15, color: 'blue', label: '百度文心千帆' },
|
||||||
{ key: 17, text: '阿里通义千问', value: 17, color: 'orange' },
|
{ key: 17, text: '阿里通义千问', value: 17, color: 'orange', label: '阿里通义千问' },
|
||||||
{ key: 18, text: '讯飞星火认知', value: 18, color: 'blue' },
|
{ key: 18, text: '讯飞星火认知', value: 18, color: 'blue', label: '讯飞星火认知' },
|
||||||
{ key: 16, text: '智谱 ChatGLM', value: 16, color: 'violet' },
|
{ key: 16, text: '智谱 ChatGLM', value: 16, color: 'violet', label: '智谱 ChatGLM' },
|
||||||
{ key: 19, text: '360 智脑', value: 19, color: 'blue' },
|
{ key: 19, text: '360 智脑', value: 19, color: 'blue', label: '360 智脑' },
|
||||||
{ key: 23, text: '腾讯混元', value: 23, color: 'teal' },
|
{ key: 23, text: '腾讯混元', value: 23, color: 'teal', label: '腾讯混元' },
|
||||||
{ key: 8, text: '自定义渠道', value: 8, color: 'pink' },
|
{ key: 8, text: '自定义渠道', value: 8, color: 'pink', label: '自定义渠道' },
|
||||||
{ key: 22, text: '知识库:FastGPT', value: 22, color: 'blue' },
|
{ key: 22, text: '知识库:FastGPT', value: 22, color: 'blue', label: '知识库:FastGPT' },
|
||||||
{ key: 21, text: '知识库:AI Proxy', value: 21, color: 'purple' },
|
{ key: 21, text: '知识库:AI Proxy', value: 21, color: 'purple', label: '知识库:AI Proxy' },
|
||||||
{ key: 20, text: '代理:OpenRouter', value: 20, color: 'black' },
|
];
|
||||||
{ key: 2, text: '代理:API2D', value: 2, color: 'blue' },
|
|
||||||
{ key: 5, text: '代理:OpenAI-SB', value: 5, color: 'brown' },
|
|
||||||
{ key: 7, text: '代理:OhMyGPT', value: 7, color: 'purple' },
|
|
||||||
{ key: 10, text: '代理:AI Proxy', value: 10, color: 'purple' },
|
|
||||||
{ key: 4, text: '代理:CloseAI', value: 4, color: 'teal' },
|
|
||||||
{ key: 6, text: '代理:OpenAI Max', value: 6, color: 'violet' },
|
|
||||||
{ key: 9, text: '代理:AI.LS', value: 9, color: 'yellow' },
|
|
||||||
{ key: 12, text: '代理:API2GPT', value: 12, color: 'blue' },
|
|
||||||
{ key: 13, text: '代理:AIGC2D', value: 13, color: 'purple' }
|
|
||||||
];
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,14 +1,19 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Header, Segment } from 'semantic-ui-react';
|
|
||||||
import ChannelsTable from '../../components/ChannelsTable';
|
import ChannelsTable from '../../components/ChannelsTable';
|
||||||
|
import {Layout} from "@douyinfe/semi-ui";
|
||||||
|
import RedemptionsTable from "../../components/RedemptionsTable";
|
||||||
|
|
||||||
const File = () => (
|
const File = () => (
|
||||||
<>
|
<>
|
||||||
<Segment>
|
<Layout>
|
||||||
<Header as='h3'>管理渠道</Header>
|
<Layout.Header>
|
||||||
<ChannelsTable />
|
<h3>管理渠道</h3>
|
||||||
</Segment>
|
</Layout.Header>
|
||||||
</>
|
<Layout.Content>
|
||||||
|
<ChannelsTable/>
|
||||||
|
</Layout.Content>
|
||||||
|
</Layout>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
|
|
||||||
export default File;
|
export default File;
|
||||||
|
Loading…
Reference in New Issue
Block a user