|
@@ -6,12 +6,12 @@ const bcrypt = require("bcryptjs");
|
|
|
const router = express.Router(); // get an instance of the express Router
|
|
|
const querystring = require("querystring");
|
|
|
var mysql = require("./mysql");
|
|
|
-// const _mysqlLabor = ["123.58.32.151", "pbl"]; //edu數據庫信息
|
|
|
-// const _mysqluser = ["123.58.32.151", "cocorobouser"]; //用户数据库信息
|
|
|
+const _mysqlLabor = ["123.58.32.151", "pbl"]; //edu數據庫信息
|
|
|
+const _mysqluser = ["123.58.32.151", "cocorobouser"]; //用户数据库信息
|
|
|
// const _getmysqlLabor = ["123.58.32.151", "pbl"]; //edu數據庫信息
|
|
|
// const _getmysqluser = ["123.58.32.151", "cocorobouser"]; //edu數據庫信息
|
|
|
-const _mysqlLabor = ["172.16.12.5", "pbl"]; //edu數據庫信息
|
|
|
-const _mysqluser = ["172.16.12.5", "cocorobouser"]; //edu數據庫信息
|
|
|
+// const _mysqlLabor = ["172.16.12.5", "pbl"]; //edu數據庫信息
|
|
|
+// const _mysqluser = ["172.16.12.5", "cocorobouser"]; //edu數據庫信息
|
|
|
// const _getmysqlLabor = ["172.16.12.5", "pbl"]; //edu數據庫信息
|
|
|
// const _getmysqluser = ["172.16.12.5", "cocorobouser"]; //edu數據庫信息
|
|
|
const _getmysqlLabor2 = ["172.16.12.7", "pbl"]; //edu數據庫信息
|
|
@@ -165,6 +165,38 @@ router.route("/getFile").all(async (req, res, next) => {
|
|
|
}
|
|
|
});
|
|
|
|
|
|
+//获取文档列表2
|
|
|
+router.route("/getFileP").all(async (req, res, next) => {
|
|
|
+ //mode的处理
|
|
|
+ if (req.body) {
|
|
|
+ p = Object.values(req.body);
|
|
|
+ p.unshift(_mysqlLabor[0], _mysqlLabor[1], "getFile");
|
|
|
+ mysql.usselect(p, async function(ret) {
|
|
|
+ let data = ret[0];
|
|
|
+ // const array = data.map(item => item.documentid);
|
|
|
+ try {
|
|
|
+ const response = await client.documents.list({ collection_ids: [req.body.folderid] });
|
|
|
+ // console.log(response);
|
|
|
+ let data2 = response.results.map(doc => {
|
|
|
+ doc.documentid = doc.id;
|
|
|
+ delete doc.id;
|
|
|
+ return doc;
|
|
|
+ });
|
|
|
+
|
|
|
+ // 合并data和data2,根据documentid
|
|
|
+ const mergedData = data.map(item => {
|
|
|
+ const correspondingDoc = data2.find(doc => doc.documentid === item.documentid);
|
|
|
+ return { ...item, ...correspondingDoc };
|
|
|
+ });
|
|
|
+
|
|
|
+ res.status(200).json({ result: mergedData });
|
|
|
+ } catch (error) {
|
|
|
+ res.status(500).json({ error: error instanceof Error ? error.message : "An error occurred" });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+});
|
|
|
+
|
|
|
//获取能关联的文件
|
|
|
router.route("/getFile2").all(async (req, res, next) => {
|
|
|
//mode的处理
|
|
@@ -272,9 +304,12 @@ router.route("/removeFile").all(async (req, res, next) => {
|
|
|
let documentids = decodeURIComponent(req.body[0].documentids).split(",")
|
|
|
let folderid = req.body[0].folderid
|
|
|
let ids = req.body[0].ids
|
|
|
- await Promise.all(documentids.map(documentid =>
|
|
|
+ documentids.map(documentid =>
|
|
|
client.collections.removeDocument({ id: folderid, documentId: documentid })
|
|
|
- ));
|
|
|
+ )
|
|
|
+ // await Promise.all(documentids.map(documentid =>
|
|
|
+ // client.collections.removeDocument({ id: folderid, documentId: documentid })
|
|
|
+ // ));
|
|
|
p = [ids, folderid];
|
|
|
p.unshift(_mysqlLabor[0], _mysqlLabor[1], "removeFile");
|
|
|
mysql.usselect(p, async function(ret) {
|
|
@@ -295,10 +330,14 @@ router.route("/moveFile").all(async (req, res, next) => {
|
|
|
let documentids = decodeURIComponent(req.body[0].documentids).split(",")
|
|
|
let folderid = req.body[0].folderid
|
|
|
let ids = decodeURIComponent(req.body[0].ids).split(",")
|
|
|
- const results = await Promise.all(documentids.map(documentid => client.collections.addDocument({
|
|
|
+ documentids.map(documentid => client.collections.addDocument({
|
|
|
id: folderid,
|
|
|
documentId: documentid
|
|
|
- })));
|
|
|
+ }))
|
|
|
+ // const results = await Promise.all(documentids.map(documentid => client.collections.addDocument({
|
|
|
+ // id: folderid,
|
|
|
+ // documentId: documentid
|
|
|
+ // })));
|
|
|
// console.log("每一条接口返回的值:", results); // 查看每一条接口返回来的值
|
|
|
|
|
|
for (const id of ids) {
|
|
@@ -321,9 +360,12 @@ router.route("/deleteFile").all(async (req, res, next) => {
|
|
|
try {
|
|
|
let documentids = decodeURIComponent(req.body[0].documentids).split(",")
|
|
|
let ids = req.body[0].ids
|
|
|
- const results = await Promise.all(documentids.map(documentid => client.documents.delete({
|
|
|
+ documentids.map(documentid => client.documents.delete({
|
|
|
id: documentid,
|
|
|
- })));
|
|
|
+ }))
|
|
|
+ // const results = await Promise.all(documentids.map(documentid => client.documents.delete({
|
|
|
+ // id: documentid,
|
|
|
+ // })));
|
|
|
// console.log("每一条接口返回的值:", results); // 查看每一条接口返回来的值
|
|
|
|
|
|
p = [ids];
|
|
@@ -339,7 +381,55 @@ router.route("/deleteFile").all(async (req, res, next) => {
|
|
|
}
|
|
|
});
|
|
|
|
|
|
+router.route("/getFolder").all((req, res, next) => {
|
|
|
+ postmysql3(req, res, "getFolder");
|
|
|
+});
|
|
|
+
|
|
|
+//search文件
|
|
|
+router.route("/searchFile").all(async (req, res, next) => {
|
|
|
+ if (req.body) {
|
|
|
+ try {
|
|
|
+ let filters = {}
|
|
|
+ if(req.body.type == 1){
|
|
|
+ filters = {"document_id": {"$in": req.body.ids}}
|
|
|
+ }else if(req.body.type == 2){
|
|
|
+ filters = {"collection_ids": {"$in": req.body.ids}}
|
|
|
+ }
|
|
|
+ const response = await client.retrieval.search({
|
|
|
+ query: req.body.query,
|
|
|
+ search_settings: {
|
|
|
+ filters: filters,
|
|
|
+ useSemanticSearch: true,
|
|
|
+ chunkSettings: {
|
|
|
+ limit: req.body.limit ? req.body.limit : 10,
|
|
|
+ enabled: true
|
|
|
+ },
|
|
|
+ }
|
|
|
+ });
|
|
|
+ res.status(200).json({ result: response.results });
|
|
|
+
|
|
|
+ } catch (error) {
|
|
|
+ res.status(500).json({ error: error instanceof Error ? error.message : "An error occurred" });
|
|
|
+ }
|
|
|
|
|
|
+ }
|
|
|
+});
|
|
|
+
|
|
|
+//提取文件实体
|
|
|
+router.route("/extractFile").all(async (req, res, next) => {
|
|
|
+ if (req.body) {
|
|
|
+ try {
|
|
|
+ const response = client.documents.extract({
|
|
|
+ id:req.body.id
|
|
|
+ })
|
|
|
+ res.status(200).json({ result: response.results });
|
|
|
+
|
|
|
+ } catch (error) {
|
|
|
+ res.status(500).json({ error: error instanceof Error ? error.message : "An error occurred" });
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+});
|
|
|
|
|
|
function generateAPIKey(username) {
|
|
|
let timeStamp = new Date().getTime();
|
|
@@ -390,6 +480,7 @@ postmysql2 = function(req, res, functionname) {
|
|
|
postmysql3 = function(req, res, functionname) {
|
|
|
//mode的處理
|
|
|
if (req.body) {
|
|
|
+ console.log(req);
|
|
|
p = Object.values(req.body);
|
|
|
p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
|
|
|
//執行存儲過程
|