mirror of
https://github.com/linux-do/new-api.git
synced 2025-11-17 19:13:42 +08:00
Compare commits
68 Commits
v0.2.9.7
...
a9e3555cac
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a9e3555cac | ||
|
|
8d83630d85 | ||
|
|
a60f209c85 | ||
|
|
208bc5e794 | ||
|
|
400b2b0ed0 | ||
|
|
27b034674d | ||
|
|
fefe5913e9 | ||
|
|
142d5fb209 | ||
|
|
f6ccd402e2 | ||
|
|
1c371300ab | ||
|
|
918690701d | ||
|
|
f0008e95fa | ||
|
|
7a249b206d | ||
|
|
0cc7f5cca6 | ||
|
|
ed86ec8b59 | ||
|
|
895ee09b33 | ||
|
|
61006bed9e | ||
|
|
58591b8c2a | ||
|
|
69b9950aa0 | ||
|
|
bcf1b160d1 | ||
|
|
1e0e40aa69 | ||
|
|
74392efbed | ||
|
|
cc020d6a40 | ||
|
|
daa1741aed | ||
|
|
a25bcaa58f | ||
|
|
d34b601dae | ||
|
|
9932962320 | ||
|
|
00d6cda9ed | ||
|
|
5ffb520363 | ||
|
|
e0f80cdb8f | ||
|
|
7a7a923504 | ||
|
|
4f6c171a08 | ||
|
|
310f8c247e | ||
|
|
811019bf5c | ||
|
|
0ed6600437 | ||
|
|
1fe7f14d57 | ||
|
|
a7bafec1bf | ||
|
|
ed951b3974 | ||
|
|
c74e43b8fd | ||
|
|
03bd9b0cc4 | ||
|
|
149902bd8a | ||
|
|
cd3ed22045 | ||
|
|
2329d387ca | ||
|
|
7d18a8e2a9 | ||
|
|
80af3718d0 | ||
|
|
77ea6bec46 | ||
|
|
c0ab8ae953 | ||
|
|
923c2dee32 | ||
|
|
ea17a46d8e | ||
|
|
bfe9e5d25a | ||
|
|
831ff47254 | ||
|
|
11eaba6b5d | ||
|
|
c2e4ec25c8 | ||
|
|
8537f10412 | ||
|
|
71d60eeef7 | ||
|
|
247ae0988f | ||
|
|
0907fa6994 | ||
|
|
9855343aa8 | ||
|
|
bd50fde268 | ||
|
|
4267de5642 | ||
|
|
8b55116563 | ||
|
|
f35e63e3f3 | ||
|
|
17c409de23 | ||
|
|
e4753e7411 | ||
|
|
9adefa80b9 | ||
|
|
4ce2381182 | ||
|
|
62afc21ea5 | ||
|
|
7ddb7c586d |
6
.github/ISSUE_TEMPLATE/config.yml
vendored
6
.github/ISSUE_TEMPLATE/config.yml
vendored
@@ -1,5 +1,5 @@
|
|||||||
blank_issues_enabled: false
|
blank_issues_enabled: false
|
||||||
contact_links:
|
contact_links:
|
||||||
- name: 项目群聊
|
- name: 交流社区
|
||||||
url: https://private-user-images.githubusercontent.com/61247483/283011625-de536a8a-0161-47a7-a0a2-66ef6de81266.jpeg?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTEiLCJleHAiOjE3MDIyMjQzOTAsIm5iZiI6MTcwMjIyNDA5MCwicGF0aCI6Ii82MTI0NzQ4My8yODMwMTE2MjUtZGU1MzZhOGEtMDE2MS00N2E3LWEwYTItNjZlZjZkZTgxMjY2LmpwZWc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBSVdOSllBWDRDU1ZFSDUzQSUyRjIwMjMxMjEwJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDIzMTIxMFQxNjAxMzBaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT02MGIxYmM3ZDQyYzBkOTA2ZTYyYmVmMzQ1NjY4NjM1YjY0NTUzNTM5NjE1NDZkYTIzODdhYTk4ZjZjODJmYzY2JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.TJ8CTfOSwR0-CHS1KLfomqgL0e4YH1luy8lSLrkv5Zg
|
url: https://linux.do
|
||||||
about: QQ 群:629454374
|
about: 项目交流社区
|
||||||
|
|||||||
5
.github/workflows/docker-image-amd64.yml
vendored
5
.github/workflows/docker-image-amd64.yml
vendored
@@ -1,9 +1,6 @@
|
|||||||
name: Publish Docker image (amd64)
|
name: Publish Docker image (amd64)
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
|
||||||
tags:
|
|
||||||
- '*'
|
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
inputs:
|
inputs:
|
||||||
name:
|
name:
|
||||||
@@ -42,7 +39,7 @@ jobs:
|
|||||||
uses: docker/metadata-action@v4
|
uses: docker/metadata-action@v4
|
||||||
with:
|
with:
|
||||||
images: |
|
images: |
|
||||||
calciumion/new-api
|
pengzhile/new-api
|
||||||
ghcr.io/${{ github.repository }}
|
ghcr.io/${{ github.repository }}
|
||||||
|
|
||||||
- name: Build and push Docker images
|
- name: Build and push Docker images
|
||||||
|
|||||||
2
.github/workflows/docker-image-arm64.yml
vendored
2
.github/workflows/docker-image-arm64.yml
vendored
@@ -49,7 +49,7 @@ jobs:
|
|||||||
uses: docker/metadata-action@v4
|
uses: docker/metadata-action@v4
|
||||||
with:
|
with:
|
||||||
images: |
|
images: |
|
||||||
calciumion/new-api
|
pengzhile/new-api
|
||||||
ghcr.io/${{ github.repository }}
|
ghcr.io/${{ github.repository }}
|
||||||
|
|
||||||
- name: Build and push Docker images
|
- name: Build and push Docker images
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ all: build-frontend start-backend
|
|||||||
|
|
||||||
build-frontend:
|
build-frontend:
|
||||||
@echo "Building frontend..."
|
@echo "Building frontend..."
|
||||||
@cd $(FRONTEND_DIR) && npm install && DISABLE_ESLINT_PLUGIN='true' VITE_REACT_APP_VERSION=$(cat VERSION) npm run build
|
@cd $(FRONTEND_DIR) && yarn install --network-timeout 1000000 && DISABLE_ESLINT_PLUGIN='true' VITE_REACT_APP_VERSION=$(cat VERSION) yarn build
|
||||||
|
|
||||||
start-backend:
|
start-backend:
|
||||||
@echo "Starting backend dev server..."
|
@echo "Starting backend dev server..."
|
||||||
@@ -44,7 +44,7 @@
|
|||||||
|
|
||||||
## 模型支持
|
## 模型支持
|
||||||
此版本额外支持以下模型:
|
此版本额外支持以下模型:
|
||||||
1. 第三方模型 **gps** (gpt-4-gizmo-*)
|
1. 第三方模型 **gps** (gpt-4-gizmo-*, g-*)
|
||||||
2. 智谱glm-4v,glm-4v识图
|
2. 智谱glm-4v,glm-4v识图
|
||||||
3. Anthropic Claude 3
|
3. Anthropic Claude 3
|
||||||
4. [Ollama](https://github.com/ollama/ollama?tab=readme-ov-file),添加渠道时,密钥可以随便填写,默认的请求地址是[http://localhost:11434](http://localhost:11434),如果需要修改请在渠道中修改
|
4. [Ollama](https://github.com/ollama/ollama?tab=readme-ov-file),添加渠道时,密钥可以随便填写,默认的请求地址是[http://localhost:11434](http://localhost:11434),如果需要修改请在渠道中修改
|
||||||
@@ -56,7 +56,7 @@
|
|||||||
10. Dify
|
10. Dify
|
||||||
11. Vertex AI,目前兼容Claude,Gemini,Llama3.1
|
11. Vertex AI,目前兼容Claude,Gemini,Llama3.1
|
||||||
|
|
||||||
您可以在渠道中添加自定义模型gpt-4-gizmo-*,此模型并非OpenAI官方模型,而是第三方模型,使用官方key无法调用。
|
您可以在渠道中添加自定义模型gpt-4-gizmo-*或g-*,此模型并非OpenAI官方模型,而是第三方模型,使用官方key无法调用。
|
||||||
|
|
||||||
## 比原版One API多出的配置
|
## 比原版One API多出的配置
|
||||||
- `STREAMING_TIMEOUT`:设置流式一次回复的超时时间,默认为 30 秒。
|
- `STREAMING_TIMEOUT`:设置流式一次回复的超时时间,默认为 30 秒。
|
||||||
|
|||||||
@@ -9,9 +9,20 @@ import (
|
|||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Pay Settings
|
||||||
|
|
||||||
|
var StripeApiSecret = ""
|
||||||
|
var StripeWebhookSecret = ""
|
||||||
|
var StripePriceId = ""
|
||||||
|
var PaymentEnabled = false
|
||||||
|
var StripeUnitPrice = 8.0
|
||||||
|
var MinTopUp = 5
|
||||||
|
|
||||||
var StartTime = time.Now().Unix() // unit: second
|
var StartTime = time.Now().Unix() // unit: second
|
||||||
var Version = "v0.0.0" // this hard coding will be replaced automatically when building, no need to manually change
|
var Version = "v0.0.0" // this hard coding will be replaced automatically when building, no need to manually change
|
||||||
var SystemName = "New API"
|
var SystemName = "New API"
|
||||||
|
var ServerAddress = "http://localhost:3000"
|
||||||
|
var OutProxyUrl = ""
|
||||||
var Footer = ""
|
var Footer = ""
|
||||||
var Logo = ""
|
var Logo = ""
|
||||||
var TopUpLink = ""
|
var TopUpLink = ""
|
||||||
@@ -41,10 +52,12 @@ var PasswordLoginEnabled = true
|
|||||||
var PasswordRegisterEnabled = true
|
var PasswordRegisterEnabled = true
|
||||||
var EmailVerificationEnabled = false
|
var EmailVerificationEnabled = false
|
||||||
var GitHubOAuthEnabled = false
|
var GitHubOAuthEnabled = false
|
||||||
|
var LinuxDoOAuthEnabled = false
|
||||||
var WeChatAuthEnabled = false
|
var WeChatAuthEnabled = false
|
||||||
var TelegramOAuthEnabled = false
|
var TelegramOAuthEnabled = false
|
||||||
var TurnstileCheckEnabled = false
|
var TurnstileCheckEnabled = false
|
||||||
var RegisterEnabled = true
|
var RegisterEnabled = true
|
||||||
|
var UserSelfDeletionEnabled = false
|
||||||
|
|
||||||
var EmailDomainRestrictionEnabled = false // 是否启用邮箱域名限制
|
var EmailDomainRestrictionEnabled = false // 是否启用邮箱域名限制
|
||||||
var EmailAliasRestrictionEnabled = false // 是否启用邮箱别名限制
|
var EmailAliasRestrictionEnabled = false // 是否启用邮箱别名限制
|
||||||
@@ -75,6 +88,10 @@ var SMTPToken = ""
|
|||||||
var GitHubClientId = ""
|
var GitHubClientId = ""
|
||||||
var GitHubClientSecret = ""
|
var GitHubClientSecret = ""
|
||||||
|
|
||||||
|
var LinuxDoClientId = ""
|
||||||
|
var LinuxDoClientSecret = ""
|
||||||
|
var LinuxDoMinLevel = 0
|
||||||
|
|
||||||
var WeChatServerAddress = ""
|
var WeChatServerAddress = ""
|
||||||
var WeChatServerToken = ""
|
var WeChatServerToken = ""
|
||||||
var WeChatAccountQRCodeImageURL = ""
|
var WeChatAccountQRCodeImageURL = ""
|
||||||
@@ -179,6 +196,12 @@ const (
|
|||||||
ChannelStatusAutoDisabled = 3
|
ChannelStatusAutoDisabled = 3
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
TopUpStatusPending = "pending"
|
||||||
|
TopUpStatusSuccess = "success"
|
||||||
|
TopUpStatusExpired = "expired"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ChannelTypeUnknown = 0
|
ChannelTypeUnknown = 0
|
||||||
ChannelTypeOpenAI = 1
|
ChannelTypeOpenAI = 1
|
||||||
|
|||||||
84
common/hash.go
Normal file
84
common/hash.go
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
package common
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/hmac"
|
||||||
|
"crypto/sha1"
|
||||||
|
"crypto/sha256"
|
||||||
|
"encoding/hex"
|
||||||
|
"math/rand"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Sha256Raw(data string) []byte {
|
||||||
|
h := sha256.New()
|
||||||
|
h.Write([]byte(data))
|
||||||
|
return h.Sum(nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Sha1Raw(data []byte) []byte {
|
||||||
|
h := sha1.New()
|
||||||
|
h.Write([]byte(data))
|
||||||
|
return h.Sum(nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Sha1(data string) string {
|
||||||
|
return hex.EncodeToString(Sha1Raw([]byte(data)))
|
||||||
|
}
|
||||||
|
|
||||||
|
func HmacSha256Raw(message, key []byte) []byte {
|
||||||
|
h := hmac.New(sha256.New, key)
|
||||||
|
h.Write(message)
|
||||||
|
return h.Sum(nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func HmacSha256(message, key string) string {
|
||||||
|
return hex.EncodeToString(HmacSha256Raw([]byte(message), []byte(key)))
|
||||||
|
}
|
||||||
|
|
||||||
|
func RandomBytes(length int) []byte {
|
||||||
|
rand.Seed(time.Now().UnixNano())
|
||||||
|
b := make([]byte, length)
|
||||||
|
if _, err := rand.Read(b); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func RandomString(length int) string {
|
||||||
|
const chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||||
|
result := make([]byte, length)
|
||||||
|
randomBytes := RandomBytes(length)
|
||||||
|
for i := 0; i < length; i++ {
|
||||||
|
result[i] = chars[randomBytes[i]%byte(len(chars))]
|
||||||
|
}
|
||||||
|
|
||||||
|
return string(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
func RandomHex(length int) string {
|
||||||
|
const chars = "abcdef0123456789"
|
||||||
|
result := make([]byte, length)
|
||||||
|
randomBytes := RandomBytes(length)
|
||||||
|
for i := 0; i < length; i++ {
|
||||||
|
result[i] = chars[randomBytes[i]%byte(len(chars))]
|
||||||
|
}
|
||||||
|
|
||||||
|
return string(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
func RandomNumber(length int) string {
|
||||||
|
const chars = "0123456789"
|
||||||
|
result := make([]byte, length)
|
||||||
|
randomBytes := RandomBytes(length)
|
||||||
|
for i := 0; i < length; i++ {
|
||||||
|
result[i] = chars[randomBytes[i]%byte(len(chars))]
|
||||||
|
}
|
||||||
|
|
||||||
|
return string(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
func RandomUUID() string {
|
||||||
|
all := RandomHex(32)
|
||||||
|
return all[:8] + "-" + all[8:12] + "-" + all[12:16] + "-" + all[16:20] + "-" + all[20:]
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package service
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
@@ -8,7 +8,6 @@ import (
|
|||||||
"golang.org/x/image/webp"
|
"golang.org/x/image/webp"
|
||||||
"image"
|
"image"
|
||||||
"io"
|
"io"
|
||||||
"one-api/common"
|
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -31,9 +30,24 @@ func DecodeBase64ImageData(base64String string) (image.Config, string, string, e
|
|||||||
return config, format, base64String, err
|
return config, format, base64String, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsImageUrl(url string) (bool, error) {
|
||||||
|
resp, err := ProxiedHttpHead(url, OutProxyUrl)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
if !strings.HasPrefix(resp.Header.Get("Content-Type"), "image/") {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
// GetImageFromUrl 获取图片的类型和base64编码的数据
|
// GetImageFromUrl 获取图片的类型和base64编码的数据
|
||||||
func GetImageFromUrl(url string) (mimeType string, data string, err error) {
|
func GetImageFromUrl(url string) (mimeType string, data string, err error) {
|
||||||
resp, err := DoImageRequest(url)
|
isImage, err := IsImageUrl(url)
|
||||||
|
if !isImage {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resp, err := ProxiedHttpGet(url, OutProxyUrl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -52,9 +66,9 @@ func GetImageFromUrl(url string) (mimeType string, data string, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func DecodeUrlImageData(imageUrl string) (image.Config, string, error) {
|
func DecodeUrlImageData(imageUrl string) (image.Config, string, error) {
|
||||||
response, err := DoImageRequest(imageUrl)
|
response, err := ProxiedHttpGet(imageUrl, OutProxyUrl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.SysLog(fmt.Sprintf("fail to get image from url: %s", err.Error()))
|
SysLog(fmt.Sprintf("fail to get image from url: %s", err.Error()))
|
||||||
return image.Config{}, "", err
|
return image.Config{}, "", err
|
||||||
}
|
}
|
||||||
defer response.Body.Close()
|
defer response.Body.Close()
|
||||||
@@ -66,7 +80,7 @@ func DecodeUrlImageData(imageUrl string) (image.Config, string, error) {
|
|||||||
|
|
||||||
var readData []byte
|
var readData []byte
|
||||||
for _, limit := range []int64{1024 * 8, 1024 * 24, 1024 * 64} {
|
for _, limit := range []int64{1024 * 8, 1024 * 24, 1024 * 64} {
|
||||||
common.SysLog(fmt.Sprintf("try to decode image config with limit: %d", limit))
|
SysLog(fmt.Sprintf("try to decode image config with limit: %d", limit))
|
||||||
|
|
||||||
// 从response.Body读取更多的数据直到达到当前的限制
|
// 从response.Body读取更多的数据直到达到当前的限制
|
||||||
additionalData := make([]byte, limit-int64(len(readData)))
|
additionalData := make([]byte, limit-int64(len(readData)))
|
||||||
@@ -92,11 +106,11 @@ func getImageConfig(reader io.Reader) (image.Config, string, error) {
|
|||||||
config, format, err := image.DecodeConfig(reader)
|
config, format, err := image.DecodeConfig(reader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.New(fmt.Sprintf("fail to decode image config(gif, jpg, png): %s", err.Error()))
|
err = errors.New(fmt.Sprintf("fail to decode image config(gif, jpg, png): %s", err.Error()))
|
||||||
common.SysLog(err.Error())
|
SysLog(err.Error())
|
||||||
config, err = webp.DecodeConfig(reader)
|
config, err = webp.DecodeConfig(reader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.New(fmt.Sprintf("fail to decode image config(webp): %s", err.Error()))
|
err = errors.New(fmt.Sprintf("fail to decode image config(webp): %s", err.Error()))
|
||||||
common.SysLog(err.Error())
|
SysLog(err.Error())
|
||||||
}
|
}
|
||||||
format = "webp"
|
format = "webp"
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,6 @@ package common
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"io"
|
"io"
|
||||||
@@ -100,12 +99,10 @@ func LogQuota(quota int) string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// LogJson 仅供测试使用 only for test
|
func LogQuotaF(quota float64) string {
|
||||||
func LogJson(ctx context.Context, msg string, obj any) {
|
if DisplayInCurrencyEnabled {
|
||||||
jsonStr, err := json.Marshal(obj)
|
return fmt.Sprintf("$%.6f 额度", quota/QuotaPerUnit)
|
||||||
if err != nil {
|
} else {
|
||||||
LogError(ctx, fmt.Sprintf("json marshal failed: %s", err.Error()))
|
return fmt.Sprintf("%d 点额度", int64(quota))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
LogInfo(ctx, fmt.Sprintf("%s | %s", msg, string(jsonStr)))
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,44 +23,42 @@ const (
|
|||||||
|
|
||||||
var defaultModelRatio = map[string]float64{
|
var defaultModelRatio = map[string]float64{
|
||||||
//"midjourney": 50,
|
//"midjourney": 50,
|
||||||
"gpt-4-gizmo-*": 15,
|
"gpt-4-gizmo-*": 15,
|
||||||
"gpt-4o-gizmo-*": 2.5,
|
"g-*": 15,
|
||||||
"gpt-4-all": 15,
|
"gpt-4": 15,
|
||||||
"gpt-4o-all": 15,
|
"gpt-4-0314": 15,
|
||||||
"gpt-4": 15,
|
"gpt-4-0613": 15,
|
||||||
//"gpt-4-0314": 15, //deprecated
|
"gpt-4-32k": 30,
|
||||||
"gpt-4-0613": 15,
|
"gpt-4-32k-0314": 30,
|
||||||
"gpt-4-32k": 30,
|
"gpt-4-32k-0613": 30,
|
||||||
//"gpt-4-32k-0314": 30, //deprecated
|
"gpt-4o-mini": 0.075, // $0.00015 / 1K tokens
|
||||||
"gpt-4-32k-0613": 30,
|
"gpt-4o-mini-2024-07-18": 0.075,
|
||||||
"gpt-4-1106-preview": 5, // $0.01 / 1K tokens
|
"chatgpt-4o-latest": 2.5, // $0.01 / 1K tokens
|
||||||
"gpt-4-0125-preview": 5, // $0.01 / 1K tokens
|
"gpt-4o": 2.5, // $0.005 / 1K tokens
|
||||||
"gpt-4-turbo-preview": 5, // $0.01 / 1K tokens
|
"gpt-4o-2024-05-13": 2.5, // $0.005 / 1K tokens
|
||||||
"gpt-4-vision-preview": 5, // $0.01 / 1K tokens
|
"gpt-4o-2024-08-06": 1.25, // $0.01 / 1K tokens
|
||||||
"gpt-4-1106-vision-preview": 5, // $0.01 / 1K tokens
|
"gpt-4-turbo": 5, // $0.01 / 1K tokens
|
||||||
"chatgpt-4o-latest": 2.5, // $0.01 / 1K tokens
|
"gpt-4-turbo-2024-04-09": 5, // $0.01 / 1K tokens
|
||||||
"gpt-4o": 2.5, // $0.01 / 1K tokens
|
"gpt-4-1106-preview": 5, // $0.01 / 1K tokens
|
||||||
"gpt-4o-2024-05-13": 2.5, // $0.01 / 1K tokens
|
"gpt-4-0125-preview": 5, // $0.01 / 1K tokens
|
||||||
"gpt-4o-2024-08-06": 1.25, // $0.01 / 1K tokens
|
"gpt-4-turbo-preview": 5, // $0.01 / 1K tokens
|
||||||
"gpt-4o-mini": 0.075,
|
"gpt-4-vision-preview": 5, // $0.01 / 1K tokens
|
||||||
"gpt-4o-mini-2024-07-18": 0.075,
|
"gpt-4-1106-vision-preview": 5, // $0.01 / 1K tokens
|
||||||
"gpt-4-turbo": 5, // $0.01 / 1K tokens
|
"gpt-3.5-turbo": 0.25, // $0.0005 / 1K tokens
|
||||||
"gpt-4-turbo-2024-04-09": 5, // $0.01 / 1K tokens
|
"gpt-3.5-turbo-0301": 0.75,
|
||||||
"gpt-3.5-turbo": 0.25, // $0.0015 / 1K tokens
|
"gpt-3.5-turbo-0613": 0.75,
|
||||||
//"gpt-3.5-turbo-0301": 0.75, //deprecated
|
"gpt-3.5-turbo-16k": 1.5, // $0.003 / 1K tokens
|
||||||
"gpt-3.5-turbo-0613": 0.75,
|
"gpt-3.5-turbo-16k-0613": 1.5,
|
||||||
"gpt-3.5-turbo-16k": 1.5, // $0.003 / 1K tokens
|
"gpt-3.5-turbo-instruct": 0.75, // $0.0015 / 1K tokens
|
||||||
"gpt-3.5-turbo-16k-0613": 1.5,
|
"gpt-3.5-turbo-1106": 0.5, // $0.001 / 1K tokens
|
||||||
"gpt-3.5-turbo-instruct": 0.75, // $0.0015 / 1K tokens
|
"gpt-3.5-turbo-0125": 0.25,
|
||||||
"gpt-3.5-turbo-1106": 0.5, // $0.001 / 1K tokens
|
"babbage-002": 0.2, // $0.0004 / 1K tokens
|
||||||
"gpt-3.5-turbo-0125": 0.25,
|
"davinci-002": 1, // $0.002 / 1K tokens
|
||||||
"babbage-002": 0.2, // $0.0004 / 1K tokens
|
"text-ada-001": 0.2,
|
||||||
"davinci-002": 1, // $0.002 / 1K tokens
|
"text-babbage-001": 0.25,
|
||||||
"text-ada-001": 0.2,
|
"text-curie-001": 1,
|
||||||
"text-babbage-001": 0.25,
|
"text-davinci-002": 10,
|
||||||
"text-curie-001": 1,
|
"text-davinci-003": 10,
|
||||||
//"text-davinci-002": 10,
|
|
||||||
//"text-davinci-003": 10,
|
|
||||||
"text-davinci-edit-001": 10,
|
"text-davinci-edit-001": 10,
|
||||||
"code-davinci-edit-001": 10,
|
"code-davinci-edit-001": 10,
|
||||||
"whisper-1": 15, // $0.006 / minute -> $0.006 / 150 words -> $0.006 / 200 tokens -> $0.03 / 1k tokens
|
"whisper-1": 15, // $0.006 / minute -> $0.006 / 150 words -> $0.006 / 200 tokens -> $0.03 / 1k tokens
|
||||||
@@ -82,9 +80,9 @@ var defaultModelRatio = map[string]float64{
|
|||||||
"claude-2.0": 4, // $8 / 1M tokens
|
"claude-2.0": 4, // $8 / 1M tokens
|
||||||
"claude-2.1": 4, // $8 / 1M tokens
|
"claude-2.1": 4, // $8 / 1M tokens
|
||||||
"claude-3-haiku-20240307": 0.125, // $0.25 / 1M tokens
|
"claude-3-haiku-20240307": 0.125, // $0.25 / 1M tokens
|
||||||
|
"claude-3-5-sonnet-20240620": 1.5, // $3 / 1M tokens
|
||||||
"claude-3-sonnet-20240229": 1.5, // $3 / 1M tokens
|
"claude-3-sonnet-20240229": 1.5, // $3 / 1M tokens
|
||||||
"claude-3-5-sonnet-20240620": 1.5,
|
"claude-3-opus-20240229": 7.5, // $15 / 1M tokens
|
||||||
"claude-3-opus-20240229": 7.5, // $15 / 1M tokens
|
|
||||||
"ERNIE-4.0-8K": 0.120 * RMB,
|
"ERNIE-4.0-8K": 0.120 * RMB,
|
||||||
"ERNIE-3.5-8K": 0.012 * RMB,
|
"ERNIE-3.5-8K": 0.012 * RMB,
|
||||||
"ERNIE-3.5-8K-0205": 0.024 * RMB,
|
"ERNIE-3.5-8K-0205": 0.024 * RMB,
|
||||||
@@ -176,8 +174,10 @@ var defaultModelRatio = map[string]float64{
|
|||||||
var defaultModelPrice = map[string]float64{
|
var defaultModelPrice = map[string]float64{
|
||||||
"suno_music": 0.1,
|
"suno_music": 0.1,
|
||||||
"suno_lyrics": 0.01,
|
"suno_lyrics": 0.01,
|
||||||
|
"dall-e-2": 0.02,
|
||||||
"dall-e-3": 0.04,
|
"dall-e-3": 0.04,
|
||||||
"gpt-4-gizmo-*": 0.1,
|
"gpt-4-gizmo-*": 0.1,
|
||||||
|
"g-*": 0.1,
|
||||||
"mj_imagine": 0.1,
|
"mj_imagine": 0.1,
|
||||||
"mj_variation": 0.1,
|
"mj_variation": 0.1,
|
||||||
"mj_reroll": 0.1,
|
"mj_reroll": 0.1,
|
||||||
@@ -207,9 +207,10 @@ var (
|
|||||||
|
|
||||||
var CompletionRatio map[string]float64 = nil
|
var CompletionRatio map[string]float64 = nil
|
||||||
var defaultCompletionRatio = map[string]float64{
|
var defaultCompletionRatio = map[string]float64{
|
||||||
"gpt-4-gizmo-*": 2,
|
"gpt-4-gizmo-*": 2,
|
||||||
"gpt-4o-gizmo-*": 3,
|
"g-*": 2,
|
||||||
"gpt-4-all": 2,
|
"gpt-4-all": 2,
|
||||||
|
"gpt-4o-all": 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetModelPriceMap() map[string]float64 {
|
func GetModelPriceMap() map[string]float64 {
|
||||||
@@ -242,9 +243,8 @@ func GetModelPrice(name string, printErr bool) (float64, bool) {
|
|||||||
GetModelPriceMap()
|
GetModelPriceMap()
|
||||||
if strings.HasPrefix(name, "gpt-4-gizmo") {
|
if strings.HasPrefix(name, "gpt-4-gizmo") {
|
||||||
name = "gpt-4-gizmo-*"
|
name = "gpt-4-gizmo-*"
|
||||||
}
|
} else if strings.HasPrefix(name, "g-") {
|
||||||
if strings.HasPrefix(name, "gpt-4o-gizmo") {
|
name = "g-*"
|
||||||
name = "gpt-4o-gizmo-*"
|
|
||||||
}
|
}
|
||||||
price, ok := modelPriceMap[name]
|
price, ok := modelPriceMap[name]
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -285,6 +285,8 @@ func GetModelRatio(name string) float64 {
|
|||||||
GetModelRatioMap()
|
GetModelRatioMap()
|
||||||
if strings.HasPrefix(name, "gpt-4-gizmo") {
|
if strings.HasPrefix(name, "gpt-4-gizmo") {
|
||||||
name = "gpt-4-gizmo-*"
|
name = "gpt-4-gizmo-*"
|
||||||
|
} else if strings.HasPrefix(name, "g-") {
|
||||||
|
name = "g-*"
|
||||||
}
|
}
|
||||||
ratio, ok := modelRatioMap[name]
|
ratio, ok := modelRatioMap[name]
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -325,29 +327,28 @@ func UpdateCompletionRatioByJSONString(jsonStr string) error {
|
|||||||
func GetCompletionRatio(name string) float64 {
|
func GetCompletionRatio(name string) float64 {
|
||||||
if strings.HasPrefix(name, "gpt-4-gizmo") {
|
if strings.HasPrefix(name, "gpt-4-gizmo") {
|
||||||
name = "gpt-4-gizmo-*"
|
name = "gpt-4-gizmo-*"
|
||||||
}
|
} else if strings.HasPrefix(name, "g-") {
|
||||||
if strings.HasPrefix(name, "gpt-4o-gizmo") {
|
name = "g-*"
|
||||||
name = "gpt-4o-gizmo-*"
|
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(name, "gpt-3.5") {
|
if strings.HasPrefix(name, "gpt-3.5") {
|
||||||
if name == "gpt-3.5-turbo" || strings.HasSuffix(name, "0125") {
|
if strings.HasSuffix(name, "0125") {
|
||||||
// https://openai.com/blog/new-embedding-models-and-api-updates
|
|
||||||
// Updated GPT-3.5 Turbo model and lower pricing
|
|
||||||
return 3
|
return 3
|
||||||
}
|
}
|
||||||
if strings.HasSuffix(name, "1106") {
|
if strings.HasSuffix(name, "1106") {
|
||||||
return 2
|
return 2
|
||||||
}
|
}
|
||||||
return 4.0 / 3.0
|
if name == "gpt-3.5-turbo" {
|
||||||
}
|
|
||||||
if strings.HasPrefix(name, "gpt-4") && !strings.HasSuffix(name, "-all") && !strings.HasSuffix(name, "-gizmo-*") {
|
|
||||||
if strings.HasPrefix(name, "gpt-4-turbo") || strings.HasSuffix(name, "preview") {
|
|
||||||
return 3
|
return 3
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(name, "gpt-4o") {
|
|
||||||
if strings.HasPrefix(name, "gpt-4o-mini") || name == "gpt-4o-2024-08-06" {
|
return 4.0 / 3.0
|
||||||
return 4
|
}
|
||||||
}
|
if strings.HasPrefix(name, "gpt-4") && name != "gpt-4-all" && name != "gpt-4-gizmo-*" {
|
||||||
|
if strings.HasPrefix(name, "gpt-4o-mini") || "gpt-4o-2024-08-06" == name {
|
||||||
|
return 4
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.HasSuffix(name, "preview") || strings.HasPrefix(name, "gpt-4-turbo") || strings.HasPrefix(name, "gpt-4o") {
|
||||||
return 3
|
return 3
|
||||||
}
|
}
|
||||||
return 2
|
return 2
|
||||||
@@ -355,11 +356,11 @@ func GetCompletionRatio(name string) float64 {
|
|||||||
if name == "chatgpt-4o-latest" {
|
if name == "chatgpt-4o-latest" {
|
||||||
return 3
|
return 3
|
||||||
}
|
}
|
||||||
if strings.Contains(name, "claude-instant-1") {
|
if strings.HasPrefix(name, "claude-instant-1") {
|
||||||
return 3
|
return 3
|
||||||
} else if strings.Contains(name, "claude-2") {
|
} else if strings.HasPrefix(name, "claude-2") {
|
||||||
return 3
|
return 3
|
||||||
} else if strings.Contains(name, "claude-3") {
|
} else if strings.HasPrefix(name, "claude-3") {
|
||||||
return 5
|
return 5
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(name, "mistral-") {
|
if strings.HasPrefix(name, "mistral-") {
|
||||||
|
|||||||
@@ -1,12 +1,17 @@
|
|||||||
package common
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
"golang.org/x/net/proxy"
|
||||||
"html/template"
|
"html/template"
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -187,3 +192,56 @@ func RandomSleep() {
|
|||||||
// Sleep for 0-3000 ms
|
// Sleep for 0-3000 ms
|
||||||
time.Sleep(time.Duration(rand.Intn(3000)) * time.Millisecond)
|
time.Sleep(time.Duration(rand.Intn(3000)) * time.Millisecond)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetProxiedHttpClient(proxyUrl string) (*http.Client, error) {
|
||||||
|
if "" == proxyUrl {
|
||||||
|
return &http.Client{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
u, err := url.Parse(proxyUrl)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.HasPrefix(proxyUrl, "http") {
|
||||||
|
|
||||||
|
return &http.Client{
|
||||||
|
Transport: &http.Transport{
|
||||||
|
Proxy: http.ProxyURL(u),
|
||||||
|
},
|
||||||
|
}, nil
|
||||||
|
} else if strings.HasPrefix(proxyUrl, "socks") {
|
||||||
|
dialer, err := proxy.FromURL(u, proxy.Direct)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &http.Client{
|
||||||
|
Transport: &http.Transport{
|
||||||
|
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||||
|
return dialer.(proxy.ContextDialer).DialContext(ctx, network, addr)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, errors.New("unsupported proxy type")
|
||||||
|
}
|
||||||
|
|
||||||
|
func ProxiedHttpGet(url, proxyUrl string) (*http.Response, error) {
|
||||||
|
client, err := GetProxiedHttpClient(proxyUrl)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return client.Get(url)
|
||||||
|
}
|
||||||
|
|
||||||
|
func ProxiedHttpHead(url, proxyUrl string) (*http.Response, error) {
|
||||||
|
client, err := GetProxiedHttpClient(proxyUrl)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return client.Head(url)
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
package constant
|
|
||||||
|
|
||||||
var ServerAddress = "http://localhost:3000"
|
|
||||||
var WorkerUrl = ""
|
|
||||||
var WorkerValidKey = ""
|
|
||||||
|
|
||||||
func EnableWorker() bool {
|
|
||||||
return WorkerUrl != ""
|
|
||||||
}
|
|
||||||
@@ -123,6 +123,8 @@ func GitHubOAuth(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if common.RegisterEnabled {
|
if common.RegisterEnabled {
|
||||||
|
user.InviterId, _ = model.GetUserIdByAffCode(c.Query("aff"))
|
||||||
|
|
||||||
user.Username = "github_" + strconv.Itoa(model.GetMaxUserId()+1)
|
user.Username = "github_" + strconv.Itoa(model.GetMaxUserId()+1)
|
||||||
if githubUser.Name != "" {
|
if githubUser.Name != "" {
|
||||||
user.DisplayName = githubUser.Name
|
user.DisplayName = githubUser.Name
|
||||||
@@ -133,7 +135,7 @@ func GitHubOAuth(c *gin.Context) {
|
|||||||
user.Role = common.RoleCommonUser
|
user.Role = common.RoleCommonUser
|
||||||
user.Status = common.UserStatusEnabled
|
user.Status = common.UserStatusEnabled
|
||||||
|
|
||||||
if err := user.Insert(0); err != nil {
|
if err := user.Insert(user.InviterId); err != nil {
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"success": false,
|
"success": false,
|
||||||
"message": err.Error(),
|
"message": err.Error(),
|
||||||
|
|||||||
239
controller/linuxdo.go
Normal file
239
controller/linuxdo.go
Normal file
@@ -0,0 +1,239 @@
|
|||||||
|
package controller
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/base64"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"github.com/gin-contrib/sessions"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"one-api/common"
|
||||||
|
"one-api/model"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type LinuxDoOAuthResponse struct {
|
||||||
|
AccessToken string `json:"access_token"`
|
||||||
|
Scope string `json:"scope"`
|
||||||
|
TokenType string `json:"token_type"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type LinuxDoUser struct {
|
||||||
|
ID int `json:"id"`
|
||||||
|
Username string `json:"username"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Active bool `json:"active"`
|
||||||
|
TrustLevel int `json:"trust_level"`
|
||||||
|
Silenced bool `json:"silenced"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func getLinuxDoUserInfoByCode(code string) (*LinuxDoUser, error) {
|
||||||
|
if code == "" {
|
||||||
|
return nil, errors.New("无效的参数")
|
||||||
|
}
|
||||||
|
auth := base64.StdEncoding.EncodeToString([]byte(common.LinuxDoClientId + ":" + common.LinuxDoClientSecret))
|
||||||
|
form := url.Values{
|
||||||
|
"grant_type": {"authorization_code"},
|
||||||
|
"code": {code},
|
||||||
|
}
|
||||||
|
req, err := http.NewRequest("POST", "https://connect.linux.do/oauth2/token", bytes.NewBufferString(form.Encode()))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||||
|
req.Header.Set("Authorization", "Basic "+auth)
|
||||||
|
req.Header.Set("Accept", "application/json")
|
||||||
|
client := http.Client{
|
||||||
|
Timeout: 5 * time.Second,
|
||||||
|
}
|
||||||
|
res, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
common.SysLog(err.Error())
|
||||||
|
return nil, errors.New("无法连接至 LINUX DO 服务器,请稍后重试!")
|
||||||
|
}
|
||||||
|
defer res.Body.Close()
|
||||||
|
var oAuthResponse LinuxDoOAuthResponse
|
||||||
|
err = json.NewDecoder(res.Body).Decode(&oAuthResponse)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
req, err = http.NewRequest("GET", "https://connect.linux.do/api/user", nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", oAuthResponse.AccessToken))
|
||||||
|
res2, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
common.SysLog(err.Error())
|
||||||
|
return nil, errors.New("无法连接至 LINUX DO 服务器,请稍后重试!")
|
||||||
|
}
|
||||||
|
defer res2.Body.Close()
|
||||||
|
var linuxdoUser LinuxDoUser
|
||||||
|
err = json.NewDecoder(res2.Body).Decode(&linuxdoUser)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if linuxdoUser.ID == 0 {
|
||||||
|
return nil, errors.New("返回值非法,用户字段为空,请稍后重试!")
|
||||||
|
}
|
||||||
|
if linuxdoUser.TrustLevel < common.LinuxDoMinLevel {
|
||||||
|
return nil, errors.New("用户 LINUX DO 信任等级不足!")
|
||||||
|
}
|
||||||
|
return &linuxdoUser, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func LinuxDoOAuth(c *gin.Context) {
|
||||||
|
session := sessions.Default(c)
|
||||||
|
state := c.Query("state")
|
||||||
|
if state == "" || session.Get("oauth_state") == nil || state != session.Get("oauth_state").(string) {
|
||||||
|
c.JSON(http.StatusForbidden, gin.H{
|
||||||
|
"success": false,
|
||||||
|
"message": "state is empty or not same",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
username := session.Get("username")
|
||||||
|
if username != nil {
|
||||||
|
LinuxDoBind(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if !common.LinuxDoOAuthEnabled {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"success": false,
|
||||||
|
"message": "管理员未开启通过 LINUX DO 登录以及注册",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
code := c.Query("code")
|
||||||
|
linuxdoUser, err := getLinuxDoUserInfoByCode(code)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"success": false,
|
||||||
|
"message": err.Error(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
user := model.User{
|
||||||
|
LinuxDoId: strconv.Itoa(linuxdoUser.ID),
|
||||||
|
LinuxDoLevel: linuxdoUser.TrustLevel,
|
||||||
|
}
|
||||||
|
if model.IsLinuxDoIdAlreadyTaken(user.LinuxDoId) {
|
||||||
|
err := user.FillUserByLinuxDoId()
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"success": false,
|
||||||
|
"message": err.Error(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
user.LinuxDoLevel = linuxdoUser.TrustLevel
|
||||||
|
err = user.Update(false)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"success": false,
|
||||||
|
"message": err.Error(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if common.RegisterEnabled {
|
||||||
|
affCode := c.Query("aff")
|
||||||
|
user.InviterId, _ = model.GetUserIdByAffCode(affCode)
|
||||||
|
|
||||||
|
user.Username = "linuxdo_" + strconv.Itoa(model.GetMaxUserId()+1)
|
||||||
|
if linuxdoUser.Name != "" {
|
||||||
|
user.DisplayName = linuxdoUser.Name
|
||||||
|
} else {
|
||||||
|
user.DisplayName = linuxdoUser.Username
|
||||||
|
}
|
||||||
|
user.Role = common.RoleCommonUser
|
||||||
|
user.Status = common.UserStatusEnabled
|
||||||
|
|
||||||
|
if err := user.Insert(user.InviterId); err != nil {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"success": false,
|
||||||
|
"message": err.Error(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"success": false,
|
||||||
|
"message": "管理员关闭了新用户注册",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if user.Status != common.UserStatusEnabled {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"message": "用户已被封禁",
|
||||||
|
"success": false,
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
setupLogin(&user, c)
|
||||||
|
}
|
||||||
|
|
||||||
|
func LinuxDoBind(c *gin.Context) {
|
||||||
|
if !common.LinuxDoOAuthEnabled {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"success": false,
|
||||||
|
"message": "管理员未开启通过 LINUX DO 登录以及注册",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
code := c.Query("code")
|
||||||
|
linuxdoUser, err := getLinuxDoUserInfoByCode(code)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"success": false,
|
||||||
|
"message": err.Error(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
user := model.User{
|
||||||
|
LinuxDoId: strconv.Itoa(linuxdoUser.ID),
|
||||||
|
LinuxDoLevel: linuxdoUser.TrustLevel,
|
||||||
|
}
|
||||||
|
if model.IsLinuxDoIdAlreadyTaken(user.LinuxDoId) {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"success": false,
|
||||||
|
"message": "该 LINUX DO 账户已被绑定",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
session := sessions.Default(c)
|
||||||
|
id := session.Get("id")
|
||||||
|
// id := c.GetInt("id") // critical bug!
|
||||||
|
user.Id = id.(int)
|
||||||
|
err = user.FillUserById()
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"success": false,
|
||||||
|
"message": err.Error(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
user.LinuxDoId = strconv.Itoa(linuxdoUser.ID)
|
||||||
|
user.LinuxDoLevel = linuxdoUser.TrustLevel
|
||||||
|
err = user.Update(false)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"success": false,
|
||||||
|
"message": err.Error(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"success": true,
|
||||||
|
"message": "bind",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
@@ -192,7 +192,7 @@ func DeleteHistoryLogs(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
count, err := model.DeleteOldLog(targetTimestamp)
|
count, err := model.DeleteOldLog(c.Request.Context(), targetTimestamp, 100)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"success": false,
|
"success": false,
|
||||||
|
|||||||
@@ -233,7 +233,7 @@ func GetAllMidjourney(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
if constant.MjForwardUrlEnabled {
|
if constant.MjForwardUrlEnabled {
|
||||||
for i, midjourney := range logs {
|
for i, midjourney := range logs {
|
||||||
midjourney.ImageUrl = constant.ServerAddress + "/mj/image/" + midjourney.MjId
|
midjourney.ImageUrl = common.ServerAddress + "/mj/image/" + midjourney.MjId
|
||||||
logs[i] = midjourney
|
logs[i] = midjourney
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -265,7 +265,7 @@ func GetUserMidjourney(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
if constant.MjForwardUrlEnabled {
|
if constant.MjForwardUrlEnabled {
|
||||||
for i, midjourney := range logs {
|
for i, midjourney := range logs {
|
||||||
midjourney.ImageUrl = constant.ServerAddress + "/mj/image/" + midjourney.MjId
|
midjourney.ImageUrl = common.ServerAddress + "/mj/image/" + midjourney.MjId
|
||||||
logs[i] = midjourney
|
logs[i] = midjourney
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,8 @@ func GetStatus(c *gin.Context) {
|
|||||||
"email_verification": common.EmailVerificationEnabled,
|
"email_verification": common.EmailVerificationEnabled,
|
||||||
"github_oauth": common.GitHubOAuthEnabled,
|
"github_oauth": common.GitHubOAuthEnabled,
|
||||||
"github_client_id": common.GitHubClientId,
|
"github_client_id": common.GitHubClientId,
|
||||||
|
"linuxdo_oauth": common.LinuxDoOAuthEnabled,
|
||||||
|
"linuxdo_client_id": common.LinuxDoClientId,
|
||||||
"telegram_oauth": common.TelegramOAuthEnabled,
|
"telegram_oauth": common.TelegramOAuthEnabled,
|
||||||
"telegram_bot_name": common.TelegramBotName,
|
"telegram_bot_name": common.TelegramBotName,
|
||||||
"system_name": common.SystemName,
|
"system_name": common.SystemName,
|
||||||
@@ -45,9 +47,9 @@ func GetStatus(c *gin.Context) {
|
|||||||
"footer_html": common.Footer,
|
"footer_html": common.Footer,
|
||||||
"wechat_qrcode": common.WeChatAccountQRCodeImageURL,
|
"wechat_qrcode": common.WeChatAccountQRCodeImageURL,
|
||||||
"wechat_login": common.WeChatAuthEnabled,
|
"wechat_login": common.WeChatAuthEnabled,
|
||||||
"server_address": constant.ServerAddress,
|
"server_address": common.ServerAddress,
|
||||||
"price": constant.Price,
|
"stripe_unit_price": common.StripeUnitPrice,
|
||||||
"min_topup": constant.MinTopUp,
|
"min_topup": common.MinTopUp,
|
||||||
"turnstile_check": common.TurnstileCheckEnabled,
|
"turnstile_check": common.TurnstileCheckEnabled,
|
||||||
"turnstile_site_key": common.TurnstileSiteKey,
|
"turnstile_site_key": common.TurnstileSiteKey,
|
||||||
"top_up_link": common.TopUpLink,
|
"top_up_link": common.TopUpLink,
|
||||||
@@ -61,7 +63,7 @@ func GetStatus(c *gin.Context) {
|
|||||||
"enable_data_export": common.DataExportEnabled,
|
"enable_data_export": common.DataExportEnabled,
|
||||||
"data_export_default_time": common.DataExportDefaultTime,
|
"data_export_default_time": common.DataExportDefaultTime,
|
||||||
"default_collapse_sidebar": common.DefaultCollapseSidebar,
|
"default_collapse_sidebar": common.DefaultCollapseSidebar,
|
||||||
"enable_online_topup": constant.PayAddress != "" && constant.EpayId != "" && constant.EpayKey != "",
|
"payment_enabled": common.PaymentEnabled,
|
||||||
"mj_notify_enabled": constant.MjNotifyEnabled,
|
"mj_notify_enabled": constant.MjNotifyEnabled,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -204,7 +206,7 @@ func SendPasswordResetEmail(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
code := common.GenerateVerificationCode(0)
|
code := common.GenerateVerificationCode(0)
|
||||||
common.RegisterVerificationCodeWithKey(email, code, common.PasswordResetPurpose)
|
common.RegisterVerificationCodeWithKey(email, code, common.PasswordResetPurpose)
|
||||||
link := fmt.Sprintf("%s/user/reset?email=%s&token=%s", constant.ServerAddress, email, code)
|
link := fmt.Sprintf("%s/user/reset?email=%s&token=%s", common.ServerAddress, email, code)
|
||||||
subject := fmt.Sprintf("%s密码重置", common.SystemName)
|
subject := fmt.Sprintf("%s密码重置", common.SystemName)
|
||||||
content := fmt.Sprintf("<p>您好,你正在进行%s密码重置。</p>"+
|
content := fmt.Sprintf("<p>您好,你正在进行%s密码重置。</p>"+
|
||||||
"<p>点击 <a href='%s'>此处</a> 进行密码重置。</p>"+
|
"<p>点击 <a href='%s'>此处</a> 进行密码重置。</p>"+
|
||||||
|
|||||||
@@ -50,6 +50,14 @@ func UpdateOption(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
case "LinuxDoOAuthEnabled":
|
||||||
|
if option.Value == "true" && common.LinuxDoClientId == "" {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"success": false,
|
||||||
|
"message": "无法启用 LINUX DO OAuth,请先填入 LINUX DO Client Id 以及 LINUX DO Client Secret!",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
case "EmailDomainRestrictionEnabled":
|
case "EmailDomainRestrictionEnabled":
|
||||||
if option.Value == "true" && len(common.EmailDomainWhitelist) == 0 {
|
if option.Value == "true" && len(common.EmailDomainWhitelist) == 0 {
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
|||||||
97
controller/stripe.go
Normal file
97
controller/stripe.go
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
package controller
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/stripe/stripe-go/v76"
|
||||||
|
"github.com/stripe/stripe-go/v76/webhook"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"one-api/common"
|
||||||
|
"one-api/model"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func StripeWebhook(c *gin.Context) {
|
||||||
|
payload, err := io.ReadAll(c.Request.Body)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("解析Stripe Webhook参数失败: %v\n", err)
|
||||||
|
c.AbortWithStatus(http.StatusServiceUnavailable)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
signature := c.GetHeader("Stripe-Signature")
|
||||||
|
endpointSecret := common.StripeWebhookSecret
|
||||||
|
event, err := webhook.ConstructEvent(payload, signature, endpointSecret)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Stripe Webhook验签失败: %v\n", err)
|
||||||
|
c.AbortWithStatus(http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
switch event.Type {
|
||||||
|
case stripe.EventTypeCheckoutSessionCompleted:
|
||||||
|
sessionCompleted(event)
|
||||||
|
case stripe.EventTypeCheckoutSessionExpired:
|
||||||
|
sessionExpired(event)
|
||||||
|
default:
|
||||||
|
log.Printf("不支持的Stripe Webhook事件类型: %s\n", event.Type)
|
||||||
|
}
|
||||||
|
|
||||||
|
c.Status(http.StatusOK)
|
||||||
|
}
|
||||||
|
|
||||||
|
func sessionCompleted(event stripe.Event) {
|
||||||
|
customerId := event.GetObjectValue("customer")
|
||||||
|
referenceId := event.GetObjectValue("client_reference_id")
|
||||||
|
status := event.GetObjectValue("status")
|
||||||
|
if "complete" != status {
|
||||||
|
log.Println("错误的Stripe Checkout完成状态:", status, ",", referenceId)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err := model.Recharge(referenceId, customerId)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err.Error(), referenceId)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
total, _ := strconv.ParseFloat(event.GetObjectValue("amount_total"), 64)
|
||||||
|
currency := strings.ToUpper(event.GetObjectValue("currency"))
|
||||||
|
log.Printf("收到款项:%s, %.2f(%s)", referenceId, total/100, currency)
|
||||||
|
}
|
||||||
|
|
||||||
|
func sessionExpired(event stripe.Event) {
|
||||||
|
referenceId := event.GetObjectValue("client_reference_id")
|
||||||
|
status := event.GetObjectValue("status")
|
||||||
|
if "expired" != status {
|
||||||
|
log.Println("错误的Stripe Checkout过期状态:", status, ",", referenceId)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if "" == referenceId {
|
||||||
|
log.Println("未提供支付单号")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
topUp := model.GetTopUpByTradeNo(referenceId)
|
||||||
|
if topUp == nil {
|
||||||
|
log.Println("充值订单不存在", referenceId)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if topUp.Status != common.TopUpStatusPending {
|
||||||
|
log.Println("充值订单状态错误", referenceId)
|
||||||
|
}
|
||||||
|
|
||||||
|
topUp.Status = common.TopUpStatusExpired
|
||||||
|
err := topUp.Update()
|
||||||
|
if err != nil {
|
||||||
|
log.Println("过期充值订单失败", referenceId, ", err:", err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Println("充值订单已过期", referenceId)
|
||||||
|
}
|
||||||
@@ -1,22 +1,20 @@
|
|||||||
package controller
|
package controller
|
||||||
|
|
||||||
|
import "C"
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/Calcium-Ion/go-epay/epay"
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/samber/lo"
|
"github.com/stripe/stripe-go/v76"
|
||||||
|
"github.com/stripe/stripe-go/v76/checkout/session"
|
||||||
"log"
|
"log"
|
||||||
"net/url"
|
|
||||||
"one-api/common"
|
"one-api/common"
|
||||||
"one-api/constant"
|
|
||||||
"one-api/model"
|
"one-api/model"
|
||||||
"one-api/service"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type EpayRequest struct {
|
type PayRequest struct {
|
||||||
Amount int `json:"amount"`
|
Amount int `json:"amount"`
|
||||||
PaymentMethod string `json:"payment_method"`
|
PaymentMethod string `json:"payment_method"`
|
||||||
TopUpCode string `json:"top_up_code"`
|
TopUpCode string `json:"top_up_code"`
|
||||||
@@ -27,201 +25,114 @@ type AmountRequest struct {
|
|||||||
TopUpCode string `json:"top_up_code"`
|
TopUpCode string `json:"top_up_code"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetEpayClient() *epay.Client {
|
func genStripeLink(referenceId string, customerId string, email string, amount int64) (string, error) {
|
||||||
if constant.PayAddress == "" || constant.EpayId == "" || constant.EpayKey == "" {
|
if !strings.HasPrefix(common.StripeApiSecret, "sk_") {
|
||||||
return nil
|
return "", fmt.Errorf("无效的Stripe API密钥")
|
||||||
}
|
}
|
||||||
withUrl, err := epay.NewClient(&epay.Config{
|
|
||||||
PartnerID: constant.EpayId,
|
stripe.Key = common.StripeApiSecret
|
||||||
Key: constant.EpayKey,
|
|
||||||
}, constant.PayAddress)
|
params := &stripe.CheckoutSessionParams{
|
||||||
|
ClientReferenceID: stripe.String(referenceId),
|
||||||
|
SuccessURL: stripe.String(common.ServerAddress + "/log"),
|
||||||
|
CancelURL: stripe.String(common.ServerAddress + "/topup"),
|
||||||
|
LineItems: []*stripe.CheckoutSessionLineItemParams{
|
||||||
|
{
|
||||||
|
Price: stripe.String(common.StripePriceId),
|
||||||
|
Quantity: stripe.Int64(amount),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Mode: stripe.String(string(stripe.CheckoutSessionModePayment)),
|
||||||
|
}
|
||||||
|
|
||||||
|
if "" == customerId {
|
||||||
|
if "" != email {
|
||||||
|
params.CustomerEmail = stripe.String(email)
|
||||||
|
}
|
||||||
|
|
||||||
|
params.CustomerCreation = stripe.String(string(stripe.CheckoutSessionCustomerCreationAlways))
|
||||||
|
} else {
|
||||||
|
params.Customer = stripe.String(customerId)
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := session.New(params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return "", err
|
||||||
}
|
}
|
||||||
return withUrl
|
|
||||||
|
return result.URL, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPayMoney(amount float64, group string) float64 {
|
func GetPayAmount(count float64) float64 {
|
||||||
if !common.DisplayInCurrencyEnabled {
|
return count * common.StripeUnitPrice
|
||||||
amount = amount / common.QuotaPerUnit
|
|
||||||
}
|
|
||||||
// 别问为什么用float64,问就是这么点钱没必要
|
|
||||||
topupGroupRatio := common.GetTopupGroupRatio(group)
|
|
||||||
if topupGroupRatio == 0 {
|
|
||||||
topupGroupRatio = 1
|
|
||||||
}
|
|
||||||
payMoney := amount * constant.Price * topupGroupRatio
|
|
||||||
return payMoney
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMinTopup() int {
|
func GetChargedAmount(count float64, user model.User) float64 {
|
||||||
minTopup := constant.MinTopUp
|
topUpGroupRatio := common.GetTopupGroupRatio(user.Group)
|
||||||
if !common.DisplayInCurrencyEnabled {
|
if topUpGroupRatio == 0 {
|
||||||
minTopup = minTopup * int(common.QuotaPerUnit)
|
topUpGroupRatio = 1
|
||||||
}
|
}
|
||||||
return minTopup
|
|
||||||
|
return count * topUpGroupRatio
|
||||||
}
|
}
|
||||||
|
|
||||||
func RequestEpay(c *gin.Context) {
|
func RequestPayLink(c *gin.Context) {
|
||||||
var req EpayRequest
|
var req PayRequest
|
||||||
err := c.ShouldBindJSON(&req)
|
err := c.ShouldBindJSON(&req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(200, gin.H{"message": "error", "data": "参数错误"})
|
c.JSON(200, gin.H{"message": err.Error(), "data": 10})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if req.Amount < getMinTopup() {
|
if !common.PaymentEnabled {
|
||||||
c.JSON(200, gin.H{"message": "error", "data": fmt.Sprintf("充值数量不能小于 %d", getMinTopup())})
|
c.JSON(200, gin.H{"message": "error", "data": "管理员未开启在线支付"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if req.PaymentMethod != "stripe" {
|
||||||
|
c.JSON(200, gin.H{"message": "error", "data": "不支持的支付渠道"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if req.Amount < common.MinTopUp {
|
||||||
|
c.JSON(200, gin.H{"message": fmt.Sprintf("充值数量不能小于 %d", common.MinTopUp), "data": 10})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if req.Amount > 10000 {
|
||||||
|
c.JSON(200, gin.H{"message": "充值数量不能大于 10000", "data": 10})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
id := c.GetInt("id")
|
id := c.GetInt("id")
|
||||||
group, err := model.CacheGetUserGroup(id)
|
user, _ := model.GetUserById(id, false)
|
||||||
if err != nil {
|
chargedMoney := GetChargedAmount(float64(req.Amount), *user)
|
||||||
c.JSON(200, gin.H{"message": "error", "data": "获取用户分组失败"})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
payMoney := getPayMoney(float64(req.Amount), group)
|
|
||||||
if payMoney < 0.01 {
|
|
||||||
c.JSON(200, gin.H{"message": "error", "data": "充值金额过低"})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var payType epay.PurchaseType
|
reference := fmt.Sprintf("new-api-ref-%d-%d-%s", user.Id, time.Now().UnixMilli(), common.RandomString(4))
|
||||||
if req.PaymentMethod == "zfb" {
|
referenceId := "ref_" + common.Sha1(reference)
|
||||||
payType = epay.Alipay
|
|
||||||
}
|
payLink, err := genStripeLink(referenceId, user.StripeCustomer, user.Email, int64(req.Amount))
|
||||||
if req.PaymentMethod == "wx" {
|
|
||||||
req.PaymentMethod = "wxpay"
|
|
||||||
payType = epay.WechatPay
|
|
||||||
}
|
|
||||||
callBackAddress := service.GetCallbackAddress()
|
|
||||||
returnUrl, _ := url.Parse(constant.ServerAddress + "/log")
|
|
||||||
notifyUrl, _ := url.Parse(callBackAddress + "/api/user/epay/notify")
|
|
||||||
tradeNo := fmt.Sprintf("%s%d", common.GetRandomString(6), time.Now().Unix())
|
|
||||||
tradeNo = fmt.Sprintf("USR%dNO%s", id, tradeNo)
|
|
||||||
client := GetEpayClient()
|
|
||||||
if client == nil {
|
|
||||||
c.JSON(200, gin.H{"message": "error", "data": "当前管理员未配置支付信息"})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
uri, params, err := client.Purchase(&epay.PurchaseArgs{
|
|
||||||
Type: payType,
|
|
||||||
ServiceTradeNo: tradeNo,
|
|
||||||
Name: fmt.Sprintf("TUC%d", req.Amount),
|
|
||||||
Money: strconv.FormatFloat(payMoney, 'f', 2, 64),
|
|
||||||
Device: epay.PC,
|
|
||||||
NotifyUrl: notifyUrl,
|
|
||||||
ReturnUrl: returnUrl,
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Println("获取Stripe Checkout支付链接失败", err)
|
||||||
c.JSON(200, gin.H{"message": "error", "data": "拉起支付失败"})
|
c.JSON(200, gin.H{"message": "error", "data": "拉起支付失败"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
amount := req.Amount
|
|
||||||
if !common.DisplayInCurrencyEnabled {
|
|
||||||
amount = amount / int(common.QuotaPerUnit)
|
|
||||||
}
|
|
||||||
topUp := &model.TopUp{
|
topUp := &model.TopUp{
|
||||||
UserId: id,
|
UserId: id,
|
||||||
Amount: amount,
|
Amount: req.Amount,
|
||||||
Money: payMoney,
|
Money: chargedMoney,
|
||||||
TradeNo: tradeNo,
|
TradeNo: referenceId,
|
||||||
CreateTime: time.Now().Unix(),
|
CreateTime: time.Now().Unix(),
|
||||||
Status: "pending",
|
Status: common.TopUpStatusPending,
|
||||||
}
|
}
|
||||||
err = topUp.Insert()
|
err = topUp.Insert()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(200, gin.H{"message": "error", "data": "创建订单失败"})
|
c.JSON(200, gin.H{"message": "error", "data": "创建订单失败"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.JSON(200, gin.H{"message": "success", "data": params, "url": uri})
|
c.JSON(200, gin.H{
|
||||||
}
|
"message": "success",
|
||||||
|
"data": gin.H{
|
||||||
// tradeNo lock
|
"payLink": payLink,
|
||||||
var orderLocks sync.Map
|
},
|
||||||
var createLock sync.Mutex
|
})
|
||||||
|
|
||||||
// LockOrder 尝试对给定订单号加锁
|
|
||||||
func LockOrder(tradeNo string) {
|
|
||||||
lock, ok := orderLocks.Load(tradeNo)
|
|
||||||
if !ok {
|
|
||||||
createLock.Lock()
|
|
||||||
defer createLock.Unlock()
|
|
||||||
lock, ok = orderLocks.Load(tradeNo)
|
|
||||||
if !ok {
|
|
||||||
lock = new(sync.Mutex)
|
|
||||||
orderLocks.Store(tradeNo, lock)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
lock.(*sync.Mutex).Lock()
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnlockOrder 释放给定订单号的锁
|
|
||||||
func UnlockOrder(tradeNo string) {
|
|
||||||
lock, ok := orderLocks.Load(tradeNo)
|
|
||||||
if ok {
|
|
||||||
lock.(*sync.Mutex).Unlock()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func EpayNotify(c *gin.Context) {
|
|
||||||
params := lo.Reduce(lo.Keys(c.Request.URL.Query()), func(r map[string]string, t string, i int) map[string]string {
|
|
||||||
r[t] = c.Request.URL.Query().Get(t)
|
|
||||||
return r
|
|
||||||
}, map[string]string{})
|
|
||||||
client := GetEpayClient()
|
|
||||||
if client == nil {
|
|
||||||
log.Println("易支付回调失败 未找到配置信息")
|
|
||||||
_, err := c.Writer.Write([]byte("fail"))
|
|
||||||
if err != nil {
|
|
||||||
log.Println("易支付回调写入失败")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
verifyInfo, err := client.Verify(params)
|
|
||||||
if err == nil && verifyInfo.VerifyStatus {
|
|
||||||
_, err := c.Writer.Write([]byte("success"))
|
|
||||||
if err != nil {
|
|
||||||
log.Println("易支付回调写入失败")
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
_, err := c.Writer.Write([]byte("fail"))
|
|
||||||
if err != nil {
|
|
||||||
log.Println("易支付回调写入失败")
|
|
||||||
}
|
|
||||||
log.Println("易支付回调签名验证失败")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if verifyInfo.TradeStatus == epay.StatusTradeSuccess {
|
|
||||||
log.Println(verifyInfo)
|
|
||||||
LockOrder(verifyInfo.ServiceTradeNo)
|
|
||||||
defer UnlockOrder(verifyInfo.ServiceTradeNo)
|
|
||||||
topUp := model.GetTopUpByTradeNo(verifyInfo.ServiceTradeNo)
|
|
||||||
if topUp == nil {
|
|
||||||
log.Printf("易支付回调未找到订单: %v", verifyInfo)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if topUp.Status == "pending" {
|
|
||||||
topUp.Status = "success"
|
|
||||||
err := topUp.Update()
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("易支付回调更新订单失败: %v", topUp)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
//user, _ := model.GetUserById(topUp.UserId, false)
|
|
||||||
//user.Quota += topUp.Amount * 500000
|
|
||||||
err = model.IncreaseUserQuota(topUp.UserId, topUp.Amount*int(common.QuotaPerUnit))
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("易支付回调更新用户失败: %v", topUp)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
log.Printf("易支付回调更新用户成功 %v", topUp)
|
|
||||||
model.RecordLog(topUp.UserId, model.LogTypeTopup, fmt.Sprintf("使用在线充值成功,充值金额: %v,支付金额:%f", common.LogQuota(topUp.Amount*int(common.QuotaPerUnit)), topUp.Money))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
log.Printf("易支付异常回调: %v", verifyInfo)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func RequestAmount(c *gin.Context) {
|
func RequestAmount(c *gin.Context) {
|
||||||
@@ -231,21 +142,23 @@ func RequestAmount(c *gin.Context) {
|
|||||||
c.JSON(200, gin.H{"message": "error", "data": "参数错误"})
|
c.JSON(200, gin.H{"message": "error", "data": "参数错误"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if !common.PaymentEnabled {
|
||||||
if req.Amount < getMinTopup() {
|
c.JSON(200, gin.H{"message": "error", "data": "管理员未开启在线支付"})
|
||||||
c.JSON(200, gin.H{"message": "error", "data": fmt.Sprintf("充值数量不能小于 %d", getMinTopup())})
|
return
|
||||||
|
}
|
||||||
|
if req.Amount < common.MinTopUp {
|
||||||
|
c.JSON(200, gin.H{"message": "error", "data": fmt.Sprintf("充值数量不能小于 %d", common.MinTopUp)})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
id := c.GetInt("id")
|
id := c.GetInt("id")
|
||||||
group, err := model.CacheGetUserGroup(id)
|
user, _ := model.GetUserById(id, false)
|
||||||
if err != nil {
|
payMoney := GetPayAmount(float64(req.Amount))
|
||||||
c.JSON(200, gin.H{"message": "error", "data": "获取用户分组失败"})
|
chargedMoney := GetChargedAmount(float64(req.Amount), *user)
|
||||||
return
|
c.JSON(200, gin.H{
|
||||||
}
|
"message": "success",
|
||||||
payMoney := getPayMoney(float64(req.Amount), group)
|
"data": gin.H{
|
||||||
if payMoney <= 0.01 {
|
"payAmount": strconv.FormatFloat(payMoney, 'f', 2, 64),
|
||||||
c.JSON(200, gin.H{"message": "error", "data": "充值金额过低"})
|
"chargedAmount": strconv.FormatFloat(chargedMoney, 'f', 2, 64),
|
||||||
return
|
},
|
||||||
}
|
})
|
||||||
c.JSON(200, gin.H{"message": "success", "data": strconv.FormatFloat(payMoney, 'f', 2, 64)})
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ func setupLogin(user *model.User, c *gin.Context) {
|
|||||||
session.Set("username", user.Username)
|
session.Set("username", user.Username)
|
||||||
session.Set("role", user.Role)
|
session.Set("role", user.Role)
|
||||||
session.Set("status", user.Status)
|
session.Set("status", user.Status)
|
||||||
|
session.Set("linuxdo_enable", user.LinuxDoId == "" || user.LinuxDoLevel >= common.LinuxDoMinLevel)
|
||||||
err := session.Save()
|
err := session.Save()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
@@ -517,7 +518,7 @@ func UpdateSelf(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeleteUser(c *gin.Context) {
|
func HardDeleteUser(c *gin.Context) {
|
||||||
id, err := strconv.Atoi(c.Param("id"))
|
id, err := strconv.Atoi(c.Param("id"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
@@ -526,7 +527,7 @@ func DeleteUser(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
originUser, err := model.GetUserById(id, false)
|
originUser, err := model.GetUserByIdUnscoped(id, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"success": false,
|
"success": false,
|
||||||
@@ -550,9 +551,23 @@ func DeleteUser(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"success": true,
|
||||||
|
"message": "",
|
||||||
|
})
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeleteSelf(c *gin.Context) {
|
func DeleteSelf(c *gin.Context) {
|
||||||
|
if !common.UserSelfDeletionEnabled {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"success": false,
|
||||||
|
"message": "当前设置不允许用户自我删除账号",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
id := c.GetInt("id")
|
id := c.GetInt("id")
|
||||||
user, _ := model.GetUserById(id, false)
|
user, _ := model.GetUserById(id, false)
|
||||||
|
|
||||||
|
|||||||
@@ -2,18 +2,17 @@ version: '3.4'
|
|||||||
|
|
||||||
services:
|
services:
|
||||||
new-api:
|
new-api:
|
||||||
image: calciumion/new-api:latest
|
image: pengzhile/new-api:latest
|
||||||
# build: .
|
|
||||||
container_name: new-api
|
container_name: new-api
|
||||||
restart: always
|
restart: always
|
||||||
command: --log-dir /app/logs
|
command: --log-dir /app/logs
|
||||||
ports:
|
ports:
|
||||||
- "3000:3000"
|
- "3000:3000"
|
||||||
volumes:
|
volumes:
|
||||||
- ./data:/data
|
- ./data/new-api:/data
|
||||||
- ./logs:/app/logs
|
- ./logs:/app/logs
|
||||||
environment:
|
environment:
|
||||||
- SQL_DSN=root:123456@tcp(host.docker.internal:3306)/new-api # 修改此行,或注释掉以使用 SQLite 作为数据库
|
- SQL_DSN=newapi:123456@tcp(db:3306)/new-api # 修改此行,或注释掉以使用 SQLite 作为数据库
|
||||||
- REDIS_CONN_STRING=redis://redis
|
- REDIS_CONN_STRING=redis://redis
|
||||||
- SESSION_SECRET=random_string # 修改为随机字符串
|
- SESSION_SECRET=random_string # 修改为随机字符串
|
||||||
- TZ=Asia/Shanghai
|
- TZ=Asia/Shanghai
|
||||||
@@ -23,13 +22,22 @@ services:
|
|||||||
|
|
||||||
depends_on:
|
depends_on:
|
||||||
- redis
|
- redis
|
||||||
healthcheck:
|
- db
|
||||||
test: [ "CMD-SHELL", "wget -q -O - http://localhost:3000/api/status | grep -o '\"success\":\\s*true' | awk -F: '{print $2}'" ]
|
|
||||||
interval: 30s
|
|
||||||
timeout: 10s
|
|
||||||
retries: 3
|
|
||||||
|
|
||||||
redis:
|
redis:
|
||||||
image: redis:latest
|
image: redis:latest
|
||||||
container_name: redis
|
container_name: redis
|
||||||
restart: always
|
restart: always
|
||||||
|
|
||||||
|
db:
|
||||||
|
image: mysql:8.2.0
|
||||||
|
container_name: mysql
|
||||||
|
restart: always
|
||||||
|
volumes:
|
||||||
|
- ./data/mysql:/var/lib/mysql # 挂载目录,持久化存储
|
||||||
|
environment:
|
||||||
|
TZ: Asia/Shanghai # 设置时区
|
||||||
|
MYSQL_ROOT_PASSWORD: 'OneAPI@justsong' # 设置 root 用户的密码
|
||||||
|
MYSQL_USER: newapi # 创建专用用户
|
||||||
|
MYSQL_PASSWORD: '123456' # 设置专用用户密码
|
||||||
|
MYSQL_DATABASE: new-api # 自动创建数据库
|
||||||
@@ -2,36 +2,38 @@ package dto
|
|||||||
|
|
||||||
import "encoding/json"
|
import "encoding/json"
|
||||||
|
|
||||||
type ResponseFormat struct {
|
|
||||||
Type string `json:"type,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type GeneralOpenAIRequest struct {
|
type GeneralOpenAIRequest struct {
|
||||||
Model string `json:"model,omitempty"`
|
Model string `json:"model,omitempty"`
|
||||||
Messages []Message `json:"messages,omitempty"`
|
Messages []Message `json:"messages,omitempty"`
|
||||||
Prompt any `json:"prompt,omitempty"`
|
Prompt any `json:"prompt,omitempty"`
|
||||||
Stream bool `json:"stream,omitempty"`
|
BestOf int `json:"best_of,omitempty"`
|
||||||
StreamOptions *StreamOptions `json:"stream_options,omitempty"`
|
Echo bool `json:"echo,omitempty"`
|
||||||
MaxTokens uint `json:"max_tokens,omitempty"`
|
Stream bool `json:"stream,omitempty"`
|
||||||
Temperature float64 `json:"temperature,omitempty"`
|
StreamOptions *StreamOptions `json:"stream_options,omitempty"`
|
||||||
TopP float64 `json:"top_p,omitempty"`
|
Suffix string `json:"suffix,omitempty"`
|
||||||
TopK int `json:"top_k,omitempty"`
|
MaxTokens uint `json:"max_tokens,omitempty"`
|
||||||
Stop any `json:"stop,omitempty"`
|
Temperature float64 `json:"temperature,omitempty"`
|
||||||
N int `json:"n,omitempty"`
|
TopP float64 `json:"top_p,omitempty"`
|
||||||
Input any `json:"input,omitempty"`
|
TopK int `json:"top_k,omitempty"`
|
||||||
Instruction string `json:"instruction,omitempty"`
|
Stop any `json:"stop,omitempty"`
|
||||||
Size string `json:"size,omitempty"`
|
N int `json:"n,omitempty"`
|
||||||
Functions any `json:"functions,omitempty"`
|
Input any `json:"input,omitempty"`
|
||||||
FrequencyPenalty float64 `json:"frequency_penalty,omitempty"`
|
Instruction string `json:"instruction,omitempty"`
|
||||||
PresencePenalty float64 `json:"presence_penalty,omitempty"`
|
Size string `json:"size,omitempty"`
|
||||||
ResponseFormat any `json:"response_format,omitempty"`
|
Functions any `json:"functions,omitempty"`
|
||||||
Seed float64 `json:"seed,omitempty"`
|
FrequencyPenalty float64 `json:"frequency_penalty,omitempty"`
|
||||||
Tools []ToolCall `json:"tools,omitempty"`
|
PresencePenalty float64 `json:"presence_penalty,omitempty"`
|
||||||
ToolChoice any `json:"tool_choice,omitempty"`
|
ResponseFormat any `json:"response_format,omitempty"`
|
||||||
User string `json:"user,omitempty"`
|
Seed float64 `json:"seed,omitempty"`
|
||||||
LogProbs bool `json:"logprobs,omitempty"`
|
Tools []ToolCall `json:"tools,omitempty"`
|
||||||
TopLogProbs int `json:"top_logprobs,omitempty"`
|
ToolChoice any `json:"tool_choice,omitempty"`
|
||||||
Dimensions int `json:"dimensions,omitempty"`
|
User string `json:"user,omitempty"`
|
||||||
|
LogitBias any `json:"logit_bias,omitempty"`
|
||||||
|
LogProbs any `json:"logprobs,omitempty"`
|
||||||
|
TopLogProbs int `json:"top_logprobs,omitempty"`
|
||||||
|
Dimensions int `json:"dimensions,omitempty"`
|
||||||
|
ParallelToolCalls bool `json:"parallel_Tool_Calls,omitempty"`
|
||||||
|
EncodingFormat string `json:"encoding_format,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type OpenAITools struct {
|
type OpenAITools struct {
|
||||||
|
|||||||
@@ -41,9 +41,9 @@ type OpenAITextResponse struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type OpenAIEmbeddingResponseItem struct {
|
type OpenAIEmbeddingResponseItem struct {
|
||||||
Object string `json:"object"`
|
Object string `json:"object"`
|
||||||
Index int `json:"index"`
|
Index int `json:"index"`
|
||||||
Embedding []float64 `json:"embedding"`
|
Embedding any `json:"embedding"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type OpenAIEmbeddingResponse struct {
|
type OpenAIEmbeddingResponse struct {
|
||||||
|
|||||||
5
go.mod
5
go.mod
@@ -6,7 +6,6 @@ go 1.21
|
|||||||
toolchain go1.22.4
|
toolchain go1.22.4
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/Calcium-Ion/go-epay v0.0.2
|
|
||||||
github.com/anknown/ahocorasick v0.0.0-20190904063843-d75dbd5169c0
|
github.com/anknown/ahocorasick v0.0.0-20190904063843-d75dbd5169c0
|
||||||
github.com/aws/aws-sdk-go-v2 v1.26.1
|
github.com/aws/aws-sdk-go-v2 v1.26.1
|
||||||
github.com/aws/aws-sdk-go-v2/credentials v1.17.11
|
github.com/aws/aws-sdk-go-v2/credentials v1.17.11
|
||||||
@@ -27,8 +26,10 @@ require (
|
|||||||
github.com/pkoukk/tiktoken-go v0.1.7
|
github.com/pkoukk/tiktoken-go v0.1.7
|
||||||
github.com/samber/lo v1.39.0
|
github.com/samber/lo v1.39.0
|
||||||
github.com/shirou/gopsutil v3.21.11+incompatible
|
github.com/shirou/gopsutil v3.21.11+incompatible
|
||||||
|
github.com/stripe/stripe-go/v76 v76.21.0
|
||||||
golang.org/x/crypto v0.26.0
|
golang.org/x/crypto v0.26.0
|
||||||
golang.org/x/image v0.15.0
|
golang.org/x/image v0.15.0
|
||||||
|
golang.org/x/net v0.28.0
|
||||||
gorm.io/driver/mysql v1.4.3
|
gorm.io/driver/mysql v1.4.3
|
||||||
gorm.io/driver/postgres v1.5.2
|
gorm.io/driver/postgres v1.5.2
|
||||||
gorm.io/driver/sqlite v1.4.3
|
gorm.io/driver/sqlite v1.4.3
|
||||||
@@ -68,7 +69,6 @@ require (
|
|||||||
github.com/leodido/go-urn v1.4.0 // indirect
|
github.com/leodido/go-urn v1.4.0 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||||
github.com/mattn/go-sqlite3 v2.0.3+incompatible // indirect
|
github.com/mattn/go-sqlite3 v2.0.3+incompatible // indirect
|
||||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
|
||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||||
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
|
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
|
||||||
@@ -80,7 +80,6 @@ require (
|
|||||||
github.com/yusufpapurcu/wmi v1.2.3 // indirect
|
github.com/yusufpapurcu/wmi v1.2.3 // indirect
|
||||||
golang.org/x/arch v0.3.0 // indirect
|
golang.org/x/arch v0.3.0 // indirect
|
||||||
golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0 // indirect
|
golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0 // indirect
|
||||||
golang.org/x/net v0.28.0 // indirect
|
|
||||||
golang.org/x/sync v0.8.0 // indirect
|
golang.org/x/sync v0.8.0 // indirect
|
||||||
golang.org/x/sys v0.24.0 // indirect
|
golang.org/x/sys v0.24.0 // indirect
|
||||||
golang.org/x/text v0.17.0 // indirect
|
golang.org/x/text v0.17.0 // indirect
|
||||||
|
|||||||
8
go.sum
8
go.sum
@@ -1,5 +1,3 @@
|
|||||||
github.com/Calcium-Ion/go-epay v0.0.2 h1:3knFBuaBFpHzsGeGQU/QxUqZSHh5s0+jGo0P62pJzWc=
|
|
||||||
github.com/Calcium-Ion/go-epay v0.0.2/go.mod h1:cxo/ZOg8ClvE3VAnCmEzbuyAZINSq7kFEN9oHj5WQ2U=
|
|
||||||
github.com/anknown/ahocorasick v0.0.0-20190904063843-d75dbd5169c0 h1:onfun1RA+KcxaMk1lfrRnwCd1UUuOjJM/lri5eM1qMs=
|
github.com/anknown/ahocorasick v0.0.0-20190904063843-d75dbd5169c0 h1:onfun1RA+KcxaMk1lfrRnwCd1UUuOjJM/lri5eM1qMs=
|
||||||
github.com/anknown/ahocorasick v0.0.0-20190904063843-d75dbd5169c0/go.mod h1:4yg+jNTYlDEzBjhGS96v+zjyA3lfXlFd5CiTLIkPBLI=
|
github.com/anknown/ahocorasick v0.0.0-20190904063843-d75dbd5169c0/go.mod h1:4yg+jNTYlDEzBjhGS96v+zjyA3lfXlFd5CiTLIkPBLI=
|
||||||
github.com/anknown/darts v0.0.0-20151216065714-83ff685239e6 h1:HblK3eJHq54yET63qPCTJnks3loDse5xRmmqHgHzwoI=
|
github.com/anknown/darts v0.0.0-20151216065714-83ff685239e6 h1:HblK3eJHq54yET63qPCTJnks3loDse5xRmmqHgHzwoI=
|
||||||
@@ -136,8 +134,6 @@ github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D
|
|||||||
github.com/mattn/go-sqlite3 v1.14.15/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
|
github.com/mattn/go-sqlite3 v1.14.15/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
|
||||||
github.com/mattn/go-sqlite3 v2.0.3+incompatible h1:gXHsfypPkaMZrKbD5209QV9jbUTJKjyR5WD3HYQSd+U=
|
github.com/mattn/go-sqlite3 v2.0.3+incompatible h1:gXHsfypPkaMZrKbD5209QV9jbUTJKjyR5WD3HYQSd+U=
|
||||||
github.com/mattn/go-sqlite3 v2.0.3+incompatible/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
|
github.com/mattn/go-sqlite3 v2.0.3+incompatible/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
|
||||||
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
|
||||||
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
|
||||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
|
||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||||
@@ -180,6 +176,8 @@ github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o
|
|||||||
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
|
github.com/stripe/stripe-go/v76 v76.21.0 h1:O3GHImHS4oUI3qWMOClHN3zAQF5/oswS/NB7leV1fsU=
|
||||||
|
github.com/stripe/stripe-go/v76 v76.21.0/go.mod h1:rw1MxjlAKKcZ+3FOXgTHgwiOa2ya6CPq6ykpJ0Q6Po4=
|
||||||
github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU=
|
github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU=
|
||||||
github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI=
|
github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI=
|
||||||
github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk=
|
github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk=
|
||||||
@@ -205,6 +203,7 @@ golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0/go.mod h1:/lliqkxwWAhPjf5oSO
|
|||||||
golang.org/x/image v0.15.0 h1:kOELfmgrmJlw4Cdb7g/QGuB3CvDrXbqEIww/pNtNBm8=
|
golang.org/x/image v0.15.0 h1:kOELfmgrmJlw4Cdb7g/QGuB3CvDrXbqEIww/pNtNBm8=
|
||||||
golang.org/x/image v0.15.0/go.mod h1:HUYqC05R2ZcZ3ejNQsIHQDQiwWM4JBqmm6MKANTp4LE=
|
golang.org/x/image v0.15.0/go.mod h1:HUYqC05R2ZcZ3ejNQsIHQDQiwWM4JBqmm6MKANTp4LE=
|
||||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||||
|
golang.org/x/net v0.0.0-20210520170846-37e1c6afe023/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||||
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
|
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
|
||||||
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
|
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
|
||||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
@@ -213,6 +212,7 @@ golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
|||||||
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ func authHelper(c *gin.Context, minRole int) {
|
|||||||
role := session.Get("role")
|
role := session.Get("role")
|
||||||
id := session.Get("id")
|
id := session.Get("id")
|
||||||
status := session.Get("status")
|
status := session.Get("status")
|
||||||
|
linuxDoEnable := session.Get("linuxdo_enable")
|
||||||
useAccessToken := false
|
useAccessToken := false
|
||||||
if username == nil {
|
if username == nil {
|
||||||
// Check access token
|
// Check access token
|
||||||
@@ -35,6 +36,7 @@ func authHelper(c *gin.Context, minRole int) {
|
|||||||
role = user.Role
|
role = user.Role
|
||||||
id = user.Id
|
id = user.Id
|
||||||
status = user.Status
|
status = user.Status
|
||||||
|
linuxDoEnable = user.LinuxDoId == "" || user.LinuxDoLevel >= common.LinuxDoMinLevel
|
||||||
useAccessToken = true
|
useAccessToken = true
|
||||||
} else {
|
} else {
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
@@ -83,6 +85,14 @@ func authHelper(c *gin.Context, minRole int) {
|
|||||||
c.Abort()
|
c.Abort()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if nil != linuxDoEnable && !linuxDoEnable.(bool) {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"success": false,
|
||||||
|
"message": "用户 LINUX DO 信任等级不足",
|
||||||
|
})
|
||||||
|
c.Abort()
|
||||||
|
return
|
||||||
|
}
|
||||||
if role.(int) < minRole {
|
if role.(int) < minRole {
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"success": false,
|
"success": false,
|
||||||
@@ -162,6 +172,15 @@ func TokenAuth() func(c *gin.Context) {
|
|||||||
abortWithOpenAiMessage(c, http.StatusForbidden, "用户已被封禁")
|
abortWithOpenAiMessage(c, http.StatusForbidden, "用户已被封禁")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
linuxDoEnabled, err := model.CacheIsLinuxDoEnabled(token.UserId)
|
||||||
|
if err != nil {
|
||||||
|
abortWithOpenAiMessage(c, http.StatusInternalServerError, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !linuxDoEnabled {
|
||||||
|
abortWithOpenAiMessage(c, http.StatusForbidden, "用户 LINUX DO 信任等级不足")
|
||||||
|
return
|
||||||
|
}
|
||||||
c.Set("id", token.UserId)
|
c.Set("id", token.UserId)
|
||||||
c.Set("token_id", token.Id)
|
c.Set("token_id", token.Id)
|
||||||
c.Set("token_name", token.Name)
|
c.Set("token_name", token.Name)
|
||||||
|
|||||||
@@ -205,6 +205,30 @@ func CacheIsUserEnabled(userId int) (bool, error) {
|
|||||||
return userEnabled, err
|
return userEnabled, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CacheIsLinuxDoEnabled(userId int) (bool, error) {
|
||||||
|
if !common.RedisEnabled {
|
||||||
|
return IsLinuxDoEnabled(userId)
|
||||||
|
}
|
||||||
|
enabled, err := common.RedisGet(fmt.Sprintf("linuxdo_enabled:%d", userId))
|
||||||
|
if err == nil {
|
||||||
|
return enabled == "1", nil
|
||||||
|
}
|
||||||
|
|
||||||
|
linuxDoEnabled, err := IsLinuxDoEnabled(userId)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
enabled = "0"
|
||||||
|
if linuxDoEnabled {
|
||||||
|
enabled = "1"
|
||||||
|
}
|
||||||
|
err = common.RedisSet(fmt.Sprintf("linuxdo_enabled:%d", userId), enabled, time.Duration(UserId2StatusCacheSeconds)*time.Second)
|
||||||
|
if err != nil {
|
||||||
|
common.SysError("Redis set linuxdo enabled error: " + err.Error())
|
||||||
|
}
|
||||||
|
return linuxDoEnabled, err
|
||||||
|
}
|
||||||
|
|
||||||
var group2model2channels map[string]map[string][]*Channel
|
var group2model2channels map[string]map[string][]*Channel
|
||||||
var channelsIDM map[int]*Channel
|
var channelsIDM map[int]*Channel
|
||||||
var channelSyncLock sync.RWMutex
|
var channelSyncLock sync.RWMutex
|
||||||
@@ -269,9 +293,8 @@ func SyncChannelCache(frequency int) {
|
|||||||
func CacheGetRandomSatisfiedChannel(group string, model string, retry int) (*Channel, error) {
|
func CacheGetRandomSatisfiedChannel(group string, model string, retry int) (*Channel, error) {
|
||||||
if strings.HasPrefix(model, "gpt-4-gizmo") {
|
if strings.HasPrefix(model, "gpt-4-gizmo") {
|
||||||
model = "gpt-4-gizmo-*"
|
model = "gpt-4-gizmo-*"
|
||||||
}
|
} else if strings.HasPrefix(model, "g-") {
|
||||||
if strings.HasPrefix(model, "gpt-4o-gizmo") {
|
model = "g-*"
|
||||||
model = "gpt-4o-gizmo-*"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if memory cache is disabled, get channel directly from database
|
// if memory cache is disabled, get channel directly from database
|
||||||
|
|||||||
24
model/log.go
24
model/log.go
@@ -247,7 +247,25 @@ func SumUsedToken(logType int, startTimestamp int64, endTimestamp int64, modelNa
|
|||||||
return token
|
return token
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeleteOldLog(targetTimestamp int64) (int64, error) {
|
func DeleteOldLog(ctx context.Context, targetTimestamp int64, limit int) (int64, error) {
|
||||||
result := LOG_DB.Where("created_at < ?", targetTimestamp).Delete(&Log{})
|
var total int64 = 0
|
||||||
return result.RowsAffected, result.Error
|
|
||||||
|
for {
|
||||||
|
if nil != ctx.Err() {
|
||||||
|
return total, ctx.Err()
|
||||||
|
}
|
||||||
|
|
||||||
|
result := LOG_DB.Where("created_at < ?", targetTimestamp).Limit(limit).Delete(&Log{})
|
||||||
|
if nil != result.Error {
|
||||||
|
return total, result.Error
|
||||||
|
}
|
||||||
|
|
||||||
|
total += result.RowsAffected
|
||||||
|
|
||||||
|
if result.RowsAffected < int64(limit) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return total, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,10 +31,12 @@ func InitOptionMap() {
|
|||||||
common.OptionMap["PasswordRegisterEnabled"] = strconv.FormatBool(common.PasswordRegisterEnabled)
|
common.OptionMap["PasswordRegisterEnabled"] = strconv.FormatBool(common.PasswordRegisterEnabled)
|
||||||
common.OptionMap["EmailVerificationEnabled"] = strconv.FormatBool(common.EmailVerificationEnabled)
|
common.OptionMap["EmailVerificationEnabled"] = strconv.FormatBool(common.EmailVerificationEnabled)
|
||||||
common.OptionMap["GitHubOAuthEnabled"] = strconv.FormatBool(common.GitHubOAuthEnabled)
|
common.OptionMap["GitHubOAuthEnabled"] = strconv.FormatBool(common.GitHubOAuthEnabled)
|
||||||
|
common.OptionMap["LinuxDoOAuthEnabled"] = strconv.FormatBool(common.LinuxDoOAuthEnabled)
|
||||||
common.OptionMap["TelegramOAuthEnabled"] = strconv.FormatBool(common.TelegramOAuthEnabled)
|
common.OptionMap["TelegramOAuthEnabled"] = strconv.FormatBool(common.TelegramOAuthEnabled)
|
||||||
common.OptionMap["WeChatAuthEnabled"] = strconv.FormatBool(common.WeChatAuthEnabled)
|
common.OptionMap["WeChatAuthEnabled"] = strconv.FormatBool(common.WeChatAuthEnabled)
|
||||||
common.OptionMap["TurnstileCheckEnabled"] = strconv.FormatBool(common.TurnstileCheckEnabled)
|
common.OptionMap["TurnstileCheckEnabled"] = strconv.FormatBool(common.TurnstileCheckEnabled)
|
||||||
common.OptionMap["RegisterEnabled"] = strconv.FormatBool(common.RegisterEnabled)
|
common.OptionMap["RegisterEnabled"] = strconv.FormatBool(common.RegisterEnabled)
|
||||||
|
common.OptionMap["UserSelfDeletionEnabled"] = strconv.FormatBool(common.UserSelfDeletionEnabled)
|
||||||
common.OptionMap["AutomaticDisableChannelEnabled"] = strconv.FormatBool(common.AutomaticDisableChannelEnabled)
|
common.OptionMap["AutomaticDisableChannelEnabled"] = strconv.FormatBool(common.AutomaticDisableChannelEnabled)
|
||||||
common.OptionMap["AutomaticEnableChannelEnabled"] = strconv.FormatBool(common.AutomaticEnableChannelEnabled)
|
common.OptionMap["AutomaticEnableChannelEnabled"] = strconv.FormatBool(common.AutomaticEnableChannelEnabled)
|
||||||
common.OptionMap["LogConsumeEnabled"] = strconv.FormatBool(common.LogConsumeEnabled)
|
common.OptionMap["LogConsumeEnabled"] = strconv.FormatBool(common.LogConsumeEnabled)
|
||||||
@@ -60,17 +62,19 @@ func InitOptionMap() {
|
|||||||
common.OptionMap["SystemName"] = common.SystemName
|
common.OptionMap["SystemName"] = common.SystemName
|
||||||
common.OptionMap["Logo"] = common.Logo
|
common.OptionMap["Logo"] = common.Logo
|
||||||
common.OptionMap["ServerAddress"] = ""
|
common.OptionMap["ServerAddress"] = ""
|
||||||
common.OptionMap["WorkerUrl"] = constant.WorkerUrl
|
common.OptionMap["OutProxyUrl"] = ""
|
||||||
common.OptionMap["WorkerValidKey"] = constant.WorkerValidKey
|
common.OptionMap["StripeApiSecret"] = common.StripeApiSecret
|
||||||
common.OptionMap["PayAddress"] = ""
|
common.OptionMap["StripeWebhookSecret"] = common.StripeWebhookSecret
|
||||||
common.OptionMap["CustomCallbackAddress"] = ""
|
common.OptionMap["StripePriceId"] = common.StripePriceId
|
||||||
common.OptionMap["EpayId"] = ""
|
common.OptionMap["PaymentEnabled"] = strconv.FormatBool(common.PaymentEnabled)
|
||||||
common.OptionMap["EpayKey"] = ""
|
common.OptionMap["StripeUnitPrice"] = strconv.FormatFloat(common.StripeUnitPrice, 'f', -1, 64)
|
||||||
common.OptionMap["Price"] = strconv.FormatFloat(constant.Price, 'f', -1, 64)
|
common.OptionMap["MinTopUp"] = strconv.Itoa(common.MinTopUp)
|
||||||
common.OptionMap["MinTopUp"] = strconv.Itoa(constant.MinTopUp)
|
|
||||||
common.OptionMap["TopupGroupRatio"] = common.TopupGroupRatio2JSONString()
|
common.OptionMap["TopupGroupRatio"] = common.TopupGroupRatio2JSONString()
|
||||||
common.OptionMap["GitHubClientId"] = ""
|
common.OptionMap["GitHubClientId"] = ""
|
||||||
common.OptionMap["GitHubClientSecret"] = ""
|
common.OptionMap["GitHubClientSecret"] = ""
|
||||||
|
common.OptionMap["LinuxDoClientId"] = ""
|
||||||
|
common.OptionMap["LinuxDoClientSecret"] = ""
|
||||||
|
common.OptionMap["LinuxDoMinLevel"] = strconv.Itoa(common.LinuxDoMinLevel)
|
||||||
common.OptionMap["TelegramBotToken"] = ""
|
common.OptionMap["TelegramBotToken"] = ""
|
||||||
common.OptionMap["TelegramBotName"] = ""
|
common.OptionMap["TelegramBotName"] = ""
|
||||||
common.OptionMap["WeChatServerAddress"] = ""
|
common.OptionMap["WeChatServerAddress"] = ""
|
||||||
@@ -173,6 +177,8 @@ func updateOptionMap(key string, value string) (err error) {
|
|||||||
common.EmailVerificationEnabled = boolValue
|
common.EmailVerificationEnabled = boolValue
|
||||||
case "GitHubOAuthEnabled":
|
case "GitHubOAuthEnabled":
|
||||||
common.GitHubOAuthEnabled = boolValue
|
common.GitHubOAuthEnabled = boolValue
|
||||||
|
case "LinuxDoOAuthEnabled":
|
||||||
|
common.LinuxDoOAuthEnabled = boolValue
|
||||||
case "WeChatAuthEnabled":
|
case "WeChatAuthEnabled":
|
||||||
common.WeChatAuthEnabled = boolValue
|
common.WeChatAuthEnabled = boolValue
|
||||||
case "TelegramOAuthEnabled":
|
case "TelegramOAuthEnabled":
|
||||||
@@ -181,6 +187,8 @@ func updateOptionMap(key string, value string) (err error) {
|
|||||||
common.TurnstileCheckEnabled = boolValue
|
common.TurnstileCheckEnabled = boolValue
|
||||||
case "RegisterEnabled":
|
case "RegisterEnabled":
|
||||||
common.RegisterEnabled = boolValue
|
common.RegisterEnabled = boolValue
|
||||||
|
case "UserSelfDeletionEnabled":
|
||||||
|
common.UserSelfDeletionEnabled = boolValue
|
||||||
case "EmailDomainRestrictionEnabled":
|
case "EmailDomainRestrictionEnabled":
|
||||||
common.EmailDomainRestrictionEnabled = boolValue
|
common.EmailDomainRestrictionEnabled = boolValue
|
||||||
case "EmailAliasRestrictionEnabled":
|
case "EmailAliasRestrictionEnabled":
|
||||||
@@ -240,29 +248,33 @@ func updateOptionMap(key string, value string) (err error) {
|
|||||||
case "SMTPToken":
|
case "SMTPToken":
|
||||||
common.SMTPToken = value
|
common.SMTPToken = value
|
||||||
case "ServerAddress":
|
case "ServerAddress":
|
||||||
constant.ServerAddress = value
|
common.ServerAddress = value
|
||||||
case "WorkerUrl":
|
case "OutProxyUrl":
|
||||||
constant.WorkerUrl = value
|
common.OutProxyUrl = value
|
||||||
case "WorkerValidKey":
|
case "StripeApiSecret":
|
||||||
constant.WorkerValidKey = value
|
common.StripeApiSecret = value
|
||||||
case "PayAddress":
|
case "StripeWebhookSecret":
|
||||||
constant.PayAddress = value
|
common.StripeWebhookSecret = value
|
||||||
case "CustomCallbackAddress":
|
case "StripePriceId":
|
||||||
constant.CustomCallbackAddress = value
|
common.StripePriceId = value
|
||||||
case "EpayId":
|
case "PaymentEnabled":
|
||||||
constant.EpayId = value
|
common.PaymentEnabled, _ = strconv.ParseBool(value)
|
||||||
case "EpayKey":
|
case "StripeUnitPrice":
|
||||||
constant.EpayKey = value
|
common.StripeUnitPrice, _ = strconv.ParseFloat(value, 64)
|
||||||
case "Price":
|
|
||||||
constant.Price, _ = strconv.ParseFloat(value, 64)
|
|
||||||
case "MinTopUp":
|
case "MinTopUp":
|
||||||
constant.MinTopUp, _ = strconv.Atoi(value)
|
common.MinTopUp, _ = strconv.Atoi(value)
|
||||||
case "TopupGroupRatio":
|
case "TopupGroupRatio":
|
||||||
err = common.UpdateTopupGroupRatioByJSONString(value)
|
err = common.UpdateTopupGroupRatioByJSONString(value)
|
||||||
case "GitHubClientId":
|
case "GitHubClientId":
|
||||||
common.GitHubClientId = value
|
common.GitHubClientId = value
|
||||||
case "GitHubClientSecret":
|
case "GitHubClientSecret":
|
||||||
common.GitHubClientSecret = value
|
common.GitHubClientSecret = value
|
||||||
|
case "LinuxDoClientId":
|
||||||
|
common.LinuxDoClientId = value
|
||||||
|
case "LinuxDoClientSecret":
|
||||||
|
common.LinuxDoClientSecret = value
|
||||||
|
case "LinuxDoMinLevel":
|
||||||
|
common.LinuxDoMinLevel, _ = strconv.Atoi(value)
|
||||||
case "Footer":
|
case "Footer":
|
||||||
common.Footer = value
|
common.Footer = value
|
||||||
case "SystemName":
|
case "SystemName":
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"one-api/common"
|
"one-api/common"
|
||||||
"one-api/constant"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@@ -294,7 +293,7 @@ func PostConsumeTokenQuota(tokenId int, userQuota int, quota int, preConsumedQuo
|
|||||||
prompt = "您的额度已用尽"
|
prompt = "您的额度已用尽"
|
||||||
}
|
}
|
||||||
if email != "" {
|
if email != "" {
|
||||||
topUpLink := fmt.Sprintf("%s/topup", constant.ServerAddress)
|
topUpLink := fmt.Sprintf("%s/topup", common.ServerAddress)
|
||||||
err = common.SendEmail(prompt, email,
|
err = common.SendEmail(prompt, email,
|
||||||
fmt.Sprintf("%s,当前剩余额度为 %d,为了不影响您的使用,请及时充值。<br/>充值链接:<a href='%s'>%s</a>", prompt, userQuota, topUpLink, topUpLink))
|
fmt.Sprintf("%s,当前剩余额度为 %d,为了不影响您的使用,请及时充值。<br/>充值链接:<a href='%s'>%s</a>", prompt, userQuota, topUpLink, topUpLink))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -1,13 +1,21 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
"one-api/common"
|
||||||
|
)
|
||||||
|
|
||||||
type TopUp struct {
|
type TopUp struct {
|
||||||
Id int `json:"id"`
|
Id int `json:"id"`
|
||||||
UserId int `json:"user_id" gorm:"index"`
|
UserId int `json:"user_id" gorm:"index"`
|
||||||
Amount int `json:"amount"`
|
Amount int `json:"amount"`
|
||||||
Money float64 `json:"money"`
|
Money float64 `json:"money"`
|
||||||
TradeNo string `json:"trade_no"`
|
TradeNo string `json:"trade_no" gorm:"unique"`
|
||||||
CreateTime int64 `json:"create_time"`
|
CreateTime int64 `json:"create_time"`
|
||||||
Status string `json:"status"`
|
CompleteTime int64 `json:"complete_time"`
|
||||||
|
Status string `json:"status"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (topUp *TopUp) Insert() error {
|
func (topUp *TopUp) Insert() error {
|
||||||
@@ -41,3 +49,51 @@ func GetTopUpByTradeNo(tradeNo string) *TopUp {
|
|||||||
}
|
}
|
||||||
return topUp
|
return topUp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Recharge(referenceId string, customerId string) (err error) {
|
||||||
|
if referenceId == "" {
|
||||||
|
return errors.New("未提供支付单号")
|
||||||
|
}
|
||||||
|
|
||||||
|
var quota float64
|
||||||
|
topUp := &TopUp{}
|
||||||
|
|
||||||
|
refCol := "`trade_no`"
|
||||||
|
if common.UsingPostgreSQL {
|
||||||
|
refCol = `"trade_no"`
|
||||||
|
}
|
||||||
|
|
||||||
|
err = DB.Transaction(func(tx *gorm.DB) error {
|
||||||
|
err := tx.Set("gorm:query_option", "FOR UPDATE").Where(refCol+" = ?", referenceId).First(topUp).Error
|
||||||
|
if err != nil {
|
||||||
|
return errors.New("充值订单不存在")
|
||||||
|
}
|
||||||
|
|
||||||
|
if topUp.Status != common.TopUpStatusPending {
|
||||||
|
return errors.New("充值订单状态错误")
|
||||||
|
}
|
||||||
|
|
||||||
|
topUp.CompleteTime = common.GetTimestamp()
|
||||||
|
topUp.Status = common.TopUpStatusSuccess
|
||||||
|
err = tx.Save(topUp).Error
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
quota = topUp.Money * common.QuotaPerUnit
|
||||||
|
err = tx.Model(&User{}).Where("id = ?", topUp.UserId).Updates(map[string]interface{}{"stripe_customer": customerId, "quota": gorm.Expr("quota + ?", quota)}).Error
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return errors.New("充值失败," + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
RecordLog(topUp.UserId, LogTypeTopup, fmt.Sprintf("使用在线充值成功,充值金额: %v,支付金额:%d", common.LogQuotaF(quota), topUp.Amount))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ type User struct {
|
|||||||
Status int `json:"status" gorm:"type:int;default:1"` // enabled, disabled
|
Status int `json:"status" gorm:"type:int;default:1"` // enabled, disabled
|
||||||
Email string `json:"email" gorm:"index" validate:"max=50"`
|
Email string `json:"email" gorm:"index" validate:"max=50"`
|
||||||
GitHubId string `json:"github_id" gorm:"column:github_id;index"`
|
GitHubId string `json:"github_id" gorm:"column:github_id;index"`
|
||||||
|
LinuxDoId string `json:"linuxdo_id" gorm:"column:linuxdo_id;index"`
|
||||||
|
LinuxDoLevel int `json:"linuxdo_level" gorm:"column:linuxdo_level;type:int;default:0"`
|
||||||
WeChatId string `json:"wechat_id" gorm:"column:wechat_id;index"`
|
WeChatId string `json:"wechat_id" gorm:"column:wechat_id;index"`
|
||||||
TelegramId string `json:"telegram_id" gorm:"column:telegram_id;index"`
|
TelegramId string `json:"telegram_id" gorm:"column:telegram_id;index"`
|
||||||
VerificationCode string `json:"verification_code" gorm:"-:all"` // this field is only for Email verification, don't save it to database!
|
VerificationCode string `json:"verification_code" gorm:"-:all"` // this field is only for Email verification, don't save it to database!
|
||||||
@@ -35,6 +37,7 @@ type User struct {
|
|||||||
AffQuota int `json:"aff_quota" gorm:"type:int;default:0;column:aff_quota"` // 邀请剩余额度
|
AffQuota int `json:"aff_quota" gorm:"type:int;default:0;column:aff_quota"` // 邀请剩余额度
|
||||||
AffHistoryQuota int `json:"aff_history_quota" gorm:"type:int;default:0;column:aff_history"` // 邀请历史额度
|
AffHistoryQuota int `json:"aff_history_quota" gorm:"type:int;default:0;column:aff_history"` // 邀请历史额度
|
||||||
InviterId int `json:"inviter_id" gorm:"type:int;column:inviter_id;index"`
|
InviterId int `json:"inviter_id" gorm:"type:int;column:inviter_id;index"`
|
||||||
|
StripeCustomer string `json:"stripe_customer" gorm:"column:stripe_customer;index"`
|
||||||
DeletedAt gorm.DeletedAt `gorm:"index"`
|
DeletedAt gorm.DeletedAt `gorm:"index"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,7 +67,7 @@ func CheckUserExistOrDeleted(username string, email string) (bool, error) {
|
|||||||
|
|
||||||
func GetMaxUserId() int {
|
func GetMaxUserId() int {
|
||||||
var user User
|
var user User
|
||||||
DB.Last(&user)
|
DB.Unscoped().Last(&user)
|
||||||
return user.Id
|
return user.Id
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,6 +122,20 @@ func GetUserById(id int, selectAll bool) (*User, error) {
|
|||||||
return &user, err
|
return &user, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetUserByIdUnscoped(id int, selectAll bool) (*User, error) {
|
||||||
|
if id == 0 {
|
||||||
|
return nil, errors.New("id 为空!")
|
||||||
|
}
|
||||||
|
user := User{Id: id}
|
||||||
|
var err error = nil
|
||||||
|
if selectAll {
|
||||||
|
err = DB.Unscoped().First(&user, "id = ?", id).Error
|
||||||
|
} else {
|
||||||
|
err = DB.Unscoped().Omit("password").First(&user, "id = ?", id).Error
|
||||||
|
}
|
||||||
|
return &user, err
|
||||||
|
}
|
||||||
|
|
||||||
func GetUserIdByAffCode(affCode string) (int, error) {
|
func GetUserIdByAffCode(affCode string) (int, error) {
|
||||||
if affCode == "" {
|
if affCode == "" {
|
||||||
return 0, errors.New("affCode 为空!")
|
return 0, errors.New("affCode 为空!")
|
||||||
@@ -331,6 +348,14 @@ func (user *User) FillUserByGitHubId() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (user *User) FillUserByLinuxDoId() error {
|
||||||
|
if user.LinuxDoId == "" {
|
||||||
|
return errors.New("LINUX DO id 为空!")
|
||||||
|
}
|
||||||
|
DB.Where(User{LinuxDoId: user.LinuxDoId}).First(user)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (user *User) FillUserByWeChatId() error {
|
func (user *User) FillUserByWeChatId() error {
|
||||||
if user.WeChatId == "" {
|
if user.WeChatId == "" {
|
||||||
return errors.New("WeChat id 为空!")
|
return errors.New("WeChat id 为空!")
|
||||||
@@ -370,6 +395,10 @@ func IsGitHubIdAlreadyTaken(githubId string) bool {
|
|||||||
return DB.Where("github_id = ?", githubId).Find(&User{}).RowsAffected == 1
|
return DB.Where("github_id = ?", githubId).Find(&User{}).RowsAffected == 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsLinuxDoIdAlreadyTaken(linuxdoId string) bool {
|
||||||
|
return DB.Where("linuxdo_id = ?", linuxdoId).Find(&User{}).RowsAffected == 1
|
||||||
|
}
|
||||||
|
|
||||||
func IsUsernameAlreadyTaken(username string) bool {
|
func IsUsernameAlreadyTaken(username string) bool {
|
||||||
return DB.Where("username = ?", username).Find(&User{}).RowsAffected == 1
|
return DB.Where("username = ?", username).Find(&User{}).RowsAffected == 1
|
||||||
}
|
}
|
||||||
@@ -415,6 +444,18 @@ func IsUserEnabled(userId int) (bool, error) {
|
|||||||
return user.Status == common.UserStatusEnabled, nil
|
return user.Status == common.UserStatusEnabled, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsLinuxDoEnabled(userId int) (bool, error) {
|
||||||
|
if userId == 0 {
|
||||||
|
return false, errors.New("user id is empty")
|
||||||
|
}
|
||||||
|
var user User
|
||||||
|
err := DB.Where("id = ?", userId).Select("linuxdo_id, linuxdo_level").Find(&user).Error
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
return user.LinuxDoId == "" || user.LinuxDoLevel >= common.LinuxDoMinLevel, nil
|
||||||
|
}
|
||||||
|
|
||||||
func ValidateAccessToken(token string) (user *User) {
|
func ValidateAccessToken(token string) (user *User) {
|
||||||
if token == "" {
|
if token == "" {
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -36,8 +36,8 @@ type AliEmbeddingRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type AliEmbedding struct {
|
type AliEmbedding struct {
|
||||||
Embedding []float64 `json:"embedding"`
|
Embedding any `json:"embedding"`
|
||||||
TextIndex int `json:"text_index"`
|
TextIndex int `json:"text_index"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AliEmbeddingResponse struct {
|
type AliEmbeddingResponse struct {
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ func responseAli2OpenAIImage(c *gin.Context, response *AliResponse, info *relayc
|
|||||||
for _, data := range response.Output.Results {
|
for _, data := range response.Output.Results {
|
||||||
var b64Json string
|
var b64Json string
|
||||||
if responseFormat == "b64_json" {
|
if responseFormat == "b64_json" {
|
||||||
_, b64, err := service.GetImageFromUrl(data.Url)
|
_, b64, err := common.GetImageFromUrl(data.Url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.LogError(c, "get_image_data_failed: "+err.Error())
|
common.LogError(c, "get_image_data_failed: "+err.Error())
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -50,9 +50,9 @@ type BaiduEmbeddingRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type BaiduEmbeddingData struct {
|
type BaiduEmbeddingData struct {
|
||||||
Object string `json:"object"`
|
Object string `json:"object"`
|
||||||
Embedding []float64 `json:"embedding"`
|
Embedding any `json:"embedding"`
|
||||||
Index int `json:"index"`
|
Index int `json:"index"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type BaiduEmbeddingResponse struct {
|
type BaiduEmbeddingResponse struct {
|
||||||
|
|||||||
@@ -193,11 +193,11 @@ func RequestOpenAI2ClaudeMessage(textRequest dto.GeneralOpenAIRequest) (*ClaudeR
|
|||||||
// 判断是否是url
|
// 判断是否是url
|
||||||
if strings.HasPrefix(imageUrl.Url, "http") {
|
if strings.HasPrefix(imageUrl.Url, "http") {
|
||||||
// 是url,获取图片的类型和base64编码的数据
|
// 是url,获取图片的类型和base64编码的数据
|
||||||
mimeType, data, _ := service.GetImageFromUrl(imageUrl.Url)
|
mimeType, data, _ := common.GetImageFromUrl(imageUrl.Url)
|
||||||
claudeMediaMessage.Source.MediaType = mimeType
|
claudeMediaMessage.Source.MediaType = mimeType
|
||||||
claudeMediaMessage.Source.Data = data
|
claudeMediaMessage.Source.Data = data
|
||||||
} else {
|
} else {
|
||||||
_, format, base64String, err := service.DecodeBase64ImageData(imageUrl.Url)
|
_, format, base64String, err := common.DecodeBase64ImageData(imageUrl.Url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ func CovertGemini2OpenAI(textRequest dto.GeneralOpenAIRequest) *GeminiChatReques
|
|||||||
// 判断是否是url
|
// 判断是否是url
|
||||||
if strings.HasPrefix(part.ImageUrl.(dto.MessageImageUrl).Url, "http") {
|
if strings.HasPrefix(part.ImageUrl.(dto.MessageImageUrl).Url, "http") {
|
||||||
// 是url,获取图片的类型和base64编码的数据
|
// 是url,获取图片的类型和base64编码的数据
|
||||||
mimeType, data, _ := service.GetImageFromUrl(part.ImageUrl.(dto.MessageImageUrl).Url)
|
mimeType, data, _ := common.GetImageFromUrl(part.ImageUrl.(dto.MessageImageUrl).Url)
|
||||||
parts = append(parts, GeminiPart{
|
parts = append(parts, GeminiPart{
|
||||||
InlineData: &GeminiInlineData{
|
InlineData: &GeminiInlineData{
|
||||||
MimeType: mimeType,
|
MimeType: mimeType,
|
||||||
@@ -94,7 +94,7 @@ func CovertGemini2OpenAI(textRequest dto.GeneralOpenAIRequest) *GeminiChatReques
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
_, format, base64String, err := service.DecodeBase64ImageData(part.ImageUrl.(dto.MessageImageUrl).Url)
|
_, format, base64String, err := common.DecodeBase64ImageData(part.ImageUrl.(dto.MessageImageUrl).Url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,5 +23,5 @@ type OllamaEmbeddingRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type OllamaEmbeddingResponse struct {
|
type OllamaEmbeddingResponse struct {
|
||||||
Embedding []float64 `json:"embedding,omitempty"`
|
Embedding any `json:"embedding,omitempty"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +1,22 @@
|
|||||||
package openai
|
package openai
|
||||||
|
|
||||||
var ModelList = []string{
|
var ModelList = []string{
|
||||||
"gpt-3.5-turbo", "gpt-3.5-turbo-0613", "gpt-3.5-turbo-1106", "gpt-3.5-turbo-0125",
|
"gpt-3.5-turbo", "gpt-3.5-turbo-0301", "gpt-3.5-turbo-0613", "gpt-3.5-turbo-1106", "gpt-3.5-turbo-0125",
|
||||||
"gpt-3.5-turbo-16k", "gpt-3.5-turbo-16k-0613",
|
"gpt-3.5-turbo-16k", "gpt-3.5-turbo-16k-0613",
|
||||||
"gpt-3.5-turbo-instruct",
|
"gpt-3.5-turbo-instruct",
|
||||||
"gpt-4", "gpt-4-0613", "gpt-4-1106-preview", "gpt-4-0125-preview",
|
"gpt-4", "gpt-4-0314", "gpt-4-0613", "gpt-4-1106-preview", "gpt-4-0125-preview",
|
||||||
"gpt-4-32k", "gpt-4-32k-0613",
|
"gpt-4-32k", "gpt-4-32k-0314", "gpt-4-32k-0613",
|
||||||
"gpt-4-turbo-preview", "gpt-4-turbo", "gpt-4-turbo-2024-04-09",
|
"gpt-4-turbo-preview", "gpt-4-turbo", "gpt-4-turbo-2024-04-09",
|
||||||
"gpt-4-vision-preview",
|
"gpt-4-vision-preview",
|
||||||
"chatgpt-4o-latest",
|
"chatgpt-4o-latest",
|
||||||
"gpt-4o", "gpt-4o-2024-05-13", "gpt-4o-2024-08-06",
|
"gpt-4o", "gpt-4o-2024-05-13", "gpt-4o-2024-08-06",
|
||||||
"gpt-4o-mini", "gpt-4o-mini-2024-07-18",
|
"gpt-4o-mini", "gpt-4o-mini-2024-07-18",
|
||||||
"text-embedding-ada-002", "text-embedding-3-small", "text-embedding-3-large",
|
"text-embedding-ada-002", "text-embedding-3-small", "text-embedding-3-large",
|
||||||
"text-curie-001", "text-babbage-001", "text-ada-001",
|
"text-curie-001", "text-babbage-001", "text-ada-001", "text-davinci-002", "text-davinci-003",
|
||||||
"text-moderation-latest", "text-moderation-stable",
|
"text-moderation-latest", "text-moderation-stable",
|
||||||
"text-davinci-edit-001",
|
"text-davinci-edit-001",
|
||||||
"davinci-002", "babbage-002",
|
"davinci-002", "babbage-002",
|
||||||
"dall-e-3",
|
"dall-e-2", "dall-e-3",
|
||||||
"whisper-1",
|
"whisper-1",
|
||||||
"tts-1", "tts-1-1106", "tts-1-hd", "tts-1-hd-1106",
|
"tts-1", "tts-1-1106", "tts-1-hd", "tts-1-hd-1106",
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ func RelayMidjourneyImage(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
resp, err := http.Get(midjourneyTask.ImageUrl)
|
resp, err := common.ProxiedHttpGet(midjourneyTask.ImageUrl, common.OutProxyUrl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
"error": "http_get_image_failed",
|
"error": "http_get_image_failed",
|
||||||
@@ -111,7 +111,7 @@ func coverMidjourneyTaskDto(c *gin.Context, originTask *model.Midjourney) (midjo
|
|||||||
midjourneyTask.FinishTime = originTask.FinishTime
|
midjourneyTask.FinishTime = originTask.FinishTime
|
||||||
midjourneyTask.ImageUrl = ""
|
midjourneyTask.ImageUrl = ""
|
||||||
if originTask.ImageUrl != "" && constant.MjForwardUrlEnabled {
|
if originTask.ImageUrl != "" && constant.MjForwardUrlEnabled {
|
||||||
midjourneyTask.ImageUrl = constant.ServerAddress + "/mj/image/" + originTask.MjId
|
midjourneyTask.ImageUrl = common.ServerAddress + "/mj/image/" + originTask.MjId
|
||||||
if originTask.Status != "SUCCESS" {
|
if originTask.Status != "SUCCESS" {
|
||||||
midjourneyTask.ImageUrl += "?rand=" + strconv.FormatInt(time.Now().UnixNano(), 10)
|
midjourneyTask.ImageUrl += "?rand=" + strconv.FormatInt(time.Now().UnixNano(), 10)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -205,6 +205,15 @@ func getPromptTokens(textRequest *dto.GeneralOpenAIRequest, info *relaycommon.Re
|
|||||||
promptTokens, err = service.CountTokenChatRequest(*textRequest, textRequest.Model)
|
promptTokens, err = service.CountTokenChatRequest(*textRequest, textRequest.Model)
|
||||||
case relayconstant.RelayModeCompletions:
|
case relayconstant.RelayModeCompletions:
|
||||||
promptTokens, err = service.CountTokenInput(textRequest.Prompt, textRequest.Model)
|
promptTokens, err = service.CountTokenInput(textRequest.Prompt, textRequest.Model)
|
||||||
|
prompts := textRequest.Prompt
|
||||||
|
switch v := prompts.(type) {
|
||||||
|
case string:
|
||||||
|
prompts = v + textRequest.Suffix
|
||||||
|
case []string:
|
||||||
|
prompts = append(v, textRequest.Suffix)
|
||||||
|
}
|
||||||
|
|
||||||
|
promptTokens, err = service.CountTokenInput(prompts, textRequest.Model)
|
||||||
case relayconstant.RelayModeModerations:
|
case relayconstant.RelayModeModerations:
|
||||||
promptTokens, err = service.CountTokenInput(textRequest.Input, textRequest.Model)
|
promptTokens, err = service.CountTokenInput(textRequest.Input, textRequest.Model)
|
||||||
case relayconstant.RelayModeEmbeddings:
|
case relayconstant.RelayModeEmbeddings:
|
||||||
@@ -353,9 +362,8 @@ func postConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, modelN
|
|||||||
if strings.HasPrefix(logModel, "gpt-4-gizmo") {
|
if strings.HasPrefix(logModel, "gpt-4-gizmo") {
|
||||||
logModel = "gpt-4-gizmo-*"
|
logModel = "gpt-4-gizmo-*"
|
||||||
logContent += fmt.Sprintf(",模型 %s", modelName)
|
logContent += fmt.Sprintf(",模型 %s", modelName)
|
||||||
}
|
} else if strings.HasPrefix(logModel, "g-") {
|
||||||
if strings.HasPrefix(logModel, "gpt-4o-gizmo") {
|
logModel = "g-*"
|
||||||
logModel = "gpt-4o-gizmo-*"
|
|
||||||
logContent += fmt.Sprintf(",模型 %s", modelName)
|
logContent += fmt.Sprintf(",模型 %s", modelName)
|
||||||
}
|
}
|
||||||
if extraContent != "" {
|
if extraContent != "" {
|
||||||
|
|||||||
@@ -18,13 +18,14 @@ func SetApiRouter(router *gin.Engine) {
|
|||||||
apiRouter.GET("/status/test", middleware.AdminAuth(), controller.TestStatus)
|
apiRouter.GET("/status/test", middleware.AdminAuth(), controller.TestStatus)
|
||||||
apiRouter.GET("/notice", controller.GetNotice)
|
apiRouter.GET("/notice", controller.GetNotice)
|
||||||
apiRouter.GET("/about", controller.GetAbout)
|
apiRouter.GET("/about", controller.GetAbout)
|
||||||
//apiRouter.GET("/midjourney", controller.GetMidjourney)
|
apiRouter.GET("/midjourney", controller.GetMidjourney)
|
||||||
apiRouter.GET("/home_page_content", controller.GetHomePageContent)
|
apiRouter.GET("/home_page_content", controller.GetHomePageContent)
|
||||||
apiRouter.GET("/pricing", middleware.TryUserAuth(), controller.GetPricing)
|
apiRouter.GET("/pricing", middleware.TryUserAuth(), controller.GetPricing)
|
||||||
apiRouter.GET("/verification", middleware.CriticalRateLimit(), middleware.TurnstileCheck(), controller.SendEmailVerification)
|
apiRouter.GET("/verification", middleware.CriticalRateLimit(), middleware.TurnstileCheck(), controller.SendEmailVerification)
|
||||||
apiRouter.GET("/reset_password", middleware.CriticalRateLimit(), middleware.TurnstileCheck(), controller.SendPasswordResetEmail)
|
apiRouter.GET("/reset_password", middleware.CriticalRateLimit(), middleware.TurnstileCheck(), controller.SendPasswordResetEmail)
|
||||||
apiRouter.POST("/user/reset", middleware.CriticalRateLimit(), controller.ResetPassword)
|
apiRouter.POST("/user/reset", middleware.CriticalRateLimit(), controller.ResetPassword)
|
||||||
apiRouter.GET("/oauth/github", middleware.CriticalRateLimit(), controller.GitHubOAuth)
|
apiRouter.GET("/oauth/github", middleware.CriticalRateLimit(), controller.GitHubOAuth)
|
||||||
|
apiRouter.GET("/oauth/linuxdo", middleware.CriticalRateLimit(), controller.LinuxDoOAuth)
|
||||||
apiRouter.GET("/oauth/state", middleware.CriticalRateLimit(), controller.GenerateOAuthCode)
|
apiRouter.GET("/oauth/state", middleware.CriticalRateLimit(), controller.GenerateOAuthCode)
|
||||||
apiRouter.GET("/oauth/wechat", middleware.CriticalRateLimit(), controller.WeChatAuth)
|
apiRouter.GET("/oauth/wechat", middleware.CriticalRateLimit(), controller.WeChatAuth)
|
||||||
apiRouter.GET("/oauth/wechat/bind", middleware.CriticalRateLimit(), middleware.UserAuth(), controller.WeChatBind)
|
apiRouter.GET("/oauth/wechat/bind", middleware.CriticalRateLimit(), middleware.UserAuth(), controller.WeChatBind)
|
||||||
@@ -32,13 +33,14 @@ func SetApiRouter(router *gin.Engine) {
|
|||||||
apiRouter.GET("/oauth/telegram/login", middleware.CriticalRateLimit(), controller.TelegramLogin)
|
apiRouter.GET("/oauth/telegram/login", middleware.CriticalRateLimit(), controller.TelegramLogin)
|
||||||
apiRouter.GET("/oauth/telegram/bind", middleware.CriticalRateLimit(), middleware.UserAuth(), controller.TelegramBind)
|
apiRouter.GET("/oauth/telegram/bind", middleware.CriticalRateLimit(), middleware.UserAuth(), controller.TelegramBind)
|
||||||
|
|
||||||
|
apiRouter.POST("/stripe/webhook", controller.StripeWebhook)
|
||||||
|
|
||||||
userRoute := apiRouter.Group("/user")
|
userRoute := apiRouter.Group("/user")
|
||||||
{
|
{
|
||||||
userRoute.POST("/register", middleware.CriticalRateLimit(), middleware.TurnstileCheck(), controller.Register)
|
userRoute.POST("/register", middleware.CriticalRateLimit(), middleware.TurnstileCheck(), controller.Register)
|
||||||
userRoute.POST("/login", middleware.CriticalRateLimit(), middleware.TurnstileCheck(), controller.Login)
|
userRoute.POST("/login", middleware.CriticalRateLimit(), middleware.TurnstileCheck(), controller.Login)
|
||||||
//userRoute.POST("/tokenlog", middleware.CriticalRateLimit(), controller.TokenLog)
|
//userRoute.POST("/tokenlog", middleware.CriticalRateLimit(), controller.TokenLog)
|
||||||
userRoute.GET("/logout", controller.Logout)
|
userRoute.GET("/logout", controller.Logout)
|
||||||
userRoute.GET("/epay/notify", controller.EpayNotify)
|
|
||||||
|
|
||||||
selfRoute := userRoute.Group("/")
|
selfRoute := userRoute.Group("/")
|
||||||
selfRoute.Use(middleware.UserAuth())
|
selfRoute.Use(middleware.UserAuth())
|
||||||
@@ -49,8 +51,8 @@ func SetApiRouter(router *gin.Engine) {
|
|||||||
selfRoute.DELETE("/self", controller.DeleteSelf)
|
selfRoute.DELETE("/self", controller.DeleteSelf)
|
||||||
selfRoute.GET("/token", controller.GenerateAccessToken)
|
selfRoute.GET("/token", controller.GenerateAccessToken)
|
||||||
selfRoute.GET("/aff", controller.GetAffCode)
|
selfRoute.GET("/aff", controller.GetAffCode)
|
||||||
selfRoute.POST("/topup", controller.TopUp)
|
selfRoute.POST("/topup", middleware.CriticalRateLimit(), controller.TopUp)
|
||||||
selfRoute.POST("/pay", controller.RequestEpay)
|
selfRoute.POST("/pay", middleware.CriticalRateLimit(), controller.RequestPayLink)
|
||||||
selfRoute.POST("/amount", controller.RequestAmount)
|
selfRoute.POST("/amount", controller.RequestAmount)
|
||||||
selfRoute.POST("/aff_transfer", controller.TransferAffQuota)
|
selfRoute.POST("/aff_transfer", controller.TransferAffQuota)
|
||||||
}
|
}
|
||||||
@@ -64,7 +66,7 @@ func SetApiRouter(router *gin.Engine) {
|
|||||||
adminRoute.POST("/", controller.CreateUser)
|
adminRoute.POST("/", controller.CreateUser)
|
||||||
adminRoute.POST("/manage", controller.ManageUser)
|
adminRoute.POST("/manage", controller.ManageUser)
|
||||||
adminRoute.PUT("/", controller.UpdateUser)
|
adminRoute.PUT("/", controller.UpdateUser)
|
||||||
adminRoute.DELETE("/:id", controller.DeleteUser)
|
adminRoute.DELETE("/:id", controller.HardDeleteUser)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
optionRoute := apiRouter.Group("/option")
|
optionRoute := apiRouter.Group("/option")
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
package service
|
|
||||||
|
|
||||||
import (
|
|
||||||
"one-api/constant"
|
|
||||||
)
|
|
||||||
|
|
||||||
func GetCallbackAddress() string {
|
|
||||||
if constant.CustomCallbackAddress == "" {
|
|
||||||
return constant.ServerAddress
|
|
||||||
}
|
|
||||||
return constant.CustomCallbackAddress
|
|
||||||
}
|
|
||||||
@@ -18,7 +18,6 @@ import (
|
|||||||
// tokenEncoderMap won't grow after initialization
|
// tokenEncoderMap won't grow after initialization
|
||||||
var tokenEncoderMap = map[string]*tiktoken.Tiktoken{}
|
var tokenEncoderMap = map[string]*tiktoken.Tiktoken{}
|
||||||
var defaultTokenEncoder *tiktoken.Tiktoken
|
var defaultTokenEncoder *tiktoken.Tiktoken
|
||||||
var cl200kTokenEncoder *tiktoken.Tiktoken
|
|
||||||
|
|
||||||
func InitTokenEncoders() {
|
func InitTokenEncoders() {
|
||||||
common.SysLog("initializing token encoders")
|
common.SysLog("initializing token encoders")
|
||||||
@@ -31,19 +30,20 @@ func InitTokenEncoders() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
common.FatalLog(fmt.Sprintf("failed to get gpt-4 token encoder: %s", err.Error()))
|
common.FatalLog(fmt.Sprintf("failed to get gpt-4 token encoder: %s", err.Error()))
|
||||||
}
|
}
|
||||||
cl200kTokenEncoder, err = tiktoken.EncodingForModel("gpt-4o")
|
|
||||||
|
gpt4oTokenEncoder, err := tiktoken.EncodingForModel("gpt-4o")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.FatalLog(fmt.Sprintf("failed to get gpt-4o token encoder: %s", err.Error()))
|
common.FatalLog(fmt.Sprintf("failed to get gpt-4o token encoder: %s", err.Error()))
|
||||||
}
|
}
|
||||||
for model, _ := range common.GetDefaultModelRatioMap() {
|
for model, _ := range common.GetDefaultModelRatioMap() {
|
||||||
if strings.HasPrefix(model, "gpt-3.5") {
|
if strings.HasPrefix(model, "gpt-3.5") {
|
||||||
tokenEncoderMap[model] = gpt35TokenEncoder
|
tokenEncoderMap[model] = gpt35TokenEncoder
|
||||||
|
} else if strings.HasPrefix(model, "gpt-4o") {
|
||||||
|
tokenEncoderMap[model] = gpt4oTokenEncoder
|
||||||
|
} else if strings.HasPrefix(model, "chatgpt-4o") {
|
||||||
|
tokenEncoderMap[model] = gpt4oTokenEncoder
|
||||||
} else if strings.HasPrefix(model, "gpt-4") {
|
} else if strings.HasPrefix(model, "gpt-4") {
|
||||||
if strings.HasPrefix(model, "gpt-4o") {
|
tokenEncoderMap[model] = gpt4TokenEncoder
|
||||||
tokenEncoderMap[model] = cl200kTokenEncoder
|
|
||||||
} else {
|
|
||||||
tokenEncoderMap[model] = gpt4TokenEncoder
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
tokenEncoderMap[model] = nil
|
tokenEncoderMap[model] = nil
|
||||||
}
|
}
|
||||||
@@ -51,13 +51,6 @@ func InitTokenEncoders() {
|
|||||||
common.SysLog("token encoders initialized")
|
common.SysLog("token encoders initialized")
|
||||||
}
|
}
|
||||||
|
|
||||||
func getModelDefaultTokenEncoder(model string) *tiktoken.Tiktoken {
|
|
||||||
if strings.HasPrefix(model, "gpt-4o") || strings.HasPrefix(model, "chatgpt-4o") {
|
|
||||||
return cl200kTokenEncoder
|
|
||||||
}
|
|
||||||
return defaultTokenEncoder
|
|
||||||
}
|
|
||||||
|
|
||||||
func getTokenEncoder(model string) *tiktoken.Tiktoken {
|
func getTokenEncoder(model string) *tiktoken.Tiktoken {
|
||||||
tokenEncoder, ok := tokenEncoderMap[model]
|
tokenEncoder, ok := tokenEncoderMap[model]
|
||||||
if ok && tokenEncoder != nil {
|
if ok && tokenEncoder != nil {
|
||||||
@@ -68,13 +61,12 @@ func getTokenEncoder(model string) *tiktoken.Tiktoken {
|
|||||||
tokenEncoder, err := tiktoken.EncodingForModel(model)
|
tokenEncoder, err := tiktoken.EncodingForModel(model)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.SysError(fmt.Sprintf("failed to get token encoder for model %s: %s, using encoder for gpt-3.5-turbo", model, err.Error()))
|
common.SysError(fmt.Sprintf("failed to get token encoder for model %s: %s, using encoder for gpt-3.5-turbo", model, err.Error()))
|
||||||
tokenEncoder = getModelDefaultTokenEncoder(model)
|
tokenEncoder = defaultTokenEncoder
|
||||||
}
|
}
|
||||||
tokenEncoderMap[model] = tokenEncoder
|
tokenEncoderMap[model] = tokenEncoder
|
||||||
return tokenEncoder
|
return tokenEncoder
|
||||||
}
|
}
|
||||||
// 如果model不在tokenEncoderMap中,直接返回默认的tokenEncoder
|
return defaultTokenEncoder
|
||||||
return getModelDefaultTokenEncoder(model)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getTokenNum(tokenEncoder *tiktoken.Tiktoken, text string) int {
|
func getTokenNum(tokenEncoder *tiktoken.Tiktoken, text string) int {
|
||||||
@@ -111,10 +103,11 @@ func getImageToken(imageUrl *dto.MessageImageUrl, model string, stream bool) (in
|
|||||||
var err error
|
var err error
|
||||||
var format string
|
var format string
|
||||||
if strings.HasPrefix(imageUrl.Url, "http") {
|
if strings.HasPrefix(imageUrl.Url, "http") {
|
||||||
config, format, err = DecodeUrlImageData(imageUrl.Url)
|
common.SysLog(fmt.Sprintf("downloading image: %s", imageUrl.Url))
|
||||||
|
config, format, err = common.DecodeUrlImageData(imageUrl.Url)
|
||||||
} else {
|
} else {
|
||||||
common.SysLog(fmt.Sprintf("decoding image"))
|
common.SysLog(fmt.Sprintf("decoding image"))
|
||||||
config, format, _, err = DecodeBase64ImageData(imageUrl.Url)
|
config, format, _, err = common.DecodeBase64ImageData(imageUrl.Url)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
|
|||||||
@@ -1,26 +0,0 @@
|
|||||||
package service
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"fmt"
|
|
||||||
"net/http"
|
|
||||||
"one-api/common"
|
|
||||||
"one-api/constant"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
func DoImageRequest(originUrl string) (resp *http.Response, err error) {
|
|
||||||
if constant.EnableWorker() {
|
|
||||||
common.SysLog(fmt.Sprintf("downloading image from worker: %s", originUrl))
|
|
||||||
workerUrl := constant.WorkerUrl
|
|
||||||
if !strings.HasSuffix(workerUrl, "/") {
|
|
||||||
workerUrl += "/"
|
|
||||||
}
|
|
||||||
// post request to worker
|
|
||||||
data := []byte(`{"url":"` + originUrl + `","key":"` + constant.WorkerValidKey + `"}`)
|
|
||||||
return http.Post(constant.WorkerUrl, "application/json", bytes.NewBuffer(data))
|
|
||||||
} else {
|
|
||||||
common.SysLog(fmt.Sprintf("downloading image from origin: %s", originUrl))
|
|
||||||
return http.Get(originUrl)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
5
web/.gitignore
vendored
5
web/.gitignore
vendored
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
# production
|
# production
|
||||||
/build
|
/build
|
||||||
|
/dist
|
||||||
|
|
||||||
# misc
|
# misc
|
||||||
.DS_Store
|
.DS_Store
|
||||||
@@ -21,6 +22,4 @@
|
|||||||
npm-debug.log*
|
npm-debug.log*
|
||||||
yarn-debug.log*
|
yarn-debug.log*
|
||||||
yarn-error.log*
|
yarn-error.log*
|
||||||
.idea
|
.idea/
|
||||||
package-lock.json
|
|
||||||
yarn.lock
|
|
||||||
@@ -1 +1 @@
|
|||||||
module.exports = require("@so1ve/prettier-config");
|
module.exports = require('@so1ve/prettier-config');
|
||||||
|
|||||||
1897
web/pnpm-lock.yaml
generated
1897
web/pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -11,6 +11,7 @@ import EditUser from './pages/User/EditUser';
|
|||||||
import { getLogo, getSystemName } from './helpers';
|
import { getLogo, getSystemName } from './helpers';
|
||||||
import PasswordResetForm from './components/PasswordResetForm';
|
import PasswordResetForm from './components/PasswordResetForm';
|
||||||
import GitHubOAuth from './components/GitHubOAuth';
|
import GitHubOAuth from './components/GitHubOAuth';
|
||||||
|
import LinuxDoOAuth from './components/LinuxDoOAuth';
|
||||||
import PasswordResetConfirm from './components/PasswordResetConfirm';
|
import PasswordResetConfirm from './components/PasswordResetConfirm';
|
||||||
import { UserContext } from './context/User';
|
import { UserContext } from './context/User';
|
||||||
import Channel from './pages/Channel';
|
import Channel from './pages/Channel';
|
||||||
@@ -23,7 +24,7 @@ import Chat from './pages/Chat';
|
|||||||
import { Layout } from '@douyinfe/semi-ui';
|
import { Layout } from '@douyinfe/semi-ui';
|
||||||
import Midjourney from './pages/Midjourney';
|
import Midjourney from './pages/Midjourney';
|
||||||
import Pricing from './pages/Pricing/index.js';
|
import Pricing from './pages/Pricing/index.js';
|
||||||
import Task from "./pages/Task/index.js";
|
import Task from './pages/Task/index.js';
|
||||||
// import Detail from './pages/Detail';
|
// import Detail from './pages/Detail';
|
||||||
|
|
||||||
const Home = lazy(() => import('./pages/Home'));
|
const Home = lazy(() => import('./pages/Home'));
|
||||||
@@ -173,6 +174,14 @@ function App() {
|
|||||||
</Suspense>
|
</Suspense>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
<Route
|
||||||
|
path='/oauth/linuxdo'
|
||||||
|
element={
|
||||||
|
<Suspense fallback={<Loading></Loading>}>
|
||||||
|
<LinuxDoOAuth />
|
||||||
|
</Suspense>
|
||||||
|
}
|
||||||
|
/>
|
||||||
<Route
|
<Route
|
||||||
path='/setting'
|
path='/setting'
|
||||||
element={
|
element={
|
||||||
@@ -224,11 +233,11 @@ function App() {
|
|||||||
<Route
|
<Route
|
||||||
path='/task'
|
path='/task'
|
||||||
element={
|
element={
|
||||||
<PrivateRoute>
|
<PrivateRoute>
|
||||||
<Suspense fallback={<Loading></Loading>}>
|
<Suspense fallback={<Loading></Loading>}>
|
||||||
<Task />
|
<Task />
|
||||||
</Suspense>
|
</Suspense>
|
||||||
</PrivateRoute>
|
</PrivateRoute>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<Route
|
<Route
|
||||||
|
|||||||
@@ -98,14 +98,18 @@ const ChannelsTable = () => {
|
|||||||
render: (text, record, index) => {
|
render: (text, record, index) => {
|
||||||
if (text === 3) {
|
if (text === 3) {
|
||||||
if (record.other_info === '') {
|
if (record.other_info === '') {
|
||||||
record.other_info = '{}'
|
record.other_info = '{}';
|
||||||
}
|
}
|
||||||
let otherInfo = JSON.parse(record.other_info);
|
let otherInfo = JSON.parse(record.other_info);
|
||||||
let reason = otherInfo['status_reason'];
|
let reason = otherInfo['status_reason'];
|
||||||
let time = otherInfo['status_time'];
|
let time = otherInfo['status_time'];
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Tooltip content={'原因:' + reason + ',时间:' + timestamp2string(time)}>
|
<Tooltip
|
||||||
|
content={
|
||||||
|
'原因:' + reason + ',时间:' + timestamp2string(time)
|
||||||
|
}
|
||||||
|
>
|
||||||
{renderStatus(text)}
|
{renderStatus(text)}
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
</div>
|
</div>
|
||||||
@@ -745,7 +749,7 @@ const ChannelsTable = () => {
|
|||||||
<Form.Select
|
<Form.Select
|
||||||
field='group'
|
field='group'
|
||||||
label='分组'
|
label='分组'
|
||||||
optionList={[{ label: '选择分组', value: null}, ...groupOptions]}
|
optionList={[{ label: '选择分组', value: null }, ...groupOptions]}
|
||||||
initValue={null}
|
initValue={null}
|
||||||
onChange={(v) => {
|
onChange={(v) => {
|
||||||
setSearchGroup(v);
|
setSearchGroup(v);
|
||||||
|
|||||||
@@ -25,11 +25,7 @@ const Footer = () => {
|
|||||||
New API {import.meta.env.VITE_REACT_APP_VERSION}{' '}
|
New API {import.meta.env.VITE_REACT_APP_VERSION}{' '}
|
||||||
</a>
|
</a>
|
||||||
由{' '}
|
由{' '}
|
||||||
<a
|
<a href='https://github.com/Calcium-Ion' target='_blank' rel='noreferrer'>
|
||||||
href='https://github.com/Calcium-Ion'
|
|
||||||
target='_blank'
|
|
||||||
rel='noreferrer'
|
|
||||||
>
|
|
||||||
Calcium-Ion
|
Calcium-Ion
|
||||||
</a>{' '}
|
</a>{' '}
|
||||||
开发,基于{' '}
|
开发,基于{' '}
|
||||||
|
|||||||
@@ -14,9 +14,14 @@ const GitHubOAuth = () => {
|
|||||||
let navigate = useNavigate();
|
let navigate = useNavigate();
|
||||||
|
|
||||||
const sendCode = async (code, state, count) => {
|
const sendCode = async (code, state, count) => {
|
||||||
const res = await API.get(`/api/oauth/github?code=${code}&state=${state}`);
|
let aff = localStorage.getItem('aff');
|
||||||
|
const res = await API.get(
|
||||||
|
`/api/oauth/github?code=${code}&state=${state}&aff=${aff}`,
|
||||||
|
);
|
||||||
const { success, message, data } = res.data;
|
const { success, message, data } = res.data;
|
||||||
if (success) {
|
if (success) {
|
||||||
|
localStorage.removeItem('aff');
|
||||||
|
|
||||||
if (message === 'bind') {
|
if (message === 'bind') {
|
||||||
showSuccess('绑定成功!');
|
showSuccess('绑定成功!');
|
||||||
navigate('/setting');
|
navigate('/setting');
|
||||||
@@ -41,6 +46,14 @@ const GitHubOAuth = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
let error = searchParams.get('error');
|
||||||
|
if (error) {
|
||||||
|
let errorDescription = searchParams.get('error_description');
|
||||||
|
showError(`授权错误:${error}: ${errorDescription}`);
|
||||||
|
navigate('/setting');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let code = searchParams.get('code');
|
let code = searchParams.get('code');
|
||||||
let state = searchParams.get('state');
|
let state = searchParams.get('state');
|
||||||
sendCode(code, state, 0).then();
|
sendCode(code, state, 0).then();
|
||||||
|
|||||||
27
web/src/components/LinuxDoIcon.js
Normal file
27
web/src/components/LinuxDoIcon.js
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { Icon } from '@douyinfe/semi-ui';
|
||||||
|
|
||||||
|
const LinuxDoIcon = (props) => {
|
||||||
|
function CustomIcon() {
|
||||||
|
return (
|
||||||
|
<svg
|
||||||
|
className='icon'
|
||||||
|
viewBox='0 0 24 24'
|
||||||
|
version='1.1'
|
||||||
|
xmlns='http://www.w3.org/2000/svg'
|
||||||
|
width='1em'
|
||||||
|
height='1em'
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
d='M19.7,17.6c-0.1-0.2-0.2-0.4-0.2-0.6c0-0.4-0.2-0.7-0.5-1c-0.1-0.1-0.3-0.2-0.4-0.2c0.6-1.8-0.3-3.6-1.3-4.9c0,0,0,0,0,0c-0.8-1.2-2-2.1-1.9-3.7c0-1.9,0.2-5.4-3.3-5.1C8.5,2.3,9.5,6,9.4,7.3c0,1.1-0.5,2.2-1.3,3.1c-0.2,0.2-0.4,0.5-0.5,0.7c-1,1.2-1.5,2.8-1.5,4.3c-0.2,0.2-0.4,0.4-0.5,0.6c-0.1,0.1-0.2,0.2-0.2,0.3c-0.1,0.1-0.3,0.2-0.5,0.3c-0.4,0.1-0.7,0.3-0.9,0.7c-0.1,0.3-0.2,0.7-0.1,1.1c0.1,0.2,0.1,0.4,0,0.7c-0.2,0.4-0.2,0.9,0,1.4c0.3,0.4,0.8,0.5,1.5,0.6c0.5,0,1.1,0.2,1.6,0.4l0,0c0.5,0.3,1.1,0.5,1.7,0.5c0.3,0,0.7-0.1,1-0.2c0.3-0.2,0.5-0.4,0.6-0.7c0.4,0,1-0.2,1.7-0.2c0.6,0,1.2,0.2,2,0.1c0,0.1,0,0.2,0.1,0.3c0.2,0.5,0.7,0.9,1.3,1c0.1,0,0.1,0,0.2,0c0.8-0.1,1.6-0.5,2.1-1.1l0,0c0.4-0.4,0.9-0.7,1.4-0.9c0.6-0.3,1-0.5,1.1-1C20.3,18.6,20.1,18.2,19.7,17.6z M12.8,4.8c0.6,0.1,1.1,0.6,1,1.2c0,0.3-0.1,0.6-0.3,0.9c0,0,0,0-0.1,0c-0.2-0.1-0.3-0.1-0.4-0.2c0.1-0.1,0.1-0.3,0.2-0.5c0-0.4-0.2-0.7-0.4-0.7c-0.3,0-0.5,0.3-0.5,0.7c0,0,0,0.1,0,0.1c-0.1-0.1-0.3-0.1-0.4-0.2c0,0,0-0.1,0-0.1C11.8,5.5,12.2,4.9,12.8,4.8z M12.5,6.8c0.1,0.1,0.3,0.2,0.4,0.2c0.1,0,0.3,0.1,0.4,0.2c0.2,0.1,0.4,0.2,0.4,0.5c0,0.3-0.3,0.6-0.9,0.8c-0.2,0.1-0.3,0.1-0.4,0.2c-0.3,0.2-0.6,0.3-1,0.3c-0.3,0-0.6-0.2-0.8-0.4c-0.1-0.1-0.2-0.2-0.4-0.3C10.1,8.2,9.9,8,9.8,7.7c0-0.1,0.1-0.2,0.2-0.3c0.3-0.2,0.4-0.3,0.5-0.4l0.1-0.1c0.2-0.3,0.6-0.5,1-0.5C11.9,6.5,12.2,6.6,12.5,6.8z M10.4,5c0.4,0,0.7,0.4,0.8,1.1c0,0.1,0,0.1,0,0.2c-0.1,0-0.3,0.1-0.4,0.2c0,0,0-0.1,0-0.2c0-0.3-0.2-0.6-0.4-0.5c-0.2,0-0.3,0.3-0.3,0.6c0,0.2,0.1,0.3,0.2,0.4l0,0c0,0-0.1,0.1-0.2,0.1C9.9,6.7,9.7,6.4,9.7,6.1C9.7,5.5,10,5,10.4,5z M9.4,21.1c-0.7,0.3-1.6,0.2-2.2-0.2c-0.6-0.3-1.1-0.4-1.8-0.4c-0.5-0.1-1-0.1-1.1-0.3c-0.1-0.2-0.1-0.5,0.1-1c0.1-0.3,0.1-0.6,0-0.9c-0.1-0.3-0.1-0.5,0-0.8C4.5,17.2,4.7,17.1,5,17c0.3-0.1,0.5-0.2,0.7-0.4c0.1-0.1,0.2-0.2,0.3-0.4c0.3-0.4,0.5-0.6,0.8-0.6c0.6,0.1,1.1,1,1.5,1.9c0.2,0.3,0.4,0.7,0.7,1c0.4,0.5,0.9,1.2,0.9,1.6C9.9,20.6,9.7,20.9,9.4,21.1z M14.3,18.9c0,0.1,0,0.1-0.1,0.2c-1.2,0.9-2.8,1-4.1,0.3c-0.2-0.3-0.4-0.6-0.6-0.9c0.9-0.1,0.7-1.3-1.2-2.5c-2-1.3-0.6-3.7,0.1-4.8c0.1-0.1,0.1,0-0.3,0.8c-0.3,0.6-0.9,2.1-0.1,3.2c0-0.8,0.2-1.6,0.5-2.4c0.7-1.3,1.2-2.8,1.5-4.3c0.1,0.1,0.1,0.1,0.2,0.1c0.1,0.1,0.2,0.2,0.3,0.2c0.2,0.3,0.6,0.4,0.9,0.4c0,0,0.1,0,0.1,0c0.4,0,0.8-0.1,1.1-0.4c0.1-0.1,0.2-0.2,0.4-0.2c0.3-0.1,0.6-0.3,0.9-0.6c0.4,1.3,0.8,2.5,1.4,3.6c0.4,0.8,0.7,1.6,0.9,2.5c0.3,0,0.7,0.1,1,0.3c0.8,0.4,1.1,0.7,1,1.2c-0.1,0-0.1,0-0.2,0c0-0.3-0.2-0.6-0.9-0.9c-0.7-0.3-1.3-0.3-1.5,0.4c-0.1,0-0.2,0.1-0.3,0.1c-0.8,0.4-0.8,1.5-0.9,2.6C14.5,18.2,14.4,18.5,14.3,18.9z M18.9,19.5c-0.6,0.2-1.1,0.6-1.5,1.1c-0.4,0.6-1.1,1-1.9,0.9c-0.4,0-0.8-0.3-0.9-0.7c-0.1-0.6-0.1-1.2,0.2-1.8c0.1-0.4,0.2-0.7,0.3-1.1c0.1-1.2,0.1-1.9,0.6-2.2h0c0,0.5,0.3,0.8,0.7,1c0.5,0,1-0.1,1.4-0.5c0.1,0,0.1,0,0.2,0c0.3,0,0.5,0,0.7,0.2c0.2,0.2,0.3,0.5,0.3,0.7c0,0.3,0.2,0.6,0.3,0.9c0.5,0.5,0.5,0.8,0.5,0.9C19.7,19.1,19.3,19.3,18.9,19.5z M9.9,7.5c-0.1,0-0.1,0-0.1,0.1c0,0,0,0.1,0.1,0.1c0,0,0,0,0,0c0.1,0,0.1,0.1,0.1,0.1c0.3,0.4,0.8,0.6,1.4,0.7c0.5-0.1,1-0.2,1.5-0.6c0.2-0.1,0.4-0.2,0.6-0.3c0.1,0,0.1-0.1,0.1-0.1c0-0.1,0-0.1-0.1-0.1l0,0c-0.2,0.1-0.5,0.2-0.7,0.3c-0.4,0.3-0.9,0.5-1.4,0.5c-0.5,0-0.9-0.3-1.2-0.6C10.1,7.6,10,7.5,9.9,7.5z'
|
||||||
|
fill='currentColor'
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return <Icon svg={<CustomIcon />} />;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default LinuxDoIcon;
|
||||||
71
web/src/components/LinuxDoOAuth.js
Normal file
71
web/src/components/LinuxDoOAuth.js
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
import React, { useContext, useEffect, useState } from 'react';
|
||||||
|
import { Dimmer, Loader, Segment } from 'semantic-ui-react';
|
||||||
|
import { useNavigate, useSearchParams } from 'react-router-dom';
|
||||||
|
import { API, showError, showSuccess } from '../helpers';
|
||||||
|
import { UserContext } from '../context/User';
|
||||||
|
|
||||||
|
const LinuxDoOAuth = () => {
|
||||||
|
const [searchParams, setSearchParams] = useSearchParams();
|
||||||
|
|
||||||
|
const [userState, userDispatch] = useContext(UserContext);
|
||||||
|
const [prompt, setPrompt] = useState('处理中...');
|
||||||
|
const [processing, setProcessing] = useState(true);
|
||||||
|
|
||||||
|
let navigate = useNavigate();
|
||||||
|
|
||||||
|
const sendCode = async (code, state, count) => {
|
||||||
|
let aff = localStorage.getItem('aff');
|
||||||
|
const res = await API.get(
|
||||||
|
`/api/oauth/linuxdo?code=${code}&state=${state}&aff=${aff}`,
|
||||||
|
);
|
||||||
|
const { success, message, data } = res.data;
|
||||||
|
if (success) {
|
||||||
|
localStorage.removeItem('aff');
|
||||||
|
|
||||||
|
if (message === 'bind') {
|
||||||
|
showSuccess('绑定成功!');
|
||||||
|
navigate('/setting');
|
||||||
|
} else {
|
||||||
|
userDispatch({ type: 'login', payload: data });
|
||||||
|
localStorage.setItem('user', JSON.stringify(data));
|
||||||
|
showSuccess('登录成功!');
|
||||||
|
navigate('/');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
showError(message);
|
||||||
|
if (count === 0) {
|
||||||
|
setPrompt(`操作失败,重定向至登录界面中...`);
|
||||||
|
navigate('/setting'); // in case this is failed to bind GitHub
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
count++;
|
||||||
|
setPrompt(`出现错误,第 ${count} 次重试中...`);
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, count * 2000));
|
||||||
|
await sendCode(code, state, count);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let error = searchParams.get('error');
|
||||||
|
if (error) {
|
||||||
|
let errorDescription = searchParams.get('error_description');
|
||||||
|
showError(`授权错误:${error}: ${errorDescription}`);
|
||||||
|
navigate('/setting');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let code = searchParams.get('code');
|
||||||
|
let state = searchParams.get('state');
|
||||||
|
sendCode(code, state, 0).then();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Segment style={{ minHeight: '300px' }}>
|
||||||
|
<Dimmer active inverted>
|
||||||
|
<Loader size='large'>{prompt}</Loader>
|
||||||
|
</Dimmer>
|
||||||
|
</Segment>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default LinuxDoOAuth;
|
||||||
@@ -1,8 +1,15 @@
|
|||||||
import React, { useContext, useEffect, useState } from 'react';
|
import React, { useContext, useEffect, useState } from 'react';
|
||||||
import { Link, useNavigate, useSearchParams } from 'react-router-dom';
|
import { Link, useNavigate, useSearchParams } from 'react-router-dom';
|
||||||
import { UserContext } from '../context/User';
|
import { UserContext } from '../context/User';
|
||||||
import { API, getLogo, showError, showInfo, showSuccess, updateAPI } from '../helpers';
|
import {
|
||||||
import { onGitHubOAuthClicked } from './utils';
|
API,
|
||||||
|
getLogo,
|
||||||
|
showError,
|
||||||
|
showInfo,
|
||||||
|
showSuccess,
|
||||||
|
updateAPI,
|
||||||
|
} from '../helpers';
|
||||||
|
import { onGitHubOAuthClicked, onLinuxDoOAuthClicked } from './utils';
|
||||||
import Turnstile from 'react-turnstile';
|
import Turnstile from 'react-turnstile';
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
@@ -18,6 +25,7 @@ import Text from '@douyinfe/semi-ui/lib/es/typography/text';
|
|||||||
import TelegramLoginButton from 'react-telegram-login';
|
import TelegramLoginButton from 'react-telegram-login';
|
||||||
|
|
||||||
import { IconGithubLogo } from '@douyinfe/semi-icons';
|
import { IconGithubLogo } from '@douyinfe/semi-icons';
|
||||||
|
import LinuxDoIcon from './LinuxDoIcon';
|
||||||
import WeChatIcon from './WeChatIcon';
|
import WeChatIcon from './WeChatIcon';
|
||||||
import { setUserData } from '../helpers/data.js';
|
import { setUserData } from '../helpers/data.js';
|
||||||
|
|
||||||
@@ -101,7 +109,7 @@ const LoginForm = () => {
|
|||||||
if (success) {
|
if (success) {
|
||||||
userDispatch({ type: 'login', payload: data });
|
userDispatch({ type: 'login', payload: data });
|
||||||
setUserData(data);
|
setUserData(data);
|
||||||
updateAPI()
|
updateAPI();
|
||||||
showSuccess('登录成功!');
|
showSuccess('登录成功!');
|
||||||
if (username === 'root' && password === '123456') {
|
if (username === 'root' && password === '123456') {
|
||||||
Modal.error({
|
Modal.error({
|
||||||
@@ -209,6 +217,7 @@ const LoginForm = () => {
|
|||||||
</Text>
|
</Text>
|
||||||
</div>
|
</div>
|
||||||
{status.github_oauth ||
|
{status.github_oauth ||
|
||||||
|
status.linuxdo_oauth ||
|
||||||
status.wechat_login ||
|
status.wechat_login ||
|
||||||
status.telegram_oauth ? (
|
status.telegram_oauth ? (
|
||||||
<>
|
<>
|
||||||
@@ -233,35 +242,43 @@ const LoginForm = () => {
|
|||||||
) : (
|
) : (
|
||||||
<></>
|
<></>
|
||||||
)}
|
)}
|
||||||
|
{status.linuxdo_oauth ? (
|
||||||
|
<Button
|
||||||
|
type='primary'
|
||||||
|
icon={<LinuxDoIcon />}
|
||||||
|
style={{ color: '#000', margin: '0 5px' }}
|
||||||
|
onClick={() =>
|
||||||
|
onLinuxDoOAuthClicked(status.linuxdo_client_id)
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<></>
|
||||||
|
)}
|
||||||
{status.wechat_login ? (
|
{status.wechat_login ? (
|
||||||
<Button
|
<Button
|
||||||
type='primary'
|
type='primary'
|
||||||
style={{ color: 'rgba(var(--semi-green-5), 1)' }}
|
style={{
|
||||||
|
color: 'rgba(var(--semi-green-5), 1)',
|
||||||
|
margin: '0 5px',
|
||||||
|
}}
|
||||||
icon={<Icon svg={<WeChatIcon />} />}
|
icon={<Icon svg={<WeChatIcon />} />}
|
||||||
onClick={onWeChatLoginClicked}
|
onClick={onWeChatLoginClicked}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<></>
|
<></>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{status.telegram_oauth ? (
|
||||||
|
<TelegramLoginButton
|
||||||
|
className='semi-button semi-button-with-icon semi-button-with-icon-only'
|
||||||
|
buttonSize='medium'
|
||||||
|
dataOnauth={onTelegramLoginClicked}
|
||||||
|
botName={status.telegram_bot_name}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<></>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
{status.telegram_oauth ? (
|
|
||||||
<>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
justifyContent: 'center',
|
|
||||||
marginTop: 5,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<TelegramLoginButton
|
|
||||||
dataOnauth={onTelegramLoginClicked}
|
|
||||||
botName={status.telegram_bot_name}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<></>
|
|
||||||
)}
|
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<></>
|
<></>
|
||||||
|
|||||||
@@ -92,9 +92,9 @@ function renderType(type) {
|
|||||||
);
|
);
|
||||||
case 'UPLOAD':
|
case 'UPLOAD':
|
||||||
return (
|
return (
|
||||||
<Tag color='blue' size='large'>
|
<Tag color='blue' size='large'>
|
||||||
上传文件
|
上传文件
|
||||||
</Tag>
|
</Tag>
|
||||||
);
|
);
|
||||||
case 'SHORTEN':
|
case 'SHORTEN':
|
||||||
return (
|
return (
|
||||||
@@ -262,7 +262,7 @@ function renderDuration(submit_time, finishTime) {
|
|||||||
|
|
||||||
// 返回带有样式的颜色标签
|
// 返回带有样式的颜色标签
|
||||||
return (
|
return (
|
||||||
<Tag color={color} size="large">
|
<Tag color={color} size='large'>
|
||||||
{durationSec} 秒
|
{durationSec} 秒
|
||||||
</Tag>
|
</Tag>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -46,37 +46,33 @@ function renderQuotaType(type) {
|
|||||||
function renderAvailable(available) {
|
function renderAvailable(available) {
|
||||||
return available ? (
|
return available ? (
|
||||||
<Popover
|
<Popover
|
||||||
content={
|
content={<div style={{ padding: 8 }}>您的分组可以使用该模型</div>}
|
||||||
<div style={{ padding: 8 }}>您的分组可以使用该模型</div>
|
position='top'
|
||||||
}
|
key={available}
|
||||||
position='top'
|
style={{
|
||||||
key={available}
|
backgroundColor: 'rgba(var(--semi-blue-4),1)',
|
||||||
style={{
|
borderColor: 'rgba(var(--semi-blue-4),1)',
|
||||||
backgroundColor: 'rgba(var(--semi-blue-4),1)',
|
color: 'var(--semi-color-white)',
|
||||||
borderColor: 'rgba(var(--semi-blue-4),1)',
|
borderWidth: 1,
|
||||||
color: 'var(--semi-color-white)',
|
borderStyle: 'solid',
|
||||||
borderWidth: 1,
|
}}
|
||||||
borderStyle: 'solid',
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<IconVerify style={{ color: 'green' }} size="large" />
|
<IconVerify style={{ color: 'green' }} size='large' />
|
||||||
</Popover>
|
</Popover>
|
||||||
) : (
|
) : (
|
||||||
<Popover
|
<Popover
|
||||||
content={
|
content={<div style={{ padding: 8 }}>您的分组无权使用该模型</div>}
|
||||||
<div style={{ padding: 8 }}>您的分组无权使用该模型</div>
|
position='top'
|
||||||
}
|
key={available}
|
||||||
position='top'
|
style={{
|
||||||
key={available}
|
backgroundColor: 'rgba(var(--semi-blue-4),1)',
|
||||||
style={{
|
borderColor: 'rgba(var(--semi-blue-4),1)',
|
||||||
backgroundColor: 'rgba(var(--semi-blue-4),1)',
|
color: 'var(--semi-color-white)',
|
||||||
borderColor: 'rgba(var(--semi-blue-4),1)',
|
borderWidth: 1,
|
||||||
color: 'var(--semi-color-white)',
|
borderStyle: 'solid',
|
||||||
borderWidth: 1,
|
}}
|
||||||
borderStyle: 'solid',
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<IconUploadError style={{ color: '#FFA54F' }} size="large" />
|
<IconUploadError style={{ color: '#FFA54F' }} size='large' />
|
||||||
</Popover>
|
</Popover>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -89,12 +85,12 @@ const ModelPricing = () => {
|
|||||||
const [isModalOpenurl, setIsModalOpenurl] = useState(false);
|
const [isModalOpenurl, setIsModalOpenurl] = useState(false);
|
||||||
|
|
||||||
const rowSelection = useMemo(
|
const rowSelection = useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
onChange: (selectedRowKeys, selectedRows) => {
|
onChange: (selectedRowKeys, selectedRows) => {
|
||||||
setSelectedRowKeys(selectedRowKeys);
|
setSelectedRowKeys(selectedRowKeys);
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
[]
|
[],
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleChange = (value) => {
|
const handleChange = (value) => {
|
||||||
@@ -168,19 +164,23 @@ const ModelPricing = () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: () => (
|
title: () => (
|
||||||
<span style={{'display':'flex','alignItems':'center'}}>
|
<span style={{ display: 'flex', alignItems: 'center' }}>
|
||||||
倍率
|
倍率
|
||||||
<Popover
|
<Popover
|
||||||
content={
|
content={
|
||||||
<div style={{ padding: 8 }}>倍率是为了方便换算不同价格的模型<br/>点击查看倍率说明</div>
|
<div style={{ padding: 8 }}>
|
||||||
|
倍率是为了方便换算不同价格的模型
|
||||||
|
<br />
|
||||||
|
点击查看倍率说明
|
||||||
|
</div>
|
||||||
}
|
}
|
||||||
position='top'
|
position='top'
|
||||||
style={{
|
style={{
|
||||||
backgroundColor: 'rgba(var(--semi-blue-4),1)',
|
backgroundColor: 'rgba(var(--semi-blue-4),1)',
|
||||||
borderColor: 'rgba(var(--semi-blue-4),1)',
|
borderColor: 'rgba(var(--semi-blue-4),1)',
|
||||||
color: 'var(--semi-color-white)',
|
color: 'var(--semi-color-white)',
|
||||||
borderWidth: 1,
|
borderWidth: 1,
|
||||||
borderStyle: 'solid',
|
borderStyle: 'solid',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<IconHelpCircle
|
<IconHelpCircle
|
||||||
@@ -200,7 +200,9 @@ const ModelPricing = () => {
|
|||||||
<>
|
<>
|
||||||
<Text>模型:{record.quota_type === 0 ? text : '无'}</Text>
|
<Text>模型:{record.quota_type === 0 ? text : '无'}</Text>
|
||||||
<br />
|
<br />
|
||||||
<Text>补全:{record.quota_type === 0 ? completionRatio : '无'}</Text>
|
<Text>
|
||||||
|
补全:{record.quota_type === 0 ? completionRatio : '无'}
|
||||||
|
</Text>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
return <div>{content}</div>;
|
return <div>{content}</div>;
|
||||||
@@ -216,7 +218,8 @@ const ModelPricing = () => {
|
|||||||
let inputRatioPrice = record.model_ratio * 2 * record.group_ratio;
|
let inputRatioPrice = record.model_ratio * 2 * record.group_ratio;
|
||||||
let completionRatioPrice =
|
let completionRatioPrice =
|
||||||
record.model_ratio *
|
record.model_ratio *
|
||||||
record.completion_ratio * 2 *
|
record.completion_ratio *
|
||||||
|
2 *
|
||||||
record.group_ratio;
|
record.group_ratio;
|
||||||
content = (
|
content = (
|
||||||
<>
|
<>
|
||||||
@@ -304,35 +307,40 @@ const ModelPricing = () => {
|
|||||||
<Layout>
|
<Layout>
|
||||||
{userState.user ? (
|
{userState.user ? (
|
||||||
<Banner
|
<Banner
|
||||||
type="success"
|
type='success'
|
||||||
fullMode={false}
|
fullMode={false}
|
||||||
closeIcon="null"
|
closeIcon='null'
|
||||||
description={`您的分组为:${userState.user.group},分组倍率为:${groupRatio}`}
|
description={`您的分组为:${userState.user.group},分组倍率为:${groupRatio}`}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<Banner
|
<Banner
|
||||||
type='warning'
|
type='warning'
|
||||||
fullMode={false}
|
fullMode={false}
|
||||||
closeIcon="null"
|
closeIcon='null'
|
||||||
description={`您还未登陆,显示的价格为默认分组倍率: ${groupRatio}`}
|
description={`您还未登陆,显示的价格为默认分组倍率: ${groupRatio}`}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<br/>
|
<br />
|
||||||
<Banner
|
<Banner
|
||||||
type="info"
|
type='info'
|
||||||
fullMode={false}
|
fullMode={false}
|
||||||
description={<div>按量计费费用 = 分组倍率 × 模型倍率 × (提示token数 + 补全token数 × 补全倍率)/ 500000 (单位:美元)</div>}
|
description={
|
||||||
closeIcon="null"
|
<div>
|
||||||
|
按量计费费用 = 分组倍率 × 模型倍率 × (提示token数 + 补全token数 ×
|
||||||
|
补全倍率)/ 500000 (单位:美元)
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
closeIcon='null'
|
||||||
/>
|
/>
|
||||||
<br/>
|
<br />
|
||||||
<Button
|
<Button
|
||||||
theme='light'
|
theme='light'
|
||||||
type='tertiary'
|
type='tertiary'
|
||||||
style={{width: 150}}
|
style={{ width: 150 }}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
copyText(selectedRowKeys);
|
copyText(selectedRowKeys);
|
||||||
}}
|
}}
|
||||||
disabled={selectedRowKeys == ""}
|
disabled={selectedRowKeys == ''}
|
||||||
>
|
>
|
||||||
复制选中模型
|
复制选中模型
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import {
|
|||||||
} from '../helpers';
|
} from '../helpers';
|
||||||
import Turnstile from 'react-turnstile';
|
import Turnstile from 'react-turnstile';
|
||||||
import { UserContext } from '../context/User';
|
import { UserContext } from '../context/User';
|
||||||
import { onGitHubOAuthClicked } from './utils';
|
import { onGitHubOAuthClicked, onLinuxDoOAuthClicked } from './utils';
|
||||||
import {
|
import {
|
||||||
Avatar,
|
Avatar,
|
||||||
Banner,
|
Banner,
|
||||||
@@ -519,6 +519,39 @@ const PersonalSetting = () => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div style={{ marginTop: 10 }}>
|
||||||
|
<Typography.Text strong>LINUX DO</Typography.Text>
|
||||||
|
<div
|
||||||
|
style={{ display: 'flex', justifyContent: 'space-between' }}
|
||||||
|
>
|
||||||
|
<div>
|
||||||
|
<Input
|
||||||
|
value={
|
||||||
|
userState.user && userState.user.linuxdo_id !== ''
|
||||||
|
? userState.user.linuxdo_id +
|
||||||
|
'(' +
|
||||||
|
userState.user.linuxdo_level +
|
||||||
|
'级)'
|
||||||
|
: '未绑定'
|
||||||
|
}
|
||||||
|
readonly={true}
|
||||||
|
></Input>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<Button
|
||||||
|
onClick={() => {
|
||||||
|
onLinuxDoOAuthClicked(status.linuxdo_client_id);
|
||||||
|
}}
|
||||||
|
disabled={
|
||||||
|
(userState.user && userState.user.linuxdo_id !== '') ||
|
||||||
|
!status.linuxdo_oauth
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{status.linuxdo_oauth ? '绑定' : '未启用'}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div style={{ marginTop: 10 }}>
|
<div style={{ marginTop: 10 }}>
|
||||||
<Typography.Text strong>Telegram</Typography.Text>
|
<Typography.Text strong>Telegram</Typography.Text>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ const RegisterForm = () => {
|
|||||||
password: '',
|
password: '',
|
||||||
password2: '',
|
password2: '',
|
||||||
email: '',
|
email: '',
|
||||||
verification_code: ''
|
verification_code: '',
|
||||||
});
|
});
|
||||||
const { username, password, password2 } = inputs;
|
const { username, password, password2 } = inputs;
|
||||||
const [showEmailVerification, setShowEmailVerification] = useState(false);
|
const [showEmailVerification, setShowEmailVerification] = useState(false);
|
||||||
@@ -65,10 +65,12 @@ const RegisterForm = () => {
|
|||||||
inputs.aff_code = affCode;
|
inputs.aff_code = affCode;
|
||||||
const res = await API.post(
|
const res = await API.post(
|
||||||
`/api/user/register?turnstile=${turnstileToken}`,
|
`/api/user/register?turnstile=${turnstileToken}`,
|
||||||
inputs
|
inputs,
|
||||||
);
|
);
|
||||||
const { success, message } = res.data;
|
const { success, message } = res.data;
|
||||||
if (success) {
|
if (success) {
|
||||||
|
localStorage.removeItem('aff');
|
||||||
|
|
||||||
navigate('/login');
|
navigate('/login');
|
||||||
showSuccess('注册成功!');
|
showSuccess('注册成功!');
|
||||||
} else {
|
} else {
|
||||||
@@ -86,7 +88,7 @@ const RegisterForm = () => {
|
|||||||
}
|
}
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const res = await API.get(
|
const res = await API.get(
|
||||||
`/api/verification?email=${inputs.email}&turnstile=${turnstileToken}`
|
`/api/verification?email=${inputs.email}&turnstile=${turnstileToken}`,
|
||||||
);
|
);
|
||||||
const { success, message } = res.data;
|
const { success, message } = res.data;
|
||||||
if (success) {
|
if (success) {
|
||||||
@@ -106,7 +108,7 @@ const RegisterForm = () => {
|
|||||||
style={{
|
style={{
|
||||||
justifyContent: 'center',
|
justifyContent: 'center',
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
marginTop: 120
|
marginTop: 120,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div style={{ width: 500 }}>
|
<div style={{ width: 500 }}>
|
||||||
@@ -114,28 +116,28 @@ const RegisterForm = () => {
|
|||||||
<Title heading={2} style={{ textAlign: 'center' }}>
|
<Title heading={2} style={{ textAlign: 'center' }}>
|
||||||
新用户注册
|
新用户注册
|
||||||
</Title>
|
</Title>
|
||||||
<Form size="large">
|
<Form size='large'>
|
||||||
<Form.Input
|
<Form.Input
|
||||||
field={'username'}
|
field={'username'}
|
||||||
label={'用户名'}
|
label={'用户名'}
|
||||||
placeholder="用户名"
|
placeholder='用户名'
|
||||||
name="username"
|
name='username'
|
||||||
onChange={(value) => handleChange('username', value)}
|
onChange={(value) => handleChange('username', value)}
|
||||||
/>
|
/>
|
||||||
<Form.Input
|
<Form.Input
|
||||||
field={'password'}
|
field={'password'}
|
||||||
label={'密码'}
|
label={'密码'}
|
||||||
placeholder="密码,最短 8 位,最长 20 位"
|
placeholder='密码,最短 8 位,最长 20 位'
|
||||||
name="password"
|
name='password'
|
||||||
type="password"
|
type='password'
|
||||||
onChange={(value) => handleChange('password', value)}
|
onChange={(value) => handleChange('password', value)}
|
||||||
/>
|
/>
|
||||||
<Form.Input
|
<Form.Input
|
||||||
field={'password2'}
|
field={'password2'}
|
||||||
label={'确认密码'}
|
label={'确认密码'}
|
||||||
placeholder="确认密码"
|
placeholder='确认密码'
|
||||||
name="password2"
|
name='password2'
|
||||||
type="password"
|
type='password'
|
||||||
onChange={(value) => handleChange('password2', value)}
|
onChange={(value) => handleChange('password2', value)}
|
||||||
/>
|
/>
|
||||||
{showEmailVerification ? (
|
{showEmailVerification ? (
|
||||||
@@ -143,12 +145,15 @@ const RegisterForm = () => {
|
|||||||
<Form.Input
|
<Form.Input
|
||||||
field={'email'}
|
field={'email'}
|
||||||
label={'邮箱'}
|
label={'邮箱'}
|
||||||
placeholder="输入邮箱地址"
|
placeholder='输入邮箱地址'
|
||||||
onChange={(value) => handleChange('email', value)}
|
onChange={(value) => handleChange('email', value)}
|
||||||
name="email"
|
name='email'
|
||||||
type="email"
|
type='email'
|
||||||
suffix={
|
suffix={
|
||||||
<Button onClick={sendVerificationCode} disabled={loading}>
|
<Button
|
||||||
|
onClick={sendVerificationCode}
|
||||||
|
disabled={loading}
|
||||||
|
>
|
||||||
获取验证码
|
获取验证码
|
||||||
</Button>
|
</Button>
|
||||||
}
|
}
|
||||||
@@ -156,9 +161,11 @@ const RegisterForm = () => {
|
|||||||
<Form.Input
|
<Form.Input
|
||||||
field={'verification_code'}
|
field={'verification_code'}
|
||||||
label={'验证码'}
|
label={'验证码'}
|
||||||
placeholder="输入验证码"
|
placeholder='输入验证码'
|
||||||
onChange={(value) => handleChange('verification_code', value)}
|
onChange={(value) =>
|
||||||
name="verification_code"
|
handleChange('verification_code', value)
|
||||||
|
}
|
||||||
|
name='verification_code'
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
@@ -179,14 +186,12 @@ const RegisterForm = () => {
|
|||||||
style={{
|
style={{
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
justifyContent: 'space-between',
|
justifyContent: 'space-between',
|
||||||
marginTop: 20
|
marginTop: 20,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Text>
|
<Text>
|
||||||
已有账户?
|
已有账户?
|
||||||
<Link to="/login">
|
<Link to='/login'>点击登录</Link>
|
||||||
点击登录
|
|
||||||
</Link>
|
|
||||||
</Text>
|
</Text>
|
||||||
</div>
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ import {
|
|||||||
import '../index.css';
|
import '../index.css';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
IconCalendarClock, IconChecklistStroked,
|
IconCalendarClock,
|
||||||
|
IconChecklistStroked,
|
||||||
IconComment,
|
IconComment,
|
||||||
IconCreditCard,
|
IconCreditCard,
|
||||||
IconGift,
|
IconGift,
|
||||||
@@ -149,9 +150,9 @@ const SiderBar = () => {
|
|||||||
to: '/task',
|
to: '/task',
|
||||||
icon: <IconChecklistStroked />,
|
icon: <IconChecklistStroked />,
|
||||||
className:
|
className:
|
||||||
localStorage.getItem('enable_task') === 'true'
|
localStorage.getItem('enable_task') === 'true'
|
||||||
? 'semi-navigation-item-normal'
|
? 'semi-navigation-item-normal'
|
||||||
: 'tableHiddle',
|
: 'tableHiddle',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
text: '设置',
|
text: '设置',
|
||||||
|
|||||||
@@ -20,6 +20,10 @@ const SystemSetting = () => {
|
|||||||
GitHubOAuthEnabled: '',
|
GitHubOAuthEnabled: '',
|
||||||
GitHubClientId: '',
|
GitHubClientId: '',
|
||||||
GitHubClientSecret: '',
|
GitHubClientSecret: '',
|
||||||
|
LinuxDoOAuthEnabled: '',
|
||||||
|
LinuxDoClientId: '',
|
||||||
|
LinuxDoClientSecret: '',
|
||||||
|
LinuxDoMinLevel: 0,
|
||||||
Notice: '',
|
Notice: '',
|
||||||
SMTPServer: '',
|
SMTPServer: '',
|
||||||
SMTPPort: '',
|
SMTPPort: '',
|
||||||
@@ -27,15 +31,14 @@ const SystemSetting = () => {
|
|||||||
SMTPFrom: '',
|
SMTPFrom: '',
|
||||||
SMTPToken: '',
|
SMTPToken: '',
|
||||||
ServerAddress: '',
|
ServerAddress: '',
|
||||||
WorkerUrl: '',
|
OutProxyUrl: '',
|
||||||
WorkerValidKey: '',
|
StripeApiSecret: '',
|
||||||
EpayId: '',
|
StripeWebhookSecret: '',
|
||||||
EpayKey: '',
|
StripePriceId: '',
|
||||||
Price: 7.3,
|
PaymentEnabled: false,
|
||||||
MinTopUp: 1,
|
StripeUnitPrice: 8.0,
|
||||||
|
MinTopUp: 5,
|
||||||
TopupGroupRatio: '',
|
TopupGroupRatio: '',
|
||||||
PayAddress: '',
|
|
||||||
CustomCallbackAddress: '',
|
|
||||||
Footer: '',
|
Footer: '',
|
||||||
WeChatAuthEnabled: '',
|
WeChatAuthEnabled: '',
|
||||||
WeChatServerAddress: '',
|
WeChatServerAddress: '',
|
||||||
@@ -45,6 +48,7 @@ const SystemSetting = () => {
|
|||||||
TurnstileSiteKey: '',
|
TurnstileSiteKey: '',
|
||||||
TurnstileSecretKey: '',
|
TurnstileSecretKey: '',
|
||||||
RegisterEnabled: '',
|
RegisterEnabled: '',
|
||||||
|
UserSelfDeletionEnabled: false,
|
||||||
EmailDomainRestrictionEnabled: '',
|
EmailDomainRestrictionEnabled: '',
|
||||||
EmailAliasRestrictionEnabled: '',
|
EmailAliasRestrictionEnabled: '',
|
||||||
SMTPSSLEnabled: '',
|
SMTPSSLEnabled: '',
|
||||||
@@ -103,6 +107,7 @@ const SystemSetting = () => {
|
|||||||
case 'PasswordRegisterEnabled':
|
case 'PasswordRegisterEnabled':
|
||||||
case 'EmailVerificationEnabled':
|
case 'EmailVerificationEnabled':
|
||||||
case 'GitHubOAuthEnabled':
|
case 'GitHubOAuthEnabled':
|
||||||
|
case 'LinuxDoOAuthEnabled':
|
||||||
case 'WeChatAuthEnabled':
|
case 'WeChatAuthEnabled':
|
||||||
case 'TelegramOAuthEnabled':
|
case 'TelegramOAuthEnabled':
|
||||||
case 'TurnstileCheckEnabled':
|
case 'TurnstileCheckEnabled':
|
||||||
@@ -110,6 +115,8 @@ const SystemSetting = () => {
|
|||||||
case 'EmailAliasRestrictionEnabled':
|
case 'EmailAliasRestrictionEnabled':
|
||||||
case 'SMTPSSLEnabled':
|
case 'SMTPSSLEnabled':
|
||||||
case 'RegisterEnabled':
|
case 'RegisterEnabled':
|
||||||
|
case 'UserSelfDeletionEnabled':
|
||||||
|
case 'PaymentEnabled':
|
||||||
value = inputs[key] === 'true' ? 'false' : 'true';
|
value = inputs[key] === 'true' ? 'false' : 'true';
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -124,9 +131,6 @@ const SystemSetting = () => {
|
|||||||
if (key === 'EmailDomainWhitelist') {
|
if (key === 'EmailDomainWhitelist') {
|
||||||
value = value.split(',');
|
value = value.split(',');
|
||||||
}
|
}
|
||||||
if (key === 'Price') {
|
|
||||||
value = parseFloat(value);
|
|
||||||
}
|
|
||||||
setInputs((inputs) => ({
|
setInputs((inputs) => ({
|
||||||
...inputs,
|
...inputs,
|
||||||
[key]: value,
|
[key]: value,
|
||||||
@@ -147,14 +151,17 @@ const SystemSetting = () => {
|
|||||||
name === 'Notice' ||
|
name === 'Notice' ||
|
||||||
(name.startsWith('SMTP') && name !== 'SMTPSSLEnabled') ||
|
(name.startsWith('SMTP') && name !== 'SMTPSSLEnabled') ||
|
||||||
name === 'ServerAddress' ||
|
name === 'ServerAddress' ||
|
||||||
name === 'WorkerUrl' ||
|
name === 'OutProxyUrl' ||
|
||||||
name === 'WorkerValidKey' ||
|
name === 'StripeApiSecret' ||
|
||||||
name === 'EpayId' ||
|
name === 'StripeWebhookSecret' ||
|
||||||
name === 'EpayKey' ||
|
name === 'StripePriceId' ||
|
||||||
name === 'Price' ||
|
name === 'StripeUnitPrice' ||
|
||||||
name === 'PayAddress' ||
|
name === 'MinTopUp' ||
|
||||||
name === 'GitHubClientId' ||
|
name === 'GitHubClientId' ||
|
||||||
name === 'GitHubClientSecret' ||
|
name === 'GitHubClientSecret' ||
|
||||||
|
name === 'LinuxDoClientId' ||
|
||||||
|
name === 'LinuxDoClientSecret' ||
|
||||||
|
name === 'LinuxDoMinLevel' ||
|
||||||
name === 'WeChatServerAddress' ||
|
name === 'WeChatServerAddress' ||
|
||||||
name === 'WeChatServerToken' ||
|
name === 'WeChatServerToken' ||
|
||||||
name === 'WeChatAccountQRCodeImageURL' ||
|
name === 'WeChatAccountQRCodeImageURL' ||
|
||||||
@@ -176,15 +183,12 @@ const SystemSetting = () => {
|
|||||||
await updateOption('ServerAddress', ServerAddress);
|
await updateOption('ServerAddress', ServerAddress);
|
||||||
};
|
};
|
||||||
|
|
||||||
const submitWorker = async () => {
|
const submitOutProxyUrl = async () => {
|
||||||
let WorkerUrl = removeTrailingSlash(inputs.WorkerUrl);
|
let OutProxyUrl = removeTrailingSlash(inputs.OutProxyUrl);
|
||||||
await updateOption('WorkerUrl', WorkerUrl);
|
await updateOption('OutProxyUrl', OutProxyUrl);
|
||||||
if (inputs.WorkerValidKey !== '') {
|
};
|
||||||
await updateOption('WorkerValidKey', inputs.WorkerValidKey);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const submitPayAddress = async () => {
|
const submitPaymentConfig = async () => {
|
||||||
if (inputs.ServerAddress === '') {
|
if (inputs.ServerAddress === '') {
|
||||||
showError('请先填写服务器地址');
|
showError('请先填写服务器地址');
|
||||||
return;
|
return;
|
||||||
@@ -196,15 +200,31 @@ const SystemSetting = () => {
|
|||||||
}
|
}
|
||||||
await updateOption('TopupGroupRatio', inputs.TopupGroupRatio);
|
await updateOption('TopupGroupRatio', inputs.TopupGroupRatio);
|
||||||
}
|
}
|
||||||
let PayAddress = removeTrailingSlash(inputs.PayAddress);
|
let stripeApiSecret = removeTrailingSlash(inputs.StripeApiSecret);
|
||||||
await updateOption('PayAddress', PayAddress);
|
if (stripeApiSecret && !stripeApiSecret.startsWith('sk_')) {
|
||||||
if (inputs.EpayId !== '') {
|
showError('输入了无效的Stripe API密钥');
|
||||||
await updateOption('EpayId', inputs.EpayId);
|
return;
|
||||||
}
|
}
|
||||||
if (inputs.EpayKey !== undefined && inputs.EpayKey !== '') {
|
stripeApiSecret && (await updateOption('StripeApiSecret', stripeApiSecret));
|
||||||
await updateOption('EpayKey', inputs.EpayKey);
|
|
||||||
|
let stripeWebhookSecret = removeTrailingSlash(inputs.StripeWebhookSecret);
|
||||||
|
if (stripeWebhookSecret && !stripeWebhookSecret.startsWith('whsec_')) {
|
||||||
|
showError('输入了无效的Stripe Webhook签名密钥');
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
await updateOption('Price', '' + inputs.Price);
|
stripeWebhookSecret &&
|
||||||
|
(await updateOption('StripeWebhookSecret', stripeWebhookSecret));
|
||||||
|
|
||||||
|
let stripePriceId = removeTrailingSlash(inputs.StripePriceId);
|
||||||
|
if (stripePriceId && !stripePriceId.startsWith('price_')) {
|
||||||
|
showError('输入了无效的Stripe 物品价格ID');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await updateOption('StripePriceId', stripePriceId);
|
||||||
|
|
||||||
|
await updateOption('PaymentEnable', inputs.PaymentEnabled);
|
||||||
|
await updateOption('StripeUnitPrice', inputs.StripeUnitPrice);
|
||||||
|
await updateOption('MinTopUp', inputs.MinTopUp);
|
||||||
};
|
};
|
||||||
|
|
||||||
const submitSMTP = async () => {
|
const submitSMTP = async () => {
|
||||||
@@ -280,6 +300,21 @@ const SystemSetting = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const submitLinuxDoOAuth = async () => {
|
||||||
|
if (originInputs['LinuxDoClientId'] !== inputs.LinuxDoClientId) {
|
||||||
|
await updateOption('LinuxDoClientId', inputs.LinuxDoClientId);
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
originInputs['LinuxDoClientSecret'] !== inputs.LinuxDoClientSecret &&
|
||||||
|
inputs.LinuxDoClientSecret !== ''
|
||||||
|
) {
|
||||||
|
await updateOption('LinuxDoClientSecret', inputs.LinuxDoClientSecret);
|
||||||
|
}
|
||||||
|
if (originInputs['LinuxDoMinLevel'] !== inputs.LinuxDoMinLevel) {
|
||||||
|
await updateOption('LinuxDoMinLevel', inputs.LinuxDoMinLevel);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const submitTelegramSettings = async () => {
|
const submitTelegramSettings = async () => {
|
||||||
// await updateOption('TelegramOAuthEnabled', inputs.TelegramOAuthEnabled);
|
// await updateOption('TelegramOAuthEnabled', inputs.TelegramOAuthEnabled);
|
||||||
await updateOption('TelegramBotToken', inputs.TelegramBotToken);
|
await updateOption('TelegramBotToken', inputs.TelegramBotToken);
|
||||||
@@ -339,76 +374,88 @@ const SystemSetting = () => {
|
|||||||
<Form.Button onClick={submitServerAddress}>
|
<Form.Button onClick={submitServerAddress}>
|
||||||
更新服务器地址
|
更新服务器地址
|
||||||
</Form.Button>
|
</Form.Button>
|
||||||
<Header as='h3' inverted={isDark}>
|
|
||||||
代理设置(支持 <a href='https://github.com/Calcium-Ion/new-api-worker' target='_blank' rel='noreferrer'>new-api-worker</a>)
|
|
||||||
</Header>
|
|
||||||
<Form.Group widths='equal'>
|
|
||||||
<Form.Input
|
|
||||||
label='Worker地址,不填写则不启用代理'
|
|
||||||
placeholder='例如:https://workername.yourdomain.workers.dev'
|
|
||||||
value={inputs.WorkerUrl}
|
|
||||||
name='WorkerUrl'
|
|
||||||
onChange={handleInputChange}
|
|
||||||
/>
|
|
||||||
<Form.Input
|
|
||||||
label='Worker密钥,根据你部署的 Worker 填写'
|
|
||||||
placeholder='例如:your_secret_key'
|
|
||||||
value={inputs.WorkerValidKey}
|
|
||||||
name='WorkerValidKey'
|
|
||||||
onChange={handleInputChange}
|
|
||||||
/>
|
|
||||||
</Form.Group>
|
|
||||||
<Form.Button onClick={submitWorker}>
|
|
||||||
更新Worker设置
|
|
||||||
</Form.Button>
|
|
||||||
<Divider />
|
<Divider />
|
||||||
<Header as='h3' inverted={isDark}>
|
<Header as='h3' inverted={isDark}>
|
||||||
支付设置(当前仅支持易支付接口,默认使用上方服务器地址作为回调地址!)
|
代理设置
|
||||||
</Header>
|
</Header>
|
||||||
<Form.Group widths='equal'>
|
<Form.Group widths='equal'>
|
||||||
<Form.Input
|
<Form.Input
|
||||||
label='支付地址,不填写则不启用在线支付'
|
label='出口代理地址'
|
||||||
placeholder='例如:https://yourdomain.com'
|
placeholder='例如:http://1.2.3.4:8888'
|
||||||
value={inputs.PayAddress}
|
value={inputs.OutProxyUrl}
|
||||||
name='PayAddress'
|
name='OutProxyUrl'
|
||||||
|
onChange={handleInputChange}
|
||||||
|
/>
|
||||||
|
</Form.Group>
|
||||||
|
<Form.Button onClick={submitOutProxyUrl}>更新代理设置</Form.Button>
|
||||||
|
<Divider />
|
||||||
|
<Header as='h3' inverted={isDark}>
|
||||||
|
支付设置(当前仅支持Stripe Checkout)
|
||||||
|
<Header.Subheader>
|
||||||
|
密钥、Webhook 等设置请
|
||||||
|
<a
|
||||||
|
href='https://dashboard.stripe.com/developers'
|
||||||
|
target='_blank'
|
||||||
|
rel='noreferrer'
|
||||||
|
>
|
||||||
|
点击此处
|
||||||
|
</a>
|
||||||
|
进行设置,最好先在
|
||||||
|
<a
|
||||||
|
href='https://dashboard.stripe.com/test/developers'
|
||||||
|
target='_blank'
|
||||||
|
rel='noreferrer'
|
||||||
|
>
|
||||||
|
测试环境
|
||||||
|
</a>
|
||||||
|
进行测试
|
||||||
|
</Header.Subheader>
|
||||||
|
</Header>
|
||||||
|
<Message>
|
||||||
|
Webhook 填:
|
||||||
|
<code>{`${inputs.ServerAddress}/api/stripe/webhook`}</code>
|
||||||
|
,需要包含事件:<code>checkout.session.completed</code> 和{' '}
|
||||||
|
<code>checkout.session.expired</code>
|
||||||
|
</Message>
|
||||||
|
<Form.Group widths='equal'>
|
||||||
|
<Form.Input
|
||||||
|
label='API密钥'
|
||||||
|
placeholder='sk_xxx的Stripe密钥,敏感信息不显示'
|
||||||
|
value={inputs.StripeApiSecret}
|
||||||
|
name='StripeApiSecret'
|
||||||
onChange={handleInputChange}
|
onChange={handleInputChange}
|
||||||
/>
|
/>
|
||||||
<Form.Input
|
<Form.Input
|
||||||
label='易支付商户ID'
|
label='Webhook签名密钥'
|
||||||
placeholder='例如:0001'
|
placeholder='whsec_xxx的Webhook签名密钥,敏感信息不显示'
|
||||||
value={inputs.EpayId}
|
value={inputs.StripeWebhookSecret}
|
||||||
name='EpayId'
|
name='StripeWebhookSecret'
|
||||||
onChange={handleInputChange}
|
onChange={handleInputChange}
|
||||||
/>
|
/>
|
||||||
<Form.Input
|
<Form.Input
|
||||||
label='易支付商户密钥'
|
label='商品价格ID'
|
||||||
placeholder='敏感信息不会发送到前端显示'
|
placeholder='price_xxx的商品价格ID,新建产品后可获得'
|
||||||
value={inputs.EpayKey}
|
value={inputs.StripePriceId}
|
||||||
name='EpayKey'
|
name='StripePriceId'
|
||||||
onChange={handleInputChange}
|
onChange={handleInputChange}
|
||||||
/>
|
/>
|
||||||
</Form.Group>
|
</Form.Group>
|
||||||
<Form.Group widths='equal'>
|
<Form.Group widths='equal'>
|
||||||
<Form.Input
|
<Form.Input
|
||||||
label='回调地址,不填写则使用上方服务器地址作为回调地址'
|
label='商品单价(元)'
|
||||||
placeholder='例如:https://yourdomain.com'
|
placeholder='商品的人民币价格'
|
||||||
value={inputs.CustomCallbackAddress}
|
value={inputs.StripeUnitPrice}
|
||||||
name='CustomCallbackAddress'
|
name='StripeUnitPrice'
|
||||||
onChange={handleInputChange}
|
type={'number'}
|
||||||
/>
|
|
||||||
<Form.Input
|
|
||||||
label='充值价格(x元/美金)'
|
|
||||||
placeholder='例如:7,就是7元/美金'
|
|
||||||
value={inputs.Price}
|
|
||||||
name='Price'
|
|
||||||
min={0}
|
min={0}
|
||||||
onChange={handleInputChange}
|
onChange={handleInputChange}
|
||||||
/>
|
/>
|
||||||
<Form.Input
|
<Form.Input
|
||||||
label='最低充值美元数量(以美金为单位,如果使用额度请自行换算!)'
|
label='最低充值数量'
|
||||||
placeholder='例如:2,就是最低充值2$'
|
placeholder='例如:2,就是最低充值2件商品'
|
||||||
value={inputs.MinTopUp}
|
value={inputs.MinTopUp}
|
||||||
name='MinTopUp'
|
name='MinTopUp'
|
||||||
|
type={'number'}
|
||||||
min={1}
|
min={1}
|
||||||
onChange={handleInputChange}
|
onChange={handleInputChange}
|
||||||
/>
|
/>
|
||||||
@@ -424,7 +471,17 @@ const SystemSetting = () => {
|
|||||||
placeholder='为一个 JSON 文本,键为组名称,值为倍率'
|
placeholder='为一个 JSON 文本,键为组名称,值为倍率'
|
||||||
/>
|
/>
|
||||||
</Form.Group>
|
</Form.Group>
|
||||||
<Form.Button onClick={submitPayAddress}>更新支付设置</Form.Button>
|
<Form.Group inline>
|
||||||
|
<Form.Button onClick={submitPaymentConfig}>
|
||||||
|
更新支付设置
|
||||||
|
</Form.Button>
|
||||||
|
<Form.Checkbox
|
||||||
|
checked={inputs.PaymentEnabled === 'true'}
|
||||||
|
label='开启在线支付'
|
||||||
|
name='PaymentEnabled'
|
||||||
|
onChange={handleInputChange}
|
||||||
|
/>
|
||||||
|
</Form.Group>
|
||||||
<Divider />
|
<Divider />
|
||||||
<Header as='h3' inverted={isDark}>
|
<Header as='h3' inverted={isDark}>
|
||||||
配置登录注册
|
配置登录注册
|
||||||
@@ -483,6 +540,12 @@ const SystemSetting = () => {
|
|||||||
name='GitHubOAuthEnabled'
|
name='GitHubOAuthEnabled'
|
||||||
onChange={handleInputChange}
|
onChange={handleInputChange}
|
||||||
/>
|
/>
|
||||||
|
<Form.Checkbox
|
||||||
|
checked={inputs.LinuxDoOAuthEnabled === 'true'}
|
||||||
|
label='允许通过 LINUX DO 账户登录 & 注册'
|
||||||
|
name='LinuxDoOAuthEnabled'
|
||||||
|
onChange={handleInputChange}
|
||||||
|
/>
|
||||||
<Form.Checkbox
|
<Form.Checkbox
|
||||||
checked={inputs.WeChatAuthEnabled === 'true'}
|
checked={inputs.WeChatAuthEnabled === 'true'}
|
||||||
label='允许通过微信登录 & 注册'
|
label='允许通过微信登录 & 注册'
|
||||||
@@ -509,6 +572,12 @@ const SystemSetting = () => {
|
|||||||
name='TurnstileCheckEnabled'
|
name='TurnstileCheckEnabled'
|
||||||
onChange={handleInputChange}
|
onChange={handleInputChange}
|
||||||
/>
|
/>
|
||||||
|
<Form.Checkbox
|
||||||
|
checked={inputs.UserSelfDeletionEnabled === 'true'}
|
||||||
|
label='允许用户自行删除账户'
|
||||||
|
name='UserSelfDeletionEnabled'
|
||||||
|
onChange={handleInputChange}
|
||||||
|
/>
|
||||||
</Form.Group>
|
</Form.Group>
|
||||||
<Divider />
|
<Divider />
|
||||||
<Header as='h3' inverted={isDark}>
|
<Header as='h3' inverted={isDark}>
|
||||||
@@ -677,6 +746,58 @@ const SystemSetting = () => {
|
|||||||
保存 GitHub OAuth 设置
|
保存 GitHub OAuth 设置
|
||||||
</Form.Button>
|
</Form.Button>
|
||||||
<Divider />
|
<Divider />
|
||||||
|
<Header as='h3'>
|
||||||
|
配置 LINUX DO Oauth
|
||||||
|
<Header.Subheader>
|
||||||
|
用以支持通过 LINUX DO 进行登录注册,
|
||||||
|
<a
|
||||||
|
href='https://connect.linux.do'
|
||||||
|
target='_blank'
|
||||||
|
rel='noreferrer'
|
||||||
|
>
|
||||||
|
点击此处
|
||||||
|
</a>
|
||||||
|
管理你的 LINUX DO OAuth
|
||||||
|
</Header.Subheader>
|
||||||
|
</Header>
|
||||||
|
<Message>
|
||||||
|
Homepage URL 填 <code>{inputs.ServerAddress}</code>
|
||||||
|
,Authorization callback URL 填{' '}
|
||||||
|
<code>{`${inputs.ServerAddress}/oauth/linuxdo`}</code>
|
||||||
|
</Message>
|
||||||
|
<Form.Group widths={3}>
|
||||||
|
<Form.Input
|
||||||
|
label='LINUX DO Client ID'
|
||||||
|
name='LinuxDoClientId'
|
||||||
|
onChange={handleInputChange}
|
||||||
|
autoComplete='new-password'
|
||||||
|
value={inputs.LinuxDoClientId}
|
||||||
|
placeholder='输入你注册的 LINUX DO OAuth 的 ID'
|
||||||
|
/>
|
||||||
|
<Form.Input
|
||||||
|
label='LINUX DO Client Secret'
|
||||||
|
name='LinuxDoClientSecret'
|
||||||
|
onChange={handleInputChange}
|
||||||
|
type='password'
|
||||||
|
autoComplete='new-password'
|
||||||
|
value={inputs.LinuxDoClientSecret}
|
||||||
|
placeholder='敏感信息不会发送到前端显示'
|
||||||
|
/>
|
||||||
|
<Form.Input
|
||||||
|
label='限制最低信任等级'
|
||||||
|
name='LinuxDoMinLevel'
|
||||||
|
onChange={handleInputChange}
|
||||||
|
type='number'
|
||||||
|
min={0}
|
||||||
|
max={4}
|
||||||
|
value={inputs.LinuxDoMinLevel}
|
||||||
|
placeholder='输入允许使用的最低 LINUX DO 信任等级'
|
||||||
|
/>
|
||||||
|
</Form.Group>
|
||||||
|
<Form.Button onClick={submitLinuxDoOAuth}>
|
||||||
|
保存 LINUX DO OAuth 设置
|
||||||
|
</Form.Button>
|
||||||
|
<Divider />
|
||||||
<Header as='h3' inverted={isDark}>
|
<Header as='h3' inverted={isDark}>
|
||||||
配置 WeChat Server
|
配置 WeChat Server
|
||||||
<Header.Subheader>
|
<Header.Subheader>
|
||||||
|
|||||||
@@ -1,400 +1,512 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import { Label } from 'semantic-ui-react';
|
import { Label } from 'semantic-ui-react';
|
||||||
import { API, copy, isAdmin, showError, showSuccess, timestamp2string } from '../helpers';
|
import {
|
||||||
|
API,
|
||||||
|
copy,
|
||||||
|
isAdmin,
|
||||||
|
showError,
|
||||||
|
showSuccess,
|
||||||
|
timestamp2string,
|
||||||
|
} from '../helpers';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Table,
|
Table,
|
||||||
Tag,
|
Tag,
|
||||||
Form,
|
Form,
|
||||||
Button,
|
Button,
|
||||||
Layout,
|
Layout,
|
||||||
Modal,
|
Modal,
|
||||||
Typography, Progress, Card
|
Typography,
|
||||||
|
Progress,
|
||||||
|
Card,
|
||||||
} from '@douyinfe/semi-ui';
|
} from '@douyinfe/semi-ui';
|
||||||
import { ITEMS_PER_PAGE } from '../constants';
|
import { ITEMS_PER_PAGE } from '../constants';
|
||||||
|
|
||||||
const colors = ['amber', 'blue', 'cyan', 'green', 'grey', 'indigo',
|
const colors = [
|
||||||
'light-blue', 'lime', 'orange', 'pink',
|
'amber',
|
||||||
'purple', 'red', 'teal', 'violet', 'yellow'
|
'blue',
|
||||||
]
|
'cyan',
|
||||||
|
'green',
|
||||||
|
'grey',
|
||||||
|
'indigo',
|
||||||
|
'light-blue',
|
||||||
|
'lime',
|
||||||
|
'orange',
|
||||||
|
'pink',
|
||||||
|
'purple',
|
||||||
|
'red',
|
||||||
|
'teal',
|
||||||
|
'violet',
|
||||||
|
'yellow',
|
||||||
|
];
|
||||||
|
|
||||||
const renderTimestamp = (timestampInSeconds) => {
|
const renderTimestamp = (timestampInSeconds) => {
|
||||||
const date = new Date(timestampInSeconds * 1000); // 从秒转换为毫秒
|
const date = new Date(timestampInSeconds * 1000); // 从秒转换为毫秒
|
||||||
|
|
||||||
const year = date.getFullYear(); // 获取年份
|
const year = date.getFullYear(); // 获取年份
|
||||||
const month = ('0' + (date.getMonth() + 1)).slice(-2); // 获取月份,从0开始需要+1,并保证两位数
|
const month = ('0' + (date.getMonth() + 1)).slice(-2); // 获取月份,从0开始需要+1,并保证两位数
|
||||||
const day = ('0' + date.getDate()).slice(-2); // 获取日期,并保证两位数
|
const day = ('0' + date.getDate()).slice(-2); // 获取日期,并保证两位数
|
||||||
const hours = ('0' + date.getHours()).slice(-2); // 获取小时,并保证两位数
|
const hours = ('0' + date.getHours()).slice(-2); // 获取小时,并保证两位数
|
||||||
const minutes = ('0' + date.getMinutes()).slice(-2); // 获取分钟,并保证两位数
|
const minutes = ('0' + date.getMinutes()).slice(-2); // 获取分钟,并保证两位数
|
||||||
const seconds = ('0' + date.getSeconds()).slice(-2); // 获取秒钟,并保证两位数
|
const seconds = ('0' + date.getSeconds()).slice(-2); // 获取秒钟,并保证两位数
|
||||||
|
|
||||||
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; // 格式化输出
|
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; // 格式化输出
|
||||||
};
|
};
|
||||||
|
|
||||||
function renderDuration(submit_time, finishTime) {
|
function renderDuration(submit_time, finishTime) {
|
||||||
// 确保startTime和finishTime都是有效的时间戳
|
// 确保startTime和finishTime都是有效的时间戳
|
||||||
if (!submit_time || !finishTime) return 'N/A';
|
if (!submit_time || !finishTime) return 'N/A';
|
||||||
|
|
||||||
// 将时间戳转换为Date对象
|
// 将时间戳转换为Date对象
|
||||||
const start = new Date(submit_time);
|
const start = new Date(submit_time);
|
||||||
const finish = new Date(finishTime);
|
const finish = new Date(finishTime);
|
||||||
|
|
||||||
// 计算时间差(毫秒)
|
// 计算时间差(毫秒)
|
||||||
const durationMs = finish - start;
|
const durationMs = finish - start;
|
||||||
|
|
||||||
// 将时间差转换为秒,并保留一位小数
|
// 将时间差转换为秒,并保留一位小数
|
||||||
const durationSec = (durationMs / 1000).toFixed(1);
|
const durationSec = (durationMs / 1000).toFixed(1);
|
||||||
|
|
||||||
// 设置颜色:大于60秒则为红色,小于等于60秒则为绿色
|
// 设置颜色:大于60秒则为红色,小于等于60秒则为绿色
|
||||||
const color = durationSec > 60 ? 'red' : 'green';
|
const color = durationSec > 60 ? 'red' : 'green';
|
||||||
|
|
||||||
// 返回带有样式的颜色标签
|
// 返回带有样式的颜色标签
|
||||||
return (
|
return (
|
||||||
<Tag color={color} size="large">
|
<Tag color={color} size='large'>
|
||||||
{durationSec} 秒
|
{durationSec} 秒
|
||||||
</Tag>
|
</Tag>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const LogsTable = () => {
|
const LogsTable = () => {
|
||||||
const [isModalOpen, setIsModalOpen] = useState(false);
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
||||||
const [modalContent, setModalContent] = useState('');
|
const [modalContent, setModalContent] = useState('');
|
||||||
const isAdminUser = isAdmin();
|
const isAdminUser = isAdmin();
|
||||||
const columns = [
|
const columns = [
|
||||||
{
|
{
|
||||||
title: "提交时间",
|
title: '提交时间',
|
||||||
dataIndex: 'submit_time',
|
dataIndex: 'submit_time',
|
||||||
render: (text, record, index) => {
|
render: (text, record, index) => {
|
||||||
return (
|
return <div>{text ? renderTimestamp(text) : '-'}</div>;
|
||||||
<div>
|
},
|
||||||
{text ? renderTimestamp(text) : "-"}
|
},
|
||||||
</div>
|
{
|
||||||
);
|
title: '结束时间',
|
||||||
},
|
dataIndex: 'finish_time',
|
||||||
},
|
render: (text, record, index) => {
|
||||||
{
|
return <div>{text ? renderTimestamp(text) : '-'}</div>;
|
||||||
title: "结束时间",
|
},
|
||||||
dataIndex: 'finish_time',
|
},
|
||||||
render: (text, record, index) => {
|
{
|
||||||
return (
|
title: '进度',
|
||||||
<div>
|
dataIndex: 'progress',
|
||||||
{text ? renderTimestamp(text) : "-"}
|
width: 50,
|
||||||
</div>
|
render: (text, record, index) => {
|
||||||
);
|
return (
|
||||||
},
|
<div>
|
||||||
},
|
{
|
||||||
{
|
// 转换例如100%为数字100,如果text未定义,返回0
|
||||||
title: '进度',
|
isNaN(text.replace('%', '')) ? (
|
||||||
dataIndex: 'progress',
|
text
|
||||||
width: 50,
|
) : (
|
||||||
render: (text, record, index) => {
|
<Progress
|
||||||
return (
|
width={42}
|
||||||
<div>
|
type='circle'
|
||||||
{
|
showInfo={true}
|
||||||
// 转换例如100%为数字100,如果text未定义,返回0
|
percent={Number(text.replace('%', '') || 0)}
|
||||||
isNaN(text.replace('%', '')) ? text : <Progress width={42} type="circle" showInfo={true} percent={Number(text.replace('%', '') || 0)} aria-label="drawing progress" />
|
aria-label='drawing progress'
|
||||||
}
|
/>
|
||||||
</div>
|
)
|
||||||
);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '花费时间',
|
|
||||||
dataIndex: 'finish_time', // 以finish_time作为dataIndex
|
|
||||||
key: 'finish_time',
|
|
||||||
render: (finish, record) => {
|
|
||||||
// 假设record.start_time是存在的,并且finish是完成时间的时间戳
|
|
||||||
return <>
|
|
||||||
{
|
|
||||||
finish ? renderDuration(record.submit_time, finish) : "-"
|
|
||||||
}
|
|
||||||
</>
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "渠道",
|
|
||||||
dataIndex: 'channel_id',
|
|
||||||
className: isAdminUser ? 'tableShow' : 'tableHiddle',
|
|
||||||
render: (text, record, index) => {
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<Tag
|
|
||||||
color={colors[parseInt(text) % colors.length]}
|
|
||||||
size='large'
|
|
||||||
onClick={() => {
|
|
||||||
copyText(text); // 假设copyText是用于文本复制的函数
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{' '}
|
|
||||||
{text}{' '}
|
|
||||||
</Tag>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "平台",
|
|
||||||
dataIndex: 'platform',
|
|
||||||
render: (text, record, index) => {
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
{renderPlatform(text)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '类型',
|
|
||||||
dataIndex: 'action',
|
|
||||||
render: (text, record, index) => {
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
{renderType(text)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '任务ID(点击查看详情)',
|
|
||||||
dataIndex: 'task_id',
|
|
||||||
render: (text, record, index) => {
|
|
||||||
return (<Typography.Text
|
|
||||||
ellipsis={{ showTooltip: true }}
|
|
||||||
//style={{width: 100}}
|
|
||||||
onClick={() => {
|
|
||||||
setModalContent(JSON.stringify(record, null, 2));
|
|
||||||
setIsModalOpen(true);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div>
|
|
||||||
{text}
|
|
||||||
</div>
|
|
||||||
</Typography.Text>);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '任务状态',
|
|
||||||
dataIndex: 'status',
|
|
||||||
render: (text, record, index) => {
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
{renderStatus(text)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
title: '失败原因',
|
|
||||||
dataIndex: 'fail_reason',
|
|
||||||
render: (text, record, index) => {
|
|
||||||
// 如果text未定义,返回替代文本,例如空字符串''或其他
|
|
||||||
if (!text) {
|
|
||||||
return '无';
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Typography.Text
|
|
||||||
ellipsis={{ showTooltip: true }}
|
|
||||||
style={{ width: 100 }}
|
|
||||||
onClick={() => {
|
|
||||||
setModalContent(text);
|
|
||||||
setIsModalOpen(true);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{text}
|
|
||||||
</Typography.Text>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '花费时间',
|
||||||
|
dataIndex: 'finish_time', // 以finish_time作为dataIndex
|
||||||
|
key: 'finish_time',
|
||||||
|
render: (finish, record) => {
|
||||||
|
// 假设record.start_time是存在的,并且finish是完成时间的时间戳
|
||||||
|
return <>{finish ? renderDuration(record.submit_time, finish) : '-'}</>;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '渠道',
|
||||||
|
dataIndex: 'channel_id',
|
||||||
|
className: isAdminUser ? 'tableShow' : 'tableHiddle',
|
||||||
|
render: (text, record, index) => {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Tag
|
||||||
|
color={colors[parseInt(text) % colors.length]}
|
||||||
|
size='large'
|
||||||
|
onClick={() => {
|
||||||
|
copyText(text); // 假设copyText是用于文本复制的函数
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{' '}
|
||||||
|
{text}{' '}
|
||||||
|
</Tag>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '平台',
|
||||||
|
dataIndex: 'platform',
|
||||||
|
render: (text, record, index) => {
|
||||||
|
return <div>{renderPlatform(text)}</div>;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '类型',
|
||||||
|
dataIndex: 'action',
|
||||||
|
render: (text, record, index) => {
|
||||||
|
return <div>{renderType(text)}</div>;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '任务ID(点击查看详情)',
|
||||||
|
dataIndex: 'task_id',
|
||||||
|
render: (text, record, index) => {
|
||||||
|
return (
|
||||||
|
<Typography.Text
|
||||||
|
ellipsis={{ showTooltip: true }}
|
||||||
|
//style={{width: 100}}
|
||||||
|
onClick={() => {
|
||||||
|
setModalContent(JSON.stringify(record, null, 2));
|
||||||
|
setIsModalOpen(true);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div>{text}</div>
|
||||||
|
</Typography.Text>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '任务状态',
|
||||||
|
dataIndex: 'status',
|
||||||
|
render: (text, record, index) => {
|
||||||
|
return <div>{renderStatus(text)}</div>;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
title: '失败原因',
|
||||||
|
dataIndex: 'fail_reason',
|
||||||
|
render: (text, record, index) => {
|
||||||
|
// 如果text未定义,返回替代文本,例如空字符串''或其他
|
||||||
|
if (!text) {
|
||||||
|
return '无';
|
||||||
}
|
}
|
||||||
];
|
|
||||||
|
|
||||||
const [logs, setLogs] = useState([]);
|
return (
|
||||||
const [loading, setLoading] = useState(true);
|
<Typography.Text
|
||||||
const [activePage, setActivePage] = useState(1);
|
ellipsis={{ showTooltip: true }}
|
||||||
const [logCount, setLogCount] = useState(ITEMS_PER_PAGE);
|
style={{ width: 100 }}
|
||||||
const [logType] = useState(0);
|
onClick={() => {
|
||||||
|
setModalContent(text);
|
||||||
|
setIsModalOpen(true);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{text}
|
||||||
|
</Typography.Text>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
let now = new Date();
|
const [logs, setLogs] = useState([]);
|
||||||
// 初始化start_timestamp为前一天
|
const [loading, setLoading] = useState(true);
|
||||||
let zeroNow = new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
const [activePage, setActivePage] = useState(1);
|
||||||
const [inputs, setInputs] = useState({
|
const [logCount, setLogCount] = useState(ITEMS_PER_PAGE);
|
||||||
channel_id: '',
|
const [logType] = useState(0);
|
||||||
task_id: '',
|
|
||||||
start_timestamp: timestamp2string(zeroNow.getTime() /1000),
|
|
||||||
end_timestamp: '',
|
|
||||||
});
|
|
||||||
const { channel_id, task_id, start_timestamp, end_timestamp } = inputs;
|
|
||||||
|
|
||||||
const handleInputChange = (value, name) => {
|
let now = new Date();
|
||||||
setInputs((inputs) => ({ ...inputs, [name]: value }));
|
// 初始化start_timestamp为前一天
|
||||||
};
|
let zeroNow = new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
||||||
|
const [inputs, setInputs] = useState({
|
||||||
|
channel_id: '',
|
||||||
|
task_id: '',
|
||||||
|
start_timestamp: timestamp2string(zeroNow.getTime() / 1000),
|
||||||
|
end_timestamp: '',
|
||||||
|
});
|
||||||
|
const { channel_id, task_id, start_timestamp, end_timestamp } = inputs;
|
||||||
|
|
||||||
|
const handleInputChange = (value, name) => {
|
||||||
|
setInputs((inputs) => ({ ...inputs, [name]: value }));
|
||||||
|
};
|
||||||
|
|
||||||
const setLogsFormat = (logs) => {
|
const setLogsFormat = (logs) => {
|
||||||
for (let i = 0; i < logs.length; i++) {
|
for (let i = 0; i < logs.length; i++) {
|
||||||
logs[i].timestamp2string = timestamp2string(logs[i].created_at);
|
logs[i].timestamp2string = timestamp2string(logs[i].created_at);
|
||||||
logs[i].key = '' + logs[i].id;
|
logs[i].key = '' + logs[i].id;
|
||||||
}
|
|
||||||
// data.key = '' + data.id
|
|
||||||
setLogs(logs);
|
|
||||||
setLogCount(logs.length + ITEMS_PER_PAGE);
|
|
||||||
// console.log(logCount);
|
|
||||||
}
|
}
|
||||||
|
// data.key = '' + data.id
|
||||||
|
setLogs(logs);
|
||||||
|
setLogCount(logs.length + ITEMS_PER_PAGE);
|
||||||
|
// console.log(logCount);
|
||||||
|
};
|
||||||
|
|
||||||
const loadLogs = async (startIdx) => {
|
const loadLogs = async (startIdx) => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
|
||||||
let url = '';
|
let url = '';
|
||||||
let localStartTimestamp = parseInt(Date.parse(start_timestamp) / 1000);
|
let localStartTimestamp = parseInt(Date.parse(start_timestamp) / 1000);
|
||||||
let localEndTimestamp = parseInt(Date.parse(end_timestamp) / 1000 );
|
let localEndTimestamp = parseInt(Date.parse(end_timestamp) / 1000);
|
||||||
if (isAdminUser) {
|
if (isAdminUser) {
|
||||||
url = `/api/task/?p=${startIdx}&channel_id=${channel_id}&task_id=${task_id}&start_timestamp=${localStartTimestamp}&end_timestamp=${localEndTimestamp}`;
|
url = `/api/task/?p=${startIdx}&channel_id=${channel_id}&task_id=${task_id}&start_timestamp=${localStartTimestamp}&end_timestamp=${localEndTimestamp}`;
|
||||||
} else {
|
} else {
|
||||||
url = `/api/task/self?p=${startIdx}&task_id=${task_id}&start_timestamp=${localStartTimestamp}&end_timestamp=${localEndTimestamp}`;
|
url = `/api/task/self?p=${startIdx}&task_id=${task_id}&start_timestamp=${localStartTimestamp}&end_timestamp=${localEndTimestamp}`;
|
||||||
}
|
|
||||||
const res = await API.get(url);
|
|
||||||
let { success, message, data } = res.data;
|
|
||||||
if (success) {
|
|
||||||
if (startIdx === 0) {
|
|
||||||
setLogsFormat(data);
|
|
||||||
} else {
|
|
||||||
let newLogs = [...logs];
|
|
||||||
newLogs.splice(startIdx * ITEMS_PER_PAGE, data.length, ...data);
|
|
||||||
setLogsFormat(newLogs);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
showError(message);
|
|
||||||
}
|
|
||||||
setLoading(false);
|
|
||||||
};
|
|
||||||
|
|
||||||
const pageData = logs.slice((activePage - 1) * ITEMS_PER_PAGE, activePage * ITEMS_PER_PAGE);
|
|
||||||
|
|
||||||
const handlePageChange = page => {
|
|
||||||
setActivePage(page);
|
|
||||||
if (page === Math.ceil(logs.length / ITEMS_PER_PAGE) + 1) {
|
|
||||||
// In this case we have to load more data and then append them.
|
|
||||||
loadLogs(page - 1).then(r => {
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const refresh = async () => {
|
|
||||||
// setLoading(true);
|
|
||||||
setActivePage(1);
|
|
||||||
await loadLogs(0);
|
|
||||||
};
|
|
||||||
|
|
||||||
const copyText = async (text) => {
|
|
||||||
if (await copy(text)) {
|
|
||||||
showSuccess('已复制:' + text);
|
|
||||||
} else {
|
|
||||||
// setSearchKeyword(text);
|
|
||||||
Modal.error({ title: "无法复制到剪贴板,请手动复制", content: text });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
const res = await API.get(url);
|
||||||
useEffect(() => {
|
let { success, message, data } = res.data;
|
||||||
refresh().then();
|
if (success) {
|
||||||
}, [logType]);
|
if (startIdx === 0) {
|
||||||
|
setLogsFormat(data);
|
||||||
const renderType = (type) => {
|
} else {
|
||||||
switch (type) {
|
let newLogs = [...logs];
|
||||||
case 'MUSIC':
|
newLogs.splice(startIdx * ITEMS_PER_PAGE, data.length, ...data);
|
||||||
return <Label basic color='grey'> 生成音乐 </Label>;
|
setLogsFormat(newLogs);
|
||||||
case 'LYRICS':
|
}
|
||||||
return <Label basic color='pink'> 生成歌词 </Label>;
|
} else {
|
||||||
|
showError(message);
|
||||||
default:
|
|
||||||
return <Label basic color='black'> 未知 </Label>;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
setLoading(false);
|
||||||
|
};
|
||||||
|
|
||||||
const renderPlatform = (type) => {
|
const pageData = logs.slice(
|
||||||
switch (type) {
|
(activePage - 1) * ITEMS_PER_PAGE,
|
||||||
case "suno":
|
activePage * ITEMS_PER_PAGE,
|
||||||
return <Label basic color='green'> Suno </Label>;
|
);
|
||||||
default:
|
|
||||||
return <Label basic color='black'> 未知 </Label>;
|
const handlePageChange = (page) => {
|
||||||
}
|
setActivePage(page);
|
||||||
|
if (page === Math.ceil(logs.length / ITEMS_PER_PAGE) + 1) {
|
||||||
|
// In this case we have to load more data and then append them.
|
||||||
|
loadLogs(page - 1).then((r) => {});
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const renderStatus = (type) => {
|
const refresh = async () => {
|
||||||
switch (type) {
|
// setLoading(true);
|
||||||
case 'SUCCESS':
|
setActivePage(1);
|
||||||
return <Label basic color='green'> 成功 </Label>;
|
await loadLogs(0);
|
||||||
case 'NOT_START':
|
};
|
||||||
return <Label basic color='black'> 未启动 </Label>;
|
|
||||||
case 'SUBMITTED':
|
const copyText = async (text) => {
|
||||||
return <Label basic color='yellow'> 队列中 </Label>;
|
if (await copy(text)) {
|
||||||
case 'IN_PROGRESS':
|
showSuccess('已复制:' + text);
|
||||||
return <Label basic color='blue'> 执行中 </Label>;
|
} else {
|
||||||
case 'FAILURE':
|
// setSearchKeyword(text);
|
||||||
return <Label basic color='red'> 失败 </Label>;
|
Modal.error({ title: '无法复制到剪贴板,请手动复制', content: text });
|
||||||
case 'QUEUED':
|
|
||||||
return <Label basic color='red'> 排队中 </Label>;
|
|
||||||
case 'UNKNOWN':
|
|
||||||
return <Label basic color='red'> 未知 </Label>;
|
|
||||||
case '':
|
|
||||||
return <Label basic color='black'> 正在提交 </Label>;
|
|
||||||
default:
|
|
||||||
return <Label basic color='black'> 未知 </Label>;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
useEffect(() => {
|
||||||
<>
|
refresh().then();
|
||||||
|
}, [logType]);
|
||||||
|
|
||||||
<Layout>
|
const renderType = (type) => {
|
||||||
<Form layout='horizontal' labelPosition='inset'>
|
switch (type) {
|
||||||
<>
|
case 'MUSIC':
|
||||||
{isAdminUser && <Form.Input field="channel_id" label='渠道 ID' style={{ width: '236px', marginBottom: '10px' }} value={channel_id}
|
return (
|
||||||
placeholder={'可选值'} name='channel_id'
|
<Label basic color='grey'>
|
||||||
onChange={value => handleInputChange(value, 'channel_id')} />
|
{' '}
|
||||||
}
|
生成音乐{' '}
|
||||||
<Form.Input field="task_id" label={"任务 ID"} style={{ width: '236px', marginBottom: '10px' }} value={task_id}
|
</Label>
|
||||||
placeholder={"可选值"}
|
);
|
||||||
name='task_id'
|
case 'LYRICS':
|
||||||
onChange={value => handleInputChange(value, 'task_id')} />
|
return (
|
||||||
|
<Label basic color='pink'>
|
||||||
|
{' '}
|
||||||
|
生成歌词{' '}
|
||||||
|
</Label>
|
||||||
|
);
|
||||||
|
|
||||||
<Form.DatePicker field="start_timestamp" label={"起始时间"} style={{ width: '236px', marginBottom: '10px' }}
|
default:
|
||||||
initValue={start_timestamp}
|
return (
|
||||||
value={start_timestamp} type='dateTime'
|
<Label basic color='black'>
|
||||||
name='start_timestamp'
|
{' '}
|
||||||
onChange={value => handleInputChange(value, 'start_timestamp')} />
|
未知{' '}
|
||||||
<Form.DatePicker field="end_timestamp" fluid label={"结束时间"} style={{ width: '236px', marginBottom: '10px' }}
|
</Label>
|
||||||
initValue={end_timestamp}
|
);
|
||||||
value={end_timestamp} type='dateTime'
|
}
|
||||||
name='end_timestamp'
|
};
|
||||||
onChange={value => handleInputChange(value, 'end_timestamp')} />
|
|
||||||
<Button label={"查询"} type="primary" htmlType="submit" className="btn-margin-right"
|
const renderPlatform = (type) => {
|
||||||
onClick={refresh}>查询</Button>
|
switch (type) {
|
||||||
</>
|
case 'suno':
|
||||||
</Form>
|
return (
|
||||||
<Card>
|
<Label basic color='green'>
|
||||||
<Table columns={columns} dataSource={pageData} pagination={{
|
{' '}
|
||||||
currentPage: activePage,
|
Suno{' '}
|
||||||
pageSize: ITEMS_PER_PAGE,
|
</Label>
|
||||||
total: logCount,
|
);
|
||||||
pageSizeOpts: [10, 20, 50, 100],
|
default:
|
||||||
onPageChange: handlePageChange,
|
return (
|
||||||
}} loading={loading} />
|
<Label basic color='black'>
|
||||||
</Card>
|
{' '}
|
||||||
<Modal
|
未知{' '}
|
||||||
visible={isModalOpen}
|
</Label>
|
||||||
onOk={() => setIsModalOpen(false)}
|
);
|
||||||
onCancel={() => setIsModalOpen(false)}
|
}
|
||||||
closable={null}
|
};
|
||||||
bodyStyle={{ height: '400px', overflow: 'auto' }} // 设置模态框内容区域样式
|
|
||||||
width={800} // 设置模态框宽度
|
const renderStatus = (type) => {
|
||||||
>
|
switch (type) {
|
||||||
<p style={{ whiteSpace: 'pre-line' }}>{modalContent}</p>
|
case 'SUCCESS':
|
||||||
</Modal>
|
return (
|
||||||
</Layout>
|
<Label basic color='green'>
|
||||||
</>
|
{' '}
|
||||||
);
|
成功{' '}
|
||||||
|
</Label>
|
||||||
|
);
|
||||||
|
case 'NOT_START':
|
||||||
|
return (
|
||||||
|
<Label basic color='black'>
|
||||||
|
{' '}
|
||||||
|
未启动{' '}
|
||||||
|
</Label>
|
||||||
|
);
|
||||||
|
case 'SUBMITTED':
|
||||||
|
return (
|
||||||
|
<Label basic color='yellow'>
|
||||||
|
{' '}
|
||||||
|
队列中{' '}
|
||||||
|
</Label>
|
||||||
|
);
|
||||||
|
case 'IN_PROGRESS':
|
||||||
|
return (
|
||||||
|
<Label basic color='blue'>
|
||||||
|
{' '}
|
||||||
|
执行中{' '}
|
||||||
|
</Label>
|
||||||
|
);
|
||||||
|
case 'FAILURE':
|
||||||
|
return (
|
||||||
|
<Label basic color='red'>
|
||||||
|
{' '}
|
||||||
|
失败{' '}
|
||||||
|
</Label>
|
||||||
|
);
|
||||||
|
case 'QUEUED':
|
||||||
|
return (
|
||||||
|
<Label basic color='red'>
|
||||||
|
{' '}
|
||||||
|
排队中{' '}
|
||||||
|
</Label>
|
||||||
|
);
|
||||||
|
case 'UNKNOWN':
|
||||||
|
return (
|
||||||
|
<Label basic color='red'>
|
||||||
|
{' '}
|
||||||
|
未知{' '}
|
||||||
|
</Label>
|
||||||
|
);
|
||||||
|
case '':
|
||||||
|
return (
|
||||||
|
<Label basic color='black'>
|
||||||
|
{' '}
|
||||||
|
正在提交{' '}
|
||||||
|
</Label>
|
||||||
|
);
|
||||||
|
default:
|
||||||
|
return (
|
||||||
|
<Label basic color='black'>
|
||||||
|
{' '}
|
||||||
|
未知{' '}
|
||||||
|
</Label>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Layout>
|
||||||
|
<Form layout='horizontal' labelPosition='inset'>
|
||||||
|
<>
|
||||||
|
{isAdminUser && (
|
||||||
|
<Form.Input
|
||||||
|
field='channel_id'
|
||||||
|
label='渠道 ID'
|
||||||
|
style={{ width: '236px', marginBottom: '10px' }}
|
||||||
|
value={channel_id}
|
||||||
|
placeholder={'可选值'}
|
||||||
|
name='channel_id'
|
||||||
|
onChange={(value) => handleInputChange(value, 'channel_id')}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
<Form.Input
|
||||||
|
field='task_id'
|
||||||
|
label={'任务 ID'}
|
||||||
|
style={{ width: '236px', marginBottom: '10px' }}
|
||||||
|
value={task_id}
|
||||||
|
placeholder={'可选值'}
|
||||||
|
name='task_id'
|
||||||
|
onChange={(value) => handleInputChange(value, 'task_id')}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Form.DatePicker
|
||||||
|
field='start_timestamp'
|
||||||
|
label={'起始时间'}
|
||||||
|
style={{ width: '236px', marginBottom: '10px' }}
|
||||||
|
initValue={start_timestamp}
|
||||||
|
value={start_timestamp}
|
||||||
|
type='dateTime'
|
||||||
|
name='start_timestamp'
|
||||||
|
onChange={(value) => handleInputChange(value, 'start_timestamp')}
|
||||||
|
/>
|
||||||
|
<Form.DatePicker
|
||||||
|
field='end_timestamp'
|
||||||
|
fluid
|
||||||
|
label={'结束时间'}
|
||||||
|
style={{ width: '236px', marginBottom: '10px' }}
|
||||||
|
initValue={end_timestamp}
|
||||||
|
value={end_timestamp}
|
||||||
|
type='dateTime'
|
||||||
|
name='end_timestamp'
|
||||||
|
onChange={(value) => handleInputChange(value, 'end_timestamp')}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
label={'查询'}
|
||||||
|
type='primary'
|
||||||
|
htmlType='submit'
|
||||||
|
className='btn-margin-right'
|
||||||
|
onClick={refresh}
|
||||||
|
>
|
||||||
|
查询
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
</Form>
|
||||||
|
<Card>
|
||||||
|
<Table
|
||||||
|
columns={columns}
|
||||||
|
dataSource={pageData}
|
||||||
|
pagination={{
|
||||||
|
currentPage: activePage,
|
||||||
|
pageSize: ITEMS_PER_PAGE,
|
||||||
|
total: logCount,
|
||||||
|
pageSizeOpts: [10, 20, 50, 100],
|
||||||
|
onPageChange: handlePageChange,
|
||||||
|
}}
|
||||||
|
loading={loading}
|
||||||
|
/>
|
||||||
|
</Card>
|
||||||
|
<Modal
|
||||||
|
visible={isModalOpen}
|
||||||
|
onOk={() => setIsModalOpen(false)}
|
||||||
|
onCancel={() => setIsModalOpen(false)}
|
||||||
|
closable={null}
|
||||||
|
bodyStyle={{ height: '400px', overflow: 'auto' }} // 设置模态框内容区域样式
|
||||||
|
width={800} // 设置模态框宽度
|
||||||
|
>
|
||||||
|
<p style={{ whiteSpace: 'pre-line' }}>{modalContent}</p>
|
||||||
|
</Modal>
|
||||||
|
</Layout>
|
||||||
|
</>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default LogsTable;
|
export default LogsTable;
|
||||||
|
|||||||
@@ -351,7 +351,9 @@ const UsersTable = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setSearching(true);
|
setSearching(true);
|
||||||
const res = await API.get(`/api/user/search?keyword=${searchKeyword}&group=${searchGroup}`);
|
const res = await API.get(
|
||||||
|
`/api/user/search?keyword=${searchKeyword}&group=${searchGroup}`,
|
||||||
|
);
|
||||||
const { success, message, data } = res.data;
|
const { success, message, data } = res.data;
|
||||||
if (success) {
|
if (success) {
|
||||||
setUsers(data);
|
setUsers(data);
|
||||||
@@ -452,34 +454,34 @@ const UsersTable = () => {
|
|||||||
>
|
>
|
||||||
<div style={{ display: 'flex' }}>
|
<div style={{ display: 'flex' }}>
|
||||||
<Space>
|
<Space>
|
||||||
<Form.Input
|
<Form.Input
|
||||||
label='搜索关键字'
|
label='搜索关键字'
|
||||||
icon='search'
|
icon='search'
|
||||||
field='keyword'
|
field='keyword'
|
||||||
iconPosition='left'
|
iconPosition='left'
|
||||||
placeholder='搜索用户的 ID,用户名,显示名称,以及邮箱地址 ...'
|
placeholder='搜索用户的 ID,用户名,显示名称,以及邮箱地址 ...'
|
||||||
value={searchKeyword}
|
value={searchKeyword}
|
||||||
loading={searching}
|
loading={searching}
|
||||||
onChange={(value) => handleKeywordChange(value)}
|
onChange={(value) => handleKeywordChange(value)}
|
||||||
/>
|
/>
|
||||||
<Form.Select
|
<Form.Select
|
||||||
field='group'
|
field='group'
|
||||||
label='分组'
|
label='分组'
|
||||||
optionList={groupOptions}
|
optionList={groupOptions}
|
||||||
onChange={(value) => {
|
onChange={(value) => {
|
||||||
setSearchGroup(value);
|
setSearchGroup(value);
|
||||||
searchUsers(searchKeyword, value);
|
searchUsers(searchKeyword, value);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<Button
|
<Button
|
||||||
label='查询'
|
label='查询'
|
||||||
type='primary'
|
type='primary'
|
||||||
htmlType='submit'
|
htmlType='submit'
|
||||||
className='btn-margin-right'
|
className='btn-margin-right'
|
||||||
style={{ marginRight: 8 }}
|
style={{ marginRight: 8 }}
|
||||||
>
|
>
|
||||||
查询
|
查询
|
||||||
</Button>
|
</Button>
|
||||||
</Space>
|
</Space>
|
||||||
</div>
|
</div>
|
||||||
</Form>
|
</Form>
|
||||||
|
|||||||
@@ -14,9 +14,13 @@ export async function getOAuthState() {
|
|||||||
export async function onGitHubOAuthClicked(github_client_id) {
|
export async function onGitHubOAuthClicked(github_client_id) {
|
||||||
const state = await getOAuthState();
|
const state = await getOAuthState();
|
||||||
if (!state) return;
|
if (!state) return;
|
||||||
window.open(
|
location.href = `https://github.com/login/oauth/authorize?client_id=${github_client_id}&state=${state}&scope=user:email`;
|
||||||
`https://github.com/login/oauth/authorize?client_id=${github_client_id}&state=${state}&scope=user:email`,
|
}
|
||||||
);
|
|
||||||
|
export async function onLinuxDoOAuthClicked(linuxdo_client_id) {
|
||||||
|
const state = await getOAuthState();
|
||||||
|
if (!state) return;
|
||||||
|
location.href = `https://connect.linux.do/oauth2/authorize?client_id=${linuxdo_client_id}&response_type=code&state=${state}&scope=user:profile`;
|
||||||
}
|
}
|
||||||
|
|
||||||
let channelModels = undefined;
|
let channelModels = undefined;
|
||||||
|
|||||||
@@ -5,21 +5,21 @@ export const CHANNEL_OPTIONS = [
|
|||||||
text: 'Midjourney Proxy',
|
text: 'Midjourney Proxy',
|
||||||
value: 2,
|
value: 2,
|
||||||
color: 'light-blue',
|
color: 'light-blue',
|
||||||
label: 'Midjourney Proxy'
|
label: 'Midjourney Proxy',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 5,
|
key: 5,
|
||||||
text: 'Midjourney Proxy Plus',
|
text: 'Midjourney Proxy Plus',
|
||||||
value: 5,
|
value: 5,
|
||||||
color: 'blue',
|
color: 'blue',
|
||||||
label: 'Midjourney Proxy Plus'
|
label: 'Midjourney Proxy Plus',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 36,
|
key: 36,
|
||||||
text: 'Suno API',
|
text: 'Suno API',
|
||||||
value: 36,
|
value: 36,
|
||||||
color: 'purple',
|
color: 'purple',
|
||||||
label: 'Suno API'
|
label: 'Suno API',
|
||||||
},
|
},
|
||||||
{ key: 4, text: 'Ollama', value: 4, color: 'grey', label: 'Ollama' },
|
{ key: 4, text: 'Ollama', value: 4, color: 'grey', label: 'Ollama' },
|
||||||
{
|
{
|
||||||
@@ -27,14 +27,14 @@ export const CHANNEL_OPTIONS = [
|
|||||||
text: 'Anthropic Claude',
|
text: 'Anthropic Claude',
|
||||||
value: 14,
|
value: 14,
|
||||||
color: 'indigo',
|
color: 'indigo',
|
||||||
label: 'Anthropic Claude'
|
label: 'Anthropic Claude',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 33,
|
key: 33,
|
||||||
text: 'AWS Claude',
|
text: 'AWS Claude',
|
||||||
value: 33,
|
value: 33,
|
||||||
color: 'indigo',
|
color: 'indigo',
|
||||||
label: 'AWS Claude'
|
label: 'AWS Claude',
|
||||||
},
|
},
|
||||||
{ key: 41, text: 'Vertex AI', value: 41, color: 'blue', label: 'Vertex AI' },
|
{ key: 41, text: 'Vertex AI', value: 41, color: 'blue', label: 'Vertex AI' },
|
||||||
{
|
{
|
||||||
@@ -42,65 +42,71 @@ export const CHANNEL_OPTIONS = [
|
|||||||
text: 'Azure OpenAI',
|
text: 'Azure OpenAI',
|
||||||
value: 3,
|
value: 3,
|
||||||
color: 'teal',
|
color: 'teal',
|
||||||
label: 'Azure OpenAI'
|
label: 'Azure OpenAI',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 24,
|
key: 24,
|
||||||
text: 'Google Gemini',
|
text: 'Google Gemini',
|
||||||
value: 24,
|
value: 24,
|
||||||
color: 'orange',
|
color: 'orange',
|
||||||
label: 'Google Gemini'
|
label: 'Google Gemini',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 34,
|
key: 34,
|
||||||
text: 'Cohere',
|
text: 'Cohere',
|
||||||
value: 34,
|
value: 34,
|
||||||
color: 'purple',
|
color: 'purple',
|
||||||
label: 'Cohere'
|
label: 'Cohere',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 15,
|
key: 15,
|
||||||
text: '百度文心千帆',
|
text: '百度文心千帆',
|
||||||
value: 15,
|
value: 15,
|
||||||
color: 'blue',
|
color: 'blue',
|
||||||
label: '百度文心千帆'
|
label: '百度文心千帆',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 17,
|
key: 17,
|
||||||
text: '阿里通义千问',
|
text: '阿里通义千问',
|
||||||
value: 17,
|
value: 17,
|
||||||
color: 'orange',
|
color: 'orange',
|
||||||
label: '阿里通义千问'
|
label: '阿里通义千问',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 18,
|
key: 18,
|
||||||
text: '讯飞星火认知',
|
text: '讯飞星火认知',
|
||||||
value: 18,
|
value: 18,
|
||||||
color: 'blue',
|
color: 'blue',
|
||||||
label: '讯飞星火认知'
|
label: '讯飞星火认知',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 16,
|
key: 16,
|
||||||
text: '智谱 ChatGLM',
|
text: '智谱 ChatGLM',
|
||||||
value: 16,
|
value: 16,
|
||||||
color: 'violet',
|
color: 'violet',
|
||||||
label: '智谱 ChatGLM'
|
label: '智谱 ChatGLM',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 26,
|
key: 26,
|
||||||
text: '智谱 GLM-4V',
|
text: '智谱 GLM-4V',
|
||||||
value: 26,
|
value: 26,
|
||||||
color: 'purple',
|
color: 'purple',
|
||||||
label: '智谱 GLM-4V'
|
label: '智谱 GLM-4V',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 11,
|
key: 11,
|
||||||
text: 'Google PaLM2',
|
text: 'Google PaLM2',
|
||||||
value: 11,
|
value: 11,
|
||||||
color: 'orange',
|
color: 'orange',
|
||||||
label: 'Google PaLM2'
|
label: 'Google PaLM2',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 39,
|
||||||
|
text: 'Cloudflare',
|
||||||
|
value: 39,
|
||||||
|
color: 'grey',
|
||||||
|
label: 'Cloudflare',
|
||||||
},
|
},
|
||||||
{ key: 39, text: 'Cloudflare', value: 39, color: 'grey', label: 'Cloudflare' },
|
|
||||||
{ key: 25, text: 'Moonshot', value: 25, color: 'green', label: 'Moonshot' },
|
{ key: 25, text: 'Moonshot', value: 25, color: 'green', label: 'Moonshot' },
|
||||||
{ key: 19, text: '360 智脑', value: 19, color: 'blue', label: '360 智脑' },
|
{ key: 19, text: '360 智脑', value: 19, color: 'blue', label: '360 智脑' },
|
||||||
{ key: 23, text: '腾讯混元', value: 23, color: 'teal', label: '腾讯混元' },
|
{ key: 23, text: '腾讯混元', value: 23, color: 'teal', label: '腾讯混元' },
|
||||||
@@ -108,20 +114,26 @@ export const CHANNEL_OPTIONS = [
|
|||||||
{ key: 35, text: 'MiniMax', value: 35, color: 'green', label: 'MiniMax' },
|
{ key: 35, text: 'MiniMax', value: 35, color: 'green', label: 'MiniMax' },
|
||||||
{ key: 37, text: 'Dify', value: 37, color: 'teal', label: 'Dify' },
|
{ key: 37, text: 'Dify', value: 37, color: 'teal', label: 'Dify' },
|
||||||
{ key: 38, text: 'Jina', value: 38, color: 'blue', label: 'Jina' },
|
{ key: 38, text: 'Jina', value: 38, color: 'blue', label: 'Jina' },
|
||||||
{ key: 40, text: 'SiliconCloud', value: 40, color: 'purple', label: 'SiliconCloud' },
|
{
|
||||||
|
key: 40,
|
||||||
|
text: 'SiliconCloud',
|
||||||
|
value: 40,
|
||||||
|
color: 'purple',
|
||||||
|
label: 'SiliconCloud',
|
||||||
|
},
|
||||||
{ key: 8, text: '自定义渠道', value: 8, color: 'pink', label: '自定义渠道' },
|
{ key: 8, text: '自定义渠道', value: 8, color: 'pink', label: '自定义渠道' },
|
||||||
{
|
{
|
||||||
key: 22,
|
key: 22,
|
||||||
text: '知识库:FastGPT',
|
text: '知识库:FastGPT',
|
||||||
value: 22,
|
value: 22,
|
||||||
color: 'blue',
|
color: 'blue',
|
||||||
label: '知识库:FastGPT'
|
label: '知识库:FastGPT',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 21,
|
key: 21,
|
||||||
text: '知识库:AI Proxy',
|
text: '知识库:AI Proxy',
|
||||||
value: 21,
|
value: 21,
|
||||||
color: 'purple',
|
color: 'purple',
|
||||||
label: '知识库:AI Proxy'
|
label: '知识库:AI Proxy',
|
||||||
}
|
},
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ export let API = axios.create({
|
|||||||
? import.meta.env.VITE_REACT_APP_SERVER_URL
|
? import.meta.env.VITE_REACT_APP_SERVER_URL
|
||||||
: '',
|
: '',
|
||||||
headers: {
|
headers: {
|
||||||
'New-API-User': getUserIdFromLocalStorage()
|
'New-API-User': getUserIdFromLocalStorage(),
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export function updateAPI() {
|
export function updateAPI() {
|
||||||
@@ -16,8 +16,8 @@ export function updateAPI() {
|
|||||||
? import.meta.env.VITE_REACT_APP_SERVER_URL
|
? import.meta.env.VITE_REACT_APP_SERVER_URL
|
||||||
: '',
|
: '',
|
||||||
headers: {
|
headers: {
|
||||||
'New-API-User': getUserIdFromLocalStorage()
|
'New-API-User': getUserIdFromLocalStorage(),
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
export function getLogOther(otherStr) {
|
export function getLogOther(otherStr) {
|
||||||
if (otherStr === undefined || otherStr === '') {
|
if (otherStr === undefined || otherStr === '') {
|
||||||
otherStr = '{}'
|
otherStr = '{}';
|
||||||
}
|
}
|
||||||
let other = JSON.parse(otherStr)
|
let other = JSON.parse(otherStr);
|
||||||
return other
|
return other;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -144,7 +144,14 @@ export function renderModelPrice(
|
|||||||
) {
|
) {
|
||||||
// 1 ratio = $0.002 / 1K tokens
|
// 1 ratio = $0.002 / 1K tokens
|
||||||
if (modelPrice !== -1) {
|
if (modelPrice !== -1) {
|
||||||
return '模型价格:$' + modelPrice + ' * 分组倍率:' + groupRatio + ' = $' + modelPrice * groupRatio;
|
return (
|
||||||
|
'模型价格:$' +
|
||||||
|
modelPrice +
|
||||||
|
' * 分组倍率:' +
|
||||||
|
groupRatio +
|
||||||
|
' = $' +
|
||||||
|
modelPrice * groupRatio
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
if (completionRatio === undefined) {
|
if (completionRatio === undefined) {
|
||||||
completionRatio = 0;
|
completionRatio = 0;
|
||||||
@@ -158,13 +165,19 @@ export function renderModelPrice(
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<article>
|
<article>
|
||||||
<p>提示:${inputRatioPrice} * {groupRatio} = ${inputRatioPrice * groupRatio} / 1M tokens</p>
|
<p>
|
||||||
<p>补全:${completionRatioPrice} * {groupRatio} = ${completionRatioPrice * groupRatio} / 1M tokens</p>
|
提示:${inputRatioPrice} * {groupRatio} = $
|
||||||
|
{inputRatioPrice * groupRatio} / 1M tokens
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
补全:${completionRatioPrice} * {groupRatio} = $
|
||||||
|
{completionRatioPrice * groupRatio} / 1M tokens
|
||||||
|
</p>
|
||||||
<p></p>
|
<p></p>
|
||||||
<p>
|
<p>
|
||||||
提示 {inputTokens} tokens / 1M tokens * ${inputRatioPrice} + 补全{' '}
|
提示 {inputTokens} tokens / 1M tokens * ${inputRatioPrice} + 补全{' '}
|
||||||
{completionTokens} tokens / 1M tokens * ${completionRatioPrice} * 分组 {groupRatio} =
|
{completionTokens} tokens / 1M tokens * ${completionRatioPrice} *
|
||||||
${price.toFixed(6)}
|
分组 {groupRatio} = ${price.toFixed(6)}
|
||||||
</p>
|
</p>
|
||||||
<p>仅供参考,以实际扣费为准</p>
|
<p>仅供参考,以实际扣费为准</p>
|
||||||
</article>
|
</article>
|
||||||
@@ -202,31 +215,34 @@ const colors = [
|
|||||||
|
|
||||||
export const modelColorMap = {
|
export const modelColorMap = {
|
||||||
'dall-e': 'rgb(147,112,219)', // 深紫色
|
'dall-e': 'rgb(147,112,219)', // 深紫色
|
||||||
// 'dall-e-2': 'rgb(147,112,219)', // 介于紫色和蓝色之间的色调
|
'dall-e-2': 'rgb(147,112,219)', // 介于紫色和蓝色之间的色调
|
||||||
'dall-e-3': 'rgb(153,50,204)', // 介于紫罗兰和洋红之间的色调
|
'dall-e-3': 'rgb(153,50,204)', // 介于紫罗兰和洋红之间的色调
|
||||||
'gpt-3.5-turbo': 'rgb(184,227,167)', // 浅绿色
|
'gpt-3.5-turbo': 'rgb(184,227,167)', // 浅绿色
|
||||||
// 'gpt-3.5-turbo-0301': 'rgb(131,220,131)', // 亮绿色
|
'gpt-3.5-turbo-0301': 'rgb(131,220,131)', // 亮绿色
|
||||||
'gpt-3.5-turbo-0613': 'rgb(60,179,113)', // 海洋绿
|
'gpt-3.5-turbo-0613': 'rgb(60,179,113)', // 海洋绿
|
||||||
'gpt-3.5-turbo-1106': 'rgb(32,178,170)', // 浅海洋绿
|
'gpt-3.5-turbo-1106': 'rgb(32,178,170)', // 浅海洋绿
|
||||||
'gpt-3.5-turbo-16k': 'rgb(149,252,206)', // 淡橙色
|
'gpt-3.5-turbo-16k': 'rgb(149,252,206)', // 淡橙色
|
||||||
'gpt-3.5-turbo-16k-0613': 'rgb(119,255,214)', // 淡桃色
|
'gpt-3.5-turbo-16k-0613': 'rgb(119,255,214)', // 淡桃色
|
||||||
'gpt-3.5-turbo-instruct': 'rgb(175,238,238)', // 粉蓝色
|
'gpt-3.5-turbo-instruct': 'rgb(175,238,238)', // 粉蓝色
|
||||||
'gpt-4': 'rgb(135,206,235)', // 天蓝色
|
'gpt-4': 'rgb(135,206,235)', // 天蓝色
|
||||||
// 'gpt-4-0314': 'rgb(70,130,180)', // 钢蓝色
|
'gpt-4-0314': 'rgb(70,130,180)', // 钢蓝色
|
||||||
'gpt-4-0613': 'rgb(100,149,237)', // 矢车菊蓝
|
'gpt-4-0613': 'rgb(100,149,237)', // 矢车菊蓝
|
||||||
'gpt-4-1106-preview': 'rgb(30,144,255)', // 道奇蓝
|
'gpt-4-1106-preview': 'rgb(30,144,255)', // 道奇蓝
|
||||||
'gpt-4-0125-preview': 'rgb(2,177,236)', // 深天蓝
|
'gpt-4-0125-preview': 'rgb(2,177,236)', // 深天蓝
|
||||||
'gpt-4-turbo-preview': 'rgb(2,177,255)', // 深天蓝
|
'gpt-4-turbo-preview': 'rgb(2,177,255)', // 深天蓝
|
||||||
|
'gpt-4-turbo': 'rgb(2,190,255)', // 深天蓝
|
||||||
|
'gpt-4-turbo-2024-04-09': 'rgb(2,200,255)', // 深天蓝
|
||||||
'gpt-4-32k': 'rgb(104,111,238)', // 中紫色
|
'gpt-4-32k': 'rgb(104,111,238)', // 中紫色
|
||||||
// 'gpt-4-32k-0314': 'rgb(90,105,205)', // 暗灰蓝色
|
'gpt-4-32k-0314': 'rgb(90,105,205)', // 暗灰蓝色
|
||||||
'gpt-4-32k-0613': 'rgb(61,71,139)', // 暗蓝灰色
|
'gpt-4-32k-0613': 'rgb(61,71,139)', // 暗蓝灰色
|
||||||
'gpt-4-all': 'rgb(65,105,225)', // 皇家蓝
|
'gpt-4-all': 'rgb(65,105,225)', // 皇家蓝
|
||||||
'gpt-4-gizmo-*': 'rgb(0,0,255)', // 纯蓝色
|
'gpt-4-gizmo-*': 'rgb(0,0,255)', // 纯蓝色
|
||||||
|
'g-*': 'rgb(0,0,255)', // 纯蓝色
|
||||||
'gpt-4-vision-preview': 'rgb(25,25,112)', // 午夜蓝
|
'gpt-4-vision-preview': 'rgb(25,25,112)', // 午夜蓝
|
||||||
'text-ada-001': 'rgb(255,192,203)', // 粉红色
|
'text-ada-001': 'rgb(255,192,203)', // 粉红色
|
||||||
'text-babbage-001': 'rgb(255,160,122)', // 浅珊瑚色
|
'text-babbage-001': 'rgb(255,160,122)', // 浅珊瑚色
|
||||||
'text-curie-001': 'rgb(219,112,147)', // 苍紫罗兰色
|
'text-curie-001': 'rgb(219,112,147)', // 苍紫罗兰色
|
||||||
// 'text-davinci-002': 'rgb(199,21,133)', // 中紫罗兰红色
|
'text-davinci-002': 'rgb(199,21,133)', // 中紫罗兰红色
|
||||||
'text-davinci-003': 'rgb(219,112,147)', // 苍紫罗兰色(与Curie相同,表示同一个系列)
|
'text-davinci-003': 'rgb(219,112,147)', // 苍紫罗兰色(与Curie相同,表示同一个系列)
|
||||||
'text-davinci-edit-001': 'rgb(255,105,180)', // 热粉色
|
'text-davinci-edit-001': 'rgb(255,105,180)', // 热粉色
|
||||||
'text-embedding-ada-002': 'rgb(255,182,193)', // 浅粉红
|
'text-embedding-ada-002': 'rgb(255,182,193)', // 浅粉红
|
||||||
|
|||||||
@@ -133,6 +133,10 @@ export function openPage(url) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function removeTrailingSlash(url) {
|
export function removeTrailingSlash(url) {
|
||||||
|
if (!url) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
if (url.endsWith('/')) {
|
if (url.endsWith('/')) {
|
||||||
return url.slice(0, -1);
|
return url.slice(0, -1);
|
||||||
} else {
|
} else {
|
||||||
@@ -234,7 +238,6 @@ export function verifyJSONPromise(value) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export function shouldShowPrompt(id) {
|
export function shouldShowPrompt(id) {
|
||||||
let prompt = localStorage.getItem(`prompt-${id}`);
|
let prompt = localStorage.getItem(`prompt-${id}`);
|
||||||
return !prompt;
|
return !prompt;
|
||||||
|
|||||||
@@ -38,11 +38,12 @@ const STATUS_CODE_MAPPING_EXAMPLE = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const REGION_EXAMPLE = {
|
const REGION_EXAMPLE = {
|
||||||
"default": "us-central1",
|
default: 'us-central1',
|
||||||
"claude-3-5-sonnet-20240620": "europe-west1"
|
'claude-3-5-sonnet-20240620': 'europe-west1',
|
||||||
}
|
};
|
||||||
|
|
||||||
const fetchButtonTips = "1. 新建渠道时,请求通过当前浏览器发出;2. 编辑已有渠道,请求通过后端服务器发出"
|
const fetchButtonTips =
|
||||||
|
'1. 新建渠道时,请求通过当前浏览器发出;2. 编辑已有渠道,请求通过后端服务器发出';
|
||||||
|
|
||||||
function type2secretPrompt(type) {
|
function type2secretPrompt(type) {
|
||||||
// inputs.type === 15 ? '按照如下格式输入:APIKey|SecretKey' : (inputs.type === 18 ? '按照如下格式输入:APPID|APISecret|APIKey' : '请输入渠道对应的鉴权密钥')
|
// inputs.type === 15 ? '按照如下格式输入:APIKey|SecretKey' : (inputs.type === 18 ? '按照如下格式输入:APPID|APISecret|APIKey' : '请输入渠道对应的鉴权密钥')
|
||||||
@@ -132,10 +133,7 @@ const EditChannel = (props) => {
|
|||||||
];
|
];
|
||||||
break;
|
break;
|
||||||
case 36:
|
case 36:
|
||||||
localModels = [
|
localModels = ['suno_music', 'suno_lyrics'];
|
||||||
'suno_music',
|
|
||||||
'suno_lyrics',
|
|
||||||
];
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
localModels = getChannelModels(value);
|
localModels = getChannelModels(value);
|
||||||
@@ -188,56 +186,54 @@ const EditChannel = (props) => {
|
|||||||
setLoading(false);
|
setLoading(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const fetchUpstreamModelList = async (name) => {
|
const fetchUpstreamModelList = async (name) => {
|
||||||
if (inputs["type"] !== 1) {
|
if (inputs['type'] !== 1) {
|
||||||
showError("仅支持 OpenAI 接口格式")
|
showError('仅支持 OpenAI 接口格式');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setLoading(true)
|
setLoading(true);
|
||||||
const models = inputs["models"] || []
|
const models = inputs['models'] || [];
|
||||||
let err = false;
|
let err = false;
|
||||||
if (isEdit) {
|
if (isEdit) {
|
||||||
const res = await API.get("/api/channel/fetch_models/" + channelId)
|
const res = await API.get('/api/channel/fetch_models/' + channelId);
|
||||||
if (res.data && res.data?.success) {
|
if (res.data && res.data?.success) {
|
||||||
models.push(...res.data.data)
|
models.push(...res.data.data);
|
||||||
} else {
|
} else {
|
||||||
err = true
|
err = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!inputs?.["key"]) {
|
if (!inputs?.['key']) {
|
||||||
showError("请填写密钥")
|
showError('请填写密钥');
|
||||||
err = true
|
err = true;
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
const host = new URL((inputs["base_url"] || "https://api.openai.com"))
|
const host = new URL(inputs['base_url'] || 'https://api.openai.com');
|
||||||
|
|
||||||
const url = `https://${host.hostname}/v1/models`;
|
const url = `https://${host.hostname}/v1/models`;
|
||||||
const key = inputs["key"];
|
const key = inputs['key'];
|
||||||
const res = await axios.get(url, {
|
const res = await axios.get(url, {
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': `Bearer ${key}`
|
Authorization: `Bearer ${key}`,
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
if (res.data && res.data?.success) {
|
if (res.data && res.data?.success) {
|
||||||
models.push(...res.data.data.map((model) => model.id))
|
models.push(...res.data.data.map((model) => model.id));
|
||||||
} else {
|
} else {
|
||||||
err = true
|
err = true;
|
||||||
}
|
}
|
||||||
}
|
} catch (error) {
|
||||||
catch (error) {
|
err = true;
|
||||||
err = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!err) {
|
if (!err) {
|
||||||
handleInputChange(name, Array.from(new Set(models)));
|
handleInputChange(name, Array.from(new Set(models)));
|
||||||
showSuccess("获取模型列表成功");
|
showSuccess('获取模型列表成功');
|
||||||
} else {
|
} else {
|
||||||
showError('获取模型列表失败');
|
showError('获取模型列表失败');
|
||||||
}
|
}
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
};
|
||||||
|
|
||||||
const fetchModels = async () => {
|
const fetchModels = async () => {
|
||||||
try {
|
try {
|
||||||
@@ -394,7 +390,6 @@ const EditChannel = (props) => {
|
|||||||
handleInputChange('models', localModels);
|
handleInputChange('models', localModels);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<SideSheet
|
<SideSheet
|
||||||
@@ -501,7 +496,8 @@ const EditChannel = (props) => {
|
|||||||
type={'warning'}
|
type={'warning'}
|
||||||
description={
|
description={
|
||||||
<>
|
<>
|
||||||
如果你对接的是上游One API或者New API等转发项目,请使用OpenAI类型,不要使用此类型,除非你知道你在做什么。
|
如果你对接的是上游One API或者New
|
||||||
|
API等转发项目,请使用OpenAI类型,不要使用此类型,除非你知道你在做什么。
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
></Banner>
|
></Banner>
|
||||||
@@ -525,31 +521,31 @@ const EditChannel = (props) => {
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
{inputs.type === 36 && (
|
{inputs.type === 36 && (
|
||||||
<>
|
<>
|
||||||
<div style={{marginTop: 10}}>
|
<div style={{ marginTop: 10 }}>
|
||||||
<Typography.Text strong>
|
<Typography.Text strong>
|
||||||
注意非Chat API,请务必填写正确的API地址,否则可能导致无法使用
|
注意非Chat API,请务必填写正确的API地址,否则可能导致无法使用
|
||||||
</Typography.Text>
|
</Typography.Text>
|
||||||
</div>
|
</div>
|
||||||
<Input
|
<Input
|
||||||
name='base_url'
|
name='base_url'
|
||||||
placeholder={
|
placeholder={
|
||||||
'请输入到 /suno 前的路径,通常就是域名,例如:https://api.example.com '
|
'请输入到 /suno 前的路径,通常就是域名,例如:https://api.example.com '
|
||||||
}
|
}
|
||||||
onChange={(value) => {
|
onChange={(value) => {
|
||||||
handleInputChange('base_url', value);
|
handleInputChange('base_url', value);
|
||||||
}}
|
}}
|
||||||
value={inputs.base_url}
|
value={inputs.base_url}
|
||||||
autoComplete='new-password'
|
autoComplete='new-password'
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
<div style={{marginTop: 10}}>
|
<div style={{ marginTop: 10 }}>
|
||||||
<Typography.Text strong>名称:</Typography.Text>
|
<Typography.Text strong>名称:</Typography.Text>
|
||||||
</div>
|
</div>
|
||||||
<Input
|
<Input
|
||||||
required
|
required
|
||||||
name='name'
|
name='name'
|
||||||
placeholder={'请为渠道命名'}
|
placeholder={'请为渠道命名'}
|
||||||
onChange={(value) => {
|
onChange={(value) => {
|
||||||
handleInputChange('name', value);
|
handleInputChange('name', value);
|
||||||
@@ -783,7 +779,8 @@ const EditChannel = (props) => {
|
|||||||
label='鉴权json'
|
label='鉴权json'
|
||||||
name='key'
|
name='key'
|
||||||
required
|
required
|
||||||
placeholder={'{\n' +
|
placeholder={
|
||||||
|
'{\n' +
|
||||||
' "type": "service_account",\n' +
|
' "type": "service_account",\n' +
|
||||||
' "project_id": "abc-bcd-123-456",\n' +
|
' "project_id": "abc-bcd-123-456",\n' +
|
||||||
' "private_key_id": "123xxxxx456",\n' +
|
' "private_key_id": "123xxxxx456",\n' +
|
||||||
@@ -795,7 +792,8 @@ const EditChannel = (props) => {
|
|||||||
' "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",\n' +
|
' "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",\n' +
|
||||||
' "client_x509_cert_url": "https://xxxxx.gserviceaccount.com",\n' +
|
' "client_x509_cert_url": "https://xxxxx.gserviceaccount.com",\n' +
|
||||||
' "universe_domain": "googleapis.com"\n' +
|
' "universe_domain": "googleapis.com"\n' +
|
||||||
'}'}
|
'}'
|
||||||
|
}
|
||||||
onChange={(value) => {
|
onChange={(value) => {
|
||||||
handleInputChange('key', value);
|
handleInputChange('key', value);
|
||||||
}}
|
}}
|
||||||
@@ -815,9 +813,8 @@ const EditChannel = (props) => {
|
|||||||
value={inputs.key}
|
value={inputs.key}
|
||||||
autoComplete='new-password'
|
autoComplete='new-password'
|
||||||
/>
|
/>
|
||||||
)
|
)}
|
||||||
}
|
</>
|
||||||
</>
|
|
||||||
)}
|
)}
|
||||||
{inputs.type === 1 && (
|
{inputs.type === 1 && (
|
||||||
<>
|
<>
|
||||||
@@ -875,23 +872,26 @@ const EditChannel = (props) => {
|
|||||||
</Space>
|
</Space>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{inputs.type !== 3 && inputs.type !== 8 && inputs.type !== 22 && inputs.type !== 36 && (
|
{inputs.type !== 3 &&
|
||||||
<>
|
inputs.type !== 8 &&
|
||||||
<div style={{ marginTop: 10 }}>
|
inputs.type !== 22 &&
|
||||||
<Typography.Text strong>代理:</Typography.Text>
|
inputs.type !== 36 && (
|
||||||
</div>
|
<>
|
||||||
<Input
|
<div style={{ marginTop: 10 }}>
|
||||||
label='代理'
|
<Typography.Text strong>代理:</Typography.Text>
|
||||||
name='base_url'
|
</div>
|
||||||
placeholder={'此项可选,用于通过代理站来进行 API 调用'}
|
<Input
|
||||||
onChange={(value) => {
|
label='代理'
|
||||||
handleInputChange('base_url', value);
|
name='base_url'
|
||||||
}}
|
placeholder={'此项可选,用于通过代理站来进行 API 调用'}
|
||||||
value={inputs.base_url}
|
onChange={(value) => {
|
||||||
autoComplete='new-password'
|
handleInputChange('base_url', value);
|
||||||
/>
|
}}
|
||||||
</>
|
value={inputs.base_url}
|
||||||
)}
|
autoComplete='new-password'
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
{inputs.type === 22 && (
|
{inputs.type === 22 && (
|
||||||
<>
|
<>
|
||||||
<div style={{ marginTop: 10 }}>
|
<div style={{ marginTop: 10 }}>
|
||||||
|
|||||||
@@ -132,6 +132,12 @@ const Home = () => {
|
|||||||
? '已启用'
|
? '已启用'
|
||||||
: '未启用'}
|
: '未启用'}
|
||||||
</p>
|
</p>
|
||||||
|
<p>
|
||||||
|
LINUX DO 身份验证:
|
||||||
|
{statusState?.status?.linuxdo_oauth === true
|
||||||
|
? '已启用'
|
||||||
|
: '未启用'}
|
||||||
|
</p>
|
||||||
<p>
|
<p>
|
||||||
微信身份验证:
|
微信身份验证:
|
||||||
{statusState?.status?.wechat_login === true
|
{statusState?.status?.wechat_login === true
|
||||||
|
|||||||
@@ -160,11 +160,7 @@ export default function SettingsDrawing(props) {
|
|||||||
<Col span={8}>
|
<Col span={8}>
|
||||||
<Form.Switch
|
<Form.Switch
|
||||||
field={'MjActionCheckSuccessEnabled'}
|
field={'MjActionCheckSuccessEnabled'}
|
||||||
label={
|
label={<>检测必须等待绘图成功才能进行放大等操作</>}
|
||||||
<>
|
|
||||||
检测必须等待绘图成功才能进行放大等操作
|
|
||||||
</>
|
|
||||||
}
|
|
||||||
size='large'
|
size='large'
|
||||||
checkedText='|'
|
checkedText='|'
|
||||||
uncheckedText='〇'
|
uncheckedText='〇'
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
import React, { useEffect, useState, useRef } from 'react';
|
import React, { useEffect, useState, useRef } from 'react';
|
||||||
import { Button, Col, Form, Popconfirm, Row, Space, Spin } from '@douyinfe/semi-ui';
|
import {
|
||||||
|
Button,
|
||||||
|
Col,
|
||||||
|
Form,
|
||||||
|
Popconfirm,
|
||||||
|
Row,
|
||||||
|
Space,
|
||||||
|
Spin,
|
||||||
|
} from '@douyinfe/semi-ui';
|
||||||
import {
|
import {
|
||||||
compareObjects,
|
compareObjects,
|
||||||
API,
|
API,
|
||||||
@@ -7,7 +15,7 @@ import {
|
|||||||
showSuccess,
|
showSuccess,
|
||||||
showWarning,
|
showWarning,
|
||||||
verifyJSON,
|
verifyJSON,
|
||||||
verifyJSONPromise
|
verifyJSONPromise,
|
||||||
} from '../../../helpers';
|
} from '../../../helpers';
|
||||||
|
|
||||||
export default function SettingsMagnification(props) {
|
export default function SettingsMagnification(props) {
|
||||||
@@ -16,7 +24,7 @@ export default function SettingsMagnification(props) {
|
|||||||
ModelPrice: '',
|
ModelPrice: '',
|
||||||
ModelRatio: '',
|
ModelRatio: '',
|
||||||
CompletionRatio: '',
|
CompletionRatio: '',
|
||||||
GroupRatio: ''
|
GroupRatio: '',
|
||||||
});
|
});
|
||||||
const refForm = useRef();
|
const refForm = useRef();
|
||||||
const [inputsRow, setInputsRow] = useState(inputs);
|
const [inputsRow, setInputsRow] = useState(inputs);
|
||||||
@@ -24,44 +32,47 @@ export default function SettingsMagnification(props) {
|
|||||||
async function onSubmit() {
|
async function onSubmit() {
|
||||||
try {
|
try {
|
||||||
console.log('Starting validation...');
|
console.log('Starting validation...');
|
||||||
await refForm.current.validate().then(() => {
|
await refForm.current
|
||||||
console.log('Validation passed');
|
.validate()
|
||||||
const updateArray = compareObjects(inputs, inputsRow);
|
.then(() => {
|
||||||
if (!updateArray.length) return showWarning('你似乎并没有修改什么');
|
console.log('Validation passed');
|
||||||
const requestQueue = updateArray.map((item) => {
|
const updateArray = compareObjects(inputs, inputsRow);
|
||||||
let value = '';
|
if (!updateArray.length) return showWarning('你似乎并没有修改什么');
|
||||||
if (typeof inputs[item.key] === 'boolean') {
|
const requestQueue = updateArray.map((item) => {
|
||||||
value = String(inputs[item.key]);
|
let value = '';
|
||||||
} else {
|
if (typeof inputs[item.key] === 'boolean') {
|
||||||
value = inputs[item.key];
|
value = String(inputs[item.key]);
|
||||||
}
|
} else {
|
||||||
return API.put('/api/option/', {
|
value = inputs[item.key];
|
||||||
key: item.key,
|
|
||||||
value
|
|
||||||
});
|
|
||||||
});
|
|
||||||
setLoading(true);
|
|
||||||
Promise.all(requestQueue)
|
|
||||||
.then((res) => {
|
|
||||||
if (requestQueue.length === 1) {
|
|
||||||
if (res.includes(undefined)) return;
|
|
||||||
} else if (requestQueue.length > 1) {
|
|
||||||
if (res.includes(undefined))
|
|
||||||
return showError('部分保存失败,请重试');
|
|
||||||
}
|
}
|
||||||
showSuccess('保存成功');
|
return API.put('/api/option/', {
|
||||||
props.refresh();
|
key: item.key,
|
||||||
})
|
value,
|
||||||
.catch(() => {
|
});
|
||||||
showError('保存失败,请重试');
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
setLoading(false);
|
|
||||||
});
|
});
|
||||||
}).catch((error) => {
|
setLoading(true);
|
||||||
console.error('Validation failed:', error);
|
Promise.all(requestQueue)
|
||||||
showError('请检查输入');
|
.then((res) => {
|
||||||
});
|
if (requestQueue.length === 1) {
|
||||||
|
if (res.includes(undefined)) return;
|
||||||
|
} else if (requestQueue.length > 1) {
|
||||||
|
if (res.includes(undefined))
|
||||||
|
return showError('部分保存失败,请重试');
|
||||||
|
}
|
||||||
|
showSuccess('保存成功');
|
||||||
|
props.refresh();
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
showError('保存失败,请重试');
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
setLoading(false);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error('Validation failed:', error);
|
||||||
|
showError('请检查输入');
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
showError('请检查输入');
|
showError('请检查输入');
|
||||||
console.error(error);
|
console.error(error);
|
||||||
@@ -120,13 +131,13 @@ export default function SettingsMagnification(props) {
|
|||||||
validator: (rule, value) => {
|
validator: (rule, value) => {
|
||||||
return verifyJSON(value);
|
return verifyJSON(value);
|
||||||
},
|
},
|
||||||
message: '不是合法的 JSON 字符串'
|
message: '不是合法的 JSON 字符串',
|
||||||
}
|
},
|
||||||
]}
|
]}
|
||||||
onChange={(value) =>
|
onChange={(value) =>
|
||||||
setInputs({
|
setInputs({
|
||||||
...inputs,
|
...inputs,
|
||||||
ModelPrice: value
|
ModelPrice: value,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
@@ -147,13 +158,13 @@ export default function SettingsMagnification(props) {
|
|||||||
validator: (rule, value) => {
|
validator: (rule, value) => {
|
||||||
return verifyJSON(value);
|
return verifyJSON(value);
|
||||||
},
|
},
|
||||||
message: '不是合法的 JSON 字符串'
|
message: '不是合法的 JSON 字符串',
|
||||||
}
|
},
|
||||||
]}
|
]}
|
||||||
onChange={(value) =>
|
onChange={(value) =>
|
||||||
setInputs({
|
setInputs({
|
||||||
...inputs,
|
...inputs,
|
||||||
ModelRatio: value
|
ModelRatio: value,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
@@ -174,13 +185,13 @@ export default function SettingsMagnification(props) {
|
|||||||
validator: (rule, value) => {
|
validator: (rule, value) => {
|
||||||
return verifyJSON(value);
|
return verifyJSON(value);
|
||||||
},
|
},
|
||||||
message: '不是合法的 JSON 字符串'
|
message: '不是合法的 JSON 字符串',
|
||||||
}
|
},
|
||||||
]}
|
]}
|
||||||
onChange={(value) =>
|
onChange={(value) =>
|
||||||
setInputs({
|
setInputs({
|
||||||
...inputs,
|
...inputs,
|
||||||
CompletionRatio: value
|
CompletionRatio: value,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
@@ -201,13 +212,13 @@ export default function SettingsMagnification(props) {
|
|||||||
validator: (rule, value) => {
|
validator: (rule, value) => {
|
||||||
return verifyJSON(value);
|
return verifyJSON(value);
|
||||||
},
|
},
|
||||||
message: '不是合法的 JSON 字符串'
|
message: '不是合法的 JSON 字符串',
|
||||||
}
|
},
|
||||||
]}
|
]}
|
||||||
onChange={(value) =>
|
onChange={(value) =>
|
||||||
setInputs({
|
setInputs({
|
||||||
...inputs,
|
...inputs,
|
||||||
GroupRatio: value
|
GroupRatio: value,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
@@ -216,9 +227,7 @@ export default function SettingsMagnification(props) {
|
|||||||
</Form.Section>
|
</Form.Section>
|
||||||
</Form>
|
</Form>
|
||||||
<Space>
|
<Space>
|
||||||
<Button onClick={onSubmit}>
|
<Button onClick={onSubmit}>保存倍率设置</Button>
|
||||||
保存倍率设置
|
|
||||||
</Button>
|
|
||||||
<Popconfirm
|
<Popconfirm
|
||||||
title='确定重置模型倍率吗?'
|
title='确定重置模型倍率吗?'
|
||||||
content='此修改将不可逆'
|
content='此修改将不可逆'
|
||||||
@@ -228,9 +237,7 @@ export default function SettingsMagnification(props) {
|
|||||||
resetModelRatio();
|
resetModelRatio();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Button type={'danger'}>
|
<Button type={'danger'}>重置模型倍率</Button>
|
||||||
重置模型倍率
|
|
||||||
</Button>
|
|
||||||
</Popconfirm>
|
</Popconfirm>
|
||||||
</Space>
|
</Space>
|
||||||
</Spin>
|
</Spin>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import TaskLogsTable from "../../components/TaskLogsTable.js";
|
import TaskLogsTable from '../../components/TaskLogsTable.js';
|
||||||
|
|
||||||
const Task = () => (
|
const Task = () => (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -1,10 +1,6 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import { API, isMobile, showError, showInfo, showSuccess } from '../../helpers';
|
import { API, isMobile, showError, showInfo, showSuccess } from '../../helpers';
|
||||||
import {
|
import { renderNumber, renderQuota } from '../../helpers/render';
|
||||||
renderNumber,
|
|
||||||
renderQuota,
|
|
||||||
renderQuotaWithAmount,
|
|
||||||
} from '../../helpers/render';
|
|
||||||
import {
|
import {
|
||||||
Col,
|
Col,
|
||||||
Layout,
|
Layout,
|
||||||
@@ -16,7 +12,6 @@ import {
|
|||||||
Divider,
|
Divider,
|
||||||
Space,
|
Space,
|
||||||
Modal,
|
Modal,
|
||||||
Toast,
|
|
||||||
} from '@douyinfe/semi-ui';
|
} from '@douyinfe/semi-ui';
|
||||||
import Title from '@douyinfe/semi-ui/lib/es/typography/title';
|
import Title from '@douyinfe/semi-ui/lib/es/typography/title';
|
||||||
import Text from '@douyinfe/semi-ui/lib/es/typography/text';
|
import Text from '@douyinfe/semi-ui/lib/es/typography/text';
|
||||||
@@ -25,20 +20,22 @@ import { Link } from 'react-router-dom';
|
|||||||
const TopUp = () => {
|
const TopUp = () => {
|
||||||
const [redemptionCode, setRedemptionCode] = useState('');
|
const [redemptionCode, setRedemptionCode] = useState('');
|
||||||
const [topUpCode, setTopUpCode] = useState('');
|
const [topUpCode, setTopUpCode] = useState('');
|
||||||
const [topUpCount, setTopUpCount] = useState(0);
|
const [topUpCount, setTopUpCount] = useState(10);
|
||||||
const [minTopupCount, setMinTopUpCount] = useState(1);
|
const [minTopupCount, setMinTopUpCount] = useState(1);
|
||||||
const [amount, setAmount] = useState(0.0);
|
const [payAmount, setPayAmount] = useState(0.0);
|
||||||
|
const [chargedAmount, setChargedAmount] = useState(0.0);
|
||||||
const [minTopUp, setMinTopUp] = useState(1);
|
const [minTopUp, setMinTopUp] = useState(1);
|
||||||
const [topUpLink, setTopUpLink] = useState('');
|
const [topUpLink, setTopUpLink] = useState('');
|
||||||
const [enableOnlineTopUp, setEnableOnlineTopUp] = useState(false);
|
const [paymentEnabled, setPaymentEnabled] = useState(false);
|
||||||
const [userQuota, setUserQuota] = useState(0);
|
const [userQuota, setUserQuota] = useState(0);
|
||||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||||
|
const [isPaying, setIsPaying] = useState(false);
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
const [payWay, setPayWay] = useState('');
|
const [payWay, setPayWay] = useState('');
|
||||||
|
|
||||||
const topUp = async () => {
|
const topUp = async () => {
|
||||||
if (redemptionCode === '') {
|
if (redemptionCode === '') {
|
||||||
showInfo('请输入兑换码!');
|
showError('请输入兑换码!');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setIsSubmitting(true);
|
setIsSubmitting(true);
|
||||||
@@ -77,11 +74,17 @@ const TopUp = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const preTopUp = async (payment) => {
|
const preTopUp = async (payment) => {
|
||||||
if (!enableOnlineTopUp) {
|
if (!paymentEnabled) {
|
||||||
showError('管理员未开启在线充值!');
|
showError('管理员未开启在线充值!');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await getAmount();
|
if (!Number.isInteger(Number(topUpCount))) {
|
||||||
|
showError('充值数量必须是整数!');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (payAmount === 0) {
|
||||||
|
await getAmount();
|
||||||
|
}
|
||||||
if (topUpCount < minTopUp) {
|
if (topUpCount < minTopUp) {
|
||||||
showError('充值数量不能小于' + minTopUp);
|
showError('充值数量不能小于' + minTopUp);
|
||||||
return;
|
return;
|
||||||
@@ -91,7 +94,7 @@ const TopUp = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const onlineTopUp = async () => {
|
const onlineTopUp = async () => {
|
||||||
if (amount === 0) {
|
if (payAmount === 0) {
|
||||||
await getAmount();
|
await getAmount();
|
||||||
}
|
}
|
||||||
if (topUpCount < minTopUp) {
|
if (topUpCount < minTopUp) {
|
||||||
@@ -100,6 +103,7 @@ const TopUp = () => {
|
|||||||
}
|
}
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
try {
|
try {
|
||||||
|
setIsPaying(true);
|
||||||
const res = await API.post('/api/user/pay', {
|
const res = await API.post('/api/user/pay', {
|
||||||
amount: parseInt(topUpCount),
|
amount: parseInt(topUpCount),
|
||||||
top_up_code: topUpCode,
|
top_up_code: topUpCode,
|
||||||
@@ -109,34 +113,13 @@ const TopUp = () => {
|
|||||||
const { message, data } = res.data;
|
const { message, data } = res.data;
|
||||||
// showInfo(message);
|
// showInfo(message);
|
||||||
if (message === 'success') {
|
if (message === 'success') {
|
||||||
let params = data;
|
location.href = data.payLink;
|
||||||
let url = res.data.url;
|
|
||||||
let form = document.createElement('form');
|
|
||||||
form.action = url;
|
|
||||||
form.method = 'POST';
|
|
||||||
// 判断是否为safari浏览器
|
|
||||||
let isSafari =
|
|
||||||
navigator.userAgent.indexOf('Safari') > -1 &&
|
|
||||||
navigator.userAgent.indexOf('Chrome') < 1;
|
|
||||||
if (!isSafari) {
|
|
||||||
form.target = '_blank';
|
|
||||||
}
|
|
||||||
for (let key in params) {
|
|
||||||
let input = document.createElement('input');
|
|
||||||
input.type = 'hidden';
|
|
||||||
input.name = key;
|
|
||||||
input.value = params[key];
|
|
||||||
form.appendChild(input);
|
|
||||||
}
|
|
||||||
document.body.appendChild(form);
|
|
||||||
form.submit();
|
|
||||||
document.body.removeChild(form);
|
|
||||||
} else {
|
} else {
|
||||||
|
setIsPaying(false);
|
||||||
showError(data);
|
showError(data);
|
||||||
// setTopUpCount(parseInt(res.data.count));
|
|
||||||
// setAmount(parseInt(data));
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
setIsPaying(false);
|
||||||
showError(res);
|
showError(res);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -165,8 +148,8 @@ const TopUp = () => {
|
|||||||
if (status.min_topup) {
|
if (status.min_topup) {
|
||||||
setMinTopUp(status.min_topup);
|
setMinTopUp(status.min_topup);
|
||||||
}
|
}
|
||||||
if (status.enable_online_topup) {
|
if (status.payment_enabled) {
|
||||||
setEnableOnlineTopUp(status.enable_online_topup);
|
setPaymentEnabled(status.payment_enabled);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
getUserQuota().then();
|
getUserQuota().then();
|
||||||
@@ -174,7 +157,7 @@ const TopUp = () => {
|
|||||||
|
|
||||||
const renderAmount = () => {
|
const renderAmount = () => {
|
||||||
// console.log(amount);
|
// console.log(amount);
|
||||||
return amount + '元';
|
return payAmount + '元';
|
||||||
};
|
};
|
||||||
|
|
||||||
const getAmount = async (value) => {
|
const getAmount = async (value) => {
|
||||||
@@ -190,10 +173,10 @@ const TopUp = () => {
|
|||||||
const { message, data } = res.data;
|
const { message, data } = res.data;
|
||||||
// showInfo(message);
|
// showInfo(message);
|
||||||
if (message === 'success') {
|
if (message === 'success') {
|
||||||
setAmount(parseFloat(data));
|
setPayAmount(parseFloat(data.payAmount));
|
||||||
|
setChargedAmount(parseFloat(data.chargedAmount));
|
||||||
} else {
|
} else {
|
||||||
setAmount(0);
|
showError(data);
|
||||||
Toast.error({ content: '错误:' + data, id: 'getAmount' });
|
|
||||||
// setTopUpCount(parseInt(res.data.count));
|
// setTopUpCount(parseInt(res.data.count));
|
||||||
// setAmount(parseInt(data));
|
// setAmount(parseInt(data));
|
||||||
}
|
}
|
||||||
@@ -226,7 +209,9 @@ const TopUp = () => {
|
|||||||
size={'small'}
|
size={'small'}
|
||||||
centered={true}
|
centered={true}
|
||||||
>
|
>
|
||||||
<p>充值数量:{topUpCount}</p>
|
<p>
|
||||||
|
充值数量:{topUpCount}$(实到:{chargedAmount}$)
|
||||||
|
</p>
|
||||||
<p>实付金额:{renderAmount()}</p>
|
<p>实付金额:{renderAmount()}</p>
|
||||||
<p>是否确认充值?</p>
|
<p>是否确认充值?</p>
|
||||||
</Modal>
|
</Modal>
|
||||||
@@ -271,52 +256,51 @@ const TopUp = () => {
|
|||||||
</Space>
|
</Space>
|
||||||
</Form>
|
</Form>
|
||||||
</div>
|
</div>
|
||||||
<div style={{ marginTop: 20 }}>
|
{paymentEnabled ? (
|
||||||
<Divider>在线充值</Divider>
|
<div style={{ marginTop: 20 }}>
|
||||||
<Form>
|
<Divider>在线充值</Divider>
|
||||||
<Form.Input
|
<Form>
|
||||||
disabled={!enableOnlineTopUp}
|
<Form.Input
|
||||||
field={'redemptionCount'}
|
disabled={!paymentEnabled}
|
||||||
label={'实付金额:' + renderAmount()}
|
field={'redemptionCount'}
|
||||||
placeholder={
|
label={'实付金额:' + renderAmount()}
|
||||||
'充值数量,最低 ' + renderQuotaWithAmount(minTopUp)
|
placeholder={'充值数量,必须整数,最低' + minTopUp + '$'}
|
||||||
}
|
name='redemptionCount'
|
||||||
name='redemptionCount'
|
type={'number'}
|
||||||
type={'number'}
|
value={topUpCount}
|
||||||
value={topUpCount}
|
suffix={'$'}
|
||||||
onChange={async (value) => {
|
min={minTopUp}
|
||||||
if (value < 1) {
|
defaultValue={minTopUp}
|
||||||
value = 1;
|
max={100000}
|
||||||
}
|
onChange={async (value) => {
|
||||||
setTopUpCount(value);
|
if (value < 1) {
|
||||||
await getAmount(value);
|
value = 1;
|
||||||
}}
|
}
|
||||||
/>
|
if (value > 100000) {
|
||||||
<Space>
|
value = 100000;
|
||||||
<Button
|
}
|
||||||
type={'primary'}
|
setTopUpCount(value);
|
||||||
theme={'solid'}
|
await getAmount(value);
|
||||||
onClick={async () => {
|
|
||||||
preTopUp('zfb');
|
|
||||||
}}
|
}}
|
||||||
>
|
/>
|
||||||
支付宝
|
<Space>
|
||||||
</Button>
|
<Button
|
||||||
<Button
|
style={{ backgroundColor: '#b161fe' }}
|
||||||
style={{
|
type={'primary'}
|
||||||
backgroundColor: 'rgba(var(--semi-green-5), 1)',
|
disabled={isPaying}
|
||||||
}}
|
theme={'solid'}
|
||||||
type={'primary'}
|
onClick={async () => {
|
||||||
theme={'solid'}
|
preTopUp('stripe');
|
||||||
onClick={async () => {
|
}}
|
||||||
preTopUp('wx');
|
>
|
||||||
}}
|
{isPaying ? '支付中...' : '去支付'}
|
||||||
>
|
</Button>
|
||||||
微信
|
</Space>
|
||||||
</Button>
|
</Form>
|
||||||
</Space>
|
</div>
|
||||||
</Form>
|
) : (
|
||||||
</div>
|
<></>
|
||||||
|
)}
|
||||||
{/*<div style={{ display: 'flex', justifyContent: 'right' }}>*/}
|
{/*<div style={{ display: 'flex', justifyContent: 'right' }}>*/}
|
||||||
{/* <Text>*/}
|
{/* <Text>*/}
|
||||||
{/* <Link onClick={*/}
|
{/* <Link onClick={*/}
|
||||||
|
|||||||
@@ -25,7 +25,10 @@ const EditUser = (props) => {
|
|||||||
display_name: '',
|
display_name: '',
|
||||||
password: '',
|
password: '',
|
||||||
github_id: '',
|
github_id: '',
|
||||||
|
linuxdo_id: '',
|
||||||
|
linuxdo_level: 0,
|
||||||
wechat_id: '',
|
wechat_id: '',
|
||||||
|
telegram_id: '',
|
||||||
email: '',
|
email: '',
|
||||||
quota: 0,
|
quota: 0,
|
||||||
group: 'default',
|
group: 'default',
|
||||||
@@ -36,6 +39,8 @@ const EditUser = (props) => {
|
|||||||
display_name,
|
display_name,
|
||||||
password,
|
password,
|
||||||
github_id,
|
github_id,
|
||||||
|
linuxdo_id,
|
||||||
|
linuxdo_level,
|
||||||
wechat_id,
|
wechat_id,
|
||||||
telegram_id,
|
telegram_id,
|
||||||
email,
|
email,
|
||||||
@@ -229,6 +234,16 @@ const EditUser = (props) => {
|
|||||||
placeholder='此项只读,需要用户通过个人设置页面的相关绑定按钮进行绑定,不可直接修改'
|
placeholder='此项只读,需要用户通过个人设置页面的相关绑定按钮进行绑定,不可直接修改'
|
||||||
readonly
|
readonly
|
||||||
/>
|
/>
|
||||||
|
<div style={{ marginTop: 20 }}>
|
||||||
|
<Typography.Text>已绑定的 LINUX DO 账户</Typography.Text>
|
||||||
|
</div>
|
||||||
|
<Input
|
||||||
|
name='linuxdo_id'
|
||||||
|
value={linuxdo_id + '(' + linuxdo_level + '级)'}
|
||||||
|
autoComplete='new-password'
|
||||||
|
placeholder='此项只读,需要用户通过个人设置页面的相关绑定按钮进行绑定,不可直接修改'
|
||||||
|
readonly
|
||||||
|
/>
|
||||||
<div style={{ marginTop: 20 }}>
|
<div style={{ marginTop: 20 }}>
|
||||||
<Typography.Text>已绑定的微信账户</Typography.Text>
|
<Typography.Text>已绑定的微信账户</Typography.Text>
|
||||||
</div>
|
</div>
|
||||||
@@ -240,21 +255,21 @@ const EditUser = (props) => {
|
|||||||
readonly
|
readonly
|
||||||
/>
|
/>
|
||||||
<div style={{ marginTop: 20 }}>
|
<div style={{ marginTop: 20 }}>
|
||||||
<Typography.Text>已绑定的邮箱账户</Typography.Text>
|
<Typography.Text>已绑定的 Telegram 账户</Typography.Text>
|
||||||
</div>
|
</div>
|
||||||
<Input
|
<Input
|
||||||
name='email'
|
name='telegram_id'
|
||||||
value={email}
|
value={telegram_id}
|
||||||
autoComplete='new-password'
|
autoComplete='new-password'
|
||||||
placeholder='此项只读,需要用户通过个人设置页面的相关绑定按钮进行绑定,不可直接修改'
|
placeholder='此项只读,需要用户通过个人设置页面的相关绑定按钮进行绑定,不可直接修改'
|
||||||
readonly
|
readonly
|
||||||
/>
|
/>
|
||||||
<div style={{ marginTop: 20 }}>
|
<div style={{ marginTop: 20 }}>
|
||||||
<Typography.Text>已绑定的Telegram账户</Typography.Text>
|
<Typography.Text>已绑定的邮箱账户</Typography.Text>
|
||||||
</div>
|
</div>
|
||||||
<Input
|
<Input
|
||||||
name='telegram_id'
|
name='email'
|
||||||
value={telegram_id}
|
value={email}
|
||||||
autoComplete='new-password'
|
autoComplete='new-password'
|
||||||
placeholder='此项只读,需要用户通过个人设置页面的相关绑定按钮进行绑定,不可直接修改'
|
placeholder='此项只读,需要用户通过个人设置页面的相关绑定按钮进行绑定,不可直接修改'
|
||||||
readonly
|
readonly
|
||||||
|
|||||||
2260
web/yarn.lock
Normal file
2260
web/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user