2023-12-19 00:48:02 +01:00
|
|
|
const { Telemetry } = require("../../models/telemetry");
|
|
|
|
const {
|
|
|
|
forwardExtensionRequest,
|
|
|
|
} = require("../../utils/files/documentProcessor");
|
|
|
|
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");
|
|
|
|
|
|
|
|
function extensionEndpoints(app) {
|
|
|
|
if (!app) return;
|
|
|
|
|
|
|
|
app.post(
|
|
|
|
"/ext/github/branches",
|
2024-01-22 23:14:01 +01:00
|
|
|
[validatedRequest, flexUserRoleValid([ROLES.admin, ROLES.manager])],
|
2023-12-19 00:48:02 +01:00
|
|
|
async (request, response) => {
|
|
|
|
try {
|
|
|
|
const responseFromProcessor = await 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",
|
2024-01-22 23:14:01 +01:00
|
|
|
[validatedRequest, flexUserRoleValid([ROLES.admin, ROLES.manager])],
|
2023-12-19 00:48:02 +01:00
|
|
|
async (request, response) => {
|
|
|
|
try {
|
|
|
|
const responseFromProcessor = await 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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
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 {
|
|
|
|
const responseFromProcessor = await 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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2023-12-19 00:48:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = { extensionEndpoints };
|