Explorar el Código

feat: import with argv --import

ryanemax hace 8 meses
padre
commit
77a8cb314f

+ 1 - 2
server/config.js

@@ -1,9 +1,8 @@
 module.exports = {
     "appName":"EduServer",
     "version":"1.0.1",
-    "PARSE_SERVERURL":"http://localhost:61337/parse",
+    "PARSE_SERVERURL":"http://8.140.98.43/parse",
     "PARSE_APPID":"edu-textbook",
     "PARSE_MASTERKEY":"EDU2024",
-    "NOVA_SERVERURL":"http://localhost:61337/",
     "DATABASE_LOCAL":false, // 加载本地测试数据库
 }

+ 9 - 2
server/db/func/import-schemas.js

@@ -7,6 +7,9 @@ export async function importAllSchemas(){
     try{
       Parse.initialize(global.config['PARSE_APPID'],null,global.config['PARSE_MASTERKEY']);
       Parse.serverURL = global.config['PARSE_SERVERURL'];
+      if(global.config["LOCAL"]){
+        Parse.serverURL = "http://127.0.0.1:61337/parse"
+      }
       Parse.Cloud.useMasterKey()
       Parse.Cloud.useMasterKey(true)
     //   Parse.masterKey = global.config['PARSE_MASTERKEY'];
@@ -46,9 +49,13 @@ export async function importAllSchemas(){
           clp.setPublicWriteAccess(true);
           schema.setCLP(clp);
           if(SchemaMap[schemaJson?.className]){
-            await schema.update({useMasterKey:true});
+            try{
+              await schema.update({useMasterKey:true});
+            }catch(err1){}
           }else{
-            await schema.save({useMasterKey:true});
+            try{
+              await schema.save({useMasterKey:true});
+            }catch(err2){}
           }
         // })
       }

+ 5 - 0
server/db/func/test/test-import-schema.js

@@ -0,0 +1,5 @@
+import { importAllSchemas } from "../import-schemas";
+global.config["PARSE_SERVERURL"] = "http://http://8.140.98.43/parse",
+global.config["PARSE_APPID"] = "edu-textbook",
+global.config["PARSE_MASTERKEY"] = "EDU2024",
+importAllSchemas()

+ 1 - 1
server/db/schemas/EduTextbook.js

@@ -196,7 +196,7 @@ export const EduTextbook = {
             "required": false
         },
         "accept": {//填写承诺书
-            "type": "string",
+            "type": "String",
             "required": false
         }
     },

+ 9 - 0
server/server.js

@@ -67,6 +67,8 @@ const app = express();
 
 const cors = require('cors');
 import { importAllSchemas } from "./db/func/import-schemas"
+
+
 import { PostgreSQLKeep } from "./lib/pg/index.js"
 app.use(cors({
     origin: '*'
@@ -135,7 +137,14 @@ process.on('uncaughtException', async (err) => {
 
 // 启动服务
 async function initParseAndDatabase(){
+  
   try{
+    // 仅导入脚本参数
+    if(argv.import){
+      console.log("importAllSchemas")
+      await importAllSchemas()
+      return
+    }
 
     console.log("正在启动微服务...")
     await startParse();

+ 27 - 27
server/vite.config.js

@@ -13,33 +13,33 @@ export default defineConfig({
             exportName:"EduTextbookServer",
             // initAppOnBoot:false,
         }),
-        obfuscatorPlugin({
-            include: ["**/*.js"],
-            exclude: [/node_modules/],
-            apply: "build",
-            debugger: true,
-            options: {
-                debugProtection:false,
-                debugProtectionInterval:0,
-                // ...  [See more options](https://github.com/javascript-obfuscator/javascript-obfuscator)
-                compact: true,
-                controlFlowFlattening: false,
-                controlFlowFlatteningThreshold: 0.5,
-                deadCodeInjection: false,
-                deadCodeInjectionThreshold: 0.2,
-                disableConsoleOutput: true,
-                identifierNamesGenerator: 'hexadecimal',
-                log: true,
-                renameGlobals: false,
-                rotateStringArray: true,
-                selfDefending: false,
-                stringArray: true,
-                stringArrayEncoding: ['base64'],
-                stringArrayThreshold: 0.5,
-                transformObjectKeys: false,
-                unicodeEscapeSequence: false
-            },
-        }),
+        // obfuscatorPlugin({
+        //     include: ["**/*.js"],
+        //     exclude: [/node_modules/],
+        //     apply: "build",
+        //     debugger: true,
+        //     options: {
+        //         debugProtection:false,
+        //         debugProtectionInterval:0,
+        //         // ...  [See more options](https://github.com/javascript-obfuscator/javascript-obfuscator)
+        //         compact: true,
+        //         controlFlowFlattening: false,
+        //         controlFlowFlatteningThreshold: 0.5,
+        //         deadCodeInjection: false,
+        //         deadCodeInjectionThreshold: 0.2,
+        //         disableConsoleOutput: true,
+        //         identifierNamesGenerator: 'hexadecimal',
+        //         log: true,
+        //         renameGlobals: false,
+        //         rotateStringArray: true,
+        //         selfDefending: false,
+        //         stringArray: true,
+        //         stringArrayEncoding: ['base64'],
+        //         stringArrayThreshold: 0.5,
+        //         transformObjectKeys: false,
+        //         unicodeEscapeSequence: false
+        //     },
+        // }),
     ],
     build: {
         lib: {