webfast 0.1.65 → 0.1.68
Sign up to get free protection for your applications and to get access to all the features.
@@ -115,6 +115,7 @@ if (telegram.initData == ``) {
|
|
115
115
|
|
116
116
|
const socketURL = `wss://${webfastSocket.replace(`https://`,``)}socket.io/?qbt=${setData}`;
|
117
117
|
|
118
|
+
let countedError = 0;
|
118
119
|
// Assuming you have a variable `socketURL` containing your WebSocket URL
|
119
120
|
web.fast.connectWebSocket = function(socketURL,maxRetries = 40, retries = 0) {
|
120
121
|
web.fast.createWebSocket = function(socketURL, maxRetries, retries) {
|
@@ -134,7 +135,16 @@ web.fast.connectWebSocket = function(socketURL,maxRetries = 40, retries = 0) {
|
|
134
135
|
const type = jQuery(this).attr(`webfast-get`);
|
135
136
|
let id = jQuery(this).attr(`id`);
|
136
137
|
if (id == undefined) {
|
137
|
-
|
138
|
+
var generateRandomId = async function(length) {
|
139
|
+
var result = '';
|
140
|
+
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
141
|
+
var charactersLength = characters.length;
|
142
|
+
for (var i = 0; i < length; i++) {
|
143
|
+
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
144
|
+
}
|
145
|
+
return result;
|
146
|
+
};
|
147
|
+
id = await generateRandomId(8); // Generate a random ID of length 8
|
138
148
|
}
|
139
149
|
arraySend.push({
|
140
150
|
id : id,
|
@@ -143,11 +153,16 @@ web.fast.connectWebSocket = function(socketURL,maxRetries = 40, retries = 0) {
|
|
143
153
|
})
|
144
154
|
console.log(`Send Array`,arraySend);
|
145
155
|
web.fast.tools.on.connect(arraySend);
|
146
|
-
|
147
|
-
|
148
|
-
|
156
|
+
} else {
|
157
|
+
if (countedError < 3) {
|
158
|
+
console.error(`Tried 10 times`);
|
159
|
+
} else {
|
160
|
+
console.error(`Try again`);
|
161
|
+
throw new Error(`error some send`);
|
162
|
+
}
|
163
|
+
|
164
|
+
}
|
149
165
|
} catch (err) {
|
150
|
-
console.error(`Try again`);
|
151
166
|
setTimeout(function(){
|
152
167
|
arraySend();
|
153
168
|
},200);
|
package/example.js
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
const path = require(`path`);
|
2
|
+
const contentPath = path.join(__dirname,`example`,`content`)
|
3
|
+
let setArray = {
|
4
|
+
wget : '/usr/local/bin/wget',
|
5
|
+
process : {
|
6
|
+
ts : Date.now(),
|
7
|
+
socket : {
|
8
|
+
api : {
|
9
|
+
list : function(program,ws,json,data,path) {
|
10
|
+
// Example to create process for websocket path action and process data
|
11
|
+
console.log(`Example of list process`);
|
12
|
+
|
13
|
+
function generateRandomText(length) {
|
14
|
+
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
15
|
+
let result = '';
|
16
|
+
|
17
|
+
for (let i = 0; i < length; i++) {
|
18
|
+
result += characters.charAt(Math.floor(Math.random() * characters.length));
|
19
|
+
}
|
20
|
+
|
21
|
+
return result;
|
22
|
+
}
|
23
|
+
|
24
|
+
|
25
|
+
// Loop for example through
|
26
|
+
let exampleData = {
|
27
|
+
list : [],
|
28
|
+
ell : data.ell,
|
29
|
+
action : data.action
|
30
|
+
}
|
31
|
+
|
32
|
+
const pushData = {};
|
33
|
+
for (let i in data.other.items) {
|
34
|
+
const item = data.other.items[i];
|
35
|
+
// We have itme
|
36
|
+
const id = item.id;
|
37
|
+
const key = item.name;
|
38
|
+
|
39
|
+
pushData[key] = {
|
40
|
+
id : id,
|
41
|
+
text : generateRandomText(10)
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
pushData.uuid = program.uuid.v4();
|
46
|
+
exampleData.list.push(pushData);
|
47
|
+
|
48
|
+
// Send websocket message create standard
|
49
|
+
const sendObject = {
|
50
|
+
func : data.function,
|
51
|
+
data : exampleData,
|
52
|
+
js : `console.log("RUN FROM BACKEND")`
|
53
|
+
}
|
54
|
+
|
55
|
+
// Sedn back to front-end
|
56
|
+
//ws.send();
|
57
|
+
|
58
|
+
return sendObject;
|
59
|
+
}
|
60
|
+
}
|
61
|
+
}
|
62
|
+
},
|
63
|
+
contentPath : contentPath
|
64
|
+
};
|
65
|
+
|
66
|
+
|
67
|
+
let program = require(path.join(__dirname,`index.js`))(setArray);
|
68
|
+
console.log(`Required`);
|
@@ -57,7 +57,7 @@ module.exports = async function(program,message,id,buttons) {
|
|
57
57
|
|
58
58
|
// Save to send so we can have the id and do things
|
59
59
|
madeRequest.result.uuid = program.uuid.v4();
|
60
|
-
let saveSend = await program.modules.data.findOrCreate(
|
60
|
+
let saveSend = await program.modules.data.findOrCreate(process.env.dbName,`send`,{
|
61
61
|
message_id : madeRequest.result.message_id
|
62
62
|
},madeRequest.result);
|
63
63
|
|
@@ -47,7 +47,7 @@ module.exports = async function(program,folder) {
|
|
47
47
|
}
|
48
48
|
middleValue.chat.ts = Date.now();
|
49
49
|
middleValue.chat.uuid = program.uuid.v4();
|
50
|
-
let user = await program.modules.data.findOrCreate(
|
50
|
+
let user = await program.modules.data.findOrCreate(process.env.dbName,`telegram`,{
|
51
51
|
id : middleValue.from.id
|
52
52
|
},middleValue.chat);
|
53
53
|
let typeOFF = typeof user;
|
@@ -71,7 +71,7 @@ module.exports = async function(program,folder) {
|
|
71
71
|
|
72
72
|
// Find or create to add message to db
|
73
73
|
body.uuid = program.uuid.v4();
|
74
|
-
let received = await program.modules.data.findOrCreate(
|
74
|
+
let received = await program.modules.data.findOrCreate(process.env.dbName,`received`,{
|
75
75
|
update_id : body.update_id
|
76
76
|
},body);
|
77
77
|
|
@@ -99,7 +99,7 @@ module.exports = async function(program,folder) {
|
|
99
99
|
const id = member.id;
|
100
100
|
console.log(`Something with member`);
|
101
101
|
|
102
|
-
const updated =await program.modules.data.update(
|
102
|
+
const updated =await program.modules.data.update(process.env.dbName,`telegram`,{
|
103
103
|
id : id
|
104
104
|
},{
|
105
105
|
$set: {
|
@@ -55,7 +55,7 @@ module.exports = async function(db,collection,query,one = false,array) {
|
|
55
55
|
|
56
56
|
// Check if profile image to get it from db
|
57
57
|
if (result.profileImage != undefined && array.image == true) {
|
58
|
-
const profileImage = await program.modules.data.file.downloadBuffer(result.profileImage
|
58
|
+
const profileImage = await program.modules.data.file.downloadBuffer(result.profileImage,process.env.dbName);
|
59
59
|
|
60
60
|
// Set in dynamic routing for serving
|
61
61
|
let sizeMeta = {};
|
package/modules/express/init.js
CHANGED
@@ -292,7 +292,7 @@ module.exports = async function (program) {
|
|
292
292
|
if (parsedQuery.user != undefined) {
|
293
293
|
// Get user
|
294
294
|
const userJSON = JSON.parse(JSON.parse(parsedQuery.user));
|
295
|
-
getUser = await program.modules.data.find(
|
295
|
+
getUser = await program.modules.data.find(process.env.dbName,`telegram`,{
|
296
296
|
id : userJSON.id
|
297
297
|
},true,{image:true,program,async function(program,json){
|
298
298
|
// Get firs timage
|