gridsome-source-confluence
Version:
Confluence source for Gridsome
53 lines (52 loc) • 2.15 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const axios_1 = __importDefault(require("axios"));
const axios_retry_1 = __importDefault(require("axios-retry"));
class Confluence {
constructor(config) {
this.config = config;
const axiosConfig = {
baseURL: config.base_url,
};
if (!this.config.public_only) {
axiosConfig.auth = {
username: config.username,
password: config.password,
};
}
this.axios = axios_1.default.create(axiosConfig);
if (this.config.retry_request) {
axios_retry_1.default(this.axios, {
retries: 15,
retryCondition: (e) => {
var _a;
console.log("[Confluence]", 'To many request, retrying...');
return ((_a = e.response) === null || _a === void 0 ? void 0 : _a.status) === 429;
},
retryDelay: axios_retry_1.default.exponentialDelay,
});
}
}
GetSpaces() {
return this.axios.get("/wiki/rest/api/space", { params: { expand: "homepage" } });
}
GetSpace(spaceKey) {
return this.axios.get(`/wiki/rest/api/space/${spaceKey}`, { params: { expand: "homepage" } });
}
GetContentById(id) {
return this.axios.get(`/wiki/rest/api/content/${id}`, { params: { expand: "body.view,space,metadata.labels,history.lastUpdated" } });
}
GetContentChildPage(id) {
return this.axios.get(`/wiki/rest/api/content/${id}/child/page`, { params: { expand: "body.view,space,metadata.labels,history.lastUpdated" } });
}
GetContentChildAttachment(id) {
return this.axios.get(`/wiki/rest/api/content/${id}/child/attachment`, { params: { expand: "space" } });
}
GetAttachment(downloadLink) {
return this.axios.get(`/wiki${downloadLink}`, { responseType: "stream" }).catch(() => null);
}
}
exports.default = Confluence;