webfast 0.0.2 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +1 -1
- package/ejs/example/link.ejs +25 -0
- package/index.js +93 -52
- package/modules/bots/applications/telegram/collect.js +3 -0
- package/modules/bots/applications/telegram/middleware/message/location.js +14 -0
- package/modules/bots/applications/telegram/middleware/message/start.js +10 -0
- package/modules/bots/applications/telegram/send.js +18 -0
- package/modules/bots/applications/telegram.js +275 -0
- package/modules/bots/init.js +37 -0
- package/modules/data/init.js +31 -0
- package/modules/data/mongo/find.js +50 -0
- package/modules/data/mongo/findOrCreate.js +62 -0
- package/modules/express/init.js +23 -3
- package/modules/express/routes/example/link.get.js +9 -2
- package/modules/generator/init.js +1 -1
- package/modules/request/functions/post.js +32 -0
- package/modules/request/init.js +32 -0
- package/package.json +3 -1
- package/.vscode/launch.json +0 -17
package/README.md
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html lang="en">
|
3
|
+
<head>
|
4
|
+
<meta charset="UTF-8">
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
+
<title><%= title %></title>
|
7
|
+
</head>
|
8
|
+
<body>
|
9
|
+
|
10
|
+
<h1>Hello, <%= name %>!</h1>
|
11
|
+
|
12
|
+
<% if (isAdmin) { %>
|
13
|
+
<p>Welcome, administrator!</p>
|
14
|
+
<% } else { %>
|
15
|
+
<p>You are not an administrator.</p>
|
16
|
+
<% } %>
|
17
|
+
|
18
|
+
<ul>
|
19
|
+
<% fruits.forEach(function(fruit) { %>
|
20
|
+
<li><%= fruit %></li>
|
21
|
+
<% }); %>
|
22
|
+
</ul>
|
23
|
+
|
24
|
+
</body>
|
25
|
+
</html>
|
package/index.js
CHANGED
@@ -10,13 +10,15 @@ let program = {
|
|
10
10
|
async function set(program) {
|
11
11
|
program.path = await require(`path`);
|
12
12
|
program.fs = await require(`fs`);
|
13
|
-
program.uuid =
|
13
|
+
program.uuid = require(`uuid`);
|
14
|
+
program.fetch = require(`fetch`);
|
14
15
|
return program;
|
15
16
|
}
|
16
17
|
|
17
18
|
// Program Fetch
|
18
19
|
program.modules.dependOn = async function(reqFunc,program,name,callback) {
|
19
20
|
console.log(`Depend On Check`);
|
21
|
+
|
20
22
|
// Loop Through dependOn if its not true then check
|
21
23
|
for (let dependIndex in reqFunc.dependOn) {
|
22
24
|
const dependOn = reqFunc.dependOn[dependIndex];
|
@@ -32,9 +34,16 @@ program.modules.dependOn = async function(reqFunc,program,name,callback) {
|
|
32
34
|
// Grab object
|
33
35
|
let toCheck = split[spl];
|
34
36
|
if (objectData[toCheck] == undefined) {
|
35
|
-
|
36
|
-
return
|
37
|
-
}
|
37
|
+
if (program.modules[name] != undefined) {
|
38
|
+
return;
|
39
|
+
} else {
|
40
|
+
program.modules[name] = {
|
41
|
+
ts : Date.now()
|
42
|
+
}
|
43
|
+
await setTimeout(async function(){
|
44
|
+
await program.modules.dependOn(reqFunc,program,name,callback);
|
45
|
+
},200);
|
46
|
+
}
|
38
47
|
} else {
|
39
48
|
// New object thing and og next
|
40
49
|
if (split.length-1 != spl) {
|
@@ -53,15 +62,44 @@ program.modules.dependOn = async function(reqFunc,program,name,callback) {
|
|
53
62
|
// We need to wait and try again untill we can return
|
54
63
|
console.log(`DependOn Fail: ${dependOn}`);
|
55
64
|
await setTimeout(async function(){
|
56
|
-
|
65
|
+
await program.modules.dependOn(reqFunc,program);
|
57
66
|
},200);
|
58
|
-
} else {
|
67
|
+
} else if (program.modules[reqFunc.name] == undefined) {
|
59
68
|
console.log(`DependOn Succes: ${dependOn}`);
|
69
|
+
|
70
|
+
// Loop Through to find where data to set
|
71
|
+
const splitLoop = String(`${fullObjectPath}.${dependOnItem}`).split(`.`);
|
72
|
+
let object;
|
73
|
+
for (let s in splitLoop) {
|
74
|
+
let key = splitLoop[s];
|
75
|
+
try {
|
76
|
+
if (object == undefined) {
|
77
|
+
object = eval(key);
|
78
|
+
} else {
|
79
|
+
object = object[key];
|
80
|
+
}
|
81
|
+
if (s == splitLoop-1) {
|
82
|
+
// It's end
|
83
|
+
object = {
|
84
|
+
depend : dependOn,
|
85
|
+
state : true,
|
86
|
+
ts : Date.now()
|
87
|
+
}
|
88
|
+
}
|
89
|
+
} catch (err) {
|
90
|
+
console.error(err);
|
91
|
+
console.error(`errror boject eval set`);
|
92
|
+
return setTimeout(async function(){
|
93
|
+
await program.modules.dependOn(reqFunc,program,name,callback);
|
94
|
+
},200);
|
95
|
+
}
|
96
|
+
}
|
97
|
+
/*
|
60
98
|
progData[dependOnItem] = {
|
61
99
|
depend : dependOn,
|
62
100
|
state : true,
|
63
101
|
ts : Date.now()
|
64
|
-
}
|
102
|
+
} */
|
65
103
|
|
66
104
|
// Now include this thing then
|
67
105
|
try {
|
@@ -121,7 +159,7 @@ program.modules.fetch = async function(folder,program) {
|
|
121
159
|
});
|
122
160
|
break;
|
123
161
|
case `function`:
|
124
|
-
program = await (require(initPath)(program));
|
162
|
+
program = await (require(initPath)(program,fileNameWithExtension));
|
125
163
|
break;
|
126
164
|
default:
|
127
165
|
console.error(`Error Missing typeOf item`);
|
@@ -135,67 +173,70 @@ program.modules.fetch = async function(folder,program) {
|
|
135
173
|
}
|
136
174
|
}
|
137
175
|
|
138
|
-
program.modules.walkDirectory = async function (directoryPath,callback,forward) {
|
139
|
-
|
140
|
-
|
176
|
+
program.modules.walkDirectory = async function (directoryPath, callback, forward) {
|
177
|
+
try {
|
178
|
+
// Read the contents of the current directory
|
179
|
+
const files = await program.fs.readdirSync(directoryPath);
|
141
180
|
|
142
|
-
|
143
|
-
|
144
|
-
|
181
|
+
let allFiles = [];
|
182
|
+
|
183
|
+
// Iterate through the files in the directory
|
184
|
+
for (let f in files) {
|
145
185
|
// Construct the full path of the current file or directory
|
146
186
|
let file = files[f];
|
147
187
|
const fullPath = await program.path.join(directoryPath, file);
|
148
|
-
|
188
|
+
|
149
189
|
// Check if the current item is a directory
|
150
190
|
const pathSync = await program.fs.statSync(fullPath);
|
151
191
|
const isDirectoryPath = await pathSync.isDirectory();
|
152
192
|
const fileExtension = await program.path.extname(fullPath);
|
153
|
-
|
193
|
+
|
154
194
|
// Get the filename without the extension
|
155
195
|
const fileName = await program.path.basename(fullPath, fileExtension);
|
196
|
+
|
156
197
|
if (isDirectoryPath) {
|
157
|
-
|
158
|
-
|
159
|
-
|
198
|
+
// If it's a directory, recursively walk through it
|
199
|
+
let pushData = await program.modules.walkDirectory(fullPath, callback, fileName);
|
200
|
+
if (pushData.length !== 0) {
|
201
|
+
allFiles = allFiles.concat(pushData); // Concatenate arrays instead of pushing an array
|
202
|
+
}
|
160
203
|
} else {
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
} else {
|
180
|
-
|
181
|
-
await allFiles.push(fileData);
|
182
|
-
}
|
204
|
+
// If it's a file, print the path
|
205
|
+
console.log('File Extension:', fileExtension);
|
206
|
+
console.log('File Name:', fileName);
|
207
|
+
|
208
|
+
// Make Key from fileName extension
|
209
|
+
const fileData = {
|
210
|
+
extension: fileExtension,
|
211
|
+
name: fileName,
|
212
|
+
path: fullPath,
|
213
|
+
sub: [],
|
214
|
+
};
|
215
|
+
|
216
|
+
if (forward !== undefined) {
|
217
|
+
// Push it to sub
|
218
|
+
fileData.sub.push(forward);
|
219
|
+
} else {
|
220
|
+
allFiles.push(fileData);
|
221
|
+
}
|
183
222
|
}
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
if (forward != undefined) {
|
223
|
+
}
|
224
|
+
|
225
|
+
if (forward !== undefined) {
|
189
226
|
// Return data
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
227
|
+
return allFiles;
|
228
|
+
}
|
229
|
+
|
230
|
+
if (callback && forward === undefined) {
|
194
231
|
await callback(allFiles);
|
195
|
-
|
232
|
+
} else {
|
196
233
|
return allFiles;
|
234
|
+
}
|
235
|
+
} catch (error) {
|
236
|
+
console.error('Error:', error.message);
|
197
237
|
}
|
198
|
-
}
|
238
|
+
};
|
239
|
+
|
199
240
|
|
200
241
|
|
201
242
|
// Run program fetch
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module.exports = async function(req,res,body,params,command,middleValue) {
|
2
|
+
console.log(`Location Telegram Function`);
|
3
|
+
// We have the start function
|
4
|
+
let locSendMessage = `No Location Service Functions yet`;
|
5
|
+
if (middleValue.location != undefined) {
|
6
|
+
locSendMessage = `Thank you for sending your location\n ${middleValue.location.longitude}\n${middleValue.location.latitude}`;
|
7
|
+
}
|
8
|
+
return {
|
9
|
+
message : locSendMessage,
|
10
|
+
response : {
|
11
|
+
message : locSendMessage
|
12
|
+
}
|
13
|
+
}
|
14
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module.exports = async function(program,message,id) {
|
2
|
+
console.log(`Telegram Send`);
|
3
|
+
// Create Request for send
|
4
|
+
const telegramURL = `https://api.telegram.org/bot${process.env.telegram}/sendMessage`;
|
5
|
+
|
6
|
+
const body = {
|
7
|
+
text: message,
|
8
|
+
disable_web_page_preview: false,
|
9
|
+
disable_notification: false,
|
10
|
+
reply_to_message_id: null,
|
11
|
+
chat_id : id,
|
12
|
+
parse_mode : 'HTML'
|
13
|
+
}
|
14
|
+
|
15
|
+
const madeRequest = await program.modules.request.post(program,telegramURL,body)
|
16
|
+
console.log(`Send Message`);
|
17
|
+
return madeRequest;
|
18
|
+
}
|
@@ -0,0 +1,275 @@
|
|
1
|
+
module.exports = async function(program,folder) {
|
2
|
+
console.log(`telegram application`);
|
3
|
+
const token = process.env.telegram;
|
4
|
+
|
5
|
+
// Create Adaptive URL
|
6
|
+
const adaptiveURL = `/api/${program.uuid.v4()}/telegram/hook`;
|
7
|
+
|
8
|
+
// Create request
|
9
|
+
const webhookURL = `${process.env.url}${adaptiveURL.slice(1)}`;
|
10
|
+
|
11
|
+
const telegramURL = `https://api.telegram.org/bot${token}/setWebhook`;
|
12
|
+
|
13
|
+
try {
|
14
|
+
const madeRequest = await program.modules.request.post(program,telegramURL,{
|
15
|
+
url : webhookURL
|
16
|
+
})
|
17
|
+
|
18
|
+
console.log(`Setup Telegram`,madeRequest);
|
19
|
+
|
20
|
+
// Set adaptive url get
|
21
|
+
program.express.url.set(adaptiveURL,`get`,async function(req,res,body,params){
|
22
|
+
console.log(`We have adaptive url get`);
|
23
|
+
res.send(`OK | GET`);
|
24
|
+
return true;
|
25
|
+
})
|
26
|
+
|
27
|
+
// Set adaptive url post
|
28
|
+
program.express.url.set(adaptiveURL,`post`,async function(req,res,body,params){
|
29
|
+
console.log(`We have adaptive url post`);
|
30
|
+
// set in collection telegram
|
31
|
+
// Process
|
32
|
+
let updateID;
|
33
|
+
|
34
|
+
for (let key in body) {
|
35
|
+
// Get Keys
|
36
|
+
if (key == `update_id`) {
|
37
|
+
updateID = body[key];
|
38
|
+
} else {
|
39
|
+
// /Try to find if this middleware is there
|
40
|
+
try {
|
41
|
+
// Try To Load it
|
42
|
+
let middleValue = body[key];
|
43
|
+
// Check for split
|
44
|
+
// Try for message
|
45
|
+
middleValue.chat.ts = Date.now();
|
46
|
+
middleValue.chat.uuid = program.uuid.v4();
|
47
|
+
let user = await program.modules.data.findOrCreate(`eventgo`,`telegram`,{
|
48
|
+
id : middleValue.chat.id
|
49
|
+
},middleValue.chat);
|
50
|
+
let typeOFF = typeof user;
|
51
|
+
if (middleValue.chat.uuid == user.uuid) {
|
52
|
+
user.new = true;
|
53
|
+
}
|
54
|
+
|
55
|
+
middleValue.chat.uuid = user.uuid;
|
56
|
+
try {
|
57
|
+
if (middleValue.text.startsWith('/')) {
|
58
|
+
// If it starts with a slash, it might be a command
|
59
|
+
const parts = middleValue.text.split(' ');
|
60
|
+
|
61
|
+
// The first part (index 0) will be the command, and the rest are potential variables
|
62
|
+
const command = parts[0].slice(1);
|
63
|
+
const variables = parts.slice(1)[0];
|
64
|
+
|
65
|
+
console.log('Command:', command);
|
66
|
+
console.log('Variables:', variables);
|
67
|
+
// Define a regular expression pattern to match the different parts
|
68
|
+
const regexPattern = /^([a-z]+)-([0-9a-f\-]+)-([a-z]+)$/;
|
69
|
+
|
70
|
+
// Use the regular expression to match the parts
|
71
|
+
let match;
|
72
|
+
if (variables != undefined) {
|
73
|
+
match = variables.match(regexPattern);
|
74
|
+
}
|
75
|
+
|
76
|
+
if (match) {
|
77
|
+
// Extract the parts
|
78
|
+
const action = match[3];
|
79
|
+
const uuid = match[2];
|
80
|
+
const subFunction = match[1];
|
81
|
+
|
82
|
+
console.log('Action:', action);
|
83
|
+
console.log('UUID:', uuid);
|
84
|
+
console.log('Sub-Function:', subFunction);
|
85
|
+
|
86
|
+
// It's something to do check if we can find this in applications
|
87
|
+
|
88
|
+
|
89
|
+
} else {
|
90
|
+
console.log('String does not match the expected pattern.');
|
91
|
+
// So run the function
|
92
|
+
try {
|
93
|
+
// Run dynamic the type of middleware
|
94
|
+
const runFunc = await program.modules.telegram.middleware[key][command](req,res,body,params,command,middleValue);
|
95
|
+
const respFunc = runFunc.response;
|
96
|
+
// PRocess response for object
|
97
|
+
const action = Object.keys(respFunc)[0];
|
98
|
+
|
99
|
+
// switch action
|
100
|
+
switch (action) {
|
101
|
+
case `message`:
|
102
|
+
console.log(`We have response, check for response message`);
|
103
|
+
const message = respFunc[action];
|
104
|
+
await program.modules.telegram.functions.send(program,message,middleValue.chat.id);
|
105
|
+
break;
|
106
|
+
default:
|
107
|
+
console.error(`Missing Response Action Telegram: ${action}`);
|
108
|
+
}
|
109
|
+
} catch (err) {
|
110
|
+
//console.error(err);
|
111
|
+
//console.error(`Error For Telegram Function`);
|
112
|
+
await program.modules.telegram.functions.send(program,`Unknown Command: ${command}`,middleValue.chat.id);
|
113
|
+
}
|
114
|
+
}
|
115
|
+
|
116
|
+
// Now you can handle the command and its associated variables as needed
|
117
|
+
res.send(`OK | ${command} | ${variables}`)
|
118
|
+
res.status(200);
|
119
|
+
} else {
|
120
|
+
// If it doesn't start with a slash, it might be something else
|
121
|
+
//console.error('Not a command:', middleValue);
|
122
|
+
|
123
|
+
// TODO Catch events for middleware now just respond
|
124
|
+
const message = `${middleValue.text}`;
|
125
|
+
const command = message;
|
126
|
+
try {
|
127
|
+
// Run dynamic the type of middleware
|
128
|
+
const runFunc = await program.modules.telegram.middleware[key][command](req,res,body,params,command,middleValue);
|
129
|
+
const respFunc = runFunc.response;
|
130
|
+
// PRocess response for object
|
131
|
+
const action = Object.keys(respFunc)[0];
|
132
|
+
|
133
|
+
// switch action
|
134
|
+
switch (action) {
|
135
|
+
case `message`:
|
136
|
+
console.log(`We have response, check for response message`);
|
137
|
+
const message = respFunc[action];
|
138
|
+
await program.modules.telegram.functions.send(program,message,middleValue.chat.id);
|
139
|
+
break;
|
140
|
+
default:
|
141
|
+
console.error(`Missing Response Action Telegram: ${action}`);
|
142
|
+
}
|
143
|
+
} catch (err) {
|
144
|
+
//console.error(err);
|
145
|
+
//console.error(`Error For Telegram Function`);
|
146
|
+
await program.modules.telegram.functions.send(program,`${command}`,middleValue.chat.id);
|
147
|
+
}
|
148
|
+
|
149
|
+
|
150
|
+
res.send(`OK`);
|
151
|
+
res.status(200);
|
152
|
+
}
|
153
|
+
} catch (message) {
|
154
|
+
// Process as other
|
155
|
+
res.send(`OK | ${command} | ${variables}`)
|
156
|
+
res.status(200);
|
157
|
+
console.log(`Process Different`);
|
158
|
+
let checkArray = [`location`];
|
159
|
+
// Loop through checkArray
|
160
|
+
for (let c in checkArray) {
|
161
|
+
const command = checkArray[c];
|
162
|
+
const indexCheck = Object.keys(middleValue).indexOf(command);
|
163
|
+
if (indexCheck != -1) {
|
164
|
+
console.log(`Run this as middleware`);
|
165
|
+
try {
|
166
|
+
const runFunc = await program.modules.telegram.middleware[key][command](req,res,body,params,command,middleValue);
|
167
|
+
const respFunc = runFunc;
|
168
|
+
// PRocess response for object
|
169
|
+
if (respFunc == undefined) {
|
170
|
+
continue;
|
171
|
+
}
|
172
|
+
let action = Object.keys(respFunc)[0];
|
173
|
+
|
174
|
+
console.log(`The Action`);
|
175
|
+
switch (action) {
|
176
|
+
case `message`:
|
177
|
+
console.log(`We have response, check for response message`);
|
178
|
+
const message = respFunc[action];
|
179
|
+
await program.modules.telegram.functions.send(program,message,middleValue.chat.id);
|
180
|
+
break;
|
181
|
+
default:
|
182
|
+
console.error(`Missing Response Action Telegram: ${action}`);
|
183
|
+
}
|
184
|
+
} catch (err) {
|
185
|
+
console.error(err);
|
186
|
+
console.error(`Missing Function For Middleware`,middleware);
|
187
|
+
|
188
|
+
// Send error
|
189
|
+
res.send(`ERROR-2395343`);
|
190
|
+
res.status(500);
|
191
|
+
}
|
192
|
+
}
|
193
|
+
}
|
194
|
+
}
|
195
|
+
} catch (err) {
|
196
|
+
console.error(err);
|
197
|
+
console.error(`Error with loading message`);
|
198
|
+
res.status(`ERROR-235235`);
|
199
|
+
res.status(500);
|
200
|
+
}
|
201
|
+
}
|
202
|
+
}
|
203
|
+
/*
|
204
|
+
|
205
|
+
res.send(`OK | POST`);
|
206
|
+
return;
|
207
|
+
*/
|
208
|
+
});
|
209
|
+
|
210
|
+
} catch(err) {
|
211
|
+
console.error(err);
|
212
|
+
console.error(`Error Setting URL`);
|
213
|
+
}
|
214
|
+
|
215
|
+
const teleData = program.path.join(__dirname,`telegram`);
|
216
|
+
let moduleData = await program.modules.walkDirectory(teleData);
|
217
|
+
// Loop Through
|
218
|
+
let telegram = {
|
219
|
+
functions : {}
|
220
|
+
};
|
221
|
+
for (let index in moduleData) {
|
222
|
+
// Lets go
|
223
|
+
let module = moduleData[index];
|
224
|
+
let key = module.name;
|
225
|
+
|
226
|
+
// Try to load it
|
227
|
+
try {
|
228
|
+
telegram.functions[key] = require(module.path);
|
229
|
+
console.log(`Having The Module`,module);
|
230
|
+
} catch (err) {
|
231
|
+
console.error(err);
|
232
|
+
console.error(`Error Setting Up Telegram Module`);
|
233
|
+
}
|
234
|
+
}
|
235
|
+
|
236
|
+
let middleWareFolder = program.path.join(__dirname,`telegram`,`middleware`);
|
237
|
+
console.log(`MiddleWare:`,middleWareFolder);
|
238
|
+
|
239
|
+
let middleWareData = program.fs.readdirSync(middleWareFolder);
|
240
|
+
|
241
|
+
// Loop Through Middleware
|
242
|
+
let middleWarFuncs = {};
|
243
|
+
for (let mi in middleWareData) {
|
244
|
+
// Then loop through middlewarefolder for types
|
245
|
+
const middleWareName = middleWareData[mi];
|
246
|
+
let middleWareLoopFolder = program.path.join(middleWareFolder,middleWareName)
|
247
|
+
try {
|
248
|
+
let middleWareDataFolderLoop = program.fs.readdirSync(middleWareLoopFolder);
|
249
|
+
middleWarFuncs[middleWareName] = {};
|
250
|
+
for (let miN in middleWareDataFolderLoop) {
|
251
|
+
// Then loop through middlewarefolder for types
|
252
|
+
const fileName = middleWareDataFolderLoop[miN];
|
253
|
+
let middleWareLoopFolderSub = program.path.join(middleWareLoopFolder,fileName);
|
254
|
+
try {
|
255
|
+
const requireFunc = require(middleWareLoopFolderSub);
|
256
|
+
middleWarFuncs[middleWareName][fileName.split(`.`)[0]] = requireFunc;
|
257
|
+
console.log(`Setted Middleware`);
|
258
|
+
} catch (err) {
|
259
|
+
console.error(err);
|
260
|
+
console.error(`Error Looping Message`);
|
261
|
+
}
|
262
|
+
|
263
|
+
}
|
264
|
+
} catch (err) {
|
265
|
+
console.error(err);
|
266
|
+
console.error(`Error Middle ware Telegram`);
|
267
|
+
}
|
268
|
+
}
|
269
|
+
|
270
|
+
// Add middleware
|
271
|
+
telegram.middleware = middleWarFuncs;
|
272
|
+
|
273
|
+
program.modules.telegram = telegram;
|
274
|
+
return program;
|
275
|
+
}
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module.exports = {
|
2
|
+
dependOn : [`express.app`],
|
3
|
+
name : 'bot',
|
4
|
+
run : async function(program,name) {
|
5
|
+
console.log(`Running ${name}`);
|
6
|
+
// Scan bots folder and exclude
|
7
|
+
const routesPath = program.path.join(__dirname,`applications`);
|
8
|
+
let moduleData = await program.modules.walkDirectory(routesPath);
|
9
|
+
|
10
|
+
// We have the folder loop through
|
11
|
+
// Set Module
|
12
|
+
let setModule = {
|
13
|
+
ts : Date.now()
|
14
|
+
}
|
15
|
+
|
16
|
+
// loop Throuh module data
|
17
|
+
for (let moduleIndex in moduleData) {
|
18
|
+
// Get the module
|
19
|
+
let module = moduleData[moduleIndex];
|
20
|
+
// Create module in setModule
|
21
|
+
try {
|
22
|
+
// We have set module
|
23
|
+
const runModule = await require(module.path)(program,module);
|
24
|
+
setModule[module.name] = runModule;
|
25
|
+
} catch (err) {
|
26
|
+
console.error(err);
|
27
|
+
console.error(`Error Setting Module Data`,module.name);
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
// Put in program modules
|
32
|
+
program.modules[this.name] = setModule;
|
33
|
+
|
34
|
+
// Here we can do whatever like grab modules for generator and represent them here
|
35
|
+
return program;
|
36
|
+
}
|
37
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module.exports = async function (program,name){
|
2
|
+
console.log(`Running ${name}`);
|
3
|
+
|
4
|
+
// Lets make a mockup
|
5
|
+
const routesPath = program.path.join(__dirname,`mongo`);
|
6
|
+
let moduleData = await program.modules.walkDirectory(routesPath);
|
7
|
+
|
8
|
+
// Set Module
|
9
|
+
let setModule = {
|
10
|
+
ts : Date.now()
|
11
|
+
}
|
12
|
+
|
13
|
+
// loop Throuh module data
|
14
|
+
for (let moduleIndex in moduleData) {
|
15
|
+
// Get the module
|
16
|
+
let module = moduleData[moduleIndex];
|
17
|
+
// Create module in setModule
|
18
|
+
try {
|
19
|
+
// We have set module
|
20
|
+
setModule[module.name] = require(module.path);
|
21
|
+
} catch (err) {
|
22
|
+
console.error(`Error Setting Module Data`,module.name);
|
23
|
+
}
|
24
|
+
}
|
25
|
+
|
26
|
+
// Put in program modules
|
27
|
+
program.modules[name] = setModule;
|
28
|
+
|
29
|
+
// Here we can do whatever like grab modules for generator and represent them here
|
30
|
+
return program;
|
31
|
+
}
|
@@ -0,0 +1,50 @@
|
|
1
|
+
const { MongoClient } = require('mongodb');
|
2
|
+
module.exports = function(db,collection) {
|
3
|
+
// Ensure the MongoDB connection string is provided
|
4
|
+
if (!process.env.mongo) {
|
5
|
+
console.error('MongoDB connection string not provided. Set process.env.mongo.');
|
6
|
+
process.exit(1);
|
7
|
+
}
|
8
|
+
|
9
|
+
// Define the MongoDB URI
|
10
|
+
const uri = process.env.mongo;
|
11
|
+
|
12
|
+
// Define the database and collection name
|
13
|
+
const dbName = db;
|
14
|
+
const collectionName = collection;
|
15
|
+
|
16
|
+
// Define the query you want to perform
|
17
|
+
const query = { /* Your query goes here */ };
|
18
|
+
|
19
|
+
async function main() {
|
20
|
+
// Create a new MongoClient
|
21
|
+
const client = new MongoClient(uri, { useNewUrlParser: true, useUnifiedTopology: true });
|
22
|
+
|
23
|
+
try {
|
24
|
+
// Connect to the MongoDB server
|
25
|
+
await client.connect();
|
26
|
+
console.log('Connected to the MongoDB server');
|
27
|
+
|
28
|
+
// Select the database
|
29
|
+
const database = client.db(dbName);
|
30
|
+
|
31
|
+
// Select the collection
|
32
|
+
const collection = database.collection(collectionName);
|
33
|
+
|
34
|
+
// Perform the find query
|
35
|
+
const result = await collection.find(query).toArray();
|
36
|
+
|
37
|
+
// Process the result
|
38
|
+
console.log('Query result:', result);
|
39
|
+
|
40
|
+
} finally {
|
41
|
+
// Close the MongoClient
|
42
|
+
await client.close();
|
43
|
+
console.log('Connection closed.');
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
47
|
+
// Execute the main function
|
48
|
+
main().catch(console.error);
|
49
|
+
|
50
|
+
}
|
@@ -0,0 +1,62 @@
|
|
1
|
+
const { MongoClient } = require('mongodb');
|
2
|
+
|
3
|
+
module.exports = async function(db, collection, condition, dataToCreate) {
|
4
|
+
// Ensure the MongoDB connection string is provided
|
5
|
+
if (!process.env.mongo) {
|
6
|
+
console.error('MongoDB connection string not provided. Set process.env.mongo.');
|
7
|
+
process.exit(1);
|
8
|
+
}
|
9
|
+
|
10
|
+
// Define the MongoDB URI
|
11
|
+
const uri = process.env.mongo;
|
12
|
+
|
13
|
+
// Define the database and collection name
|
14
|
+
const dbName = db;
|
15
|
+
const collectionName = collection;
|
16
|
+
|
17
|
+
async function main() {
|
18
|
+
// Create a new MongoClient
|
19
|
+
const client = new MongoClient(uri);
|
20
|
+
|
21
|
+
try {
|
22
|
+
// Connect to the MongoDB server
|
23
|
+
await client.connect();
|
24
|
+
console.log('Connected to the MongoDB server');
|
25
|
+
|
26
|
+
// Select the database
|
27
|
+
const database = client.db(dbName);
|
28
|
+
|
29
|
+
// Select the collection
|
30
|
+
const collection = database.collection(collectionName);
|
31
|
+
|
32
|
+
// Check if a document exists based on the condition
|
33
|
+
const existingDocument = await collection.findOne(condition);
|
34
|
+
|
35
|
+
if (existingDocument) {
|
36
|
+
// If a document exists, return it
|
37
|
+
console.log('Document found:', existingDocument);
|
38
|
+
return existingDocument;
|
39
|
+
} else {
|
40
|
+
// If no document exists, create a new one
|
41
|
+
console.log('Document not found. Creating a new one.');
|
42
|
+
const result = await collection.insertOne(dataToCreate);
|
43
|
+
|
44
|
+
if (result.acknowledged === true) {
|
45
|
+
console.log('New document created:', result.insertedId);
|
46
|
+
const existingDocument = await collection.findOne(condition);
|
47
|
+
return existingDocument;
|
48
|
+
} else {
|
49
|
+
console.error('Failed to create a new document.');
|
50
|
+
return null;
|
51
|
+
}
|
52
|
+
}
|
53
|
+
} finally {
|
54
|
+
// Close the MongoClient
|
55
|
+
await client.close();
|
56
|
+
console.log('Connection closed.');
|
57
|
+
}
|
58
|
+
}
|
59
|
+
|
60
|
+
// Execute the main function
|
61
|
+
return main().catch(console.error);
|
62
|
+
};
|
package/modules/express/init.js
CHANGED
@@ -127,11 +127,31 @@ module.exports = async function(program) {
|
|
127
127
|
console.error(`Error Routes`);
|
128
128
|
}
|
129
129
|
|
130
|
-
|
130
|
+
program.express.app = app;
|
131
131
|
app.listen(port, () => {
|
132
132
|
console.log(`Server Listening`,port,basePath);
|
133
133
|
});
|
134
|
-
|
135
|
-
|
134
|
+
|
135
|
+
// For creating adaptive url
|
136
|
+
program.express.url = {
|
137
|
+
adaptive : {
|
138
|
+
get : [],
|
139
|
+
post : []
|
140
|
+
},
|
141
|
+
set : function(requestPath,actionType,callback) {
|
142
|
+
// Callback is for when we run through adpative url
|
143
|
+
|
144
|
+
program.express.url.adaptive[actionType] = app[actionType](requestPath,async (req,res) => {
|
145
|
+
// Process body
|
146
|
+
let run = await callback(req,res,req.body,req.params);
|
147
|
+
|
148
|
+
return run;
|
149
|
+
});
|
150
|
+
return true;
|
151
|
+
}
|
152
|
+
}
|
153
|
+
|
154
|
+
program.express.setted = true;
|
155
|
+
|
136
156
|
return program;
|
137
157
|
}
|
@@ -1,5 +1,12 @@
|
|
1
1
|
module.exports = async function(program,req,res,route) {
|
2
2
|
console.log(`Create`);
|
3
|
-
|
4
|
-
|
3
|
+
const fullPath = program.path.join(__dirname, `..`,`..`,`..`,`..`,`ejs`,`example`,`link.ejs`);
|
4
|
+
|
5
|
+
// Render the EJS template
|
6
|
+
res.render(fullPath, {
|
7
|
+
title: 'EJS Example',
|
8
|
+
name: 'John Doe',
|
9
|
+
isAdmin: true,
|
10
|
+
fruits: ['Apple', 'Banana', 'Orange']
|
11
|
+
});
|
5
12
|
}
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module.exports = async function(program, url, body) {
|
2
|
+
console.log(`Fetch Post`);
|
3
|
+
// Register websocket url
|
4
|
+
try {
|
5
|
+
const headers = {
|
6
|
+
accept: 'application/json',
|
7
|
+
'content-type': 'application/json'
|
8
|
+
};
|
9
|
+
|
10
|
+
let theOptions = {
|
11
|
+
method: 'POST',
|
12
|
+
headers: headers,
|
13
|
+
body: JSON.stringify(body),
|
14
|
+
};
|
15
|
+
|
16
|
+
// Using standard fetch function
|
17
|
+
const response = await fetch(url, theOptions);
|
18
|
+
|
19
|
+
if (!response.ok) {
|
20
|
+
throw new Error(`HTTP error! Status: ${response.status}`);
|
21
|
+
}
|
22
|
+
|
23
|
+
const responseData = await response.json();
|
24
|
+
console.log('Response Data:', responseData);
|
25
|
+
|
26
|
+
// Return response data or true to indicate success
|
27
|
+
return responseData || true;
|
28
|
+
} catch (err) {
|
29
|
+
console.error('Error in post:', err.message);
|
30
|
+
return false;
|
31
|
+
}
|
32
|
+
};
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module.exports = async function(program,name) {
|
2
|
+
console.log(`Running ${name}`);
|
3
|
+
|
4
|
+
// Lets make a mockup
|
5
|
+
const routesPath = program.path.join(__dirname,`functions`);
|
6
|
+
let moduleData = await program.modules.walkDirectory(routesPath);
|
7
|
+
|
8
|
+
// Set Module
|
9
|
+
let setModule = {
|
10
|
+
ts : Date.now()
|
11
|
+
}
|
12
|
+
|
13
|
+
// loop Throuh module data
|
14
|
+
for (let moduleIndex in moduleData) {
|
15
|
+
// Get the module
|
16
|
+
let module = moduleData[moduleIndex];
|
17
|
+
// Create module in setModule
|
18
|
+
try {
|
19
|
+
// We have set module
|
20
|
+
setModule[module.name] = require(module.path);
|
21
|
+
} catch (err) {
|
22
|
+
console.error(`Error Setting Module Data`,module.name);
|
23
|
+
console.error(err);
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
// Put in program modules
|
28
|
+
program.modules.request = setModule;
|
29
|
+
|
30
|
+
// Here we can do whatever like grab modules for generator and represent them here
|
31
|
+
return program;
|
32
|
+
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "webfast",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.8",
|
4
4
|
"description": "WebFast!! Bot Application, including TON mini-apps",
|
5
5
|
"main": "index.js",
|
6
6
|
"repository": {
|
@@ -28,6 +28,8 @@
|
|
28
28
|
"fetch": "^1.1.0",
|
29
29
|
"fs": "^0.0.1-security",
|
30
30
|
"js": "^0.1.0",
|
31
|
+
"mongodb": "^6.3.0",
|
32
|
+
"node-fetch": "^3.3.2",
|
31
33
|
"path": "^0.12.7",
|
32
34
|
"uuid": "^9.0.1"
|
33
35
|
}
|
package/.vscode/launch.json
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
{
|
2
|
-
// Use IntelliSense to learn about possible attributes.
|
3
|
-
// Hover to view descriptions of existing attributes.
|
4
|
-
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
5
|
-
"version": "0.2.0",
|
6
|
-
"configurations": [
|
7
|
-
{
|
8
|
-
"type": "node",
|
9
|
-
"request": "launch",
|
10
|
-
"name": "Launch Program",
|
11
|
-
"skipFiles": [
|
12
|
-
"<node_internals>/**"
|
13
|
-
],
|
14
|
-
"program": "${workspaceFolder}/index.js"
|
15
|
-
}
|
16
|
-
]
|
17
|
-
}
|