mirror of
https://github.com/Mintplex-Labs/anything-llm.git
synced 2024-11-11 17:20:13 +01:00
612a7e1662
* WIP website depth scraping, (sort of works) * website depth data connector stable + add maxLinks option * linting + loading small ui tweak * refactor website depth data connector for stability, speed, & readability * patch: remove console log Guard clause on URL validitiy check reasonable overrides --------- Co-authored-by: Timothy Carambat <rambat1010@gmail.com>
120 lines
3.4 KiB
JavaScript
120 lines
3.4 KiB
JavaScript
const { Telemetry } = require("../../models/telemetry");
|
|
const { CollectorApi } = require("../../utils/collectorApi");
|
|
const {
|
|
flexUserRoleValid,
|
|
ROLES,
|
|
} = require("../../utils/middleware/multiUserProtected");
|
|
const { validatedRequest } = require("../../utils/middleware/validatedRequest");
|
|
|
|
function extensionEndpoints(app) {
|
|
if (!app) return;
|
|
|
|
app.post(
|
|
"/ext/github/branches",
|
|
[validatedRequest, flexUserRoleValid([ROLES.admin, ROLES.manager])],
|
|
async (request, response) => {
|
|
try {
|
|
const responseFromProcessor =
|
|
await new CollectorApi().forwardExtensionRequest({
|
|
endpoint: "/ext/github-repo/branches",
|
|
method: "POST",
|
|
body: request.body,
|
|
});
|
|
response.status(200).json(responseFromProcessor);
|
|
} catch (e) {
|
|
console.error(e);
|
|
response.sendStatus(500).end();
|
|
}
|
|
}
|
|
);
|
|
|
|
app.post(
|
|
"/ext/github/repo",
|
|
[validatedRequest, flexUserRoleValid([ROLES.admin, ROLES.manager])],
|
|
async (request, response) => {
|
|
try {
|
|
const responseFromProcessor =
|
|
await new CollectorApi().forwardExtensionRequest({
|
|
endpoint: "/ext/github-repo",
|
|
method: "POST",
|
|
body: request.body,
|
|
});
|
|
await Telemetry.sendTelemetry("extension_invoked", {
|
|
type: "github_repo",
|
|
});
|
|
response.status(200).json(responseFromProcessor);
|
|
} catch (e) {
|
|
console.error(e);
|
|
response.sendStatus(500).end();
|
|
}
|
|
}
|
|
);
|
|
|
|
app.post(
|
|
"/ext/youtube/transcript",
|
|
[validatedRequest, flexUserRoleValid([ROLES.admin, ROLES.manager])],
|
|
async (request, response) => {
|
|
try {
|
|
const responseFromProcessor =
|
|
await new CollectorApi().forwardExtensionRequest({
|
|
endpoint: "/ext/youtube-transcript",
|
|
method: "POST",
|
|
body: request.body,
|
|
});
|
|
await Telemetry.sendTelemetry("extension_invoked", {
|
|
type: "youtube_transcript",
|
|
});
|
|
response.status(200).json(responseFromProcessor);
|
|
} catch (e) {
|
|
console.error(e);
|
|
response.sendStatus(500).end();
|
|
}
|
|
}
|
|
);
|
|
|
|
app.post(
|
|
"/ext/confluence",
|
|
[validatedRequest, flexUserRoleValid([ROLES.admin, ROLES.manager])],
|
|
async (request, response) => {
|
|
try {
|
|
const responseFromProcessor =
|
|
await new CollectorApi().forwardExtensionRequest({
|
|
endpoint: "/ext/confluence",
|
|
method: "POST",
|
|
body: request.body,
|
|
});
|
|
await Telemetry.sendTelemetry("extension_invoked", {
|
|
type: "confluence",
|
|
});
|
|
response.status(200).json(responseFromProcessor);
|
|
} catch (e) {
|
|
console.error(e);
|
|
response.sendStatus(500).end();
|
|
}
|
|
}
|
|
);
|
|
app.post(
|
|
"/ext/website-depth",
|
|
[validatedRequest, flexUserRoleValid([ROLES.admin, ROLES.manager])],
|
|
async (request, response) => {
|
|
try {
|
|
const responseFromProcessor =
|
|
await new CollectorApi().forwardExtensionRequest({
|
|
endpoint: "/ext/website-depth",
|
|
method: "POST",
|
|
body: request.body,
|
|
});
|
|
await Telemetry.sendTelemetry("extension_invoked", {
|
|
type: "website_depth",
|
|
});
|
|
response.status(200).json(responseFromProcessor);
|
|
} catch (e) {
|
|
console.error(e);
|
|
response.sendStatus(500).end();
|
|
}
|
|
}
|
|
);
|
|
}
|
|
|
|
module.exports = { extensionEndpoints };
|