mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-11-02 06:43:41 +08:00
Compare commits
5 Commits
v0.5.11-al
...
v0.5.11-al
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bdd4be562d | ||
|
|
37afb313b5 | ||
|
|
c9ebcab8b8 | ||
|
|
86261cc656 | ||
|
|
8491785c9d |
@@ -100,7 +100,11 @@ var RelayTimeout = GetOrDefault("RELAY_TIMEOUT", 0) // unit is second
|
||||
|
||||
var GeminiSafetySetting = GetOrDefaultString("GEMINI_SAFETY_SETTING", "BLOCK_NONE")
|
||||
|
||||
var Theme = GetOrDefaultString("THEME", "default")
|
||||
var Theme = "default"
|
||||
var ValidThemes = map[string]bool{
|
||||
"default": true,
|
||||
"berry": true,
|
||||
}
|
||||
|
||||
const (
|
||||
RequestIdKey = "X-Oneapi-Request-Id"
|
||||
|
||||
@@ -42,6 +42,14 @@ func UpdateOption(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
switch option.Key {
|
||||
case "Theme":
|
||||
if !common.ValidThemes[option.Value] {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "无效的主题",
|
||||
})
|
||||
return
|
||||
}
|
||||
case "GitHubOAuthEnabled":
|
||||
if option.Value == "true" && common.GitHubClientId == "" {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
|
||||
3
main.go
3
main.go
@@ -20,7 +20,7 @@ var buildFS embed.FS
|
||||
|
||||
func main() {
|
||||
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" {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
}
|
||||
@@ -47,6 +47,7 @@ func main() {
|
||||
|
||||
// Initialize options
|
||||
model.InitOptionMap()
|
||||
common.SysLog(fmt.Sprintf("using theme %s", common.Theme))
|
||||
if common.RedisEnabled {
|
||||
// for compatibility with old versions
|
||||
common.MemoryCacheEnabled = true
|
||||
|
||||
@@ -218,7 +218,5 @@ func SearchLogsByDayAndModel(userId, start, end int) (LogStatistics []*LogStatis
|
||||
ORDER BY day, model_name
|
||||
`, userId, start, end).Scan(&LogStatistics).Error
|
||||
|
||||
fmt.Println(userId, start, end)
|
||||
|
||||
return LogStatistics, err
|
||||
}
|
||||
|
||||
@@ -72,6 +72,7 @@ func InitOptionMap() {
|
||||
common.OptionMap["ChatLink"] = common.ChatLink
|
||||
common.OptionMap["QuotaPerUnit"] = strconv.FormatFloat(common.QuotaPerUnit, 'f', -1, 64)
|
||||
common.OptionMap["RetryTimes"] = strconv.Itoa(common.RetryTimes)
|
||||
common.OptionMap["Theme"] = common.Theme
|
||||
common.OptionMapRWMutex.Unlock()
|
||||
loadOptionsFromDatabase()
|
||||
}
|
||||
@@ -220,6 +221,8 @@ func updateOptionMap(key string, value string) (err error) {
|
||||
common.ChannelDisableThreshold, _ = strconv.ParseFloat(value, 64)
|
||||
case "QuotaPerUnit":
|
||||
common.QuotaPerUnit, _ = strconv.ParseFloat(value, 64)
|
||||
case "Theme":
|
||||
common.Theme = value
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ const panel = {
|
||||
url: '/panel/profile',
|
||||
icon: icons.IconUserScan,
|
||||
breadcrumbs: false,
|
||||
isAdmin: true
|
||||
isAdmin: false
|
||||
},
|
||||
{
|
||||
id: 'setting',
|
||||
|
||||
@@ -14,7 +14,7 @@ API.interceptors.response.use(
|
||||
if (error.response?.status === 401) {
|
||||
localStorage.removeItem('user');
|
||||
store.dispatch({ type: LOGIN, payload: null });
|
||||
window.location.href = config.basename + '/login';
|
||||
window.location.href = config.basename + 'login';
|
||||
}
|
||||
|
||||
if (error.response?.data?.message) {
|
||||
|
||||
@@ -38,8 +38,6 @@ const validationSchema = Yup.object().shape({
|
||||
then: Yup.string().required("密钥 不能为空"),
|
||||
}),
|
||||
other: Yup.string(),
|
||||
proxy: Yup.string(),
|
||||
test_model: Yup.string(),
|
||||
models: Yup.array().min(1, "模型 不能为空"),
|
||||
groups: Yup.array().min(1, "用户组 不能为空"),
|
||||
base_url: Yup.string().when("type", {
|
||||
@@ -623,71 +621,6 @@ const EditModal = ({ open, channelId, onCancel, onOk }) => {
|
||||
</FormHelperText>
|
||||
)}
|
||||
</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>
|
||||
<Button onClick={onCancel}>取消</Button>
|
||||
<Button
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import SubCard from 'ui-component/cards/SubCard';
|
||||
import {
|
||||
Stack,
|
||||
FormControl,
|
||||
InputLabel,
|
||||
OutlinedInput,
|
||||
Button,
|
||||
Alert,
|
||||
TextField,
|
||||
Dialog,
|
||||
DialogTitle,
|
||||
DialogActions,
|
||||
DialogContent,
|
||||
Divider
|
||||
Stack,
|
||||
FormControl,
|
||||
InputLabel,
|
||||
OutlinedInput,
|
||||
Button,
|
||||
Alert,
|
||||
TextField,
|
||||
Dialog,
|
||||
DialogTitle,
|
||||
DialogActions,
|
||||
DialogContent,
|
||||
Divider, Link
|
||||
} from '@mui/material';
|
||||
import Grid from '@mui/material/Unstable_Grid2';
|
||||
import { showError, showSuccess } from 'utils/common'; //,
|
||||
@@ -26,7 +26,8 @@ const OtherSetting = () => {
|
||||
About: '',
|
||||
SystemName: '',
|
||||
Logo: '',
|
||||
HomePageContent: ''
|
||||
HomePageContent: '',
|
||||
Theme: '',
|
||||
});
|
||||
let [loading, setLoading] = useState(false);
|
||||
const [showUpdateModal, setShowUpdateModal] = useState(false);
|
||||
@@ -88,6 +89,10 @@ const OtherSetting = () => {
|
||||
await updateOption('SystemName', inputs.SystemName);
|
||||
};
|
||||
|
||||
const submitTheme = async () => {
|
||||
await updateOption('Theme', inputs.Theme);
|
||||
};
|
||||
|
||||
const submitLogo = async () => {
|
||||
await updateOption('Logo', inputs.Logo);
|
||||
};
|
||||
@@ -171,6 +176,25 @@ const OtherSetting = () => {
|
||||
设置系统名称
|
||||
</Button>
|
||||
</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}>
|
||||
<FormControl fullWidth>
|
||||
<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 { API, showError, showSuccess } from '../helpers';
|
||||
import { marked } from 'marked';
|
||||
import { Link } from 'react-router-dom';
|
||||
|
||||
const OtherSetting = () => {
|
||||
let [inputs, setInputs] = useState({
|
||||
@@ -10,7 +11,8 @@ const OtherSetting = () => {
|
||||
About: '',
|
||||
SystemName: '',
|
||||
Logo: '',
|
||||
HomePageContent: ''
|
||||
HomePageContent: '',
|
||||
Theme: ''
|
||||
});
|
||||
let [loading, setLoading] = useState(false);
|
||||
const [showUpdateModal, setShowUpdateModal] = useState(false);
|
||||
@@ -70,6 +72,10 @@ const OtherSetting = () => {
|
||||
await updateOption('SystemName', inputs.SystemName);
|
||||
};
|
||||
|
||||
const submitTheme = async () => {
|
||||
await updateOption('Theme', inputs.Theme);
|
||||
};
|
||||
|
||||
const submitLogo = async () => {
|
||||
await updateOption('Logo', inputs.Logo);
|
||||
};
|
||||
@@ -132,6 +138,17 @@ const OtherSetting = () => {
|
||||
/>
|
||||
</Form.Group>
|
||||
<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.Input
|
||||
label='Logo 图片地址'
|
||||
@@ -165,7 +182,8 @@ const OtherSetting = () => {
|
||||
/>
|
||||
</Form.Group>
|
||||
<Form.Button onClick={submitAbout}>保存关于</Form.Button>
|
||||
<Message>移除 One API 的版权标识必须首先获得授权,项目维护需要花费大量精力,如果本项目对你有意义,请主动支持本项目。</Message>
|
||||
<Message>移除 One API
|
||||
的版权标识必须首先获得授权,项目维护需要花费大量精力,如果本项目对你有意义,请主动支持本项目。</Message>
|
||||
<Form.Group widths='equal'>
|
||||
<Form.Input
|
||||
label='页脚'
|
||||
|
||||
Reference in New Issue
Block a user