Skip to content

Commit 2b13851

Browse files
committed
v1.0.4 Update
1 parent b45c160 commit 2b13851

5 files changed

Lines changed: 172 additions & 30 deletions

File tree

app.js

Lines changed: 87 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,24 @@ const port = 3000;
55
const path = require('path');
66
const request_lib = require('request');
77
const multer = require('multer');
8-
const storage = multer.diskStorage({
8+
storage = multer.diskStorage({
99
destination: function (req, file, cb) {
10-
cb(null, './uploads')
10+
cb(null, './servers/' + req.query["server"])
1111
},
1212
filename: function (req, file, cb) {
13-
cb(null, file.originalname)
13+
cb(null, req.query["type"])
1414
}
1515
})
16-
const upload = multer({
17-
storage: storage
16+
upload = multer({
17+
storage: storage,
18+
fileFilter: function (req, file, callback) {
19+
var ext = path.extname(file.originalname);
20+
if (ext !== '.png') {
21+
return callback('Only png allowed');
22+
}
23+
callback(null, true)
24+
}
1825
});
19-
2026
var spParser = require("minecraft-server-properties");
2127
const fs = require('fs');
2228
var colors = require('colors');
@@ -50,7 +56,7 @@ const fse = require('fs-extra');
5056
const {
5157
response
5258
} = require('express');
53-
const version = "v1.0.4";
59+
const version = "v1.0.5";
5460

5561
var customHeaderRequest = request_lib.defaults({
5662
headers: {
@@ -94,6 +100,58 @@ request_lib.get("https://api.github.com/repos/Seeroy/kubek-minecraft-dashboard/r
94100
if (firstStart == false) {
95101
app.use("/", express.static(path.join(__dirname, './www')));
96102

103+
app.get("/server/icon", function (req, res) {
104+
if (typeof (req.query.server) !== "undefined") {
105+
if (fs.existsSync("./servers/" + req.query.server + "/server-icon.png")) {
106+
res.sendFile("servers/" + req.query.server + "/server-icon.png", {
107+
root: "./"
108+
});
109+
} else {
110+
res.sendFile("www/assets/k.png", {
111+
root: "./"
112+
});
113+
}
114+
} else {
115+
res.sendFile("www/assets/k.png", {
116+
root: "./"
117+
});
118+
}
119+
});
120+
121+
app.get('/bukkitorg/plugins/search', function (request, response) {
122+
console.log(getTimeFormatted(), "GET", request.originalUrl.green);
123+
response.set('Content-Type', 'application/json');
124+
var jsons = [];
125+
var pg = "";
126+
customHeaderRequest.get("https://dev.bukkit.org/search?search=" + request.query.search, options, (error, res, body) => {
127+
if (error) {
128+
return console.error(error);
129+
}
130+
131+
if (!error && res.statusCode == 200) {
132+
const $ = cheerio.load(body);
133+
$(".results-name").each(function (i, plugin) {
134+
if (typeof (plugin.parent.parent.children[1].children[1].children[1]) !== "undefined") {
135+
var pluginn = {
136+
name: plugin.children[1].children[0].data,
137+
url: "https://dev.bukkit.org" + plugin.children[1].attribs.href,
138+
download_url: "https://dev.bukkit.org" + plugin.children[1].attribs.href + "/files/latest",
139+
image_url: plugin.parent.parent.children[1].children[1].children[1].attribs.src
140+
};
141+
} else {
142+
var pluginn = {
143+
name: plugin.children[1].children[0].data,
144+
url: "https://dev.bukkit.org" + plugin.children[1].attribs.href,
145+
download_url: "https://dev.bukkit.org" + plugin.children[1].attribs.href + "/files/latest"
146+
};
147+
}
148+
jsons.push(pluginn);
149+
});
150+
response.send(JSON.stringify(jsons));
151+
};
152+
});
153+
});
154+
97155
app.get('/bukkitorg/plugins/list', function (request, response) {
98156
console.log(getTimeFormatted(), "GET", request.originalUrl.green);
99157
response.set('Content-Type', 'application/json');
@@ -190,21 +248,29 @@ if (firstStart == false) {
190248
json: false
191249
};
192250
var jsonss = [];
193-
request_lib.get(request.query.url, optionss, (error, res, body) => {
251+
request_lib.get(request.query.url.replace('/files/latest', ''), optionss, (error, res, body) => {
194252
if (error) {
195253
return console.error(error);
196254
}
197255

198256
if (!error && res.statusCode == 200) {
199-
const $ = cheerio.load(body);
200-
$(".project-file-list-item .project-file-name").each(function (i, item) {
201-
var dnn = {
202-
name: item.children[1].children[3].children[1].attribs["data-name"],
203-
url: "https://dev.bukkit.org" + item.children[1].children[3].children[1].attribs.href + "/download"
257+
request_lib.get("https://dev.bukkit.org" + res.req.path + "/files", optionss, (error, res, body) => {
258+
if (error) {
259+
return console.error(error);
260+
}
261+
262+
if (!error && res.statusCode == 200) {
263+
const $ = cheerio.load(body);
264+
$(".project-file-list-item .project-file-name").each(function (i, item) {
265+
var dnn = {
266+
name: item.children[1].children[3].children[1].attribs["data-name"],
267+
url: "https://dev.bukkit.org" + item.children[1].children[3].children[1].attribs.href + "/download"
268+
};
269+
jsonss.push(dnn);
270+
});
271+
response.send(jsonss);
204272
};
205-
jsonss.push(dnn);
206273
});
207-
response.send(jsonss);
208274
};
209275
});
210276
});
@@ -587,7 +653,10 @@ app.get('/kubek/usage', (request, response) => {
587653
});
588654
});
589655

590-
app.post('/core/uploadOwn', upload.single('avatar'), (req, res) => {
591-
console.log(req.file, req.body);
592-
res.send("uploaded");
656+
app.post('/file/upload', upload.single('g-img-input'), (req, res) => {
657+
if(req.query["type"] == "server-icon" && fs.existsSync("./servers/" + req.query["server"])){
658+
res.send("uploaded");
659+
} else {
660+
res.send('false');
661+
}
593662
});

www/css/styles.css

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,25 +197,27 @@ body {
197197

198198
.lay2 .gcont {
199199
display: grid;
200-
grid-template-columns: max-content max-content max-content max-content;
200+
grid-template-columns: max-content max-content max-content max-content max-content;
201201
grid-template-rows: 1fr 1fr;
202202
gap: 0px 0px;
203203
grid-auto-flow: row;
204204
justify-items: start;
205205
align-items: center;
206206
grid-template-areas:
207-
"g-caption g-caption g-caption g-caption"
208-
"g-srvaddr g-srvplayers g-srvcore g-srvstatus";
207+
"g-img g-caption g-caption g-caption g-caption"
208+
"g-img g-srvaddr g-srvplayers g-srvcore g-srvstatus";
209209
width: max-content;
210210
height: max-content;
211211
}
212212

213213
.lay2 .gcont .g-caption {
214214
grid-area: g-caption;
215+
margin-left: 16px;
215216
}
216217

217218
.lay2 .gcont .g-srvaddr {
218219
grid-area: g-srvaddr;
220+
margin-left: 10px;
219221
}
220222

221223
.lay2 .gcont .g-srvplayers {
@@ -226,6 +228,10 @@ body {
226228
grid-area: g-srvcore;
227229
}
228230

231+
.lay2 .gcont .g-img {
232+
grid-area: g-img;
233+
}
234+
229235
.lay2 .gcont .g-srvstatus {
230236
grid-area: g-srvstatus;
231237
}

www/index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ <h5 class="modal-title" id="createServerModalLabel">Creating server</h5>
137137
<div class="hdr">
138138
<div class="hdr-left">
139139
<div class="gcont">
140+
<div class="g-img" style="cursor: pointer;" onclick="changeServerIcon()"><img alt="" height=64
141+
class="rounded"></div>
142+
<form id="g-img-form" enctype="multipart/form-data">
143+
<input name="g-img-input" id="g-img-input"
144+
style="position: absolute; left: -2582px; right: 0; top: 0; bottom: 0; z-index: -285;" type="file">
145+
</form>
140146
<div class="g-caption servername" style="font-size: 20pt; font-weight: 500;"></div>
141147
<div class="g-srvaddr">
142148
<div class="seamlessCont" style="color: rgb(140,140,140);">

www/js/app.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ $(document).ready(function () {
7373
currentServer = findGetParameter("server");
7474
cBar.animate(0.0);
7575
mBar.animate(0.0);
76+
$(".g-img img").attr("src", "/server/icon?server=" + currentServer);
7677
$(".kubekVersion").load("/kubek/version");
7778
$(".lay2 .tabs .tab").click(function () {
7879
$(".lay2 .tabs .selected").removeClass("selected");
@@ -150,6 +151,42 @@ function updateUsage() {
150151
});
151152
}
152153

154+
function changeServerIcon(){
155+
$("#g-img-input").trigger('click');
156+
$("#g-img-input").off("change");
157+
$("#g-img-input").change(function () {
158+
alert($(this).val());
159+
$("#g-type-input").val("server-icon");
160+
$("#g-server-input").val(currentServer);
161+
var formData = new FormData($("#g-img-form")[0]);
162+
console.log(formData);
163+
jQuery.ajax({
164+
url: '/file/upload?type=server-icon.png&server=' + currentServer,
165+
type: "POST",
166+
data: formData,
167+
success: function(data) {
168+
Swal.fire(
169+
'Success :)',
170+
'Restart server to see changes',
171+
'success'
172+
).then((result) => {
173+
window.location="";
174+
});
175+
},
176+
error: function(data) {
177+
Swal.fire(
178+
'Oops :(',
179+
'Error while upload. Try other .png files',
180+
'error'
181+
);
182+
},
183+
cache: false,
184+
contentType: false,
185+
processData: false,
186+
});
187+
});
188+
}
189+
153190
function getProgress(jarfile) {
154191
$.get("/tasks/progress", function (data) {
155192
if (typeof (old_rgr) === "undefined" || old_rgr != data) {

www/pages/plugins.html

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<button type="button" class="btn btn-primary btn-sm" onclick="loadPage('plmanager')">Plugin manager</button>
55
</div>
66
<div class="blck" style="height: 512px; overflow: auto;">
7+
<input type="text" class="form-control searchBar" placeholder="Search"><br>
78
<table class="ttt2"></table><br><br>
89
<div class="ggg" style="width: auto; justify-content: center;">
910
<div class="ggg-box">
@@ -51,26 +52,47 @@ <h5 class="modal-title" id="selectPluginModallLabel">Downloading file</h5>
5152
data.forEach(function (elem) {
5253
btnt = "";
5354
if (elem.showbtn == true) {
54-
btnt = '<button class="btn btn-light" style="color: black;" onclick="downloadPlugin(' + "'" + elem.name + "'" + ', ' + "'" + elem.download_url + "'" + ')" data-toggle="tooltip" data-placement="top" title="Download"><span class="material-icons material-icons-outlined">download</i></button>';
55+
btnt = '<button class="btn btn-light" style="color: black;" onclick="downloadPlugin(' + "'" + elem
56+
.name + "'" + ', ' + "'" + elem.download_url + "'" +
57+
')" data-toggle="tooltip" data-placement="top" title="Download"><span class="material-icons material-icons-outlined">download</i></button>';
5558
}
56-
$(".blck .ttt2").append('<tr><td><img alt="" src="' + elem.image_url + '"></td><td>' + elem.name + '</td><td>' + btnt + '</td></tr>');
59+
$(".blck .ttt2").append('<tr><td><img alt="" src="' + elem.image_url + '"></td><td>' + elem.name +
60+
'</td><td>' + btnt + '</td></tr>');
5761
});
5862
$(".loadBg").hide();
5963
});
6064
} else {
6165
$.get("/bukkitorg/plugins/list?page=" + page + "&server=" + currentServer, function (data) {
6266
data.forEach(function (elem) {
63-
btnt = "";
64-
if (elem.showbtn == true) {
65-
btnt = '<button class="btn btn-light" style="color: black;" onclick="downloadPlugin(' + "'" + elem.name + "'" + ', ' + "'" + elem.download_url + "'" + ')" data-toggle="tooltip" data-placement="top" title="Download"><span class="material-icons material-icons-outlined">download</i></button>';
66-
}
67-
$(".blck .ttt2").append('<tr><td><img alt="" src="' + elem.image_url + '"></td><td>' + elem.name + '</td><td>' + btnt + '</td></tr>');
67+
btnt = '<button class="btn btn-light" style="color: black;" onclick="downloadPlugin(' + "'" + elem
68+
.name + "'" + ', ' + "'" + elem.download_url + "'" +
69+
')" data-toggle="tooltip" data-placement="top" title="Download"><span class="material-icons material-icons-outlined">download</i></button>';
70+
$(".blck .ttt2").append('<tr><td><img alt="" src="' + elem.image_url + '"></td><td>' + elem.name +
71+
'</td><td>' + btnt + '</td></tr>');
6872
});
6973
$(".loadBg").hide();
7074
});
7175
}
7276
}
7377

78+
$(".searchBar").keydown(function (e) {
79+
if (e.keyCode == 13) {
80+
$(".loadBg").show();
81+
$(".blck .ttt2").html("");
82+
$.get("/bukkitorg/plugins/search?search=" + $(".searchBar").val(), function (data) {
83+
data.forEach(function (elem) {
84+
btnt = '<button class="btn btn-light" style="color: black;" onclick="downloadPlugin(' + "'" + elem
85+
.name + "'" + ', ' + "'" + elem.url + "'" +
86+
')" data-toggle="tooltip" data-placement="top" title="Download"><span class="material-icons material-icons-outlined">download</i></button>';
87+
$(".blck .ttt2").append('<tr><td><img alt="" src="' + elem.image_url + '"></td><td>' + elem.name +
88+
'</td><td>' + btnt + '</td></tr>');
89+
});
90+
$(".loadBg").hide();
91+
});
92+
$(".searchBar").val("");
93+
}
94+
});
95+
7496
function prevPage() {
7597
if (page != 1) {
7698
page--;
@@ -97,13 +119,15 @@ <h5 class="modal-title" id="selectPluginModallLabel">Downloading file</h5>
97119
$("#selectPluginModal .spInstall").show();
98120
$("#selectPluginModal .spStatus").html("Select version");
99121
data.forEach(function (item) {
100-
$("#selectPluginModal .spSelect").append("<option data-url='" + item.url + "'>" + item.name + "</option>");
122+
$("#selectPluginModal .spSelect").append("<option data-url='" + item.url + "'>" + item.name +
123+
"</option>");
101124
});
102125
});
103126

104127
$("#selectPluginModal .spInstall").unbind("click");
105128
$("#selectPluginModal .spInstall").click(function () {
106-
fnn = $("#selectPluginModal #selectPluginModallLabel").html().split(" ").join("_") + "-" + $("#selectPluginModal .spSelect option:selected").html().split(" ").join("_") + ".jar";
129+
fnn = $("#selectPluginModal #selectPluginModallLabel").html().split(" ").join("_") + "-" + $(
130+
"#selectPluginModal .spSelect option:selected").html().split(" ").join("_") + ".jar";
107131
urll = $("#selectPluginModal .spSelect option:selected").data("url");
108132
$.get("/file/download?filename=" + fnn + "&url=" + urll + "&server=" + currentServer + "&type=plugin");
109133
myModal.hide();

0 commit comments

Comments
 (0)