|
@@ -140,12 +140,43 @@ router.route("/getFile").all(async (req, res, next) => {
|
|
p = Object.values(req.body[0]);
|
|
p = Object.values(req.body[0]);
|
|
p.unshift(_mysqlLabor[0], _mysqlLabor[1], "getFile");
|
|
p.unshift(_mysqlLabor[0], _mysqlLabor[1], "getFile");
|
|
mysql.usselect(p, async function(ret) {
|
|
mysql.usselect(p, async function(ret) {
|
|
- console.log(ret);
|
|
|
|
let data = ret[0];
|
|
let data = ret[0];
|
|
- const array = data.map(item => item.documentid);
|
|
|
|
|
|
+ // const array = data.map(item => item.documentid);
|
|
try {
|
|
try {
|
|
- const response = await client.documents.list({ ids: array });
|
|
|
|
- console.log(response);
|
|
|
|
|
|
+ const response = await client.documents.list({ collection_ids: [req.body[0].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的处理
|
|
|
|
+ if (req.body[0]) {
|
|
|
|
+ p = Object.values(req.body[0]);
|
|
|
|
+ p.unshift(_mysqlLabor[0], _mysqlLabor[1], "getFile2");
|
|
|
|
+ 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[0].folderid] });
|
|
|
|
+ // console.log(response);
|
|
let data2 = response.results.map(doc => {
|
|
let data2 = response.results.map(doc => {
|
|
doc.documentid = doc.id;
|
|
doc.documentid = doc.id;
|
|
delete doc.id;
|
|
delete doc.id;
|
|
@@ -172,8 +203,8 @@ router.route("/addFolder").all(async (req, res, next) => {
|
|
if (req.body[0]) {
|
|
if (req.body[0]) {
|
|
try {
|
|
try {
|
|
const response = await client.collections.create({
|
|
const response = await client.collections.create({
|
|
- name: req.body[0].n,
|
|
|
|
- description: req.body[0].fd
|
|
|
|
|
|
+ name: decodeURIComponent(req.body[0].n),
|
|
|
|
+ description: decodeURIComponent(req.body[0].fd)
|
|
});
|
|
});
|
|
p = [...Object.values(req.body[0]), response.results.id];
|
|
p = [...Object.values(req.body[0]), response.results.id];
|
|
p.unshift(_mysqlLabor[0], _mysqlLabor[1], "addFolder");
|
|
p.unshift(_mysqlLabor[0], _mysqlLabor[1], "addFolder");
|
|
@@ -188,6 +219,126 @@ router.route("/addFolder").all(async (req, res, next) => {
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+//删除文件夹
|
|
|
|
+router.route("/deleteFolder").all(async (req, res, next) => {
|
|
|
|
+ //mode的处理
|
|
|
|
+ if (req.body[0]) {
|
|
|
|
+ try {
|
|
|
|
+ let folderids = decodeURIComponent(req.body[0].folderids).split(",")
|
|
|
|
+ let ids = req.body[0].ids
|
|
|
|
+ await Promise.all(folderids.map(folderid => client.collections.delete({ id: folderid })));
|
|
|
|
+ p = [ids];
|
|
|
|
+ p.unshift(_mysqlLabor[0], _mysqlLabor[1], "deleteFolder");
|
|
|
|
+ mysql.usselect(p, async function(ret) {
|
|
|
|
+ res.end(JSON.stringify(ret));
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ } catch (error) {
|
|
|
|
+ res.status(500).json({ error: error instanceof Error ? error.message : "An error occurred" });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+});
|
|
|
|
+
|
|
|
|
+//修改文件夹
|
|
|
|
+router.route("/updateFolder").all(async (req, res, next) => {
|
|
|
|
+ //mode的处理
|
|
|
|
+ if (req.body[0]) {
|
|
|
|
+ try {
|
|
|
|
+ const { folderid, ...folderData } = req.body[0]; // 解构赋值,排除folderid
|
|
|
|
+ const response = await client.collections.update({
|
|
|
|
+ id: folderid,
|
|
|
|
+ description: decodeURIComponent(req.body[0].d)
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ p = Object.values(folderData); // 获取剩余属性的键
|
|
|
|
+
|
|
|
|
+ p.unshift(_mysqlLabor[0], _mysqlLabor[1], "updateFolder");
|
|
|
|
+ mysql.usselect(p, async function(ret) {
|
|
|
|
+ res.end(JSON.stringify(ret));
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ } catch (error) {
|
|
|
|
+ res.status(500).json({ error: error instanceof Error ? error.message : "An error occurred" });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+});
|
|
|
|
+
|
|
|
|
+//移除文件
|
|
|
|
+router.route("/removeFile").all(async (req, res, next) => {
|
|
|
|
+ if (req.body[0]) {
|
|
|
|
+ try {
|
|
|
|
+ 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 =>
|
|
|
|
+ client.collections.removeDocument({ id: folderid, documentId: documentid })
|
|
|
|
+ ));
|
|
|
|
+ p = [ids, folderid];
|
|
|
|
+ p.unshift(_mysqlLabor[0], _mysqlLabor[1], "removeFile");
|
|
|
|
+ mysql.usselect(p, async function(ret) {
|
|
|
|
+ res.end(JSON.stringify(ret));
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ } catch (error) {
|
|
|
|
+ res.status(500).json({ error: error instanceof Error ? error.message : "An error occurred" });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+});
|
|
|
|
+
|
|
|
|
+//移入文件
|
|
|
|
+router.route("/moveFile").all(async (req, res, next) => {
|
|
|
|
+ if (req.body[0]) {
|
|
|
|
+ try {
|
|
|
|
+ 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({
|
|
|
|
+ id: folderid,
|
|
|
|
+ documentId: documentid
|
|
|
|
+ })));
|
|
|
|
+ // console.log("每一条接口返回的值:", results); // 查看每一条接口返回来的值
|
|
|
|
+
|
|
|
|
+ for (const id of ids) {
|
|
|
|
+ p = [id, folderid];
|
|
|
|
+ p.unshift(_mysqlLabor[0], _mysqlLabor[1], "moveFile");
|
|
|
|
+ const ret = await mysql.usselect(p, async function(ret) {});
|
|
|
|
+ }
|
|
|
|
+ res.status(200).json({ messages: "移动成功" });
|
|
|
|
+
|
|
|
|
+ } catch (error) {
|
|
|
|
+ res.status(500).json({ error: error instanceof Error ? error.message : "An error occurred" });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+});
|
|
|
|
+
|
|
|
|
+//移入文件
|
|
|
|
+router.route("/deleteFile").all(async (req, res, next) => {
|
|
|
|
+ if (req.body[0]) {
|
|
|
|
+ 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({
|
|
|
|
+ id: documentid,
|
|
|
|
+ })));
|
|
|
|
+ // console.log("每一条接口返回的值:", results); // 查看每一条接口返回来的值
|
|
|
|
+
|
|
|
|
+ p = [ids];
|
|
|
|
+ p.unshift(_mysqlLabor[0], _mysqlLabor[1], "deleteFile");
|
|
|
|
+ mysql.usselect(p, async function(ret) {
|
|
|
|
+ res.end(JSON.stringify(ret));
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ } catch (error) {
|
|
|
|
+ res.status(500).json({ error: error instanceof Error ? error.message : "An error occurred" });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+});
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
function generateAPIKey(username) {
|
|
function generateAPIKey(username) {
|