lsc 4 months ago
parent
commit
d045a98470
1 changed files with 56 additions and 1 deletions
  1. 56 1
      pbl.js

+ 56 - 1
pbl.js

@@ -22,12 +22,67 @@ const crypto = require("crypto");
 const https = require("https");
 const { Pool } = require('pg');
 const axios = require('axios');
+
 const loginHandler = require('./login'); // 确保路径正确
+const { r2rClient } = require("r2r-js");
+const client = new r2rClient("https://r2rserver.cocorobo.cn/");
+
 
 router.route("/login").all(async (req, res, next) => {
-    loginHandler(req, res);
+    loginHandler(req, res)
+});
+
+router.route("/logout").all(async (req, res, next) => {
+    try {
+        const response = await client.users.logout();
+        res.status(200).json({result: response.results});
+    } catch (error) {
+        res.status(500).json({error: error instanceof Error ? error.message : "An error occurred"});
+    }
+});
+
+router.route("/getDocument").all(async (req, res, next) => {
+    try {
+        const response = await client.documents.list({
+            limit: 10,
+            offset: 0,
+        });
+        console.log(response);
+        
+        res.status(200).json({ result: response.results });
+    } catch (error) {
+        res.status(500).json({ error: error instanceof Error ? error.message : "An error occurred" });
+    }
 });
 
+//列出文档块
+router.route("/listChunks").all(async (req, res, next) => {
+    try {
+        const response = await client.documents.listChunks({
+            id: "5111165f-965c-5d61-89e3-1f74b0178032",
+        });
+        console.log(response);
+        
+        res.status(200).json({ result: response.results });
+    } catch (error) {
+        res.status(500).json({ error: error instanceof Error ? error.message : "An error occurred" });
+    }
+});
+
+//提取实体和关系
+router.route("/extract").all(async (req, res, next) => {
+    try {
+        const response = await client.documents.extract({ id: "5111165f-965c-5d61-89e3-1f74b0178032" })
+        console.log(response);
+        
+        res.status(200).json({ result: response.results });
+    } catch (error) {
+        res.status(500).json({ error: error instanceof Error ? error.message : "An error occurred" });
+    }
+});
+
+
+
 router.route("/selectUser").all((req, res, next) => {
     var json = queryString(req.url);
     getmysql(req, res, "selectUser", json["userid"]);