|
@@ -186,6 +186,23 @@ router.route("/getFile").all(async (req, res, next) => {
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+//获取文档列表
|
|
|
|
+router.route("/getFileR2r").all(async (req, res, next) => {
|
|
|
|
+ //mode的处理
|
|
|
|
+ if (req.body[0]) {
|
|
|
|
+ let fileid = decodeURIComponent(req.body[0].fileids).split(",");
|
|
|
|
+ try {
|
|
|
|
+ const response = await client.documents.list({ ids: fileid });
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ res.status(200).json({ result: response.results });
|
|
|
|
+ } catch (error) {
|
|
|
|
+ res.status(500).json({ error: error instanceof Error ? error.message : "An error occurred" });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+});
|
|
|
|
+
|
|
|
|
+
|
|
//获取文档列表
|
|
//获取文档列表
|
|
router.route("/getFileD").all(async (req, res, next) => {
|
|
router.route("/getFileD").all(async (req, res, next) => {
|
|
//mode的处理
|
|
//mode的处理
|
|
@@ -762,6 +779,111 @@ router.route("/getRelationships").all(async (req, res, next) => {
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+//提取整个文件夹的关系
|
|
|
|
+router.route("/resetGraphs").all(async (req, res, next) => {
|
|
|
|
+ if (req.body[0]) {
|
|
|
|
+ try {
|
|
|
|
+ // const response = await client.graphs.pull({
|
|
|
|
+ // collectionId: req.body[0].collectionId,
|
|
|
|
+ // });
|
|
|
|
+ const response = await client.graphs.reset({
|
|
|
|
+ collectionId: req.body[0].collectionId,
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ res.status(200).json({ result: response });
|
|
|
|
+
|
|
|
|
+ } catch (error) {
|
|
|
|
+ res.status(500).json({ error: error instanceof Error ? error.message : "An error occurred" });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+});
|
|
|
|
+
|
|
|
|
+//获取整个文件夹的关系
|
|
|
|
+router.route("/getRelationshipsGraphs").all(async (req, res, next) => {
|
|
|
|
+ if (req.body[0]) {
|
|
|
|
+ try {
|
|
|
|
+ await client.graphs.pull({
|
|
|
|
+ collectionId: req.body[0].collectionId,
|
|
|
|
+ });
|
|
|
|
+ const response = await client.graphs.listRelationships({
|
|
|
|
+ collectionId: req.body[0].collectionId,
|
|
|
|
+ offset: req.body[0].page ? req.body[0].page : 0,
|
|
|
|
+ limit: 1000
|
|
|
|
+ });
|
|
|
|
+ res.status(200).json({ result: response });
|
|
|
|
+
|
|
|
|
+ } catch (error) {
|
|
|
|
+ res.status(500).json({ error: error instanceof Error ? error.message : "An error occurred" });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+});
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+//提取知识图谱
|
|
|
|
+router.route("/getGraphs").all(async (req, res, next) => {
|
|
|
|
+ console.log(req.body);
|
|
|
|
+
|
|
|
|
+ //mode的处理
|
|
|
|
+ if (req.body[0]) {
|
|
|
|
+ try {
|
|
|
|
+ //创建临时文件夹
|
|
|
|
+ const folder = await client.collections.create({
|
|
|
|
+ name: "临时文件夹",
|
|
|
|
+ description: "临时文件夹"
|
|
|
|
+ });
|
|
|
|
+ let folderid = folder.results.id
|
|
|
|
+ console.log(folder.results.id);
|
|
|
|
+
|
|
|
|
+ //将要提取的文件添加到临时文件夹
|
|
|
|
+ let documentids = decodeURIComponent(req.body[0].fileids).split(",");
|
|
|
|
+ // 使用 Promise.all 确保所有添加操作都被执行
|
|
|
|
+ await Promise.all(documentids.map(documentid =>
|
|
|
|
+ client.collections.addDocument({
|
|
|
|
+ id: folderid,
|
|
|
|
+ documentId: documentid
|
|
|
|
+ }).catch(error => {
|
|
|
|
+ console.error("移动文件时发生错误:", error);
|
|
|
|
+ })
|
|
|
|
+ ));
|
|
|
|
+
|
|
|
|
+ //将临时文件夹提取知识图谱
|
|
|
|
+ await client.graphs.pull({
|
|
|
|
+ collectionId: folderid
|
|
|
|
+ });
|
|
|
|
+ let offset = 0;
|
|
|
|
+ let results = [];
|
|
|
|
+ let totalEntries = 0;
|
|
|
|
+ do {
|
|
|
|
+ const response = await client.graphs.listRelationships({
|
|
|
|
+ collectionId: folderid,
|
|
|
|
+ offset: offset,
|
|
|
|
+ limit: 1000
|
|
|
|
+ });
|
|
|
|
+ results = results.concat(response.results);
|
|
|
|
+ totalEntries = response.totalEntries;
|
|
|
|
+ offset += 1000;
|
|
|
|
+ } while (offset < totalEntries);
|
|
|
|
+
|
|
|
|
+ //移除临时文件夹的文件
|
|
|
|
+ const files = await client.collections.listDocuments({ id: folderid, offset: 0, limit: 999 });
|
|
|
|
+ await Promise.all(files.results.map(file =>
|
|
|
|
+ client.collections.removeDocument({ id: folderid, documentId: file.id })
|
|
|
|
+ ));
|
|
|
|
+
|
|
|
|
+ //删除临时文件夹
|
|
|
|
+ await client.collections.delete({ id: folderid });
|
|
|
|
+
|
|
|
|
+ res.status(200).json({ result: results });
|
|
|
|
+
|
|
|
|
+ } catch (error) {
|
|
|
|
+ res.status(500).json({ error: error instanceof Error ? error.message : "An error occurred" });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+});
|
|
|
|
+
|
|
//获取实体和关系
|
|
//获取实体和关系
|
|
router.route("/getEntitiesAndRelationships").all(async (req, res, next) => {
|
|
router.route("/getEntitiesAndRelationships").all(async (req, res, next) => {
|
|
if (req.body[0]) {
|
|
if (req.body[0]) {
|