teralomaniac commited on
Commit
8e1cf68
1 Parent(s): 0a67b3e
Files changed (3) hide show
  1. clewd.js +15 -2
  2. docker-compose.yml +3 -3
  3. lib/clewd-utils.js +1 -1
clewd.js CHANGED
@@ -26,7 +26,19 @@ CookieChanger.on('ChangeCookie', () => {
26
  }, !Config.rProxy || Config.rProxy === AI.end() ? 15000 + timestamp - Date.now() : 0);
27
  });
28
 
29
- const convertToType = value => {
 
 
 
 
 
 
 
 
 
 
 
 
30
  if (value === 'true') return true;
31
  if (value === 'false') return false;
32
  if (/^\d+$/.test(value)) return parseInt(value);
@@ -241,6 +253,7 @@ const updateParams = res => {
241
  try {
242
  /***************************** */
243
  if ('SET YOUR COOKIE HERE' === Config.Cookie || Config.Cookie?.length < 1 || (Config.CookieArray?.length > 0 && invalidtime > totaltime)) { //if ('SET YOUR COOKIE HERE' === Config.Cookie || Config.Cookie?.length < 1) {
 
244
  return console.log(`No cookie available, apiKey-Only mode enabled.\n`); //throw Error('Set your cookie inside config.js');
245
  }
246
  updateCookies(Config.Cookie.replace(/^(sessionKey=)?/, 'sessionKey=')); //updateCookies(Config.Cookie);
@@ -359,7 +372,7 @@ const updateParams = res => {
359
  }
360
  }), conversations = await convRes.json();
361
  updateParams(convRes);
362
- conversations.length > 0 && await Promise.all(conversations.map((conv => deleteChat(conv.uuid))));
363
  /***************************** */
364
  invalidtime = 0;
365
  } catch (err) {
 
26
  }, !Config.rProxy || Config.rProxy === AI.end() ? 15000 + timestamp - Date.now() : 0);
27
  });
28
 
29
+ const asyncPool = async (poolLimit, array, iteratorFn) => {
30
+ const ret = [], executing = [];
31
+ for (const item of array) {
32
+ const p = Promise.resolve().then(() => iteratorFn(item));
33
+ ret.push(p);
34
+ if (poolLimit <= array.length) {
35
+ const e = p.then(() => executing.splice(executing.indexOf(e), 1));
36
+ executing.push(e);
37
+ if (executing.length >= poolLimit) await Promise.race(executing);
38
+ }
39
+ }
40
+ return Promise.all(ret);
41
+ }, convertToType = value => {
42
  if (value === 'true') return true;
43
  if (value === 'false') return false;
44
  if (/^\d+$/.test(value)) return parseInt(value);
 
253
  try {
254
  /***************************** */
255
  if ('SET YOUR COOKIE HERE' === Config.Cookie || Config.Cookie?.length < 1 || (Config.CookieArray?.length > 0 && invalidtime > totaltime)) { //if ('SET YOUR COOKIE HERE' === Config.Cookie || Config.Cookie?.length < 1) {
256
+ changing = false; //
257
  return console.log(`No cookie available, apiKey-Only mode enabled.\n`); //throw Error('Set your cookie inside config.js');
258
  }
259
  updateCookies(Config.Cookie.replace(/^(sessionKey=)?/, 'sessionKey=')); //updateCookies(Config.Cookie);
 
372
  }
373
  }), conversations = await convRes.json();
374
  updateParams(convRes);
375
+ conversations.length > 0 && await asyncPool(10, conversations, async (conv) => await deleteChat(conv.uuid)); //await Promise.all(conversations.map((conv => deleteChat(conv.uuid))));
376
  /***************************** */
377
  invalidtime = 0;
378
  } catch (err) {
docker-compose.yml CHANGED
@@ -2,10 +2,10 @@ version: '3'
2
  services:
3
  app:
4
  build:
5
- context: ..
6
- dockerfile: docker/Dockerfile
7
 
8
  ports:
9
  - 8444:8444
10
  volumes:
11
- - ..:/app
 
2
  services:
3
  app:
4
  build:
5
+ context: .
6
+ dockerfile: Dockerfile
7
 
8
  ports:
9
  - 8444:8444
10
  volumes:
11
+ - .:/app
lib/clewd-utils.js CHANGED
@@ -5,7 +5,7 @@
5
  'use strict';
6
 
7
  const {randomInt, randomBytes} = require('node:crypto'), {version: Version} = require('../package.json'), Encoder = (new TextDecoder,
8
- new TextEncoder), Main = 'clewd修改版 v' + Version + '(1) by tera', Replacements = {
9
  user: 'Human',
10
  assistant: 'Assistant',
11
  system: '',
 
5
  'use strict';
6
 
7
  const {randomInt, randomBytes} = require('node:crypto'), {version: Version} = require('../package.json'), Encoder = (new TextDecoder,
8
+ new TextEncoder), Main = 'clewd修改版 v' + Version + '(2) by tera', Replacements = {
9
  user: 'Human',
10
  assistant: 'Assistant',
11
  system: '',