mirror of
https://github.com/Mintplex-Labs/anything-llm.git
synced 2024-11-15 19:00:33 +01:00
42235fcd8a
* Add support for GitLab repo collection as well as Github Repo collection * Refactor for repo collectors to be more compact --------- Co-authored-by: Emil Rofors <emirof@gmail.com>
133 lines
3.8 KiB
JavaScript
133 lines
3.8 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");
|
|
const {
|
|
isSupportedRepoProvider,
|
|
} = require("../../utils/middleware/isSupportedRepoProviders");
|
|
|
|
function extensionEndpoints(app) {
|
|
if (!app) return;
|
|
|
|
app.post(
|
|
"/ext/:repo_platform/branches",
|
|
[
|
|
validatedRequest,
|
|
flexUserRoleValid([ROLES.admin, ROLES.manager]),
|
|
isSupportedRepoProvider,
|
|
],
|
|
async (request, response) => {
|
|
try {
|
|
const { repo_platform } = request.params;
|
|
const responseFromProcessor =
|
|
await new CollectorApi().forwardExtensionRequest({
|
|
endpoint: `/ext/${repo_platform}-repo/branches`,
|
|
method: "POST",
|
|
body: request.body,
|
|
});
|
|
response.status(200).json(responseFromProcessor);
|
|
} catch (e) {
|
|
console.error(e);
|
|
response.sendStatus(500).end();
|
|
}
|
|
}
|
|
);
|
|
|
|
app.post(
|
|
"/ext/:repo_platform/repo",
|
|
[
|
|
validatedRequest,
|
|
flexUserRoleValid([ROLES.admin, ROLES.manager]),
|
|
isSupportedRepoProvider,
|
|
],
|
|
async (request, response) => {
|
|
try {
|
|
const { repo_platform } = request.params;
|
|
const responseFromProcessor =
|
|
await new CollectorApi().forwardExtensionRequest({
|
|
endpoint: `/ext/${repo_platform}-repo`,
|
|
method: "POST",
|
|
body: request.body,
|
|
});
|
|
await Telemetry.sendTelemetry("extension_invoked", {
|
|
type: `${repo_platform}_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 };
|