Akane710 commited on
Commit
6de0d93
·
verified ·
1 Parent(s): ce55394

Update server.js

Browse files
Files changed (1) hide show
  1. server.js +38 -6
server.js CHANGED
@@ -1,20 +1,17 @@
1
- // File: server.js
2
-
3
  import express from 'express';
4
  import { CAINode } from 'cainode';
5
  import bodyParser from "body-parser";
6
- import os from "os"
7
 
8
  const app = express();
9
  const PORT = 7860;
10
  const HOST = "0.0.0.0";
11
  app.use(bodyParser.json());
12
 
13
- // API endpoint for chatting
14
  // API endpoint for chatting
15
  app.get('/chat', async (req, res) => {
16
  const token = req.query.token || process.env.token;
17
- const characterId = req.query.characterId
18
  const chatId = req.query.chatId;
19
  const voiceId = req.query.voiceId || 'f4b33b1d-2e5a-40a8-8a07-958140cd104d';
20
  const message = req.query.message;
@@ -84,6 +81,41 @@ app.get('/chat', async (req, res) => {
84
  }
85
  });
86
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
  app.listen(PORT, HOST, () => {
88
  console.log(`Running on http://${HOST}:${PORT}`);
89
- });
 
 
 
1
  import express from 'express';
2
  import { CAINode } from 'cainode';
3
  import bodyParser from "body-parser";
4
+ import os from "os";
5
 
6
  const app = express();
7
  const PORT = 7860;
8
  const HOST = "0.0.0.0";
9
  app.use(bodyParser.json());
10
 
 
11
  // API endpoint for chatting
12
  app.get('/chat', async (req, res) => {
13
  const token = req.query.token || process.env.token;
14
+ const characterId = req.query.characterId;
15
  const chatId = req.query.chatId;
16
  const voiceId = req.query.voiceId || 'f4b33b1d-2e5a-40a8-8a07-958140cd104d';
17
  const message = req.query.message;
 
81
  }
82
  });
83
 
84
+ // API endpoint for character search
85
+ app.get('/search', async (req, res) => {
86
+ const token = req.query.token || process.env.token;
87
+ const query = req.query.query;
88
+
89
+ if (!query) {
90
+ return res.status(400).json({ error: 'Query parameter is required.' });
91
+ }
92
+
93
+ let client;
94
+ try {
95
+ client = new CAINode();
96
+
97
+ // Login to the client
98
+ await client.login(token);
99
+
100
+ // Search for characters
101
+ const searchResults = await client.character.search(query);
102
+
103
+ // Return the search results
104
+ res.json({ results: searchResults });
105
+
106
+ // Logout and cleanup
107
+ await client.logout();
108
+
109
+ } catch (error) {
110
+ console.error('Error:', error.message);
111
+ res.status(500).json({ error: error.message });
112
+
113
+ if (client) {
114
+ await client.logout();
115
+ }
116
+ }
117
+ });
118
+
119
  app.listen(PORT, HOST, () => {
120
  console.log(`Running on http://${HOST}:${PORT}`);
121
+ });