mirror of
https://github.com/Mintplex-Labs/anything-llm.git
synced 2024-11-19 12:40:09 +01:00
Add dropdown for confluence connector deployment (#2376)
This commit is contained in:
parent
4488744850
commit
961b567541
@ -13,6 +13,7 @@ class ConfluencePagesLoader {
|
|||||||
limit = 25,
|
limit = 25,
|
||||||
expand = "body.storage,version",
|
expand = "body.storage,version",
|
||||||
personalAccessToken,
|
personalAccessToken,
|
||||||
|
cloud = true,
|
||||||
}) {
|
}) {
|
||||||
this.baseUrl = baseUrl;
|
this.baseUrl = baseUrl;
|
||||||
this.spaceKey = spaceKey;
|
this.spaceKey = spaceKey;
|
||||||
@ -21,6 +22,7 @@ class ConfluencePagesLoader {
|
|||||||
this.limit = limit;
|
this.limit = limit;
|
||||||
this.expand = expand;
|
this.expand = expand;
|
||||||
this.personalAccessToken = personalAccessToken;
|
this.personalAccessToken = personalAccessToken;
|
||||||
|
this.cloud = cloud;
|
||||||
}
|
}
|
||||||
|
|
||||||
get authorizationHeader() {
|
get authorizationHeader() {
|
||||||
@ -74,7 +76,11 @@ class ConfluencePagesLoader {
|
|||||||
|
|
||||||
// https://developer.atlassian.com/cloud/confluence/rest/v2/intro/#auth
|
// https://developer.atlassian.com/cloud/confluence/rest/v2/intro/#auth
|
||||||
async fetchAllPagesInSpace(start = 0, limit = this.limit) {
|
async fetchAllPagesInSpace(start = 0, limit = this.limit) {
|
||||||
const url = `${this.baseUrl}/wiki/rest/api/content?spaceKey=${this.spaceKey}&limit=${limit}&start=${start}&expand=${this.expand}`;
|
const url = `${this.baseUrl}${
|
||||||
|
this.cloud ? "/wiki" : ""
|
||||||
|
}/rest/api/content?spaceKey=${
|
||||||
|
this.spaceKey
|
||||||
|
}&limit=${limit}&start=${start}&expand=${this.expand}`;
|
||||||
const data = await this.fetchConfluenceData(url);
|
const data = await this.fetchConfluenceData(url);
|
||||||
if (data.size === 0) {
|
if (data.size === 0) {
|
||||||
return [];
|
return [];
|
||||||
|
@ -13,7 +13,13 @@ const { ConfluencePagesLoader } = require("./ConfluenceLoader");
|
|||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
async function loadConfluence(
|
async function loadConfluence(
|
||||||
{ baseUrl = null, spaceKey = null, username = null, accessToken = null },
|
{
|
||||||
|
baseUrl = null,
|
||||||
|
spaceKey = null,
|
||||||
|
username = null,
|
||||||
|
accessToken = null,
|
||||||
|
cloud = true,
|
||||||
|
},
|
||||||
response
|
response
|
||||||
) {
|
) {
|
||||||
if (!baseUrl || !spaceKey || !username || !accessToken) {
|
if (!baseUrl || !spaceKey || !username || !accessToken) {
|
||||||
@ -45,6 +51,7 @@ async function loadConfluence(
|
|||||||
spaceKey,
|
spaceKey,
|
||||||
username,
|
username,
|
||||||
accessToken,
|
accessToken,
|
||||||
|
cloud,
|
||||||
});
|
});
|
||||||
|
|
||||||
const { docs, error } = await loader
|
const { docs, error } = await loader
|
||||||
@ -66,7 +73,7 @@ async function loadConfluence(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
const outFolder = slugify(
|
const outFolder = slugify(
|
||||||
`confluence-${origin}-${v4().slice(0, 4)}`
|
`confluence-${hostname}-${v4().slice(0, 4)}`
|
||||||
).toLowerCase();
|
).toLowerCase();
|
||||||
|
|
||||||
const outFolderPath =
|
const outFolderPath =
|
||||||
@ -91,7 +98,7 @@ async function loadConfluence(
|
|||||||
description: doc.metadata.title,
|
description: doc.metadata.title,
|
||||||
docSource: `${origin} Confluence`,
|
docSource: `${origin} Confluence`,
|
||||||
chunkSource: generateChunkSource(
|
chunkSource: generateChunkSource(
|
||||||
{ doc, baseUrl: origin, spaceKey, accessToken, username },
|
{ doc, baseUrl: origin, spaceKey, accessToken, username, cloud },
|
||||||
response.locals.encryptionWorker
|
response.locals.encryptionWorker
|
||||||
),
|
),
|
||||||
published: new Date().toLocaleString(),
|
published: new Date().toLocaleString(),
|
||||||
@ -130,6 +137,7 @@ async function fetchConfluencePage({
|
|||||||
spaceKey,
|
spaceKey,
|
||||||
username,
|
username,
|
||||||
accessToken,
|
accessToken,
|
||||||
|
cloud = true,
|
||||||
}) {
|
}) {
|
||||||
if (!pageUrl || !baseUrl || !spaceKey || !username || !accessToken) {
|
if (!pageUrl || !baseUrl || !spaceKey || !username || !accessToken) {
|
||||||
return {
|
return {
|
||||||
@ -162,6 +170,7 @@ async function fetchConfluencePage({
|
|||||||
spaceKey,
|
spaceKey,
|
||||||
username,
|
username,
|
||||||
accessToken,
|
accessToken,
|
||||||
|
cloud,
|
||||||
});
|
});
|
||||||
|
|
||||||
const { docs, error } = await loader
|
const { docs, error } = await loader
|
||||||
@ -225,7 +234,7 @@ function validBaseUrl(baseUrl) {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
function generateChunkSource(
|
function generateChunkSource(
|
||||||
{ doc, baseUrl, spaceKey, accessToken, username },
|
{ doc, baseUrl, spaceKey, accessToken, username, cloud },
|
||||||
encryptionWorker
|
encryptionWorker
|
||||||
) {
|
) {
|
||||||
const payload = {
|
const payload = {
|
||||||
@ -233,6 +242,7 @@ function generateChunkSource(
|
|||||||
spaceKey,
|
spaceKey,
|
||||||
token: accessToken,
|
token: accessToken,
|
||||||
username,
|
username,
|
||||||
|
cloud,
|
||||||
};
|
};
|
||||||
return `confluence://${doc.metadata.url}?payload=${encryptionWorker.encrypt(
|
return `confluence://${doc.metadata.url}?payload=${encryptionWorker.encrypt(
|
||||||
JSON.stringify(payload)
|
JSON.stringify(payload)
|
||||||
|
@ -26,6 +26,7 @@ export default function ConfluenceOptions() {
|
|||||||
spaceKey: form.get("spaceKey"),
|
spaceKey: form.get("spaceKey"),
|
||||||
username: form.get("username"),
|
username: form.get("username"),
|
||||||
accessToken: form.get("accessToken"),
|
accessToken: form.get("accessToken"),
|
||||||
|
cloud: form.get("isCloud") === "true",
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!!error) {
|
if (!!error) {
|
||||||
@ -54,6 +55,31 @@ export default function ConfluenceOptions() {
|
|||||||
<form className="w-full" onSubmit={handleSubmit}>
|
<form className="w-full" onSubmit={handleSubmit}>
|
||||||
<div className="w-full flex flex-col py-2">
|
<div className="w-full flex flex-col py-2">
|
||||||
<div className="w-full flex flex-col gap-4">
|
<div className="w-full flex flex-col gap-4">
|
||||||
|
<div className="flex flex-col pr-10">
|
||||||
|
<div className="flex flex-col gap-y-1 mb-4">
|
||||||
|
<label className="text-white text-sm font-bold flex gap-x-2 items-center">
|
||||||
|
<p className="font-bold text-white">
|
||||||
|
Confluence deployment type
|
||||||
|
</p>
|
||||||
|
</label>
|
||||||
|
<p className="text-xs font-normal text-white/50">
|
||||||
|
Determine if your Confluence instance is hosted on Atlassian
|
||||||
|
cloud or self-hosted.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<select
|
||||||
|
name="isCloud"
|
||||||
|
className="bg-zinc-900 text-white placeholder:text-white/20 text-sm rounded-lg focus:outline-primary-button active:outline-primary-button outline-none block w-full p-2.5"
|
||||||
|
required={true}
|
||||||
|
autoComplete="off"
|
||||||
|
spellCheck={false}
|
||||||
|
defaultValue="true"
|
||||||
|
>
|
||||||
|
<option value="true">Atlassian Cloud</option>
|
||||||
|
<option value="false">Self-hosted</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="flex flex-col pr-10">
|
<div className="flex flex-col pr-10">
|
||||||
<div className="flex flex-col gap-y-1 mb-4">
|
<div className="flex flex-col gap-y-1 mb-4">
|
||||||
<label className="text-white text-sm font-bold flex gap-x-2 items-center">
|
<label className="text-white text-sm font-bold flex gap-x-2 items-center">
|
||||||
|
@ -119,7 +119,13 @@ const DataConnector = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
confluence: {
|
confluence: {
|
||||||
collect: async function ({ baseUrl, spaceKey, username, accessToken }) {
|
collect: async function ({
|
||||||
|
baseUrl,
|
||||||
|
spaceKey,
|
||||||
|
username,
|
||||||
|
accessToken,
|
||||||
|
cloud,
|
||||||
|
}) {
|
||||||
return await fetch(`${API_BASE}/ext/confluence`, {
|
return await fetch(`${API_BASE}/ext/confluence`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: baseHeaders(),
|
headers: baseHeaders(),
|
||||||
@ -128,6 +134,7 @@ const DataConnector = {
|
|||||||
spaceKey,
|
spaceKey,
|
||||||
username,
|
username,
|
||||||
accessToken,
|
accessToken,
|
||||||
|
cloud,
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
.then((res) => res.json())
|
.then((res) => res.json())
|
||||||
|
Loading…
Reference in New Issue
Block a user