| 35 | const init = () => {}; |
| 36 | |
| 37 | const getModule = async ( |
| 38 | serverInfo: ServerInfo, |
| 39 | option?: { |
| 40 | throwException: boolean; |
| 41 | }, |
| 42 | ): Promise<ServerContext> => { |
| 43 | option = Object.assign( |
| 44 | { |
| 45 | throwException: true, |
| 46 | }, |
| 47 | option, |
| 48 | ); |
| 49 | // console.log('getModule', serverInfo) |
| 50 | if (!serverModule[serverInfo.localPath]) { |
| 51 | try { |
| 52 | if (serverInfo.name.startsWith("Cloud")) { |
| 53 | const server = new AigcServer["Cloud"](); |
| 54 | server.type = "buildIn"; |
| 55 | server.ServerApi = ServerApi; |
| 56 | await server.init(); |
| 57 | serverModule[serverInfo.localPath] = server; |
| 58 | } else if (serverInfo.name in AigcServer) { |
| 59 | const server = AigcServer[serverInfo.name] as ServerContext; |
| 60 | server.type = "buildIn"; |
| 61 | server.ServerApi = ServerApi; |
| 62 | await server.init(); |
| 63 | serverModule[serverInfo.localPath] = server; |
| 64 | } else if (serverInfo.type === EnumServerType.REMOTE) { |
| 65 | const server = new AigcServer["RemoteServer"](serverInfo); |
| 66 | server.type = "buildIn"; |
| 67 | server.ServerApi = ServerApi; |
| 68 | await server.init(); |
| 69 | serverModule[serverInfo.localPath] = server; |
| 70 | } else { |
| 71 | const serverPath = `${serverInfo.localPath}/server.js`; |
| 72 | const configPath = `${serverInfo.localPath}/config.json`; |
| 73 | |
| 74 | let server = null; |
| 75 | if ( |
| 76 | await Files.exists(serverPath, { |
| 77 | isDataPath: false, |
| 78 | }) |
| 79 | ) { |
| 80 | const module = await import(`file://${serverPath}`); |
| 81 | server = module.default; |
| 82 | } |
| 83 | if ( |
| 84 | !server && |
| 85 | (await Files.exists(configPath, { |
| 86 | isDataPath: false, |
| 87 | })) |
| 88 | ) { |
| 89 | const configContent = await Files.read(configPath, { |
| 90 | isDataPath: false, |
| 91 | }); |
| 92 | try { |
| 93 | const config = JSON.parse(configContent); |
| 94 | if (config.entry === "__EasyServer__") { |