-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathapp.js
131 lines (117 loc) · 4.65 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
global.config = require('./config.js');
global.express = require('express');
global.app = express();
global.mongoose = require('mongoose');
global.Schema = mongoose.Schema;
global.moment = require('moment');
global.crypto = require('crypto');
global.colors = require('colors');
global.axios = require('axios');
global.cron = require('node-cron');
global.md5 = require('md5');
global.sha256 = require('sha256');
global.cookieParser = require('cookie-parser');
global.qs = require('qs');
global.fs = require('fs');
//////////////////////////// Multi Language ////////////////////////////
const { I18n } = require('i18n');
global.i18n = new I18n({
locales: fs.readdirSync(__dirname + '/languages').filter(x => x.endsWith('.json')).map(x => x.replace('.json', '')),
directory: __dirname + '/languages',
defaultLocale: 'tr',
cookie: 'lang',
autoReload: true,
mustacheConfig:
{
tags: ['{{', '}}'], // Örnek: {{__ 'Merhaba'}}
disable: false
}
});
app.use(cookieParser());
app.use(i18n.init);
//////////////////////////// DATABASE ////////////////////////////
global.mongoDB = mongoose.createConnection(config.mongoDB,
{
useNewUrlParser: true, useUnifiedTopology: true
}).addListener('connected', function () {
console.log('MongoDB baglantisi basarili.');
}).addListener('disconnected', function (err) {
console.log('MongoDB baglantisi kesildi.');
}).addListener('error', function (err) {
console.log('MongoDB baglantisi basarisiz.');
});
//////////////////////////// SCHEMA ////////////////////////////
global.ticketModel = require('./database/ticket.js');
global.notificationModel = require('./database/notification.js');
global.refillModel = require('./database/refill.js');
global.userModel = require('./database/user.js');
global.orderModel = require('./database/order.js');
global.payModel = require('./database/pay.js');
global.siteModel = require('./database/site.js');
global.serviceModel = require('./database/service.js');
global.platformModel = require('./database/platform.js');
global.categoryModel = require('./database/category.js');
global.analyticsModel = require('./database/sAnalytics.js');
global.childpanelModel = require('./database/childpanel.js');
global.siteData;
global.siteAdmins;
//////////////////////////// Functions ////////////////////////////
global.sendNotification = require('./plugins/sendNotification.js');
//////////////////////////// Load Plugins ////////////////////////////
const { glob } = require("glob");
const { promisify } = require("util");
global.globPromise = promisify(glob);
let plugins = [
"sendMail",
"fastexchange",
"bizimSms",
"netGsm",
"iletiMerkezi",
"fastCrypto",
"recaptcha",
"hcaptcha",
"payTR",
"sendNotification",
"speedAnalytics"
];
// PLUGINS Kısmı api dan çekilecek
(async () => {
siteData = await siteModel.findOne({});
let loaded_plugins = [];
const commandFiles = await globPromise(`${process.cwd()}/plugins/**/*.js`);
commandFiles.map((value) => {
const file = require(value);
if (!file.name) return;
if(!plugins.includes(file.name)) return console.log(`[Plugin] ${file.name} isimli plugin yuklenemedi. Eklenti'nin Yüklenmesi İçin Lütfen Sitemiz'den Satın Alın.`.red);
if (loaded_plugins.includes(file.name)) return console.log(`[Plugin] ${file.name} isimli plugin zaten yuklu.`.red);
console.log(`[Plugin] Yapımcı: ${file.author}, ${file.name}(${file.version}) yuklendi.`.green);
global[file.name] = file;
loaded_plugins.push(file.name);
});
console.log(`[Plugin] Toplam ${loaded_plugins.length} adet plugin yuklendi.`.green);
})();
//////////////////////////// ---- ////////////////////////////
(async () => {
let site = await siteModel.countDocuments();
if (site == 0) {
console.log(`[Site] Site verileri bulunamadı. Yeni site verileri oluşturuluyor.`.red);
new siteModel({}).save();
}
setTimeout(async () => {
siteData = await siteModel.findOne({});
sitePages = await siteData.site.pages;
siteAdmins = await userModel.find({ role: "admin" });
setInterval(async () => {
siteData = await siteModel.findOne({});
sitePages = await siteData.site.pages;
siteAdmins = await userModel.find({ role: "admin" });
//}, 60 * 1000 * 5);
}, 7000); // Test Modu Oldugu Icin 7 Saniyede Bir Cekiyor.
require('./routers/routes.js')(this);
}, 2000);
})();
//////////////////////////// ---- ////////////////////////////
require('./cron/jobs.js')(this);
app.listen(config.port, function () {
console.log(`SpeedSmm V3 Scripti ${config.port} portunda calisiyor.`);
});