mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-24 22:03:54 +00:00
feat: admin set env
This commit is contained in:
@@ -3,4 +3,6 @@ MONGODB_NAME=fastgpt
|
||||
ADMIN_USER=username
|
||||
ADMIN_PASS=password
|
||||
ADMIN_SECRET=any
|
||||
PARENT_URL=http://localhost:3000 # FastGpt服务的地址
|
||||
PARENT_ROOT_KEY=rootkey # FastGpt 的rootkey
|
||||
VITE_PUBLIC_SERVER_URL=http://localhost:3001 # 和server.js一致
|
@@ -1,4 +1,5 @@
|
||||
import jwt from 'jsonwebtoken';
|
||||
import { System } from '../schema.js';
|
||||
|
||||
const adminAuth = {
|
||||
username: process.env.ADMIN_USER,
|
||||
@@ -6,6 +7,14 @@ const adminAuth = {
|
||||
};
|
||||
const authSecret = process.env.ADMIN_SECRET;
|
||||
|
||||
const postParent = () => {
|
||||
fetch(`${process.env.PARENT_URL}/api/system/updateEnv`, {
|
||||
headers: {
|
||||
rootkey: process.env.PARENT_ROOT_KEY
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useSystemRoute = (app) => {
|
||||
app.post('/api/login', (req, res) => {
|
||||
if (!adminAuth.username || !adminAuth.password) {
|
||||
@@ -37,6 +46,63 @@ export const useSystemRoute = (app) => {
|
||||
res.status(401).end('username or password incorrect');
|
||||
}
|
||||
});
|
||||
app.get('/system', auth(), async (req, res) => {
|
||||
try {
|
||||
const data = await System.find();
|
||||
const totalCount = await System.countDocuments();
|
||||
|
||||
res.header('Access-Control-Expose-Headers', 'X-Total-Count');
|
||||
res.header('X-Total-Count', totalCount);
|
||||
res.json(
|
||||
data.map((item) => {
|
||||
const obj = item.toObject();
|
||||
return {
|
||||
...obj,
|
||||
id: obj._id
|
||||
};
|
||||
})
|
||||
);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
|
||||
res.status(500).json({ error: 'Error creating system env' });
|
||||
}
|
||||
});
|
||||
app.post('/system', auth(), async (req, res) => {
|
||||
try {
|
||||
await System.create({
|
||||
...req.body,
|
||||
sensitiveCheck: req.body.sensitiveCheck === 'true'
|
||||
});
|
||||
postParent();
|
||||
res.json({});
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: 'Error creating system env' });
|
||||
}
|
||||
});
|
||||
app.put('/system/:id', auth(), async (req, res) => {
|
||||
try {
|
||||
const _id = req.params.id;
|
||||
await System.findByIdAndUpdate(_id, {
|
||||
...req.body,
|
||||
sensitiveCheck: req.body.sensitiveCheck === 'true'
|
||||
});
|
||||
postParent();
|
||||
res.json({});
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: 'Error updating system env' });
|
||||
}
|
||||
});
|
||||
app.delete('/system/:id', auth(), async (req, res) => {
|
||||
try {
|
||||
const _id = req.params.id;
|
||||
await System.findByIdAndDelete(_id);
|
||||
|
||||
res.json({});
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: 'Error updating system env' });
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const auth = () => {
|
||||
|
@@ -84,7 +84,35 @@ const modelSchema = new mongoose.Schema({
|
||||
updateTime: Date
|
||||
});
|
||||
|
||||
export const Model = mongoose.model('Model', modelSchema);
|
||||
export const Kb = mongoose.model('Kb', kbSchema);
|
||||
export const User = mongoose.model('User', userSchema, 'users');
|
||||
export const Pay = mongoose.model('Pay', paySchema, 'pays');
|
||||
const SystemSchema = new mongoose.Schema({
|
||||
openAIKeys: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
openAITrainingKeys: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
gpt4Key: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
vectorMaxProcess: {
|
||||
type: Number,
|
||||
default: 10
|
||||
},
|
||||
qaMaxProcess: {
|
||||
type: Number,
|
||||
default: 10
|
||||
},
|
||||
sensitiveCheck: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
});
|
||||
|
||||
export const Model = mongoose.models['model'] || mongoose.model('model', modelSchema);
|
||||
export const Kb = mongoose.models['kb'] || mongoose.model('kb', kbSchema);
|
||||
export const User = mongoose.models['user'] || mongoose.model('user', userSchema);
|
||||
export const Pay = mongoose.models['pay'] || mongoose.model('pay', paySchema);
|
||||
export const System = mongoose.models['system'] || mongoose.model('system', SystemSchema);
|
||||
|
@@ -7,7 +7,7 @@ import {
|
||||
fetchJSON
|
||||
} from 'tushan';
|
||||
import { authProvider } from './auth';
|
||||
import { userFields, payFields, kbFields, ModelFields } from './fields';
|
||||
import { userFields, payFields, kbFields, ModelFields, SystemFields } from './fields';
|
||||
import { Dashboard } from './Dashboard';
|
||||
|
||||
const authStorageKey = 'tushan:auth';
|
||||
@@ -88,6 +88,16 @@ function App() {
|
||||
label="应用"
|
||||
list={<ListTable fields={ModelFields} action={{ detail: true }} />}
|
||||
/>
|
||||
<Resource
|
||||
name="system"
|
||||
label="系统"
|
||||
list={
|
||||
<ListTable
|
||||
fields={SystemFields}
|
||||
action={{ detail: true, edit: true, create: true, delete: true }}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
</Tushan>
|
||||
);
|
||||
}
|
||||
|
@@ -38,3 +38,12 @@ export const ModelFields = [
|
||||
}),
|
||||
createTextField('temperature', { label: '温度' })
|
||||
];
|
||||
|
||||
export const SystemFields = [
|
||||
createTextField('openAIKeys', { label: 'openAIKeys,逗号隔开' }),
|
||||
createTextField('openAITrainingKeys', { label: 'openAITrainingKeys' }),
|
||||
createTextField('gpt4Key', { label: 'gpt4Key' }),
|
||||
createTextField('vectorMaxProcess', { label: '向量最大进程' }),
|
||||
createTextField('qaMaxProcess', { label: 'qa最大进程' }),
|
||||
createTextField('sensitiveCheck', { label: '敏感词校验(true,false)' })
|
||||
];
|
||||
|
Reference in New Issue
Block a user