mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-27 08:25:07 +00:00
feat: admin add user
This commit is contained in:
@@ -46,63 +46,6 @@ 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 = () => {
|
||||
@@ -110,7 +53,7 @@ export const auth = () => {
|
||||
try {
|
||||
const authorization = req.headers.authorization;
|
||||
if (!authorization) {
|
||||
return next(new Error("unAuthorization"))
|
||||
return next(new Error('unAuthorization'));
|
||||
}
|
||||
|
||||
const token = authorization.slice('Bearer '.length);
|
||||
|
Reference in New Issue
Block a user