mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-11-08 09:43:42 +08:00
Compare commits
11 Commits
v0.5.11-al
...
v0.5.11-al
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d062bc60e4 | ||
|
|
39c1882970 | ||
|
|
9c42c7dfd9 | ||
|
|
903aaeded0 | ||
|
|
bdd4be562d | ||
|
|
37afb313b5 | ||
|
|
c9ebcab8b8 | ||
|
|
86261cc656 | ||
|
|
8491785c9d | ||
|
|
e848a3f7fa | ||
|
|
318adf5985 |
@@ -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 \
|
||||||
|
|||||||
@@ -101,6 +101,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"
|
||||||
|
|||||||
@@ -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{
|
||||||
|
|||||||
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
|
||||||
|
|||||||
@@ -212,13 +212,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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,6 +72,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()
|
||||||
}
|
}
|
||||||
@@ -220,6 +221,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='页脚'
|
||||||
|
|||||||
Reference in New Issue
Block a user