2023-12-19 00:48:02 +01:00
|
|
|
const { Telemetry } = require("../../models/telemetry");
|
2024-02-17 01:32:25 +01:00
|
|
|
const { CollectorApi } = require("../../utils/collectorApi");
|
2023-12-19 00:48:02 +01:00
|
|
|
const {
|
|
|
|
flexUserRoleValid,
|
2024-01-22 23:14:01 +01:00
|
|
|
ROLES,
|
2023-12-19 00:48:02 +01:00
|
|
|
} = require("../../utils/middleware/multiUserProtected");
|
|
|
|
const { validatedRequest } = require("../../utils/middleware/validatedRequest");
|
2024-07-23 21:23:51 +02:00
|
|
|
const {
|
|
|
|
isSupportedRepoProvider,
|
|
|
|
} = require("../../utils/middleware/isSupportedRepoProviders");
|
2023-12-19 00:48:02 +01:00
|
|
|
|
|
|
|
function extensionEndpoints(app) {
|
|
|
|
if (!app) return;
|
|
|
|
|
|
|
|
app.post(
|
2024-07-23 21:23:51 +02:00
|
|
|
"/ext/:repo_platform/branches",
|
|
|
|
[
|
|
|
|
validatedRequest,
|
|
|
|
flexUserRoleValid([ROLES.admin, ROLES.manager]),
|
|
|
|
isSupportedRepoProvider,
|
|
|
|
],
|
2023-12-19 00:48:02 +01:00
|
|
|
async (request, response) => {
|
|
|
|
try {
|
2024-07-23 21:23:51 +02:00
|
|
|
const { repo_platform } = request.params;
|
2024-02-17 01:32:25 +01:00
|
|
|
const responseFromProcessor =
|
|
|
|
await new CollectorApi().forwardExtensionRequest({
|
2024-07-23 21:23:51 +02:00
|
|
|
endpoint: `/ext/${repo_platform}-repo/branches`,
|
2024-02-17 01:32:25 +01:00
|
|
|
method: "POST",
|
|
|
|
body: request.body,
|
|
|
|
});
|
2023-12-19 00:48:02 +01:00
|
|
|
response.status(200).json(responseFromProcessor);
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
response.sendStatus(500).end();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
app.post(
|
2024-07-23 21:23:51 +02:00
|
|
|
"/ext/:repo_platform/repo",
|
|
|
|
[
|
|
|
|
validatedRequest,
|
|
|
|
flexUserRoleValid([ROLES.admin, ROLES.manager]),
|
|
|
|
isSupportedRepoProvider,
|
|
|
|
],
|
2023-12-19 00:48:02 +01:00
|
|
|
async (request, response) => {
|
|
|
|
try {
|
2024-07-23 21:23:51 +02:00
|
|
|
const { repo_platform } = request.params;
|
2024-02-17 01:32:25 +01:00
|
|
|
const responseFromProcessor =
|
|
|
|
await new CollectorApi().forwardExtensionRequest({
|
2024-07-23 21:23:51 +02:00
|
|
|
endpoint: `/ext/${repo_platform}-repo`,
|
2024-02-17 01:32:25 +01:00
|
|
|
method: "POST",
|
|
|
|
body: request.body,
|
|
|
|
});
|
2023-12-19 00:48:02 +01:00
|
|
|
await Telemetry.sendTelemetry("extension_invoked", {
|
2024-07-23 21:23:51 +02:00
|
|
|
type: `${repo_platform}_repo`,
|
2023-12-19 00:48:02 +01:00
|
|
|
});
|
|
|
|
response.status(200).json(responseFromProcessor);
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
response.sendStatus(500).end();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2023-12-19 02:17:26 +01:00
|
|
|
|
|
|
|
app.post(
|
|
|
|
"/ext/youtube/transcript",
|
2024-01-22 23:14:01 +01:00
|
|
|
[validatedRequest, flexUserRoleValid([ROLES.admin, ROLES.manager])],
|
2023-12-19 02:17:26 +01:00
|
|
|
async (request, response) => {
|
|
|
|
try {
|
2024-02-17 01:32:25 +01:00
|
|
|
const responseFromProcessor =
|
|
|
|
await new CollectorApi().forwardExtensionRequest({
|
|
|
|
endpoint: "/ext/youtube-transcript",
|
|
|
|
method: "POST",
|
|
|
|
body: request.body,
|
|
|
|
});
|
2023-12-19 02:17:26 +01:00
|
|
|
await Telemetry.sendTelemetry("extension_invoked", {
|
|
|
|
type: "youtube_transcript",
|
|
|
|
});
|
|
|
|
response.status(200).json(responseFromProcessor);
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
response.sendStatus(500).end();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2024-04-26 02:53:38 +02:00
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2024-05-14 21:49:14 +02:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2023-12-19 00:48:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = { extensionEndpoints };
|