Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
陈曦
sub2api
Commits
0ffb3201
"vscode:/vscode.git/clone" did not exist on "c8e55ab2ac7ce51409d09071156fd153d526c81d"
Commit
0ffb3201
authored
Dec 31, 2025
by
yangjianbo
Browse files
Merge branch 'main' of
https://github.com/mt21625457/aicodex2api
parents
6f6dc303
4368966e
Changes
4
Hide whitespace changes
Inline
Side-by-side
.github/workflows/release.yml
View file @
0ffb3201
...
@@ -98,6 +98,13 @@ jobs:
...
@@ -98,6 +98,13 @@ jobs:
username
:
${{ secrets.DOCKERHUB_USERNAME }}
username
:
${{ secrets.DOCKERHUB_USERNAME }}
password
:
${{ secrets.DOCKERHUB_TOKEN }}
password
:
${{ secrets.DOCKERHUB_TOKEN }}
-
name
:
Login to GitHub Container Registry
uses
:
docker/login-action@v3
with
:
registry
:
ghcr.io
username
:
${{ github.repository_owner }}
password
:
${{ secrets.GITHUB_TOKEN }}
-
name
:
Fetch tags with annotations
-
name
:
Fetch tags with annotations
run
:
|
run
:
|
# 确保获取完整的 annotated tag 信息
# 确保获取完整的 annotated tag 信息
...
@@ -161,6 +168,7 @@ jobs:
...
@@ -161,6 +168,7 @@ jobs:
VERSION=${TAG_NAME#v}
VERSION=${TAG_NAME#v}
REPO="${{ github.repository }}"
REPO="${{ github.repository }}"
DOCKER_IMAGE="${{ secrets.DOCKERHUB_USERNAME }}/sub2api"
DOCKER_IMAGE="${{ secrets.DOCKERHUB_USERNAME }}/sub2api"
GHCR_IMAGE="ghcr.io/${REPO}"
# 获取 tag message 内容
# 获取 tag message 内容
TAG_MESSAGE='${{ steps.tag_message.outputs.message }}'
TAG_MESSAGE='${{ steps.tag_message.outputs.message }}'
...
@@ -181,12 +189,15 @@ jobs:
...
@@ -181,12 +189,15 @@ jobs:
MESSAGE+="🐳 *Docker 部署:*"$'\n'
MESSAGE+="🐳 *Docker 部署:*"$'\n'
MESSAGE+="\`\`\`bash"$'\n'
MESSAGE+="\`\`\`bash"$'\n'
MESSAGE+="# Docker Hub"$'\n'
MESSAGE+="docker pull ${DOCKER_IMAGE}:${TAG_NAME}"$'\n'
MESSAGE+="docker pull ${DOCKER_IMAGE}:${TAG_NAME}"$'\n'
MESSAGE+="docker pull ${DOCKER_IMAGE}:latest"$'\n'
MESSAGE+="# GitHub Container Registry"$'\n'
MESSAGE+="docker pull ${GHCR_IMAGE}:${TAG_NAME}"$'\n'
MESSAGE+="\`\`\`"$'\n'$'\n'
MESSAGE+="\`\`\`"$'\n'$'\n'
MESSAGE+="🔗 *相关链接:*"$'\n'
MESSAGE+="🔗 *相关链接:*"$'\n'
MESSAGE+="• [GitHub Release](https://github.com/${REPO}/releases/tag/${TAG_NAME})"$'\n'
MESSAGE+="• [GitHub Release](https://github.com/${REPO}/releases/tag/${TAG_NAME})"$'\n'
MESSAGE+="• [Docker Hub](https://hub.docker.com/r/${DOCKER_IMAGE})"$'\n'$'\n'
MESSAGE+="• [Docker Hub](https://hub.docker.com/r/${DOCKER_IMAGE})"$'\n'
MESSAGE+="• [GitHub Packages](https://github.com/${REPO}/pkgs/container/sub2api)"$'\n'$'\n'
MESSAGE+="#Sub2API #Release #${TAG_NAME//./_}"
MESSAGE+="#Sub2API #Release #${TAG_NAME//./_}"
# 发送消息
# 发送消息
...
...
.goreleaser.yaml
View file @
0ffb3201
...
@@ -78,6 +78,33 @@ dockers:
...
@@ -78,6 +78,33 @@ dockers:
-
"
--label=org.opencontainers.image.version={{
.Version
}}"
-
"
--label=org.opencontainers.image.version={{
.Version
}}"
-
"
--label=org.opencontainers.image.revision={{
.Commit
}}"
-
"
--label=org.opencontainers.image.revision={{
.Commit
}}"
# GHCR images
-
id
:
ghcr-amd64
goos
:
linux
goarch
:
amd64
image_templates
:
-
"
ghcr.io/{{
.Env.GITHUB_REPO_OWNER
}}/sub2api:{{
.Version
}}-amd64"
dockerfile
:
Dockerfile.goreleaser
use
:
buildx
build_flag_templates
:
-
"
--platform=linux/amd64"
-
"
--label=org.opencontainers.image.version={{
.Version
}}"
-
"
--label=org.opencontainers.image.revision={{
.Commit
}}"
-
"
--label=org.opencontainers.image.source=https://github.com/{{
.Env.GITHUB_REPO_OWNER
}}/{{
.Env.GITHUB_REPO_NAME
}}"
-
id
:
ghcr-arm64
goos
:
linux
goarch
:
arm64
image_templates
:
-
"
ghcr.io/{{
.Env.GITHUB_REPO_OWNER
}}/sub2api:{{
.Version
}}-arm64"
dockerfile
:
Dockerfile.goreleaser
use
:
buildx
build_flag_templates
:
-
"
--platform=linux/arm64"
-
"
--label=org.opencontainers.image.version={{
.Version
}}"
-
"
--label=org.opencontainers.image.revision={{
.Commit
}}"
-
"
--label=org.opencontainers.image.source=https://github.com/{{
.Env.GITHUB_REPO_OWNER
}}/{{
.Env.GITHUB_REPO_NAME
}}"
# Docker manifests for multi-arch support
# Docker manifests for multi-arch support
docker_manifests
:
docker_manifests
:
-
name_template
:
"
{{
.Env.DOCKERHUB_USERNAME
}}/sub2api:{{
.Version
}}"
-
name_template
:
"
{{
.Env.DOCKERHUB_USERNAME
}}/sub2api:{{
.Version
}}"
...
@@ -100,6 +127,27 @@ docker_manifests:
...
@@ -100,6 +127,27 @@ docker_manifests:
-
"
{{
.Env.DOCKERHUB_USERNAME
}}/sub2api:{{
.Version
}}-amd64"
-
"
{{
.Env.DOCKERHUB_USERNAME
}}/sub2api:{{
.Version
}}-amd64"
-
"
{{
.Env.DOCKERHUB_USERNAME
}}/sub2api:{{
.Version
}}-arm64"
-
"
{{
.Env.DOCKERHUB_USERNAME
}}/sub2api:{{
.Version
}}-arm64"
# GHCR manifests
-
name_template
:
"
ghcr.io/{{
.Env.GITHUB_REPO_OWNER
}}/sub2api:{{
.Version
}}"
image_templates
:
-
"
ghcr.io/{{
.Env.GITHUB_REPO_OWNER
}}/sub2api:{{
.Version
}}-amd64"
-
"
ghcr.io/{{
.Env.GITHUB_REPO_OWNER
}}/sub2api:{{
.Version
}}-arm64"
-
name_template
:
"
ghcr.io/{{
.Env.GITHUB_REPO_OWNER
}}/sub2api:latest"
image_templates
:
-
"
ghcr.io/{{
.Env.GITHUB_REPO_OWNER
}}/sub2api:{{
.Version
}}-amd64"
-
"
ghcr.io/{{
.Env.GITHUB_REPO_OWNER
}}/sub2api:{{
.Version
}}-arm64"
-
name_template
:
"
ghcr.io/{{
.Env.GITHUB_REPO_OWNER
}}/sub2api:{{
.Major
}}.{{
.Minor
}}"
image_templates
:
-
"
ghcr.io/{{
.Env.GITHUB_REPO_OWNER
}}/sub2api:{{
.Version
}}-amd64"
-
"
ghcr.io/{{
.Env.GITHUB_REPO_OWNER
}}/sub2api:{{
.Version
}}-arm64"
-
name_template
:
"
ghcr.io/{{
.Env.GITHUB_REPO_OWNER
}}/sub2api:{{
.Major
}}"
image_templates
:
-
"
ghcr.io/{{
.Env.GITHUB_REPO_OWNER
}}/sub2api:{{
.Version
}}-amd64"
-
"
ghcr.io/{{
.Env.GITHUB_REPO_OWNER
}}/sub2api:{{
.Version
}}-arm64"
release
:
release
:
github
:
github
:
owner
:
"
{{
.Env.GITHUB_REPO_OWNER
}}"
owner
:
"
{{
.Env.GITHUB_REPO_OWNER
}}"
...
@@ -119,6 +167,15 @@ release:
...
@@ -119,6 +167,15 @@ release:
## 📥 Installation
## 📥 Installation
**Docker:**
```bash
# Docker Hub
docker pull {{ .Env.DOCKERHUB_USERNAME }}/sub2api:{{ .Version }}
# GitHub Container Registry
docker pull ghcr.io/{{ .Env.GITHUB_REPO_OWNER }}/sub2api:{{ .Version }}
```
**One-line install (Linux):**
**One-line install (Linux):**
```bash
```bash
curl -sSL https://raw.githubusercontent.com/{{ .Env.GITHUB_REPO_OWNER }}/{{ .Env.GITHUB_REPO_NAME }}/main/deploy/install.sh | sudo bash
curl -sSL https://raw.githubusercontent.com/{{ .Env.GITHUB_REPO_OWNER }}/{{ .Env.GITHUB_REPO_NAME }}/main/deploy/install.sh | sudo bash
...
...
backend/internal/service/openai_gateway_service.go
View file @
0ffb3201
...
@@ -240,7 +240,7 @@ func (s *OpenAIGatewayService) GetAccessToken(ctx context.Context, account *Acco
...
@@ -240,7 +240,7 @@ func (s *OpenAIGatewayService) GetAccessToken(ctx context.Context, account *Acco
func
(
s
*
OpenAIGatewayService
)
shouldFailoverUpstreamError
(
statusCode
int
)
bool
{
func
(
s
*
OpenAIGatewayService
)
shouldFailoverUpstreamError
(
statusCode
int
)
bool
{
switch
statusCode
{
switch
statusCode
{
case
401
,
403
,
429
,
529
:
case
401
,
402
,
403
,
429
,
529
:
return
true
return
true
default
:
default
:
return
statusCode
>=
500
return
statusCode
>=
500
...
@@ -454,6 +454,10 @@ func (s *OpenAIGatewayService) handleErrorResponse(ctx context.Context, resp *ht
...
@@ -454,6 +454,10 @@ func (s *OpenAIGatewayService) handleErrorResponse(ctx context.Context, resp *ht
statusCode
=
http
.
StatusBadGateway
statusCode
=
http
.
StatusBadGateway
errType
=
"upstream_error"
errType
=
"upstream_error"
errMsg
=
"Upstream authentication failed, please contact administrator"
errMsg
=
"Upstream authentication failed, please contact administrator"
case
402
:
statusCode
=
http
.
StatusBadGateway
errType
=
"upstream_error"
errMsg
=
"Upstream payment required: insufficient balance or billing issue"
case
403
:
case
403
:
statusCode
=
http
.
StatusBadGateway
statusCode
=
http
.
StatusBadGateway
errType
=
"upstream_error"
errType
=
"upstream_error"
...
...
backend/internal/service/ratelimit_service.go
View file @
0ffb3201
...
@@ -39,6 +39,10 @@ func (s *RateLimitService) HandleUpstreamError(ctx context.Context, account *Acc
...
@@ -39,6 +39,10 @@ func (s *RateLimitService) HandleUpstreamError(ctx context.Context, account *Acc
// 认证失败:停止调度,记录错误
// 认证失败:停止调度,记录错误
s
.
handleAuthError
(
ctx
,
account
,
"Authentication failed (401): invalid or expired credentials"
)
s
.
handleAuthError
(
ctx
,
account
,
"Authentication failed (401): invalid or expired credentials"
)
return
true
return
true
case
402
:
// 支付要求:余额不足或计费问题,停止调度
s
.
handleAuthError
(
ctx
,
account
,
"Payment required (402): insufficient balance or billing issue"
)
return
true
case
403
:
case
403
:
// 禁止访问:停止调度,记录错误
// 禁止访问:停止调度,记录错误
s
.
handleAuthError
(
ctx
,
account
,
"Access forbidden (403): account may be suspended or lack permissions"
)
s
.
handleAuthError
(
ctx
,
account
,
"Access forbidden (403): account may be suspended or lack permissions"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment