Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
218ad6b
🎨 refactor(ui): scope table scrolling to console cards & refine overa…
t0ng7u Jul 17, 2025
ead43f0
🎉 feat(i18n): integrate Semi UI LocaleProvider with dynamic i18next l…
t0ng7u Jul 18, 2025
f43c695
🗑️ refactor(table): remove custom `formatPageText` from all table com…
t0ng7u Jul 18, 2025
6799daa
🚀 feat(web/channels): Deep modular refactor of Channels table
t0ng7u Jul 18, 2025
3fe5097
♻️ refactor: restructure LogsTable into modular component architecture
t0ng7u Jul 18, 2025
5407a83
♻️ refactor: restructure MjLogsTable into modular component architecture
t0ng7u Jul 18, 2025
3b67759
♻️ refactor: restructure TaskLogsTable into modular component archite…
t0ng7u Jul 18, 2025
42a26f0
♻️ refactor: modularize TokensTable component into maintainable archi…
t0ng7u Jul 18, 2025
c05d6f7
♻️ refactor(components): restructure RedemptionsTable to modular arch…
t0ng7u Jul 18, 2025
d762da9
♻️ refactor(users): modularize UsersTable component into microcompone…
t0ng7u Jul 18, 2025
be16ad2
🏗️ refactor: complete table module architecture unification and cleanup
t0ng7u Jul 18, 2025
de9d18a
♻️ refactor(channels): migrate edit components to modals structure
t0ng7u Jul 18, 2025
56c1fbe
🌟 feat(ui): reusable CompactModeToggle & mobile-friendly CardPro
t0ng7u Jul 18, 2025
97a9c86
Merge remote-tracking branch 't0ng7u/alpha' into refactor/layout-Ⅱ
t0ng7u Jul 18, 2025
301909e
📱 feat(ui): Introduce responsive `CardTable` with mobile card view, d…
t0ng7u Jul 18, 2025
3b3ae9c
💄 refactor(CardTable): proper empty-state handling & pagination visib…
t0ng7u Jul 18, 2025
6a827fc
📝 docs(Table): simplify table description for cleaner UI
t0ng7u Jul 18, 2025
26644bf
🎨 style(card-table): replace Tailwind border‐gray util with Semi UI b…
t0ng7u Jul 18, 2025
38e72e1
🎨 chore: integrate ESLint header automation with AGPL-3.0 notice
t0ng7u Jul 18, 2025
635bfd4
✨ fix(cardpro): Keep actions & search areas mounted on mobile to auto…
t0ng7u Jul 18, 2025
f3bcf57
🐛 fix(model-test-modal): keep Modal mounted to restore body overflow …
t0ng7u Jul 19, 2025
3234171
Merge remote-tracking branch 'origin/alpha' into refactor/layout-Ⅱ
t0ng7u Jul 19, 2025
a1018c5
💄 style(CardPro): Enhance CardPro layout handling
t0ng7u Jul 19, 2025
847a8c8
✨ refactor: unify model-select searching & UX across the dashboard
t0ng7u Jul 19, 2025
0a79dc9
✨ **fix: Always display token quota tooltip for unlimited tokens**
t0ng7u Jul 19, 2025
4fccaf3
✨ feat(ui): Replace Spin with animated Skeleton in UsageLogsActions
t0ng7u Jul 19, 2025
e944983
📱 feat(ui): Enhance mobile log table UX & fix StrictMode warning
t0ng7u Jul 19, 2025
1b739e8
🤢 fix(ui): UsageLogsTable skeleton dimensions to avoid layout shift
t0ng7u Jul 19, 2025
1fa4518
🎨 feat(ui): enhance UserInfoModal with improved layout and additional…
t0ng7u Jul 19, 2025
39079e7
💄 refactor: Users table UI & state handling
t0ng7u Jul 19, 2025
252fddf
🚀 feat: Enhance table UX & fix reset actions across Users / Tokens / …
t0ng7u Jul 19, 2025
818e346
✨ refactor: move table pagination to CardPro footer for consistent la…
t0ng7u Jul 19, 2025
805464e
🚑 fix: resolve React hooks order violation in pagination components
t0ng7u Jul 20, 2025
1d4ecad
Merge remote-tracking branch 'origin/alpha' into refactor/layout-Ⅱ
t0ng7u Jul 20, 2025
19c522d
Merge branch 'alpha' into refactor/layout-Ⅱ
t0ng7u Jul 20, 2025
4d7562f
🐛 fix(ui): prevent pagination flicker when tables have no data
t0ng7u Jul 20, 2025
b5d4535
♻️ refactor: Extract scroll effect logic into reusable ScrollableCont…
t0ng7u Jul 20, 2025
d74a5bd
♻️ refactor: Extract scroll effect into reusable ScrollableContainer …
t0ng7u Jul 20, 2025
0eaeef5
📚 refactor(dashboard): modularize dashboard page into reusable hooks …
t0ng7u Jul 20, 2025
fa506ec
Merge remote-tracking branch 'origin/alpha' into refactor/layout-Ⅱ
t0ng7u Jul 20, 2025
cddb778
⚖️ docs(about): update license information from Apache 2.0 to AGPL v3.0
t0ng7u Jul 20, 2025
4d8189f
⚖️ docs(LICENSE): update license information from Apache 2.0 to New A…
t0ng7u Jul 20, 2025
7d50e43
fix: 根据OpenAI最新的计费规则,更新其Web Search Tools价格
ZhangYichi-ZYc Jul 20, 2025
8bc6ddb
💄 refactor(playground): migrate inline styles to TailwindCSS v3 classes
t0ng7u Jul 20, 2025
fd7a446
🖼️ feat(header): improve logo loading UX with skeleton overlay
t0ng7u Jul 20, 2025
f77aef8
Merge branch 'alpha' into refactor/layout-Ⅱ
t0ng7u Jul 20, 2025
3538cef
fix: page query param is p
feitianbubu Jul 21, 2025
ba40748
🤝 docs(README): Add trusted partners section to README files
t0ng7u Jul 21, 2025
66dd514
🤝 docs(README): refactor trusted partners section for GitHub compatib…
t0ng7u Jul 21, 2025
d16cb90
🔗 docs(README): add Alibaba Cloud partner and make all logos clickable
t0ng7u Jul 21, 2025
5589878
📱 docs(README): refactor partners section for responsive layout
t0ng7u Jul 21, 2025
7902570
📱 docs(README): refactor partners section for responsive layout
t0ng7u Jul 21, 2025
5fbadc6
📱 docs(README): refactor partners section for responsive layout
t0ng7u Jul 21, 2025
fcc006e
feat: channel kling support New API
feitianbubu Jul 21, 2025
f144518
📱 docs(README): refactor partners section for responsive layout
t0ng7u Jul 21, 2025
8e280a6
📱 docs(README): refactor partners section for responsive layout
t0ng7u Jul 21, 2025
2a366c1
🔖 chore: remove useless ui component
t0ng7u Jul 21, 2025
efe894c
Merge branch 'pr/support-New-API-proxy-kling' of github.com:feitianbu…
creamlike1024 Jul 21, 2025
6ef5acb
Merge branch 'feitianbubu-pr/support-New-API-proxy-kling' into alpha
creamlike1024 Jul 21, 2025
d058946
✨ feat(middleware): enhance Kling request adapter to support both 'mo…
t0ng7u Jul 21, 2025
90011aa
✨ feat(kling): send both `model_name` and `model` fields for upstream…
t0ng7u Jul 21, 2025
e224ee5
🍎 style(ui): add shape="circle" prop to Tag component to display circ…
t0ng7u Jul 21, 2025
f32cf02
fix: avoid relayError nil panic
feitianbubu Jul 22, 2025
2402715
fix: add Think field to OllamaRequest and support extra parameters in…
Calcium-Ion Jul 22, 2025
6c4ada5
Merge remote-tracking branch 'origin/alpha' into alpha
Calcium-Ion Jul 22, 2025
bcd2362
Merge pull request #1415 from feitianbubu/pr/fix-relayError-nil
Calcium-Ion Jul 22, 2025
f5a6b7d
Merge pull request #1410 from feitianbubu/pr/fix-page-param
Calcium-Ion Jul 22, 2025
0c5c582
♻️ refactor: restructure ModelPricing component into modular architec…
t0ng7u Jul 22, 2025
722b187
Merge remote-tracking branch 'origin/alpha' into alpha
t0ng7u Jul 22, 2025
d4b32a4
Merge branch 'alpha' of github.com:ZhangYichi-ZYc/new-api into ZhangY…
creamlike1024 Jul 22, 2025
136a029
refactor: simplify WebSearchPrice const
creamlike1024 Jul 22, 2025
2f80c81
Merge branch 'ZhangYichi-ZYc-alpha' into alpha
creamlike1024 Jul 22, 2025
057e551
🌐 feat: implement left-right pagination layout with i18n support
t0ng7u Jul 22, 2025
7bc9192
chore: opt video channel and platform
feitianbubu Jul 22, 2025
07b64ff
Merge pull request #1416 from feitianbubu/pr/opt-video-channel
creamlike1024 Jul 22, 2025
e0b859d
🐛 fix(EditChannelModal): hide empty “API Config” card for VolcEngine …
t0ng7u Jul 22, 2025
756a8c5
fix: improve error messages for channel retrieval failures in distrib…
Calcium-Ion Jul 23, 2025
eaee89f
fix(distributor): add validation for model name in channel selection
Calcium-Ion Jul 23, 2025
6f74e7b
fix(adaptor): implement request conversion methods for Claude and Ima…
Calcium-Ion Jul 23, 2025
13bdb80
fix(adaptor): update relay mode handling #1419
Calcium-Ion Jul 23, 2025
ae04616
feat: support ollama claude format
Calcium-Ion Jul 23, 2025
77e3502
fix(adaptor): enhance response handling and error logging for Claude …
Calcium-Ion Jul 23, 2025
e162b9c
feat: support multi-key mode
Calcium-Ion Jul 23, 2025
8205ad2
fix: playground chat vip group
feitianbubu Jul 24, 2025
352da66
feat: add vidu video channel
feitianbubu Jul 23, 2025
b704fc9
Merge pull request #1425 from feitianbubu/pr/add-vidu-video-channel
creamlike1024 Jul 24, 2025
b25841e
feat: add upstream error type and default handling for OpenAI and Cla…
Calcium-Ion Jul 25, 2025
1430c05
🌟 fix: standardize and improve Playground Chat VIP group functionality
t0ng7u Jul 25, 2025
fe16d05
🔒 fix: Enforce admin-only column visibility in logs tables
t0ng7u Jul 25, 2025
df647e7
判断兑换码名称长度,改为按字符长度计算
Raymondxox Jul 25, 2025
d6cbf43
Merge remote-tracking branch 'origin/alpha' into alpha
Calcium-Ion Jul 26, 2025
1297add
feat: enhance request handling with pass-through options and system p…
Calcium-Ion Jul 26, 2025
2469c43
fix: improve error messaging and JSON schema handling in distributor …
Calcium-Ion Jul 26, 2025
c51ec31
Merge pull request #1441 from QuantumNous/system_prompt
Calcium-Ion Jul 26, 2025
8e3cf2e
feat: support claude convert to gemini
Calcium-Ion Jul 26, 2025
f15a53f
🎨 refactor(ui): redesign channel extra settings section in EditChanne…
t0ng7u Jul 26, 2025
a435672
Merge pull request #1437 from Raymondxox/fix
Calcium-Ion Jul 26, 2025
e7524c8
Merge pull request #1443 from QuantumNous/claude_to_gemini
Calcium-Ion Jul 26, 2025
41856e8
feat: add Claude Code channel support with OAuth integration
seefs001 Jul 26, 2025
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
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
.vscode
.gitignore
Makefile
docs
docs
.eslintcache
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ web/dist
.env
one-api
.DS_Store
tiktoken_cache
tiktoken_cache
.eslintcache
304 changes: 103 additions & 201 deletions LICENSE

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,24 @@ If you have any questions, please refer to [Help and Support](https://docs.newap
- [Issue Feedback](https://docs.newapi.pro/support/feedback-issues)
- [FAQ](https://docs.newapi.pro/support/faq)

## 🤝 Trusted Partners

<p align="center">
<a href="https://www.cherry-ai.com/" target="_blank"><img
src="./docs/images/cherry-studio.svg" alt="Cherry Studio" height="58"
/></a>
&nbsp;&nbsp;&nbsp;&nbsp;
<a href="https://bda.pku.edu.cn/" target="_blank"><img
src="./docs/images/pku.png" alt="Peking University" height="58"
/></a>
&nbsp;&nbsp;&nbsp;&nbsp;
<a href="https://www.compshare.cn/?ytag=GPU_yy_gh_newapi" target="_blank"><img
src="./docs/images/ucloud.svg" alt="UCloud" height="58"
/></a>
</p>

<p align="center"><em>No particular order</em></p>

## 🌟 Star History

[![Star History Chart](https://api.star-history.com/svg?repos=Calcium-Ion/new-api&type=Date)](https://star-history.com/#Calcium-Ion/new-api&Date)
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,24 @@ docker run --name new-api -d --restart always -p 3000:3000 -e SQL_DSN="root:1234
- [反馈问题](https://docs.newapi.pro/support/feedback-issues)
- [常见问题](https://docs.newapi.pro/support/faq)

## 🤝 我们信任的合作伙伴

<p align="center">
<a href="https://www.cherry-ai.com/" target="_blank"><img
src="./docs/images/cherry-studio.svg" alt="Cherry Studio" height="58"
/></a>
&nbsp;&nbsp;&nbsp;&nbsp;
<a href="https://bda.pku.edu.cn/" target="_blank"><img
src="./docs/images/pku.png" alt="北京大学" height="58"
/></a>
&nbsp;&nbsp;&nbsp;&nbsp;
<a href="https://www.compshare.cn/?ytag=GPU_yy_gh_newapi" target="_blank"><img
src="./docs/images/ucloud.svg" alt="UCloud 优刻得" height="58"
/></a>
</p>

<p align="center"><em>排名不分先后</em></p>

## 🌟 Star History

[![Star History Chart](https://api.star-history.com/svg?repos=Calcium-Ion/new-api&type=Date)](https://star-history.com/#Calcium-Ion/new-api&Date)
2 changes: 2 additions & 0 deletions common/api_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ func ChannelType2APIType(channelType int) (int, bool) {
apiType = constant.APITypeCoze
case constant.ChannelTypeJimeng:
apiType = constant.APITypeJimeng
case constant.ChannelTypeClaudeCode:
apiType = constant.APITypeClaudeCode
}
if apiType == -1 {
return constant.APITypeOpenAI, false
Expand Down
2 changes: 1 addition & 1 deletion common/page_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (p *PageInfo) SetItems(items any) {
func GetPageQuery(c *gin.Context) *PageInfo {
pageInfo := &PageInfo{}
// 手动获取并处理每个参数
if page, err := strconv.Atoi(c.Query("page")); err == nil {
if page, err := strconv.Atoi(c.Query("p")); err == nil {
pageInfo.Page = page
}
if pageSize, err := strconv.Atoi(c.Query("page_size")); err == nil {
Expand Down
1 change: 1 addition & 0 deletions constant/api_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ const (
APITypeXai
APITypeCoze
APITypeJimeng
APITypeClaudeCode
APITypeDummy // this one is only for count, do not add any channel after this
)
4 changes: 4 additions & 0 deletions constant/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ const (
ChannelTypeCoze = 49
ChannelTypeKling = 50
ChannelTypeJimeng = 51
ChannelTypeVidu = 52
ChannelTypeClaudeCode = 53
ChannelTypeDummy // this one is only for count, do not add any channel after this

)
Expand Down Expand Up @@ -106,4 +108,6 @@ var ChannelBaseURLs = []string{
"https://api.coze.cn", //49
"https://api.klingai.com", //50
"https://visual.volcengineapi.com", //51
"https://api.vidu.cn", //52
"https://api.anthropic.com", //53
}
2 changes: 0 additions & 2 deletions constant/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ type TaskPlatform string
const (
TaskPlatformSuno TaskPlatform = "suno"
TaskPlatformMidjourney = "mj"
TaskPlatformKling TaskPlatform = "kling"
TaskPlatformJimeng TaskPlatform = "jimeng"
)

const (
Expand Down
6 changes: 6 additions & 0 deletions controller/channel-test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ func testChannel(channel *model.Channel, testModel string) testResult {
newAPIError: nil,
}
}
if channel.Type == constant.ChannelTypeVidu {
return testResult{
localErr: errors.New("vidu channel test is not supported"),
newAPIError: nil,
}
}
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)

Expand Down
73 changes: 73 additions & 0 deletions controller/claude_oauth.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package controller

import (
"net/http"
"one-api/common"
"one-api/service"

"github.com/gin-gonic/gin"
)

// ExchangeCodeRequest 授权码交换请求
type ExchangeCodeRequest struct {
AuthorizationCode string `json:"authorization_code" binding:"required"`
CodeVerifier string `json:"code_verifier" binding:"required"`
State string `json:"state" binding:"required"`
}

// GenerateClaudeOAuthURL 生成Claude OAuth授权URL
func GenerateClaudeOAuthURL(c *gin.Context) {
params, err := service.GenerateOAuthParams()
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{
"success": false,
"message": "生成OAuth授权URL失败: " + err.Error(),
})
return
}

c.JSON(http.StatusOK, gin.H{
"success": true,
"message": "生成OAuth授权URL成功",
"data": params,
})
}

// ExchangeClaudeOAuthCode 交换Claude OAuth授权码
func ExchangeClaudeOAuthCode(c *gin.Context) {
var req ExchangeCodeRequest
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{
"success": false,
"message": "请求参数错误: " + err.Error(),
})
return
}

// 解析授权码
cleanedCode, err := service.ParseAuthorizationCode(req.AuthorizationCode)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{
"success": false,
"message": err.Error(),
})
return
}

// 交换token
tokenResult, err := service.ExchangeCode(cleanedCode, req.CodeVerifier, req.State, nil)
if err != nil {
common.SysError("Claude OAuth token exchange failed: " + err.Error())
c.JSON(http.StatusInternalServerError, gin.H{
"success": false,
"message": "授权码交换失败: " + err.Error(),
})
return
}

c.JSON(http.StatusOK, gin.H{
"success": true,
"message": "授权码交换成功",
"data": tokenResult,
})
}
3 changes: 2 additions & 1 deletion controller/redemption.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"one-api/common"
"one-api/model"
"strconv"
"unicode/utf8"

"github.com/gin-gonic/gin"
)
Expand Down Expand Up @@ -63,7 +64,7 @@ func AddRedemption(c *gin.Context) {
common.ApiError(c, err)
return
}
if len(redemption.Name) == 0 || len(redemption.Name) > 20 {
if utf8.RuneCountInString(redemption.Name) == 0 || utf8.RuneCountInString(redemption.Name) > 20 {
c.JSON(http.StatusOK, gin.H{
"success": false,
"message": "兑换码名称长度必须在1-20之间",
Expand Down
12 changes: 6 additions & 6 deletions controller/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func relayHandler(c *gin.Context, relayMode int) *types.NewAPIError {
userGroup := c.GetString("group")
channelId := c.GetInt("channel_id")
other := make(map[string]interface{})
other["error_type"] = err.ErrorType
other["error_type"] = err.GetErrorType()
other["error_code"] = err.GetErrorCode()
other["status_code"] = err.StatusCode
other["channel_id"] = channelId
Expand Down Expand Up @@ -259,10 +259,10 @@ func getChannel(c *gin.Context, group, originalModel string, retryCount int) (*m
}
channel, selectGroup, err := model.CacheGetRandomSatisfiedChannel(c, group, originalModel, retryCount)
if err != nil {
if group == "auto" {
return nil, types.NewError(errors.New(fmt.Sprintf("获取自动分组下模型 %s 的可用渠道失败: %s", originalModel, err.Error())), types.ErrorCodeGetChannelFailed)
}
return nil, types.NewError(errors.New(fmt.Sprintf("获取分组 %s 下模型 %s 的可用渠道失败: %s", selectGroup, originalModel, err.Error())), types.ErrorCodeGetChannelFailed)
return nil, types.NewError(errors.New(fmt.Sprintf("获取分组 %s 下模型 %s 的可用渠道失败(retry): %s", selectGroup, originalModel, err.Error())), types.ErrorCodeGetChannelFailed)
}
if channel == nil {
return nil, types.NewError(errors.New(fmt.Sprintf("分组 %s 下模型 %s 的可用渠道不存在(数据库一致性已被破坏,retry)", selectGroup, originalModel)), types.ErrorCodeGetChannelFailed)
}
newAPIError := middleware.SetupContextForSelectedChannel(c, channel, originalModel)
if newAPIError != nil {
Expand Down Expand Up @@ -428,7 +428,7 @@ func RelayTask(c *gin.Context) {
func taskRelayHandler(c *gin.Context, relayMode int) *dto.TaskError {
var err *dto.TaskError
switch relayMode {
case relayconstant.RelayModeSunoFetch, relayconstant.RelayModeSunoFetchByID, relayconstant.RelayModeKlingFetchByID:
case relayconstant.RelayModeSunoFetch, relayconstant.RelayModeSunoFetchByID, relayconstant.RelayModeVideoFetchByID:
err = relay.RelayTaskFetch(c, relayMode)
default:
err = relay.RelayTaskSubmit(c, relayMode)
Expand Down
20 changes: 20 additions & 0 deletions controller/swag_video.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,23 @@ type KlingImage2VideoRequest struct {
CallbackURL string `json:"callback_url,omitempty" example:"https://your.domain/callback"`
ExternalTaskId string `json:"external_task_id,omitempty" example:"custom-task-002"`
}

// KlingImage2videoTaskId godoc
// @Summary 可灵任务查询--图生视频
// @Description Query the status and result of a Kling video generation task by task ID
// @Tags Origin
// @Accept json
// @Produce json
// @Param task_id path string true "Task ID"
// @Router /kling/v1/videos/image2video/{task_id} [get]
func KlingImage2videoTaskId(c *gin.Context) {}

// KlingText2videoTaskId godoc
// @Summary 可灵任务查询--文生视频
// @Description Query the status and result of a Kling text-to-video generation task by task ID
// @Tags Origin
// @Accept json
// @Produce json
// @Param task_id path string true "Task ID"
// @Router /kling/v1/videos/text2video/{task_id} [get]
func KlingText2videoTaskId(c *gin.Context) {}
6 changes: 3 additions & 3 deletions controller/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ func UpdateTaskByPlatform(platform constant.TaskPlatform, taskChannelM map[int][
//_ = UpdateMidjourneyTaskAll(context.Background(), tasks)
case constant.TaskPlatformSuno:
_ = UpdateSunoTaskAll(context.Background(), taskChannelM, taskM)
case constant.TaskPlatformKling, constant.TaskPlatformJimeng:
_ = UpdateVideoTaskAll(context.Background(), platform, taskChannelM, taskM)
default:
common.SysLog("未知平台")
if err := UpdateVideoTaskAll(context.Background(), platform, taskChannelM, taskM); err != nil {
common.SysLog(fmt.Sprintf("UpdateVideoTaskAll fail: %s", err))
}
}
}

Expand Down
23 changes: 16 additions & 7 deletions controller/task_video.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ package controller

import (
"context"
"encoding/json"
"fmt"
"io"
"one-api/common"
"one-api/constant"
"one-api/dto"
"one-api/model"
"one-api/relay"
"one-api/relay/channel"
relaycommon "one-api/relay/common"
"time"
)

Expand Down Expand Up @@ -77,13 +80,21 @@ func updateVideoSingleTask(ctx context.Context, adaptor channel.TaskAdaptor, cha
return fmt.Errorf("readAll failed for task %s: %w", taskId, err)
}

taskResult, err := adaptor.ParseTaskResult(responseBody)
if err != nil {
taskResult := &relaycommon.TaskInfo{}
// try parse as New API response format
var responseItems dto.TaskResponse[model.Task]
if err = json.Unmarshal(responseBody, &responseItems); err == nil && responseItems.IsSuccess() {
t := responseItems.Data
taskResult.TaskID = t.TaskID
taskResult.Status = string(t.Status)
taskResult.Url = t.FailReason
taskResult.Progress = t.Progress
taskResult.Reason = t.FailReason
} else if taskResult, err = adaptor.ParseTaskResult(responseBody); err != nil {
return fmt.Errorf("parseTaskResult failed for task %s: %w", taskId, err)
} else {
task.Data = responseBody
}
//if taskResult.Code != 0 {
// return fmt.Errorf("video task fetch failed for task %s", taskId)
//}

now := time.Now().Unix()
if taskResult.Status == "" {
Expand Down Expand Up @@ -128,8 +139,6 @@ func updateVideoSingleTask(ctx context.Context, adaptor channel.TaskAdaptor, cha
if taskResult.Progress != "" {
task.Progress = taskResult.Progress
}

task.Data = responseBody
if err := task.Update(); err != nil {
common.SysError("UpdateVideoTask task error: " + err.Error())
}
Expand Down
Loading
Loading