forked from bill-ahmed/qbit-matUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
116 lines (100 loc) · 3.12 KB
/
index.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
var express = require('express');
var path = require('path')
var bodyParser = require('body-parser');
var cors = require('cors');
var cookieParser = require('cookie-parser')
var multer = require('multer');
var GetMainData = require('./sample_data').GetMainData;
var GetUserPreferences = require('./sample_data').GetUserPreferences;
var GetAppVersion = require('./sample_data').GetAppVersion;
var GetAPIVersion = require('./sample_data').GetAPIVersion;
var GetRandomInt = require('./utils.js').GetRandomInt;
var upload = multer();
var app = express();
const PORT = process.env.PORT || 4300;
const CREDS = require('./config.json');
app.use(cors());
app.use(cookieParser());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
// For parsing multipart/form-data
app.use(upload.array());
app.use('/', express.static(path.join(__dirname, 'public')));
app.post('/api/v2/auth/login', function (req, res, next) {
var user = req.body.username;
var pass = req.body.password;
if(user === CREDS.login.username && pass === CREDS.login.password){
res.cookie('SID', '8c212779b4abde7A');
res.send("Ok.");
} else {
res.send("Fail.");
}
next();
});
app.get('/', function(req, res) {
res.render('public/index');
});
app.get('/api/v2/sync/maindata', function(req, res) {
let response = GetMainData();
res.json(response);
});
const torrent_priorities = [0, 1, 6, 7];
app.post('/api/v2/torrents/files', function(req, res) {
let response = [{
name: "Ubuntu LTS 18.04/something.iso",
/** File size (bytes) */
size: GetRandomInt(0, 900000000000),
progress: Math.random(),
priority: torrent_priorities[GetRandomInt(0, torrent_priorities.length)],
is_seed: true,
piece_range: [],
availability: Math.random(),
index: 0,
},
{
name: "Ubuntu LTS 20.20/another.iso",
/** File size (bytes) */
size: GetRandomInt(0, 900000000000),
progress: Math.random(),
priority: torrent_priorities[GetRandomInt(0, torrent_priorities.length)],
is_seed: false,
piece_range: [],
availability: Math.random(),
index: 1
},
{
name: "Ubuntu LTS 20.20/folder1/new.iso",
/** File size (bytes) */
size: GetRandomInt(0, 900000000000),
progress: Math.random(),
priority: 7,//torrent_priorities[GetRandomInt(0, torrent_priorities.length)],
is_seed: false,
piece_range: [],
availability: Math.random(),
index: 2
}
];
res.json(response);
});
app.get('/api/v2/app/preferences', function(req, res) {
let response = GetUserPreferences();
res.json(response);
});
app.get('/api/v2/app/version', function(req, res) {
let response = GetAppVersion();
res.send(response);
});
app.get('/api/v2/app/webapiVersion', function(req, res) {
let response = GetAPIVersion();
res.send(response);
});
/** KEEP THIS AT THE END!
* All un-set routes will go through here.
*/
app.use(function(req, res){
res.status(200).send();
});
app.listen(PORT, function () {
console.log(`Server listening on: http://localhost:${PORT}\n`);
console.log(`Username: ${CREDS.login.username}, Password: ${CREDS.login.password}`)
})