mirror of
https://github.com/ItzCrazyKns/Perplexica.git
synced 2025-09-21 08:41:32 +00:00
feat(app): add password auth for settings
This commit is contained in:
@@ -9,11 +9,23 @@ import {
|
||||
getAnthropicApiKey,
|
||||
getOpenaiApiKey,
|
||||
updateConfig,
|
||||
getConfigPassword,
|
||||
isLibraryEnabled,
|
||||
isCopilotEnabled,
|
||||
isDiscoverEnabled,
|
||||
} from '../config';
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
router.get('/', async (_, res) => {
|
||||
router.get('/', async (req, res) => {
|
||||
const authHeader = req.headers['authorization']?.split(' ')[1];
|
||||
const password = getConfigPassword();
|
||||
|
||||
if (authHeader !== password) {
|
||||
res.status(401).json({ message: 'Unauthorized' });
|
||||
return;
|
||||
}
|
||||
|
||||
const config = {};
|
||||
|
||||
const [chatModelProviders, embeddingModelProviders] = await Promise.all([
|
||||
@@ -40,14 +52,30 @@ router.get('/', async (_, res) => {
|
||||
config['ollamaApiUrl'] = getOllamaApiEndpoint();
|
||||
config['anthropicApiKey'] = getAnthropicApiKey();
|
||||
config['groqApiKey'] = getGroqApiKey();
|
||||
config['isLibraryEnabled'] = isLibraryEnabled();
|
||||
config['isCopilotEnabled'] = isCopilotEnabled();
|
||||
config['isDiscoverEnabled'] = isDiscoverEnabled();
|
||||
|
||||
res.status(200).json(config);
|
||||
});
|
||||
|
||||
router.post('/', async (req, res) => {
|
||||
const authHeader = req.headers['authorization']?.split(' ')[1];
|
||||
const password = getConfigPassword();
|
||||
|
||||
if (authHeader !== password) {
|
||||
res.status(401).json({ message: 'Unauthorized' });
|
||||
return;
|
||||
}
|
||||
|
||||
const config = req.body;
|
||||
|
||||
const updatedConfig = {
|
||||
GENERAL: {
|
||||
DISCOVER_ENABLED: config.isDiscoverEnabled,
|
||||
LIBRARY_ENABLED: config.isLibraryEnabled,
|
||||
COPILOT_ENABLED: config.isCopilotEnabled,
|
||||
},
|
||||
API_KEYS: {
|
||||
OPENAI: config.openaiApiKey,
|
||||
GROQ: config.groqApiKey,
|
||||
@@ -63,4 +91,14 @@ router.post('/', async (req, res) => {
|
||||
res.status(200).json({ message: 'Config updated' });
|
||||
});
|
||||
|
||||
router.get('/preferences', (_, res) => {
|
||||
const preferences = {
|
||||
isLibraryEnabled: isLibraryEnabled(),
|
||||
isCopilotEnabled: isCopilotEnabled(),
|
||||
isDiscoverEnabled: isDiscoverEnabled(),
|
||||
};
|
||||
|
||||
res.status(200).json(preferences);
|
||||
});
|
||||
|
||||
export default router;
|
||||
|
Reference in New Issue
Block a user