jsir 2.5.3 → 2.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/deps/room.js CHANGED
@@ -6,6 +6,7 @@ const {fileJson, fileLock, vl, createConsole, getKeyTips, getValTips,
6
6
  } = require('./util');
7
7
  const {setRoute, createSign} = require('../deps/server')
8
8
  const roomDataFile = "jsirRoom.json"
9
+ const jsirNodesFile = "jsirNodes.json"
9
10
  const roomsDirLockKey = "RW_" + getRoomsDir();
10
11
  const syncRoomsLockKey = "SyncRooms_" + getRoomsDir();
11
12
  const syncConfigsLockKey = "SyncConfigs_" + getConfigDir();
@@ -134,6 +135,7 @@ async function getTailscaleNodes() {
134
135
 
135
136
  async function updateRoomInfo() {
136
137
  setting.nodeMap = await getTailscaleNodes();
138
+ await fileJson("jsirNodes.json", obj => setting.nodeMap);
137
139
  let nodes = Object.keys(setting.nodeMap)
138
140
  let ip = getSelfIP(nodes)
139
141
  await fileJson(roomDataFile, async room => {
@@ -180,7 +182,9 @@ async function syncRooms() {
180
182
  }
181
183
  }
182
184
  if (respBody) {
183
- syncRooms.push(JSON.parse(respBody))
185
+ let currRoom = JSON.parse(respBody);
186
+ currRoom.selfNode = node;
187
+ syncRooms.push(currRoom)
184
188
  debug(`sync ${node} success`);
185
189
  }
186
190
  } catch (e) {
@@ -275,6 +279,7 @@ async function _syncSetting(room) {
275
279
  }
276
280
 
277
281
  async function initRoom() {
282
+ setting.nodeMap = await fileJson(jsirNodesFile);
278
283
  let roomUpdateTouchTime = false;
279
284
  await fileJson(roomDataFile, async room => {
280
285
  await initRoomJsir(room)
package/deps/server.js CHANGED
@@ -7,6 +7,7 @@ const preferredPort = setting.defaultPort;
7
7
  // 路由存储
8
8
  const routes = setting.routes;
9
9
  let invokeStart = false;
10
+ const apiReg = /[^a-zA-Z]api[^a-zA-Z]|[^a-zA-Z]api$/i;
10
11
 
11
12
  function debug(...args) {
12
13
  if (global.$DEBUG) {
@@ -35,7 +36,7 @@ function createSign() {
35
36
  async function process(routeKey, req, res, params) {
36
37
  let router = routes[routeKey]
37
38
  if (router) {
38
- if ("get /" !== routeKey && !router.isApi) {
39
+ if ("get /" !== routeKey && !router.isApi && !apiReg.test(routeKey)) {
39
40
  // 如果不是api接口,则校验签名
40
41
  // 取header里的sign字段
41
42
  const sign = req.headers['sign'];
@@ -140,7 +141,7 @@ async function startServer() {
140
141
  method, url, fn(req, res, err), null
141
142
  err: {code, msg}
142
143
  */
143
- function setRoute(method, url, fn, handler = jsonHandle, isApi) {
144
+ function setRoute(method, url, fn, isApi = false, handler = jsonHandle) {
144
145
  startServer();
145
146
 
146
147
  const routeKey = `${method.toLowerCase()} ${url}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsir",
3
- "version": "2.5.3",
3
+ "version": "2.5.5",
4
4
  "description": "JavaScript Script Management Tool",
5
5
  "main": "index.js",
6
6
  "scripts": {