Compare commits
14 Commits
v0.5.11-al
...
v0.5.11-de
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
227e11c5ac | ||
|
|
b0bf224bb1 | ||
|
|
5342af9222 | ||
|
|
d062bc60e4 | ||
|
|
39c1882970 | ||
|
|
9c42c7dfd9 | ||
|
|
903aaeded0 | ||
|
|
bdd4be562d | ||
|
|
37afb313b5 | ||
|
|
c9ebcab8b8 | ||
|
|
86261cc656 | ||
|
|
8491785c9d | ||
|
|
e848a3f7fa | ||
|
|
318adf5985 |
49
.github/workflows/docker-image-amd64-en.yml
vendored
49
.github/workflows/docker-image-amd64-en.yml
vendored
@@ -1,49 +0,0 @@
|
|||||||
name: Publish Docker image (amd64, English)
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
tags:
|
|
||||||
- '*'
|
|
||||||
workflow_dispatch:
|
|
||||||
inputs:
|
|
||||||
name:
|
|
||||||
description: 'reason'
|
|
||||||
required: false
|
|
||||||
jobs:
|
|
||||||
push_to_registries:
|
|
||||||
name: Push Docker image to multiple registries
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
permissions:
|
|
||||||
packages: write
|
|
||||||
contents: read
|
|
||||||
steps:
|
|
||||||
- name: Check out the repo
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Save version info
|
|
||||||
run: |
|
|
||||||
git describe --tags > VERSION
|
|
||||||
|
|
||||||
- name: Translate
|
|
||||||
run: |
|
|
||||||
python ./i18n/translate.py --repository_path . --json_file_path ./i18n/en.json
|
|
||||||
- name: Log in to Docker Hub
|
|
||||||
uses: docker/login-action@v2
|
|
||||||
with:
|
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
||||||
|
|
||||||
- name: Extract metadata (tags, labels) for Docker
|
|
||||||
id: meta
|
|
||||||
uses: docker/metadata-action@v4
|
|
||||||
with:
|
|
||||||
images: |
|
|
||||||
justsong/one-api-en
|
|
||||||
|
|
||||||
- name: Build and push Docker images
|
|
||||||
uses: docker/build-push-action@v3
|
|
||||||
with:
|
|
||||||
context: .
|
|
||||||
push: true
|
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
|
||||||
22
.github/workflows/docker-image-amd64.yml
vendored
22
.github/workflows/docker-image-amd64.yml
vendored
@@ -1,34 +1,28 @@
|
|||||||
name: Publish Docker image (amd64)
|
name: Publish Docker image (amd64)
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
|
||||||
tags:
|
|
||||||
- '*'
|
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
inputs:
|
inputs:
|
||||||
name:
|
name:
|
||||||
description: 'reason'
|
description: 'reason'
|
||||||
required: false
|
required: false
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
push_to_registries:
|
build-and-push-image:
|
||||||
name: Push Docker image to multiple registries
|
name: Push Docker image to GitHub registry
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
permissions:
|
||||||
packages: write
|
packages: write
|
||||||
contents: read
|
contents: read
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
|
||||||
- name: Check out the repo
|
- name: Check out the repo
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Save version info
|
- name: Save version info
|
||||||
run: |
|
run: |
|
||||||
git describe --tags > VERSION
|
git describe --tags > VERSION
|
||||||
|
|
||||||
- name: Log in to Docker Hub
|
|
||||||
uses: docker/login-action@v2
|
|
||||||
with:
|
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
||||||
|
|
||||||
- name: Log in to the Container registry
|
- name: Log in to the Container registry
|
||||||
uses: docker/login-action@v2
|
uses: docker/login-action@v2
|
||||||
@@ -41,9 +35,7 @@ jobs:
|
|||||||
id: meta
|
id: meta
|
||||||
uses: docker/metadata-action@v4
|
uses: docker/metadata-action@v4
|
||||||
with:
|
with:
|
||||||
images: |
|
images: ghcr.io/${{ github.repository }}
|
||||||
justsong/one-api
|
|
||||||
ghcr.io/${{ github.repository }}
|
|
||||||
|
|
||||||
- name: Build and push Docker images
|
- name: Build and push Docker images
|
||||||
uses: docker/build-push-action@v3
|
uses: docker/build-push-action@v3
|
||||||
|
|||||||
62
.github/workflows/docker-image-arm64.yml
vendored
62
.github/workflows/docker-image-arm64.yml
vendored
@@ -1,62 +0,0 @@
|
|||||||
name: Publish Docker image (arm64)
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
tags:
|
|
||||||
- '*'
|
|
||||||
- '!*-alpha*'
|
|
||||||
workflow_dispatch:
|
|
||||||
inputs:
|
|
||||||
name:
|
|
||||||
description: 'reason'
|
|
||||||
required: false
|
|
||||||
jobs:
|
|
||||||
push_to_registries:
|
|
||||||
name: Push Docker image to multiple registries
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
permissions:
|
|
||||||
packages: write
|
|
||||||
contents: read
|
|
||||||
steps:
|
|
||||||
- name: Check out the repo
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Save version info
|
|
||||||
run: |
|
|
||||||
git describe --tags > VERSION
|
|
||||||
|
|
||||||
- name: Set up QEMU
|
|
||||||
uses: docker/setup-qemu-action@v2
|
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v2
|
|
||||||
|
|
||||||
- name: Log in to Docker Hub
|
|
||||||
uses: docker/login-action@v2
|
|
||||||
with:
|
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
||||||
|
|
||||||
- name: Log in to the Container registry
|
|
||||||
uses: docker/login-action@v2
|
|
||||||
with:
|
|
||||||
registry: ghcr.io
|
|
||||||
username: ${{ github.actor }}
|
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
|
|
||||||
- name: Extract metadata (tags, labels) for Docker
|
|
||||||
id: meta
|
|
||||||
uses: docker/metadata-action@v4
|
|
||||||
with:
|
|
||||||
images: |
|
|
||||||
justsong/one-api
|
|
||||||
ghcr.io/${{ github.repository }}
|
|
||||||
|
|
||||||
- name: Build and push Docker images
|
|
||||||
uses: docker/build-push-action@v3
|
|
||||||
with:
|
|
||||||
context: .
|
|
||||||
platforms: linux/amd64,linux/arm64
|
|
||||||
push: true
|
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
|
||||||
59
.github/workflows/linux-release.yml
vendored
59
.github/workflows/linux-release.yml
vendored
@@ -1,59 +0,0 @@
|
|||||||
name: Linux Release
|
|
||||||
permissions:
|
|
||||||
contents: write
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
tags:
|
|
||||||
- '*'
|
|
||||||
- '!*-alpha*'
|
|
||||||
workflow_dispatch:
|
|
||||||
inputs:
|
|
||||||
name:
|
|
||||||
description: 'reason'
|
|
||||||
required: false
|
|
||||||
jobs:
|
|
||||||
release:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
- uses: actions/setup-node@v3
|
|
||||||
with:
|
|
||||||
node-version: 16
|
|
||||||
- name: Build Frontend (theme default)
|
|
||||||
env:
|
|
||||||
CI: ""
|
|
||||||
run: |
|
|
||||||
cd web
|
|
||||||
git describe --tags > VERSION
|
|
||||||
REACT_APP_VERSION=$(git describe --tags) chmod u+x ./build.sh && ./build.sh
|
|
||||||
cd ..
|
|
||||||
- name: Set up Go
|
|
||||||
uses: actions/setup-go@v3
|
|
||||||
with:
|
|
||||||
go-version: '>=1.18.0'
|
|
||||||
- name: Build Backend (amd64)
|
|
||||||
run: |
|
|
||||||
go mod download
|
|
||||||
go build -ldflags "-s -w -X 'one-api/common.Version=$(git describe --tags)' -extldflags '-static'" -o one-api
|
|
||||||
|
|
||||||
- name: Build Backend (arm64)
|
|
||||||
run: |
|
|
||||||
sudo apt-get update
|
|
||||||
sudo apt-get install gcc-aarch64-linux-gnu
|
|
||||||
CC=aarch64-linux-gnu-gcc CGO_ENABLED=1 GOOS=linux GOARCH=arm64 go build -ldflags "-s -w -X 'one-api/common.Version=$(git describe --tags)' -extldflags '-static'" -o one-api-arm64
|
|
||||||
|
|
||||||
- name: Release
|
|
||||||
uses: softprops/action-gh-release@v1
|
|
||||||
if: startsWith(github.ref, 'refs/tags/')
|
|
||||||
with:
|
|
||||||
files: |
|
|
||||||
one-api
|
|
||||||
one-api-arm64
|
|
||||||
draft: true
|
|
||||||
generate_release_notes: true
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
50
.github/workflows/macos-release.yml
vendored
50
.github/workflows/macos-release.yml
vendored
@@ -1,50 +0,0 @@
|
|||||||
name: macOS Release
|
|
||||||
permissions:
|
|
||||||
contents: write
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
tags:
|
|
||||||
- '*'
|
|
||||||
- '!*-alpha*'
|
|
||||||
workflow_dispatch:
|
|
||||||
inputs:
|
|
||||||
name:
|
|
||||||
description: 'reason'
|
|
||||||
required: false
|
|
||||||
jobs:
|
|
||||||
release:
|
|
||||||
runs-on: macos-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
- uses: actions/setup-node@v3
|
|
||||||
with:
|
|
||||||
node-version: 16
|
|
||||||
- name: Build Frontend (theme default)
|
|
||||||
env:
|
|
||||||
CI: ""
|
|
||||||
run: |
|
|
||||||
cd web
|
|
||||||
git describe --tags > VERSION
|
|
||||||
REACT_APP_VERSION=$(git describe --tags) chmod u+x ./build.sh && ./build.sh
|
|
||||||
cd ..
|
|
||||||
- name: Set up Go
|
|
||||||
uses: actions/setup-go@v3
|
|
||||||
with:
|
|
||||||
go-version: '>=1.18.0'
|
|
||||||
- name: Build Backend
|
|
||||||
run: |
|
|
||||||
go mod download
|
|
||||||
go build -ldflags "-X 'one-api/common.Version=$(git describe --tags)'" -o one-api-macos
|
|
||||||
- name: Release
|
|
||||||
uses: softprops/action-gh-release@v1
|
|
||||||
if: startsWith(github.ref, 'refs/tags/')
|
|
||||||
with:
|
|
||||||
files: one-api-macos
|
|
||||||
draft: true
|
|
||||||
generate_release_notes: true
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
53
.github/workflows/windows-release.yml
vendored
53
.github/workflows/windows-release.yml
vendored
@@ -1,53 +0,0 @@
|
|||||||
name: Windows Release
|
|
||||||
permissions:
|
|
||||||
contents: write
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
tags:
|
|
||||||
- '*'
|
|
||||||
- '!*-alpha*'
|
|
||||||
workflow_dispatch:
|
|
||||||
inputs:
|
|
||||||
name:
|
|
||||||
description: 'reason'
|
|
||||||
required: false
|
|
||||||
jobs:
|
|
||||||
release:
|
|
||||||
runs-on: windows-latest
|
|
||||||
defaults:
|
|
||||||
run:
|
|
||||||
shell: bash
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
- uses: actions/setup-node@v3
|
|
||||||
with:
|
|
||||||
node-version: 16
|
|
||||||
- name: Build Frontend (theme default)
|
|
||||||
env:
|
|
||||||
CI: ""
|
|
||||||
run: |
|
|
||||||
cd web/default
|
|
||||||
npm install
|
|
||||||
REACT_APP_VERSION=$(git describe --tags) npm run build
|
|
||||||
cd ../..
|
|
||||||
- name: Set up Go
|
|
||||||
uses: actions/setup-go@v3
|
|
||||||
with:
|
|
||||||
go-version: '>=1.18.0'
|
|
||||||
- name: Build Backend
|
|
||||||
run: |
|
|
||||||
go mod download
|
|
||||||
go build -ldflags "-s -w -X 'one-api/common.Version=$(git describe --tags)'" -o one-api.exe
|
|
||||||
- name: Release
|
|
||||||
uses: softprops/action-gh-release@v1
|
|
||||||
if: startsWith(github.ref, 'refs/tags/')
|
|
||||||
with:
|
|
||||||
files: one-api.exe
|
|
||||||
draft: true
|
|
||||||
generate_release_notes: true
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
@@ -12,11 +12,6 @@ WORKDIR /web/berry
|
|||||||
RUN npm install
|
RUN npm install
|
||||||
RUN DISABLE_ESLINT_PLUGIN='true' REACT_APP_VERSION=$(cat VERSION) npm run build
|
RUN DISABLE_ESLINT_PLUGIN='true' REACT_APP_VERSION=$(cat VERSION) npm run build
|
||||||
|
|
||||||
WORKDIR /web
|
|
||||||
RUN ls
|
|
||||||
RUN ls ./build
|
|
||||||
RUN ls ./build/default
|
|
||||||
|
|
||||||
FROM golang AS builder2
|
FROM golang AS builder2
|
||||||
|
|
||||||
ENV GO111MODULE=on \
|
ENV GO111MODULE=on \
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ var SMTPPort = 587
|
|||||||
var SMTPAccount = ""
|
var SMTPAccount = ""
|
||||||
var SMTPFrom = ""
|
var SMTPFrom = ""
|
||||||
var SMTPToken = ""
|
var SMTPToken = ""
|
||||||
|
var SMTPAuthLoginEnabled = false
|
||||||
|
|
||||||
var GitHubClientId = ""
|
var GitHubClientId = ""
|
||||||
var GitHubClientSecret = ""
|
var GitHubClientSecret = ""
|
||||||
@@ -101,6 +102,10 @@ var RelayTimeout = GetOrDefault("RELAY_TIMEOUT", 0) // unit is second
|
|||||||
var GeminiSafetySetting = GetOrDefaultString("GEMINI_SAFETY_SETTING", "BLOCK_NONE")
|
var GeminiSafetySetting = GetOrDefaultString("GEMINI_SAFETY_SETTING", "BLOCK_NONE")
|
||||||
|
|
||||||
var Theme = GetOrDefaultString("THEME", "default")
|
var Theme = GetOrDefaultString("THEME", "default")
|
||||||
|
var ValidThemes = map[string]bool{
|
||||||
|
"default": true,
|
||||||
|
"berry": true,
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
RequestIdKey = "X-Oneapi-Request-Id"
|
RequestIdKey = "X-Oneapi-Request-Id"
|
||||||
|
|||||||
@@ -4,12 +4,39 @@ import (
|
|||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/smtp"
|
"net/smtp"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type loginAuth struct {
|
||||||
|
username, password string
|
||||||
|
}
|
||||||
|
|
||||||
|
func LoginAuth(username, password string) smtp.Auth {
|
||||||
|
return &loginAuth{username, password}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *loginAuth) Start(_ *smtp.ServerInfo) (string, []byte, error) {
|
||||||
|
return "LOGIN", []byte(a.username), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *loginAuth) Next(fromServer []byte, more bool) ([]byte, error) {
|
||||||
|
if more {
|
||||||
|
switch string(fromServer) {
|
||||||
|
case "Username:":
|
||||||
|
return []byte(a.username), nil
|
||||||
|
case "Password:":
|
||||||
|
return []byte(a.password), nil
|
||||||
|
default:
|
||||||
|
return nil, errors.New("unknown command from server during login auth")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
func SendEmail(subject string, receiver string, content string) error {
|
func SendEmail(subject string, receiver string, content string) error {
|
||||||
if SMTPFrom == "" { // for compatibility
|
if SMTPFrom == "" { // for compatibility
|
||||||
SMTPFrom = SMTPAccount
|
SMTPFrom = SMTPAccount
|
||||||
@@ -37,7 +64,13 @@ func SendEmail(subject string, receiver string, content string) error {
|
|||||||
"Date: %s\r\n"+
|
"Date: %s\r\n"+
|
||||||
"Content-Type: text/html; charset=UTF-8\r\n\r\n%s\r\n",
|
"Content-Type: text/html; charset=UTF-8\r\n\r\n%s\r\n",
|
||||||
receiver, SystemName, SMTPFrom, encodedSubject, messageId, time.Now().Format(time.RFC1123Z), content))
|
receiver, SystemName, SMTPFrom, encodedSubject, messageId, time.Now().Format(time.RFC1123Z), content))
|
||||||
auth := smtp.PlainAuth("", SMTPAccount, SMTPToken, SMTPServer)
|
|
||||||
|
var auth smtp.Auth
|
||||||
|
if SMTPAuthLoginEnabled {
|
||||||
|
auth = LoginAuth(SMTPAccount, SMTPToken)
|
||||||
|
} else {
|
||||||
|
auth = smtp.PlainAuth("", SMTPAccount, SMTPToken, SMTPServer)
|
||||||
|
}
|
||||||
addr := fmt.Sprintf("%s:%d", SMTPServer, SMTPPort)
|
addr := fmt.Sprintf("%s:%d", SMTPServer, SMTPPort)
|
||||||
to := strings.Split(receiver, ";")
|
to := strings.Split(receiver, ";")
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,23 @@ import (
|
|||||||
"one-api/common"
|
"one-api/common"
|
||||||
"one-api/model"
|
"one-api/model"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func parseIntArray(input string) []int {
|
||||||
|
values := strings.Split(input, ",")
|
||||||
|
result := make([]int, 0)
|
||||||
|
|
||||||
|
for _, value := range values {
|
||||||
|
num, err := strconv.Atoi(strings.TrimSpace(value))
|
||||||
|
if err == nil {
|
||||||
|
result = append(result, num)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
func GetAllLogs(c *gin.Context) {
|
func GetAllLogs(c *gin.Context) {
|
||||||
p, _ := strconv.Atoi(c.Query("p"))
|
p, _ := strconv.Atoi(c.Query("p"))
|
||||||
if p < 0 {
|
if p < 0 {
|
||||||
@@ -19,8 +34,8 @@ func GetAllLogs(c *gin.Context) {
|
|||||||
username := c.Query("username")
|
username := c.Query("username")
|
||||||
tokenName := c.Query("token_name")
|
tokenName := c.Query("token_name")
|
||||||
modelName := c.Query("model_name")
|
modelName := c.Query("model_name")
|
||||||
channel, _ := strconv.Atoi(c.Query("channel"))
|
channels := parseIntArray(c.Query("channel"))
|
||||||
logs, err := model.GetAllLogs(logType, startTimestamp, endTimestamp, modelName, username, tokenName, p*common.ItemsPerPage, common.ItemsPerPage, channel)
|
logs, err := model.GetAllLogs(logType, startTimestamp, endTimestamp, modelName, username, tokenName, p*common.ItemsPerPage, common.ItemsPerPage, channels)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"success": false,
|
"success": false,
|
||||||
@@ -107,8 +122,8 @@ func GetLogsStat(c *gin.Context) {
|
|||||||
tokenName := c.Query("token_name")
|
tokenName := c.Query("token_name")
|
||||||
username := c.Query("username")
|
username := c.Query("username")
|
||||||
modelName := c.Query("model_name")
|
modelName := c.Query("model_name")
|
||||||
channel, _ := strconv.Atoi(c.Query("channel"))
|
channels := parseIntArray(c.Query("channel"))
|
||||||
quotaNum := model.SumUsedQuota(logType, startTimestamp, endTimestamp, modelName, username, tokenName, channel)
|
quotaNum := model.SumUsedQuota(logType, startTimestamp, endTimestamp, modelName, username, tokenName, channels)
|
||||||
//tokenNum := model.SumUsedToken(logType, startTimestamp, endTimestamp, modelName, username, "")
|
//tokenNum := model.SumUsedToken(logType, startTimestamp, endTimestamp, modelName, username, "")
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"success": true,
|
"success": true,
|
||||||
@@ -128,8 +143,8 @@ func GetLogsSelfStat(c *gin.Context) {
|
|||||||
endTimestamp, _ := strconv.ParseInt(c.Query("end_timestamp"), 10, 64)
|
endTimestamp, _ := strconv.ParseInt(c.Query("end_timestamp"), 10, 64)
|
||||||
tokenName := c.Query("token_name")
|
tokenName := c.Query("token_name")
|
||||||
modelName := c.Query("model_name")
|
modelName := c.Query("model_name")
|
||||||
channel, _ := strconv.Atoi(c.Query("channel"))
|
channels := parseIntArray(c.Query("channel"))
|
||||||
quotaNum := model.SumUsedQuota(logType, startTimestamp, endTimestamp, modelName, username, tokenName, channel)
|
quotaNum := model.SumUsedQuota(logType, startTimestamp, endTimestamp, modelName, username, tokenName, channels)
|
||||||
//tokenNum := model.SumUsedToken(logType, startTimestamp, endTimestamp, modelName, username, tokenName)
|
//tokenNum := model.SumUsedToken(logType, startTimestamp, endTimestamp, modelName, username, tokenName)
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"success": true,
|
"success": true,
|
||||||
|
|||||||
@@ -42,6 +42,14 @@ func UpdateOption(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
switch option.Key {
|
switch option.Key {
|
||||||
|
case "Theme":
|
||||||
|
if !common.ValidThemes[option.Value] {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"success": false,
|
||||||
|
"message": "无效的主题",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
case "GitHubOAuthEnabled":
|
case "GitHubOAuthEnabled":
|
||||||
if option.Value == "true" && common.GitHubClientId == "" {
|
if option.Value == "true" && common.GitHubClientId == "" {
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
|||||||
@@ -330,6 +330,7 @@
|
|||||||
"通常和邮箱地址保持一致": "Usually consistent with the email address",
|
"通常和邮箱地址保持一致": "Usually consistent with the email address",
|
||||||
"SMTP 访问凭证": "SMTP Access Credential",
|
"SMTP 访问凭证": "SMTP Access Credential",
|
||||||
"敏感信息不会发送到前端显示": "Sensitive information will not be displayed in the frontend",
|
"敏感信息不会发送到前端显示": "Sensitive information will not be displayed in the frontend",
|
||||||
|
"使用 SMTP LOGIN 认证方式": "Use LOGIN as SMTP authentication method",
|
||||||
"保存 SMTP 设置": "Save SMTP Settings",
|
"保存 SMTP 设置": "Save SMTP Settings",
|
||||||
"配置 GitHub OAuth App": "Configure GitHub OAuth App",
|
"配置 GitHub OAuth App": "Configure GitHub OAuth App",
|
||||||
"用以支持通过 GitHub 进行登录注册": "To support login & registration via GitHub",
|
"用以支持通过 GitHub 进行登录注册": "To support login & registration via GitHub",
|
||||||
|
|||||||
3
main.go
3
main.go
@@ -20,7 +20,7 @@ var buildFS embed.FS
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
common.SetupLogger()
|
common.SetupLogger()
|
||||||
common.SysLog(fmt.Sprintf("One API %s started with theme %s", common.Version, common.Theme))
|
common.SysLog(fmt.Sprintf("One API %s started", common.Version))
|
||||||
if os.Getenv("GIN_MODE") != "debug" {
|
if os.Getenv("GIN_MODE") != "debug" {
|
||||||
gin.SetMode(gin.ReleaseMode)
|
gin.SetMode(gin.ReleaseMode)
|
||||||
}
|
}
|
||||||
@@ -47,6 +47,7 @@ func main() {
|
|||||||
|
|
||||||
// Initialize options
|
// Initialize options
|
||||||
model.InitOptionMap()
|
model.InitOptionMap()
|
||||||
|
common.SysLog(fmt.Sprintf("using theme %s", common.Theme))
|
||||||
if common.RedisEnabled {
|
if common.RedisEnabled {
|
||||||
// for compatibility with old versions
|
// for compatibility with old versions
|
||||||
common.MemoryCacheEnabled = true
|
common.MemoryCacheEnabled = true
|
||||||
|
|||||||
21
model/log.go
21
model/log.go
@@ -72,7 +72,7 @@ func RecordConsumeLog(ctx context.Context, userId int, channelId int, promptToke
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetAllLogs(logType int, startTimestamp int64, endTimestamp int64, modelName string, username string, tokenName string, startIdx int, num int, channel int) (logs []*Log, err error) {
|
func GetAllLogs(logType int, startTimestamp int64, endTimestamp int64, modelName string, username string, tokenName string, startIdx int, num int, channels []int) (logs []*Log, err error) {
|
||||||
var tx *gorm.DB
|
var tx *gorm.DB
|
||||||
if logType == LogTypeUnknown {
|
if logType == LogTypeUnknown {
|
||||||
tx = DB
|
tx = DB
|
||||||
@@ -94,9 +94,12 @@ func GetAllLogs(logType int, startTimestamp int64, endTimestamp int64, modelName
|
|||||||
if endTimestamp != 0 {
|
if endTimestamp != 0 {
|
||||||
tx = tx.Where("created_at <= ?", endTimestamp)
|
tx = tx.Where("created_at <= ?", endTimestamp)
|
||||||
}
|
}
|
||||||
if channel != 0 {
|
if len(channels) > 1 {
|
||||||
tx = tx.Where("channel_id = ?", channel)
|
tx = tx.Where("channel_id IN ?", channels)
|
||||||
|
} else if len(channels) == 1 && channels[0] != 0 {
|
||||||
|
tx = tx.Where("channel_id = ?", channels[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
err = tx.Order("id desc").Limit(num).Offset(startIdx).Find(&logs).Error
|
err = tx.Order("id desc").Limit(num).Offset(startIdx).Find(&logs).Error
|
||||||
return logs, err
|
return logs, err
|
||||||
}
|
}
|
||||||
@@ -134,7 +137,7 @@ func SearchUserLogs(userId int, keyword string) (logs []*Log, err error) {
|
|||||||
return logs, err
|
return logs, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func SumUsedQuota(logType int, startTimestamp int64, endTimestamp int64, modelName string, username string, tokenName string, channel int) (quota int) {
|
func SumUsedQuota(logType int, startTimestamp int64, endTimestamp int64, modelName string, username string, tokenName string, channels []int) (quota int) {
|
||||||
tx := DB.Table("logs").Select("ifnull(sum(quota),0)")
|
tx := DB.Table("logs").Select("ifnull(sum(quota),0)")
|
||||||
if username != "" {
|
if username != "" {
|
||||||
tx = tx.Where("username = ?", username)
|
tx = tx.Where("username = ?", username)
|
||||||
@@ -151,8 +154,10 @@ func SumUsedQuota(logType int, startTimestamp int64, endTimestamp int64, modelNa
|
|||||||
if modelName != "" {
|
if modelName != "" {
|
||||||
tx = tx.Where("model_name = ?", modelName)
|
tx = tx.Where("model_name = ?", modelName)
|
||||||
}
|
}
|
||||||
if channel != 0 {
|
if len(channels) > 1 {
|
||||||
tx = tx.Where("channel_id = ?", channel)
|
tx = tx.Where("channel_id IN ?", channels)
|
||||||
|
} else if len(channels) == 1 && channels[0] != 0 {
|
||||||
|
tx = tx.Where("channel_id = ?", channels[0])
|
||||||
}
|
}
|
||||||
tx.Where("type = ?", LogTypeConsume).Scan("a)
|
tx.Where("type = ?", LogTypeConsume).Scan("a)
|
||||||
return quota
|
return quota
|
||||||
@@ -212,13 +217,11 @@ func SearchLogsByDayAndModel(userId, start, end int) (LogStatistics []*LogStatis
|
|||||||
sum(completion_tokens) as completion_tokens
|
sum(completion_tokens) as completion_tokens
|
||||||
FROM logs
|
FROM logs
|
||||||
WHERE type=2
|
WHERE type=2
|
||||||
AND userId= ?
|
AND user_id= ?
|
||||||
AND created_at BETWEEN ? AND ?
|
AND created_at BETWEEN ? AND ?
|
||||||
GROUP BY day, model_name
|
GROUP BY day, model_name
|
||||||
ORDER BY day, model_name
|
ORDER BY day, model_name
|
||||||
`, userId, start, end).Scan(&LogStatistics).Error
|
`, userId, start, end).Scan(&LogStatistics).Error
|
||||||
|
|
||||||
fmt.Println(userId, start, end)
|
|
||||||
|
|
||||||
return LogStatistics, err
|
return LogStatistics, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ func InitOptionMap() {
|
|||||||
common.OptionMap["SMTPPort"] = strconv.Itoa(common.SMTPPort)
|
common.OptionMap["SMTPPort"] = strconv.Itoa(common.SMTPPort)
|
||||||
common.OptionMap["SMTPAccount"] = ""
|
common.OptionMap["SMTPAccount"] = ""
|
||||||
common.OptionMap["SMTPToken"] = ""
|
common.OptionMap["SMTPToken"] = ""
|
||||||
|
common.OptionMap["SMTPAuthLoginEnabled"] = strconv.FormatBool(common.SMTPAuthLoginEnabled)
|
||||||
common.OptionMap["Notice"] = ""
|
common.OptionMap["Notice"] = ""
|
||||||
common.OptionMap["About"] = ""
|
common.OptionMap["About"] = ""
|
||||||
common.OptionMap["HomePageContent"] = ""
|
common.OptionMap["HomePageContent"] = ""
|
||||||
@@ -72,6 +73,7 @@ func InitOptionMap() {
|
|||||||
common.OptionMap["ChatLink"] = common.ChatLink
|
common.OptionMap["ChatLink"] = common.ChatLink
|
||||||
common.OptionMap["QuotaPerUnit"] = strconv.FormatFloat(common.QuotaPerUnit, 'f', -1, 64)
|
common.OptionMap["QuotaPerUnit"] = strconv.FormatFloat(common.QuotaPerUnit, 'f', -1, 64)
|
||||||
common.OptionMap["RetryTimes"] = strconv.Itoa(common.RetryTimes)
|
common.OptionMap["RetryTimes"] = strconv.Itoa(common.RetryTimes)
|
||||||
|
common.OptionMap["Theme"] = common.Theme
|
||||||
common.OptionMapRWMutex.Unlock()
|
common.OptionMapRWMutex.Unlock()
|
||||||
loadOptionsFromDatabase()
|
loadOptionsFromDatabase()
|
||||||
}
|
}
|
||||||
@@ -158,6 +160,8 @@ func updateOptionMap(key string, value string) (err error) {
|
|||||||
common.DisplayInCurrencyEnabled = boolValue
|
common.DisplayInCurrencyEnabled = boolValue
|
||||||
case "DisplayTokenStatEnabled":
|
case "DisplayTokenStatEnabled":
|
||||||
common.DisplayTokenStatEnabled = boolValue
|
common.DisplayTokenStatEnabled = boolValue
|
||||||
|
case "SMTPAuthLoginEnabled":
|
||||||
|
common.SMTPAuthLoginEnabled = boolValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
switch key {
|
switch key {
|
||||||
@@ -220,6 +224,8 @@ func updateOptionMap(key string, value string) (err error) {
|
|||||||
common.ChannelDisableThreshold, _ = strconv.ParseFloat(value, 64)
|
common.ChannelDisableThreshold, _ = strconv.ParseFloat(value, 64)
|
||||||
case "QuotaPerUnit":
|
case "QuotaPerUnit":
|
||||||
common.QuotaPerUnit, _ = strconv.ParseFloat(value, 64)
|
common.QuotaPerUnit, _ = strconv.ParseFloat(value, 64)
|
||||||
|
case "Theme":
|
||||||
|
common.Theme = value
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,9 @@
|
|||||||
|
|
||||||
1. 在 `web` 文件夹下新建一个文件夹,文件夹名为主题名。
|
1. 在 `web` 文件夹下新建一个文件夹,文件夹名为主题名。
|
||||||
2. 把你的主题文件放到这个文件夹下。
|
2. 把你的主题文件放到这个文件夹下。
|
||||||
3. 修改 `package.json` 文件,把 `build` 命令改为:`"build": "react-scripts build && mv -f build ../build/default"`,其中 `default` 为你的主题名。
|
3. 修改你的 `package.json` 文件,把 `build` 命令改为:`"build": "react-scripts build && mv -f build ../build/default"`,其中 `default` 为你的主题名。
|
||||||
|
4. 修改 `common/constants.go` 中的 `ValidThemes`,把你的主题名称注册进去。
|
||||||
|
5. 修改 `web/THEMES` 文件,这里也需要同步修改。
|
||||||
|
|
||||||
## 主题列表
|
## 主题列表
|
||||||
|
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ const panel = {
|
|||||||
url: '/panel/profile',
|
url: '/panel/profile',
|
||||||
icon: icons.IconUserScan,
|
icon: icons.IconUserScan,
|
||||||
breadcrumbs: false,
|
breadcrumbs: false,
|
||||||
isAdmin: true
|
isAdmin: false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'setting',
|
id: 'setting',
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ API.interceptors.response.use(
|
|||||||
if (error.response?.status === 401) {
|
if (error.response?.status === 401) {
|
||||||
localStorage.removeItem('user');
|
localStorage.removeItem('user');
|
||||||
store.dispatch({ type: LOGIN, payload: null });
|
store.dispatch({ type: LOGIN, payload: null });
|
||||||
window.location.href = config.basename + '/login';
|
window.location.href = config.basename + 'login';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (error.response?.data?.message) {
|
if (error.response?.data?.message) {
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ const LoginForm = ({ ...others }) => {
|
|||||||
<Box sx={{ mr: { xs: 1, sm: 2, width: 20 }, display: 'flex', alignItems: 'center' }}>
|
<Box sx={{ mr: { xs: 1, sm: 2, width: 20 }, display: 'flex', alignItems: 'center' }}>
|
||||||
<img src={Github} alt="github" width={25} height={25} style={{ marginRight: matchDownSM ? 8 : 16 }} />
|
<img src={Github} alt="github" width={25} height={25} style={{ marginRight: matchDownSM ? 8 : 16 }} />
|
||||||
</Box>
|
</Box>
|
||||||
使用 Github 登录
|
使用 GitHub 登录
|
||||||
</Button>
|
</Button>
|
||||||
</AnimateButton>
|
</AnimateButton>
|
||||||
</Grid>
|
</Grid>
|
||||||
@@ -115,7 +115,7 @@ const LoginForm = ({ ...others }) => {
|
|||||||
<Box sx={{ mr: { xs: 1, sm: 2, width: 20 }, display: 'flex', alignItems: 'center' }}>
|
<Box sx={{ mr: { xs: 1, sm: 2, width: 20 }, display: 'flex', alignItems: 'center' }}>
|
||||||
<img src={Wechat} alt="Wechat" width={25} height={25} style={{ marginRight: matchDownSM ? 8 : 16 }} />
|
<img src={Wechat} alt="Wechat" width={25} height={25} style={{ marginRight: matchDownSM ? 8 : 16 }} />
|
||||||
</Box>
|
</Box>
|
||||||
使用 Wechat 登录
|
使用微信登录
|
||||||
</Button>
|
</Button>
|
||||||
</AnimateButton>
|
</AnimateButton>
|
||||||
<WechatModal open={openWechat} handleClose={handleWechatClose} wechatLogin={wechatLogin} qrCode={siteInfo.wechat_qrcode} />
|
<WechatModal open={openWechat} handleClose={handleWechatClose} wechatLogin={wechatLogin} qrCode={siteInfo.wechat_qrcode} />
|
||||||
|
|||||||
@@ -38,8 +38,6 @@ const validationSchema = Yup.object().shape({
|
|||||||
then: Yup.string().required("密钥 不能为空"),
|
then: Yup.string().required("密钥 不能为空"),
|
||||||
}),
|
}),
|
||||||
other: Yup.string(),
|
other: Yup.string(),
|
||||||
proxy: Yup.string(),
|
|
||||||
test_model: Yup.string(),
|
|
||||||
models: Yup.array().min(1, "模型 不能为空"),
|
models: Yup.array().min(1, "模型 不能为空"),
|
||||||
groups: Yup.array().min(1, "用户组 不能为空"),
|
groups: Yup.array().min(1, "用户组 不能为空"),
|
||||||
base_url: Yup.string().when("type", {
|
base_url: Yup.string().when("type", {
|
||||||
@@ -623,71 +621,6 @@ const EditModal = ({ open, channelId, onCancel, onOk }) => {
|
|||||||
</FormHelperText>
|
</FormHelperText>
|
||||||
)}
|
)}
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormControl
|
|
||||||
fullWidth
|
|
||||||
error={Boolean(touched.proxy && errors.proxy)}
|
|
||||||
sx={{ ...theme.typography.otherInput }}
|
|
||||||
>
|
|
||||||
<InputLabel htmlFor="channel-proxy-label">
|
|
||||||
{inputLabel.proxy}
|
|
||||||
</InputLabel>
|
|
||||||
<OutlinedInput
|
|
||||||
id="channel-proxy-label"
|
|
||||||
label={inputLabel.proxy}
|
|
||||||
type="text"
|
|
||||||
value={values.proxy}
|
|
||||||
name="proxy"
|
|
||||||
onBlur={handleBlur}
|
|
||||||
onChange={handleChange}
|
|
||||||
inputProps={{}}
|
|
||||||
aria-describedby="helper-text-channel-proxy-label"
|
|
||||||
/>
|
|
||||||
{touched.proxy && errors.proxy ? (
|
|
||||||
<FormHelperText error id="helper-tex-channel-proxy-label">
|
|
||||||
{errors.proxy}
|
|
||||||
</FormHelperText>
|
|
||||||
) : (
|
|
||||||
<FormHelperText id="helper-tex-channel-proxy-label">
|
|
||||||
{" "}
|
|
||||||
{inputPrompt.proxy}{" "}
|
|
||||||
</FormHelperText>
|
|
||||||
)}
|
|
||||||
</FormControl>
|
|
||||||
{inputPrompt.test_model && (
|
|
||||||
<FormControl
|
|
||||||
fullWidth
|
|
||||||
error={Boolean(touched.test_model && errors.test_model)}
|
|
||||||
sx={{ ...theme.typography.otherInput }}
|
|
||||||
>
|
|
||||||
<InputLabel htmlFor="channel-test_model-label">
|
|
||||||
{inputLabel.test_model}
|
|
||||||
</InputLabel>
|
|
||||||
<OutlinedInput
|
|
||||||
id="channel-test_model-label"
|
|
||||||
label={inputLabel.test_model}
|
|
||||||
type="text"
|
|
||||||
value={values.test_model}
|
|
||||||
name="test_model"
|
|
||||||
onBlur={handleBlur}
|
|
||||||
onChange={handleChange}
|
|
||||||
inputProps={{}}
|
|
||||||
aria-describedby="helper-text-channel-test_model-label"
|
|
||||||
/>
|
|
||||||
{touched.test_model && errors.test_model ? (
|
|
||||||
<FormHelperText
|
|
||||||
error
|
|
||||||
id="helper-tex-channel-test_model-label"
|
|
||||||
>
|
|
||||||
{errors.test_model}
|
|
||||||
</FormHelperText>
|
|
||||||
) : (
|
|
||||||
<FormHelperText id="helper-tex-channel-test_model-label">
|
|
||||||
{" "}
|
|
||||||
{inputPrompt.test_model}{" "}
|
|
||||||
</FormHelperText>
|
|
||||||
)}
|
|
||||||
</FormControl>
|
|
||||||
)}
|
|
||||||
<DialogActions>
|
<DialogActions>
|
||||||
<Button onClick={onCancel}>取消</Button>
|
<Button onClick={onCancel}>取消</Button>
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
import { useState, useEffect } from 'react';
|
import { useState, useEffect } from 'react';
|
||||||
import SubCard from 'ui-component/cards/SubCard';
|
import SubCard from 'ui-component/cards/SubCard';
|
||||||
import {
|
import {
|
||||||
Stack,
|
Stack,
|
||||||
FormControl,
|
FormControl,
|
||||||
InputLabel,
|
InputLabel,
|
||||||
OutlinedInput,
|
OutlinedInput,
|
||||||
Button,
|
Button,
|
||||||
Alert,
|
Alert,
|
||||||
TextField,
|
TextField,
|
||||||
Dialog,
|
Dialog,
|
||||||
DialogTitle,
|
DialogTitle,
|
||||||
DialogActions,
|
DialogActions,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
Divider
|
Divider, Link
|
||||||
} from '@mui/material';
|
} from '@mui/material';
|
||||||
import Grid from '@mui/material/Unstable_Grid2';
|
import Grid from '@mui/material/Unstable_Grid2';
|
||||||
import { showError, showSuccess } from 'utils/common'; //,
|
import { showError, showSuccess } from 'utils/common'; //,
|
||||||
@@ -26,7 +26,8 @@ const OtherSetting = () => {
|
|||||||
About: '',
|
About: '',
|
||||||
SystemName: '',
|
SystemName: '',
|
||||||
Logo: '',
|
Logo: '',
|
||||||
HomePageContent: ''
|
HomePageContent: '',
|
||||||
|
Theme: '',
|
||||||
});
|
});
|
||||||
let [loading, setLoading] = useState(false);
|
let [loading, setLoading] = useState(false);
|
||||||
const [showUpdateModal, setShowUpdateModal] = useState(false);
|
const [showUpdateModal, setShowUpdateModal] = useState(false);
|
||||||
@@ -88,6 +89,10 @@ const OtherSetting = () => {
|
|||||||
await updateOption('SystemName', inputs.SystemName);
|
await updateOption('SystemName', inputs.SystemName);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const submitTheme = async () => {
|
||||||
|
await updateOption('Theme', inputs.Theme);
|
||||||
|
};
|
||||||
|
|
||||||
const submitLogo = async () => {
|
const submitLogo = async () => {
|
||||||
await updateOption('Logo', inputs.Logo);
|
await updateOption('Logo', inputs.Logo);
|
||||||
};
|
};
|
||||||
@@ -171,6 +176,25 @@ const OtherSetting = () => {
|
|||||||
设置系统名称
|
设置系统名称
|
||||||
</Button>
|
</Button>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
<Grid xs={12}>
|
||||||
|
<FormControl fullWidth>
|
||||||
|
<InputLabel htmlFor="Theme">主题名称</InputLabel>
|
||||||
|
<OutlinedInput
|
||||||
|
id="Theme"
|
||||||
|
name="Theme"
|
||||||
|
value={inputs.Theme || ''}
|
||||||
|
onChange={handleInputChange}
|
||||||
|
label="主题名称"
|
||||||
|
placeholder="请输入主题名称"
|
||||||
|
disabled={loading}
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
</Grid>
|
||||||
|
<Grid xs={12}>
|
||||||
|
<Button variant="contained" onClick={submitTheme}>
|
||||||
|
设置主题(重启生效)
|
||||||
|
</Button>
|
||||||
|
</Grid>
|
||||||
<Grid xs={12}>
|
<Grid xs={12}>
|
||||||
<FormControl fullWidth>
|
<FormControl fullWidth>
|
||||||
<InputLabel htmlFor="Logo">Logo 图片地址</InputLabel>
|
<InputLabel htmlFor="Logo">Logo 图片地址</InputLabel>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import React, { useEffect, useState } from 'react';
|
|||||||
import { Button, Divider, Form, Grid, Header, Message, Modal } from 'semantic-ui-react';
|
import { Button, Divider, Form, Grid, Header, Message, Modal } from 'semantic-ui-react';
|
||||||
import { API, showError, showSuccess } from '../helpers';
|
import { API, showError, showSuccess } from '../helpers';
|
||||||
import { marked } from 'marked';
|
import { marked } from 'marked';
|
||||||
|
import { Link } from 'react-router-dom';
|
||||||
|
|
||||||
const OtherSetting = () => {
|
const OtherSetting = () => {
|
||||||
let [inputs, setInputs] = useState({
|
let [inputs, setInputs] = useState({
|
||||||
@@ -10,7 +11,8 @@ const OtherSetting = () => {
|
|||||||
About: '',
|
About: '',
|
||||||
SystemName: '',
|
SystemName: '',
|
||||||
Logo: '',
|
Logo: '',
|
||||||
HomePageContent: ''
|
HomePageContent: '',
|
||||||
|
Theme: ''
|
||||||
});
|
});
|
||||||
let [loading, setLoading] = useState(false);
|
let [loading, setLoading] = useState(false);
|
||||||
const [showUpdateModal, setShowUpdateModal] = useState(false);
|
const [showUpdateModal, setShowUpdateModal] = useState(false);
|
||||||
@@ -70,6 +72,10 @@ const OtherSetting = () => {
|
|||||||
await updateOption('SystemName', inputs.SystemName);
|
await updateOption('SystemName', inputs.SystemName);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const submitTheme = async () => {
|
||||||
|
await updateOption('Theme', inputs.Theme);
|
||||||
|
};
|
||||||
|
|
||||||
const submitLogo = async () => {
|
const submitLogo = async () => {
|
||||||
await updateOption('Logo', inputs.Logo);
|
await updateOption('Logo', inputs.Logo);
|
||||||
};
|
};
|
||||||
@@ -132,6 +138,17 @@ const OtherSetting = () => {
|
|||||||
/>
|
/>
|
||||||
</Form.Group>
|
</Form.Group>
|
||||||
<Form.Button onClick={submitSystemName}>设置系统名称</Form.Button>
|
<Form.Button onClick={submitSystemName}>设置系统名称</Form.Button>
|
||||||
|
<Form.Group widths='equal'>
|
||||||
|
<Form.Input
|
||||||
|
label={<label>主题名称(<Link
|
||||||
|
to='https://github.com/songquanpeng/one-api/blob/main/web/README.md'>当前可用主题</Link>)</label>}
|
||||||
|
placeholder='请输入主题名称'
|
||||||
|
value={inputs.Theme}
|
||||||
|
name='Theme'
|
||||||
|
onChange={handleInputChange}
|
||||||
|
/>
|
||||||
|
</Form.Group>
|
||||||
|
<Form.Button onClick={submitTheme}>设置主题(重启生效)</Form.Button>
|
||||||
<Form.Group widths='equal'>
|
<Form.Group widths='equal'>
|
||||||
<Form.Input
|
<Form.Input
|
||||||
label='Logo 图片地址'
|
label='Logo 图片地址'
|
||||||
@@ -165,7 +182,8 @@ const OtherSetting = () => {
|
|||||||
/>
|
/>
|
||||||
</Form.Group>
|
</Form.Group>
|
||||||
<Form.Button onClick={submitAbout}>保存关于</Form.Button>
|
<Form.Button onClick={submitAbout}>保存关于</Form.Button>
|
||||||
<Message>移除 One API 的版权标识必须首先获得授权,项目维护需要花费大量精力,如果本项目对你有意义,请主动支持本项目。</Message>
|
<Message>移除 One API
|
||||||
|
的版权标识必须首先获得授权,项目维护需要花费大量精力,如果本项目对你有意义,请主动支持本项目。</Message>
|
||||||
<Form.Group widths='equal'>
|
<Form.Group widths='equal'>
|
||||||
<Form.Input
|
<Form.Input
|
||||||
label='页脚'
|
label='页脚'
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ const SystemSetting = () => {
|
|||||||
SMTPAccount: '',
|
SMTPAccount: '',
|
||||||
SMTPFrom: '',
|
SMTPFrom: '',
|
||||||
SMTPToken: '',
|
SMTPToken: '',
|
||||||
|
SMTPAuthLoginEnabled: '',
|
||||||
ServerAddress: '',
|
ServerAddress: '',
|
||||||
Footer: '',
|
Footer: '',
|
||||||
WeChatAuthEnabled: '',
|
WeChatAuthEnabled: '',
|
||||||
@@ -72,6 +73,7 @@ const SystemSetting = () => {
|
|||||||
case 'TurnstileCheckEnabled':
|
case 'TurnstileCheckEnabled':
|
||||||
case 'EmailDomainRestrictionEnabled':
|
case 'EmailDomainRestrictionEnabled':
|
||||||
case 'RegisterEnabled':
|
case 'RegisterEnabled':
|
||||||
|
case 'SMTPAuthLoginEnabled':
|
||||||
value = inputs[key] === 'true' ? 'false' : 'true';
|
value = inputs[key] === 'true' ? 'false' : 'true';
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -103,7 +105,7 @@ const SystemSetting = () => {
|
|||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
name === 'Notice' ||
|
name === 'Notice' ||
|
||||||
name.startsWith('SMTP') ||
|
(name.startsWith('SMTP') && !name.endsWith('Enabled')) ||
|
||||||
name === 'ServerAddress' ||
|
name === 'ServerAddress' ||
|
||||||
name === 'GitHubClientId' ||
|
name === 'GitHubClientId' ||
|
||||||
name === 'GitHubClientSecret' ||
|
name === 'GitHubClientSecret' ||
|
||||||
@@ -411,6 +413,12 @@ const SystemSetting = () => {
|
|||||||
checked={inputs.RegisterEnabled === 'true'}
|
checked={inputs.RegisterEnabled === 'true'}
|
||||||
placeholder='敏感信息不会发送到前端显示'
|
placeholder='敏感信息不会发送到前端显示'
|
||||||
/>
|
/>
|
||||||
|
<Form.Checkbox
|
||||||
|
checked={inputs.SMTPAuthLoginEnabled === 'true'}
|
||||||
|
label='使用 SMTP LOGIN 认证方式'
|
||||||
|
name='SMTPAuthLoginEnabled'
|
||||||
|
onChange={handleInputChange}
|
||||||
|
/>
|
||||||
</Form.Group>
|
</Form.Group>
|
||||||
<Form.Button onClick={submitSMTP}>保存 SMTP 设置</Form.Button>
|
<Form.Button onClick={submitSMTP}>保存 SMTP 设置</Form.Button>
|
||||||
<Divider />
|
<Divider />
|
||||||
|
|||||||
Reference in New Issue
Block a user