mirror of
https://github.com/Mintplex-Labs/anything-llm.git
synced 2024-11-19 20:50:09 +01:00
29df483a27
* initial commit for chrome extension * wip browser extension backend * wip frontend browser extension settings * fix typo for browserExtension route * implement verification codes + frontend panel for browser extension keys * reorganize + state management for all connection states * implement embed to workspace * add send page to anythingllm extension option + refactor * refactor connection string auth + update context menus + organize background.js into models * popup extension from main app and save if successful * fix hebrew translation misspelling * fetch custom logo inside chrome extension * delete api keys on disconnect of extension * use correct apiUrl constant in frontend + remove unneeded comments * remove upload-link endpoint and send inner text html to raw text collector endpoint * update readme * fix readme link * fix readme typo * update readme * handle deletion of browser keys with key id and DELETE endpoint * move event string to constant * remove tablename and writable fields from BrowserExtensionApiKey backend model * add border-none to all buttons and inputs for desktop compatibility * patch prisma injections * update delete endpoints to delete keys by id * remove unused prop * add button to attempt browser extension connection + remove max active keys * wip multi user mode support * multi user mode support * clean up backend + show created by in frotend browser extension page * show multi user warning message on key creation + hide context menus when no workspaces * show browser extension options to managers * small backend changes and refactors * extension cleanup * rename submodule * extension updates & docs * dev docker build --------- Co-authored-by: shatfield4 <seanhatfield5@gmail.com>
37 lines
978 B
JavaScript
37 lines
978 B
JavaScript
const {
|
|
BrowserExtensionApiKey,
|
|
} = require("../../models/browserExtensionApiKey");
|
|
const { SystemSettings } = require("../../models/systemSettings");
|
|
const { User } = require("../../models/user");
|
|
|
|
async function validBrowserExtensionApiKey(request, response, next) {
|
|
const multiUserMode = await SystemSettings.isMultiUserMode();
|
|
response.locals.multiUserMode = multiUserMode;
|
|
|
|
const auth = request.header("Authorization");
|
|
const bearerKey = auth ? auth.split(" ")[1] : null;
|
|
if (!bearerKey) {
|
|
response.status(403).json({
|
|
error: "No valid API key found.",
|
|
});
|
|
return;
|
|
}
|
|
|
|
const apiKey = await BrowserExtensionApiKey.validate(bearerKey);
|
|
if (!apiKey) {
|
|
response.status(403).json({
|
|
error: "No valid API key found.",
|
|
});
|
|
return;
|
|
}
|
|
|
|
if (multiUserMode) {
|
|
response.locals.user = await User.get({ id: apiKey.user_id });
|
|
}
|
|
|
|
response.locals.apiKey = apiKey;
|
|
next();
|
|
}
|
|
|
|
module.exports = { validBrowserExtensionApiKey };
|