Przeglądaj źródła

update:soul-server

cainiao-hue 3 miesięcy temu
rodzic
commit
30b47f906d

+ 3 - 3
soul-server/lib/ncloud.js

@@ -38,9 +38,9 @@ class CloudObject{
     // 更新
     async save(){
         let method = "POST"
-        let url = "http://dev.fmode.cn:1337/parse/classes/" + this.className //默认
+        let url = "http://dev.fmode.cn:1337/parse/classes/" + this.className; //默认
         if(this.id){
-            url = "/"+this.id
+            url += "/"+this.id
             method = "PUT"
         } 
         let body = JSON.stringify(this.data)
@@ -50,7 +50,7 @@ class CloudObject{
           "x-parse-application-id": "dev"
         },
         "body": body,
-        "method": "POST",
+        "method": method,
         "mode": "cors",
         "credentials": "omit"
       });

+ 43 - 43
soul-server/migration/data.js

@@ -1,62 +1,62 @@
+module.exports.ChatRecordList = [
+  {
+    "objectId": "chat001",
+    "timestamp": "2024-12-17T14:00:00Z",
+    "chatContent": [
+      "用户:你好,我最近感到很焦虑。",
+      "陪聊师:你好,李明在这里。可以告诉我是什么让你感到焦虑吗?",
+      "用户:我总是担心工作上的事情。",
+      "陪聊师:工作压力确实会影响我们的情绪。你觉得具体是哪些方面让你感到压力呢?"
+    ],
+    //"user": { "objectId": "user001" },
+    "chatpartner": { "objectId": "part001" }
+  },
+  {
+    "objectId": "chat002",
+    "timestamp": "2024-12-17T14:10:00Z",
+    "chatContent": [
+      "用户:我有个孩子,他最近有些不开心。",
+      "陪聊师:你好,张华在这里。你能告诉我一些关于他不开心的事情吗?",
+      "用户:他在学校里交不到朋友。",
+      "陪聊师:社交问题对孩子来说是很常见的。我们可以一起探讨一些解决方法。"
+    ],
+    //"user": { "objectId": "user002" },
+    "chatpartner": { "objectId": "part002" }
+  },
+  {
+    "objectId": "chat003",
+    "timestamp": "2024-12-17T14:20:00Z",
+    "chatContent": [
+      "用户:我感觉有点孤独。",
+      "陪聊师:你好,王芳在这里。孤独的感觉是很正常的,你想聊聊吗?",
+      "用户:我不知道该怎么开始。",
+      "陪聊师:没关系,我们可以慢慢来。你最近有什么有趣的事情吗?"
+    ],
+    //"user": { "objectId": "user003" },
+    "chatpartner": { "objectId": "part003" }
+  }
+]
+
 module.exports.ChatPartnerList = [
     {
       "objectId": "part001",
       "name": "李明",
       "expertise": "心理咨询",
-      "avatar": "https://example.com/avatars/therapist_001.jpg",
+      "avatar": "https://nova-cloud.obs.cn-south-1.myhuaweicloud.com/storage/aigc/imagine/CpmyF1nqRF-0.png",
       "bio": "李明是一名拥有十年经验的心理咨询师,专注于焦虑和抑郁的治疗。"
     },
     {
       "objectId": "part002",
       "name": "张华",
       "expertise": "儿童心理",
-      "avatar": "https://example.com/avatars/therapist_002.jpg",
+      "avatar": "https://nova-cloud.obs.cn-south-1.myhuaweicloud.com/storage/aigc/imagine/CpmyF1nqRF-0.png",
       "bio": "张华专注于儿童心理健康,致力于帮助孩子们克服成长中的挑战。"
     },
     {
       "objectId": "part003",
       "name": "王芳",
       "expertise": "",
-      "avatar": "https://example.com/avatars/therapist_003.jpg",
+      "avatar": "https://nova-cloud.obs.cn-south-1.myhuaweicloud.com/storage/aigc/imagine/CpmyF1nqRF-0.png",
       "bio": "王芳是一名普通陪聊师,擅长倾听和陪伴。"
     }
-]
-
-module.exports.ChatRecordList = [
-    {
-      "objectId": "chat001",
-      "timestamp": "2024-12-17T14:00:00Z",
-      "chatContent": [
-        "用户:你好,我最近感到很焦虑。",
-        "陪聊师:你好,李明在这里。可以告诉我是什么让你感到焦虑吗?",
-        "用户:我总是担心工作上的事情。",
-        "陪聊师:工作压力确实会影响我们的情绪。你觉得具体是哪些方面让你感到压力呢?"
-      ],
-      //"user": { "objectId": "user001" },
-      "chatpartner": { "objectId": "part001" }
-    },
-    {
-      "objectId": "chat002",
-      "timestamp": "2024-12-17T14:10:00Z",
-      "chatContent": [
-        "用户:我有个孩子,他最近有些不开心。",
-        "陪聊师:你好,张华在这里。你能告诉我一些关于他不开心的事情吗?",
-        "用户:他在学校里交不到朋友。",
-        "陪聊师:社交问题对孩子来说是很常见的。我们可以一起探讨一些解决方法。"
-      ],
-      //"user": { "objectId": "user002" },
-      "chatpartner": { "objectId": "part002" }
-    },
-    {
-      "objectId": "chat003",
-      "timestamp": "2024-12-17T14:20:00Z",
-      "chatContent": [
-        "用户:我感觉有点孤独。",
-        "陪聊师:你好,王芳在这里。孤独的感觉是很正常的,你想聊聊吗?",
-        "用户:我不知道该怎么开始。",
-        "陪聊师:没关系,我们可以慢慢来。你最近有什么有趣的事情吗?"
-      ],
-      //"user": { "objectId": "user003" },
-      "chatpartner": { "objectId": "part003" }
-    }
-]
+]

+ 10 - 8
soul-server/migration/import-data.js

@@ -3,8 +3,8 @@ const { ChatPartnerList, ChatRecordList } = require("./data");
 
 DataMap = {
     ChatPartner:{},
-    ChatRecord:{}
-}
+    ChatRecord:{},
+};
 
 // 查询
 //async function testQuery(){
@@ -60,20 +60,22 @@ async function importObject(className,data){
     // 导入 新对象需要添加
     // 导入前批量处理Pointer类型数据,进行重定向
     Object.keys(data)?.forEach(key=>{
-        let field = data[key]
-        let srcId = field?.objectId
+        let field = data[key];
+        let srcId = field?.objectId;
         if(srcId){ // 数组字段
             if(key=="chatpartner"){
                 data[key] = DataMap["ChatPartner"]?.[srcId]?.toPointer();
             }
         }
-    })
+    });
     // 新对象需要添加
     if(!importObj?.id){
         importObj = new CloudObject(className)
-        data.srcId = srcId;
-        importObj.set(data);
-        importObj = await importObj.save();
     }
+    //保存或更新数据
+    data.srcId = srcId;
+    importObj.set(data);
+    importObj = await importObj.save();
+
     DataMap[className][srcId] = importObj
 }