2024-06-21 22:38:50 +02:00
|
|
|
const { setDataSigner } = require("../middleware/setDataSigner");
|
2024-04-01 22:56:35 +02:00
|
|
|
const { verifyPayloadIntegrity } = require("../middleware/verifyIntegrity");
|
2023-12-19 00:48:02 +01:00
|
|
|
const { reqBody } = require("../utils/http");
|
2024-05-14 21:49:14 +02:00
|
|
|
const { validURL } = require("../utils/url");
|
2024-06-21 22:38:50 +02:00
|
|
|
const RESYNC_METHODS = require("./resync");
|
2023-12-19 00:48:02 +01:00
|
|
|
|
|
|
|
function extensions(app) {
|
|
|
|
if (!app) return;
|
|
|
|
|
2024-06-21 22:38:50 +02:00
|
|
|
app.post(
|
|
|
|
"/ext/resync-source-document",
|
|
|
|
[verifyPayloadIntegrity, setDataSigner],
|
|
|
|
async function (request, response) {
|
|
|
|
try {
|
|
|
|
const { type, options } = reqBody(request);
|
|
|
|
if (!RESYNC_METHODS.hasOwnProperty(type)) throw new Error(`Type "${type}" is not a valid type to sync.`);
|
|
|
|
return await RESYNC_METHODS[type](options, response);
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
response.status(200).json({
|
|
|
|
success: false,
|
|
|
|
content: null,
|
|
|
|
reason: e.message || "A processing error occurred.",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2024-04-26 02:53:38 +02:00
|
|
|
app.post(
|
|
|
|
"/ext/github-repo",
|
2024-06-21 22:38:50 +02:00
|
|
|
[verifyPayloadIntegrity, setDataSigner],
|
2024-04-26 02:53:38 +02:00
|
|
|
async function (request, response) {
|
|
|
|
try {
|
2024-06-21 22:38:50 +02:00
|
|
|
const { loadGithubRepo } = require("../utils/extensions/GithubRepo");
|
2024-04-26 02:53:38 +02:00
|
|
|
const { success, reason, data } = await loadGithubRepo(
|
2024-06-21 22:38:50 +02:00
|
|
|
reqBody(request),
|
|
|
|
response,
|
2024-04-26 02:53:38 +02:00
|
|
|
);
|
|
|
|
response.status(200).json({
|
|
|
|
success,
|
|
|
|
reason,
|
|
|
|
data,
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
response.status(200).json({
|
|
|
|
success: false,
|
|
|
|
reason: e.message || "A processing error occurred.",
|
|
|
|
data: {},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return;
|
2023-12-19 00:48:02 +01:00
|
|
|
}
|
2024-04-26 02:53:38 +02:00
|
|
|
);
|
2023-12-19 00:48:02 +01:00
|
|
|
|
|
|
|
// gets all branches for a specific repo
|
2024-04-26 02:53:38 +02:00
|
|
|
app.post(
|
|
|
|
"/ext/github-repo/branches",
|
|
|
|
[verifyPayloadIntegrity],
|
|
|
|
async function (request, response) {
|
|
|
|
try {
|
|
|
|
const GithubRepoLoader = require("../utils/extensions/GithubRepo/RepoLoader");
|
|
|
|
const allBranches = await new GithubRepoLoader(
|
|
|
|
reqBody(request)
|
|
|
|
).getRepoBranches();
|
|
|
|
response.status(200).json({
|
|
|
|
success: true,
|
|
|
|
reason: null,
|
|
|
|
data: {
|
|
|
|
branches: allBranches,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
response.status(400).json({
|
|
|
|
success: false,
|
|
|
|
reason: e.message,
|
|
|
|
data: {
|
|
|
|
branches: [],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return;
|
2023-12-19 00:48:02 +01:00
|
|
|
}
|
2024-04-26 02:53:38 +02:00
|
|
|
);
|
2023-12-19 02:17:26 +01:00
|
|
|
|
2024-04-26 02:53:38 +02:00
|
|
|
app.post(
|
|
|
|
"/ext/youtube-transcript",
|
|
|
|
[verifyPayloadIntegrity],
|
|
|
|
async function (request, response) {
|
|
|
|
try {
|
2024-06-21 22:38:50 +02:00
|
|
|
const { loadYouTubeTranscript } = require("../utils/extensions/YoutubeTranscript");
|
2024-04-26 02:53:38 +02:00
|
|
|
const { success, reason, data } = await loadYouTubeTranscript(
|
|
|
|
reqBody(request)
|
|
|
|
);
|
|
|
|
response.status(200).json({ success, reason, data });
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
response.status(400).json({
|
|
|
|
success: false,
|
|
|
|
reason: e.message,
|
|
|
|
data: {
|
|
|
|
title: null,
|
|
|
|
author: null,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return;
|
2023-12-19 02:17:26 +01:00
|
|
|
}
|
2024-04-26 02:53:38 +02:00
|
|
|
);
|
|
|
|
|
2024-05-14 21:49:14 +02:00
|
|
|
app.post(
|
|
|
|
"/ext/website-depth",
|
|
|
|
[verifyPayloadIntegrity],
|
|
|
|
async function (request, response) {
|
|
|
|
try {
|
|
|
|
const websiteDepth = require("../utils/extensions/WebsiteDepth");
|
|
|
|
const { url, depth = 1, maxLinks = 20 } = reqBody(request);
|
|
|
|
if (!validURL(url)) return { success: false, reason: "Not a valid URL." };
|
|
|
|
|
|
|
|
const scrapedData = await websiteDepth(url, depth, maxLinks);
|
|
|
|
response.status(200).json({ success: true, data: scrapedData });
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
response.status(400).json({ success: false, reason: e.message });
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2024-04-26 02:53:38 +02:00
|
|
|
app.post(
|
|
|
|
"/ext/confluence",
|
2024-06-21 22:38:50 +02:00
|
|
|
[verifyPayloadIntegrity, setDataSigner],
|
2024-04-26 02:53:38 +02:00
|
|
|
async function (request, response) {
|
|
|
|
try {
|
2024-06-21 22:38:50 +02:00
|
|
|
const { loadConfluence } = require("../utils/extensions/Confluence");
|
2024-04-26 02:53:38 +02:00
|
|
|
const { success, reason, data } = await loadConfluence(
|
2024-06-21 22:38:50 +02:00
|
|
|
reqBody(request),
|
|
|
|
response
|
2024-04-26 02:53:38 +02:00
|
|
|
);
|
|
|
|
response.status(200).json({ success, reason, data });
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
response.status(400).json({
|
|
|
|
success: false,
|
|
|
|
reason: e.message,
|
|
|
|
data: {
|
|
|
|
title: null,
|
|
|
|
author: null,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
);
|
2023-12-19 00:48:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = extensions;
|