@@ -5,18 +5,24 @@ const port = 3000;
55const path = require ( 'path' ) ;
66const request_lib = require ( 'request' ) ;
77const 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-
2026var spParser = require ( "minecraft-server-properties" ) ;
2127const fs = require ( 'fs' ) ;
2228var colors = require ( 'colors' ) ;
@@ -50,7 +56,7 @@ const fse = require('fs-extra');
5056const {
5157 response
5258} = require ( 'express' ) ;
53- const version = "v1.0.4 " ;
59+ const version = "v1.0.5 " ;
5460
5561var customHeaderRequest = request_lib . defaults ( {
5662 headers : {
@@ -94,6 +100,58 @@ request_lib.get("https://api.github.com/repos/Seeroy/kubek-minecraft-dashboard/r
94100if ( 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} ) ;
0 commit comments