webfast 0.1.69 → 0.1.71

Sign up to get free protection for your applications and to get access to all the features.
@@ -125,34 +125,13 @@ web.fast.connectWebSocket = function(socketURL,maxRetries = 40, retries = 0) {
125
125
  console.log('WebSocket connected');
126
126
  // Start other things (e.g., send initial data)
127
127
  web.fast.que.state = true;
128
-
129
128
  //alert(web.fast.tools.isMobile);
130
- function arraySend() {
129
+ function arraySendFunction() {
131
130
  try {
132
- if (web.fast.user != undefined || window.Telegram.WebApp.initData == ``) {
131
+ if (web.fast.que.state == false || window.Telegram.WebApp.initData == ``) {
133
132
  let arraySend = [];
134
- jQuery(`[webfast-get]`).each(async function(){
135
- const type = jQuery(this).attr(`webfast-get`);
136
- let id = jQuery(this).attr(`id`);
137
- if (id == undefined) {
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
148
- }
149
- arraySend.push({
150
- id : id,
151
- type : type
152
- })
153
- })
154
- console.log(`Send Array`,arraySend);
155
- web.fast.tools.on.connect(arraySend);
133
+ //alert(`Connected`);
134
+
156
135
  } else {
157
136
  if (countedError < 3) {
158
137
  console.error(`Tried 10 times`);
@@ -163,13 +142,14 @@ web.fast.connectWebSocket = function(socketURL,maxRetries = 40, retries = 0) {
163
142
 
164
143
  }
165
144
  } catch (err) {
145
+ alert(`err`);
166
146
  setTimeout(function(){
167
- arraySend();
147
+ arraySendFunction();
168
148
  },200);
169
149
  }
170
150
  }
171
151
  // send array
172
- arraySend();
152
+ arraySendFunction();
173
153
 
174
154
  };
175
155
 
@@ -183,6 +163,7 @@ web.fast.connectWebSocket = function(socketURL,maxRetries = 40, retries = 0) {
183
163
  // We have user data
184
164
  console.log(`Set User Data`);
185
165
  web.fast.user = json;
166
+
186
167
  // Now go Through to set all data
187
168
  // Get all webfast client
188
169
  jQuery(`[webfast-client]`).each(function(){
@@ -224,6 +205,32 @@ web.fast.connectWebSocket = function(socketURL,maxRetries = 40, retries = 0) {
224
205
 
225
206
  web.fast.que.state = Date.now();
226
207
  web.fast.receive(`socket`,event.data); // Placeholder for processing response
208
+
209
+ let arraySend = [];
210
+ jQuery(`[webfast-get]`).each(async function(){
211
+ const type = jQuery(this).attr(`webfast-get`);
212
+ let id = jQuery(this).attr(`id`);
213
+ if (id == undefined) {
214
+ var generateRandomId = async function(length) {
215
+ var result = '';
216
+ var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
217
+ var charactersLength = characters.length;
218
+ for (var i = 0; i < length; i++) {
219
+ result += characters.charAt(Math.floor(Math.random() * charactersLength));
220
+ }
221
+ return result;
222
+ };
223
+ id = await generateRandomId(8); // Generate a random ID of length 8
224
+ }
225
+ arraySend.push({
226
+ id : id,
227
+ type : type
228
+ })
229
+ })
230
+ console.log(`Send Array`,arraySend);
231
+ web.fast.tools.on.connect(arraySend);
232
+ web.fast.que.state = true;
233
+
227
234
  } catch (err) {
228
235
  console.error(`Error Receiving`);
229
236
  console.error(event);
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`);
@@ -1,6 +1,6 @@
1
1
  const { MongoClient } = require('mongodb');
2
2
 
3
- module.exports = async function(db, collection, condition, dataToCreate) {
3
+ module.exports = async function(db, collection, condition, dataToCreate,options = {}) {
4
4
  // Ensure the MongoDB connection string is provided
5
5
  if (!process.env.mongo) {
6
6
  console.error('MongoDB connection string not provided. Set process.env.mongo.');
@@ -30,7 +30,7 @@ module.exports = async function(db, collection, condition, dataToCreate) {
30
30
  const collection = database.collection(collectionName);
31
31
 
32
32
  // Check if a document exists based on the condition
33
- const existingDocument = await collection.findOne(condition);
33
+ const existingDocument = await collection.findOne(condition,options);
34
34
 
35
35
  if (existingDocument) {
36
36
  // If a document exists, return it
@@ -43,7 +43,7 @@ module.exports = async function(db, collection, condition, dataToCreate) {
43
43
 
44
44
  if (result.acknowledged === true) {
45
45
  console.log('New document created:', result.insertedId);
46
- const existingDocument = await collection.findOne(condition);
46
+ const existingDocument = await collection.findOne(condition,options);
47
47
  return dataToCreate;
48
48
  } else {
49
49
  console.error('Failed to create a new document.');
@@ -1,6 +1,6 @@
1
1
  const { MongoClient } = require('mongodb');
2
2
 
3
- module.exports = async function (db, collection, condition, dataToUpdate) {
3
+ module.exports = async function (db, collection, condition, dataToUpdate,options = { upsert: true }) {
4
4
  // Ensure the MongoDB connection string is provided
5
5
  if (!process.env.mongo) {
6
6
  console.error('MongoDB connection string not provided. Set process.env.mongo.');
@@ -30,7 +30,7 @@ module.exports = async function (db, collection, condition, dataToUpdate) {
30
30
  const collection = database.collection(collectionName);
31
31
 
32
32
  // Perform the update or create operation
33
- const result = await collection.updateOne(condition, { $set: dataToUpdate }, { upsert: true });
33
+ const result = await collection.updateOne(condition, { $set: dataToUpdate }, options);
34
34
 
35
35
  // If a document was upserted, retrieve the upserted document
36
36
  const upsertedDocument = result.upsertedId
@@ -176,7 +176,7 @@ module.exports = async function (program) {
176
176
  // Now read the dir
177
177
  // Create app.get
178
178
  try {
179
- const theRoute = `/inc/${dirItem}/*`;
179
+ const theRoute = `git pu${dirItem}/*`;
180
180
  app.get(theRoute, async (req, res) => {
181
181
  const params = req.params;
182
182
 
@@ -1,10 +1,12 @@
1
- module.exports = async function(program, url, body) {
1
+ module.exports = async function(program, url, body,headers) {
2
2
  console.log(`Fetch Post`);
3
3
  // Register websocket url
4
4
  try {
5
- const headers = {
5
+ if (headers == undefined) {
6
+ headers = {
6
7
  accept: 'application/json',
7
8
  'content-type': 'application/json'
9
+ }
8
10
  };
9
11
 
10
12
  let theOptions = {
@@ -1,11 +1,13 @@
1
- module.exports = async function(program, url, body) {
1
+ module.exports = async function(program, url, body,headers) {
2
2
  console.log(`Fetch Post`);
3
3
  // Register websocket url
4
4
  try {
5
- const headers = {
6
- accept: 'application/json',
7
- 'content-type': 'application/json'
8
- };
5
+ if (headers == undefined) {
6
+ headers = {
7
+ accept: 'application/json',
8
+ 'content-type': 'application/json'
9
+ };
10
+ }
9
11
 
10
12
  let theOptions = {
11
13
  method: 'POST',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webfast",
3
- "version": "0.1.69",
3
+ "version": "0.1.71",
4
4
  "description": "WebFast! Bot Application, including TON mini-apps for makign it easy and fast to build ini-apps",
5
5
  "main": "index.js",
6
6
  "repository": {