mirror of
https://github.com/Mintplex-Labs/anything-llm.git
synced 2025-03-22 10:02:22 +00:00
* wip: init refactor of document processor to JS * add NodeJs PDF support * wip: partity with python processor feat: add pptx support * fix: forgot files * Remove python scripts totally * wip:update docker to boot new collector * add package.json support * update dockerfile for new build * update gitignore and linting * add more protections on file lookup * update package.json * test build * update docker commands to use cap-add=SYS_ADMIN so web scraper can run update all scripts to reflect this remove docker build for branch
67 lines
1.9 KiB
JavaScript
67 lines
1.9 KiB
JavaScript
// When running locally will occupy the 0.0.0.0 hostname space but when deployed inside
|
|
// of docker this endpoint is not exposed so it is only on the Docker instances internal network
|
|
// so no additional security is needed on the endpoint directly. Auth is done however by the express
|
|
// middleware prior to leaving the node-side of the application so that is good enough >:)
|
|
const PROCESSOR_API = "http://0.0.0.0:8888";
|
|
async function checkProcessorAlive() {
|
|
return await fetch(`${PROCESSOR_API}`)
|
|
.then((res) => res.ok)
|
|
.catch((e) => false);
|
|
}
|
|
|
|
async function acceptedFileTypes() {
|
|
return await fetch(`${PROCESSOR_API}/accepts`)
|
|
.then((res) => {
|
|
if (!res.ok) throw new Error("Could not reach");
|
|
return res.json();
|
|
})
|
|
.then((res) => res)
|
|
.catch(() => null);
|
|
}
|
|
|
|
async function processDocument(filename = "") {
|
|
if (!filename) return false;
|
|
return await fetch(`${PROCESSOR_API}/process`, {
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify({ filename }),
|
|
})
|
|
.then((res) => {
|
|
if (!res.ok) throw new Error("Response could not be completed");
|
|
return res.json();
|
|
})
|
|
.then((res) => res)
|
|
.catch((e) => {
|
|
console.log(e.message);
|
|
return { success: false, reason: e.message };
|
|
});
|
|
}
|
|
|
|
async function processLink(link = "") {
|
|
if (!link) return false;
|
|
return await fetch(`${PROCESSOR_API}/process-link`, {
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify({ link }),
|
|
})
|
|
.then((res) => {
|
|
if (!res.ok) throw new Error("Response could not be completed");
|
|
return res.json();
|
|
})
|
|
.then((res) => res)
|
|
.catch((e) => {
|
|
console.log(e.message);
|
|
return { success: false, reason: e.message };
|
|
});
|
|
}
|
|
|
|
module.exports = {
|
|
checkProcessorAlive,
|
|
processDocument,
|
|
processLink,
|
|
acceptedFileTypes,
|
|
};
|