mirror of
https://github.com/Mintplex-Labs/anything-llm.git
synced 2024-11-11 01:10:11 +01:00
[FEAT] Confluence Data Connector handles custom Confluence urls (#1362)
* chore: confluence data connector can now handle custom urls, in addition to default {subdomain}.atlassian.net ones * chore: formatting as per yarn lint
This commit is contained in:
parent
95f6000a67
commit
78e3e35d27
@ -2,6 +2,7 @@ const fs = require("fs");
|
|||||||
const path = require("path");
|
const path = require("path");
|
||||||
const { default: slugify } = require("slugify");
|
const { default: slugify } = require("slugify");
|
||||||
const { v4 } = require("uuid");
|
const { v4 } = require("uuid");
|
||||||
|
const UrlPattern = require("url-pattern");
|
||||||
const { writeToServerDocuments } = require("../../files");
|
const { writeToServerDocuments } = require("../../files");
|
||||||
const { tokenizeString } = require("../../tokenizer");
|
const { tokenizeString } = require("../../tokenizer");
|
||||||
const {
|
const {
|
||||||
@ -9,13 +10,29 @@ const {
|
|||||||
} = require("langchain/document_loaders/web/confluence");
|
} = require("langchain/document_loaders/web/confluence");
|
||||||
|
|
||||||
function validSpaceUrl(spaceUrl = "") {
|
function validSpaceUrl(spaceUrl = "") {
|
||||||
const UrlPattern = require("url-pattern");
|
// Atlassian default URL match
|
||||||
const pattern = new UrlPattern(
|
const atlassianPattern = new UrlPattern(
|
||||||
"https\\://(:subdomain).atlassian.net/wiki/spaces/(:spaceKey)*"
|
"https\\://(:subdomain).atlassian.net/wiki/spaces/(:spaceKey)/*"
|
||||||
);
|
);
|
||||||
const match = pattern.match(spaceUrl);
|
const atlassianMatch = atlassianPattern.match(spaceUrl);
|
||||||
if (!match) return { valid: false, result: null };
|
if (atlassianMatch) {
|
||||||
return { valid: true, result: match };
|
return { valid: true, result: atlassianMatch };
|
||||||
|
}
|
||||||
|
|
||||||
|
// Custom Confluence URL match
|
||||||
|
const customPattern = new UrlPattern(
|
||||||
|
"https\\://(:subdomain.):domain.:tld/wiki/spaces/(:spaceKey)/*"
|
||||||
|
);
|
||||||
|
const customMatch = customPattern.match(spaceUrl);
|
||||||
|
if (customMatch) {
|
||||||
|
customMatch.customDomain =
|
||||||
|
(customMatch.subdomain ? `${customMatch.subdomain}.` : "") + //
|
||||||
|
`${customMatch.domain}.${customMatch.tld}`;
|
||||||
|
return { valid: true, result: customMatch, custom: true };
|
||||||
|
}
|
||||||
|
|
||||||
|
// No match
|
||||||
|
return { valid: false, result: null };
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadConfluence({ pageUrl, username, accessToken }) {
|
async function loadConfluence({ pageUrl, username, accessToken }) {
|
||||||
@ -32,14 +49,19 @@ async function loadConfluence({ pageUrl, username, accessToken }) {
|
|||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
reason:
|
reason:
|
||||||
"Confluence space URL is not in the expected format of https://domain.atlassian.net/wiki/space/~SPACEID/*",
|
"Confluence space URL is not in the expected format of https://domain.atlassian.net/wiki/space/~SPACEID/* or https://customDomain/wiki/space/~SPACEID/*",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const { subdomain, spaceKey } = validSpace.result;
|
const { subdomain, customDomain, spaceKey } = validSpace.result;
|
||||||
console.log(`-- Working Confluence ${subdomain}.atlassian.net --`);
|
let baseUrl = `https://${subdomain}.atlassian.net/wiki`;
|
||||||
|
if (customDomain) {
|
||||||
|
baseUrl = `https://${customDomain}/wiki`;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`-- Working Confluence ${baseUrl} --`);
|
||||||
const loader = new ConfluencePagesLoader({
|
const loader = new ConfluencePagesLoader({
|
||||||
baseUrl: `https://${subdomain}.atlassian.net/wiki`,
|
baseUrl,
|
||||||
spaceKey,
|
spaceKey,
|
||||||
username,
|
username,
|
||||||
accessToken,
|
accessToken,
|
||||||
|
Loading…
Reference in New Issue
Block a user