Skip to content

Commit 9b7e732

Browse files
authored
Windows server app update!
+ Added the logger! + Set a strict height of 250px on the logger. + Updated to Electron 4.0.8.
1 parent 001c04b commit 9b7e732

5 files changed

Lines changed: 82 additions & 55 deletions

File tree

electron app/resources/datpart/display_script.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,15 @@
1010

1111
document.querySelectorAll("a.external-link").forEach(function (el) {
1212
el.onclick = function(){shell.openExternal(el.href);return false;};
13-
});
13+
});
14+
15+
var logToScreen = function(log) {
16+
console.log(log);
17+
var printLog = log;
18+
/* if (typeof log == 'object') {
19+
printLog = JSON.stringify(log);
20+
} */
21+
var logger = document.getElementById("logger");
22+
logger.textContent += printLog + "\n" + "\r\n";
23+
logger.scrollTop = logger.scrollHeight;
24+
};

electron app/resources/datpart/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"type": "git",
88
"url": "https://github.com/HughIsaacs2/DatPart.git"
99
},
10-
"version": "0.0.16",
10+
"version": "0.0.20",
1111
"author": "Hugh Isaacs II <hughisaacs@acrylicstyle.com>",
1212
"license": "MIT",
1313
"main": "launch.js",
@@ -67,7 +67,7 @@
6767
"dist": "build"
6868
},
6969
"devDependencies": {
70-
"dat-node": "^3.5.13",
71-
"electron": "4.0.0"
70+
"dat-node": "3.5.14",
71+
"electron": "4.0.8"
7272
}
7373
}

electron app/resources/datpart/server_app.html

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,12 @@
88
<script type="text/javascript" src="server_script.js" defer="true" lazyload="1"></script>
99

1010
<link type="text/css" href="style.css" rel="stylesheet" lazyload="1" />
11-
<style type="text/css" rel="stylesheet">
12-
#logger {
13-
max-height: 100px;
14-
overflow-y: auto;
15-
border-top: solid 1px #c6c6c6;
16-
border-bottom: solid 1px #c6c6c6;
17-
}
18-
</style>
1911
</head>
2012
<body>
2113
<div class="hero-unit">
2214
<h1 id="header">DatPart server <span id="version-number"></span></h1>
2315
<p>Serving Dat sites locally<br/><br/><a href="http://1c7639eedaf8f7533f92e7c34f5a6d2b43645347836ab5e9f2489e89d3b08306.dat_site/" target="_blank" class="button external-link">Test site: 1c7639eedaf8f7533f92e7c34f5a6d2b43645347836ab5e9f2489e89d3b08306</a>
16+
<details><summary class="button">Log</summary><br/><pre id="logger"></pre></details>
2417
<br/><br/>If you don't have it, <a href="https://chrome.google.com/webstore/detail/datpart-extension/hnblaajbillhajijlbaepnjglfgepdgm" target="_blank" class="external-link">get the Chrome Extension here</a>.
2518
</p>
2619
<footer>

electron app/resources/datpart/server_script.js

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
var versionNumber = require('electron').remote.getGlobal('sharedObject').appVersionNumber;
1818

19-
console.log("DatPart Server Version "+versionNumber);
19+
logToScreen("DatPart Server Version "+versionNumber);
2020

2121
var datMap = {};
2222

@@ -66,7 +66,6 @@
6666
"otf": "font/opentype",
6767
"eot": "application/vnd.ms-fontobject",
6868
//video formats
69-
"av1": "video/av1",
7069
"webm": "video/webm",
7170
"mp4": "video/mp4",
7271
"m4v": "video/m4v",
@@ -160,8 +159,8 @@
160159
}
161160

162161
const requestHandler = (request, response) => {
163-
console.log(request.url);
164-
console.log(request);
162+
logToScreen(request.url);
163+
logToScreen(request);
165164

166165
var uri = url.parse(request.url).pathname,
167166
filename = path.join(process.cwd(), uri);
@@ -178,20 +177,21 @@ const requestHandler = (request, response) => {
178177

179178
var datPath = url.parse(request.url).pathname;
180179

181-
console.log(datPath);
180+
logToScreen(datPath);
182181

183182
if(request.method == 'GET' && currentTLD == 'dat_site' || request.method == 'GET' && currentTLD == 'datsite') {
184183
datMap[currentURLhostNoTLD] = {};
185184
dat( __dirname + '/../../dats/'+currentURLhostNoTLD, {
186185
// 2. Tell Dat what link I want
187186
key: currentURLhostNoTLD, temp: true, sparse: true // (a 64 character hash from above)
188187
}, function (err, dat) {
189-
if (err) {throw err;console.log(err);}
188+
if (err) {throw err;logToScreen(err);}
190189

191190
var stats = dat.trackStats();
192-
console.log(currentURLhostNoTLD+" "+dat.stats.get());
193-
console.log(dat.stats.get());
194-
console.log("Dat Version: "+dat.stats.get().version);
191+
logToScreen(currentURLhostNoTLD+" "+dat.stats.get());
192+
logToScreen(dat.stats.get());
193+
logToScreen("Dat Version: "+dat.stats.get().version);
194+
logToScreen("Number of files: "+dat.stats.get().files);
195195

196196
var fourOhFourPage = null;
197197

@@ -215,70 +215,70 @@ dat( __dirname + '/../../dats/'+currentURLhostNoTLD, {
215215
/*
216216
dat.archive.readFile(datPath+'/dat.json', function (err, content) {
217217
if (content != null) {
218-
console.log("Got dat.json for "+ currentURLhostNoTLD);
219-
console.log(datMap[currentURLhostNoTLD]);
218+
logToScreen("Got dat.json for "+ currentURLhostNoTLD);
219+
logToScreen(datMap[currentURLhostNoTLD]);
220220
221221
if (JSON.parse(content.toString()).content_security_policy != null || JSON.parse(content.toString()).content_security_policy != undefined) {
222222
datMap[currentURLhostNoTLD].contentSecurityPolicy = JSON.parse(content.toString()).content_security_policy;
223-
console.log(JSON.parse(content.toString()).content_security_policy);
223+
logToScreen(JSON.parse(content.toString()).content_security_policy);
224224
} else {
225225
datMap[currentURLhostNoTLD].contentSecurityPolicy = "";
226226
}
227227
228228
if (JSON.parse(content.toString()).fallback_page != null || JSON.parse(content.toString()).fallback_page != undefined) {
229229
datMap[currentURLhostNoTLD].fallback_page = JSON.parse(content.toString()).fallback_page;
230-
console.log(JSON.parse(content.toString()).fallback_page);
230+
logToScreen(JSON.parse(content.toString()).fallback_page);
231231
} else {
232232
datMap[currentURLhostNoTLD].fallback_page = "";
233233
}
234234
235235
} else {
236-
console.log("dat.json not found for "+ currentURLhostNoTLD);
236+
logToScreen("dat.json not found for "+ currentURLhostNoTLD);
237237
238238
}
239-
if (err) {throw err; console.log(err);}
239+
if (err) {throw err; logToScreen(err);}
240240
});
241241
*/
242242

243243
/*
244244
datMap[currentURLhostNoTLD].fourOhFourFallback = new Promise(function(resolve, reject) {
245245
dat.archive.readFile('/dat.json', function (err, content) {
246246
247-
console.log("Grabbing JSON for fallback_page "+JSON.stringify(content));
247+
logToScreen("Grabbing JSON for fallback_page "+JSON.stringify(content));
248248
249249
dat.archive.readFile(content.fallback_page, function (err, fallbackContent) {
250250
if (fallbackContent != null) {
251-
console.log("Got fallback page for dat://"+ currentURLhostNoTLD +" " + content.fallback_page);
251+
logToScreen("Got fallback page for dat://"+ currentURLhostNoTLD +" " + content.fallback_page);
252252
resolve(fallbackContent);
253253
} else {
254-
console.log("fallback_page not found for dat://"+ currentURLhostNoTLD);
254+
logToScreen("fallback_page not found for dat://"+ currentURLhostNoTLD);
255255
reject("fallback_page not found for dat://"+ currentURLhostNoTLD);
256256
}
257257
});
258258
259259
}, function(err) {
260-
console.log(err);
260+
logToScreen(err);
261261
});
262262
});
263263
*/
264264
/*
265265
datMap[currentURLhostNoTLD].contentSecurityPolicy = new Promise(function(resolve, reject) {
266266
datMap[currentURLhostNoTLD].datJSON.then(function(result) {
267267
268-
console.log("Grabbing JSON for content_security_policy "+JSON.stringify(result));
268+
logToScreen("Grabbing JSON for content_security_policy "+JSON.stringify(result));
269269
270270
dat.archive.readFile(result.content_security_policy, function (err, cspContent) {
271271
if (cspContent != null) {
272-
console.log("Got fallback page for dat://"+ currentURLhostNoTLD +" " + result.content_security_policy);
272+
logToScreen("Got fallback page for dat://"+ currentURLhostNoTLD +" " + result.content_security_policy);
273273
resolve(cspContent);
274274
} else {
275-
console.log("content_security_policy not found for dat://"+ currentURLhostNoTLD);
275+
logToScreen("content_security_policy not found for dat://"+ currentURLhostNoTLD);
276276
reject("content_security_policy not found for dat://"+ currentURLhostNoTLD);
277277
}
278278
});
279279
280280
}, function(err) {
281-
console.log(err);
281+
logToScreen(err);
282282
});
283283
});
284284
*/
@@ -288,7 +288,7 @@ if (lastChar == '/') { // If the last character is not a slash
288288
dat.archive.readFile(datPath+'/index.html', function (err, content) {
289289

290290
if (content != null) {
291-
console.log(datPath);
291+
logToScreen(datPath);
292292
var newHeaders = HTTPheaders;
293293
delete newHeaders["X-Frame-Options"];
294294
delete newHeaders["Location"];
@@ -302,7 +302,7 @@ if (lastChar == '/') { // If the last character is not a slash
302302
response.writeHead(200, newHeaders);
303303
response.end(content);
304304
} else {
305-
console.log("File "+datPath+" not found!");
305+
logToScreen("File "+datPath+" not found!");
306306

307307
var newHeaders = HTTPheaders;
308308
delete newHeaders["X-Frame-Options"];
@@ -311,7 +311,7 @@ if (lastChar == '/') { // If the last character is not a slash
311311
newHeaders["X-Frame-Options"] = "DENY";
312312

313313
if(datMap[currentURLhostNoTLD].fourOhFourFallback != null) {
314-
console.log(result);
314+
logToScreen(result);
315315

316316
newHeaders["Alt-Svc"] = "dat='dat://"+currentURLhostNoTLD+datPath+"'";
317317
newHeaders["Dat-Url"] = "dat://"+currentURLhostNoTLD+datPath;
@@ -321,21 +321,21 @@ if (lastChar == '/') { // If the last character is not a slash
321321
response.writeHead(404, newHeaders);
322322
response.end(result);
323323
} else {
324-
console.log(err);
324+
logToScreen(err);
325325
response.writeHead(204, newHeaders);
326326
response.end("Nothing");
327327
}
328328

329329
}
330-
if (err) {throw err; console.log(err);}
330+
if (err) {throw err; logToScreen(err);}
331331
});
332332

333333
} else {
334334

335335
dat.archive.readFile(datPath, function (err, content) {
336336

337337
if (content != null) {
338-
console.log(datPath);
338+
logToScreen(datPath);
339339

340340
var newHeaders = HTTPheaders;
341341
delete newHeaders["X-Frame-Options"];
@@ -354,7 +354,7 @@ if (lastChar == '/') { // If the last character is not a slash
354354
response.writeHead(200, newHeaders);
355355
response.end(content);
356356
} else {
357-
console.log("File "+datPath+" not found!");
357+
logToScreen("File "+datPath+" not found!");
358358

359359
var newHeaders = HTTPheaders;
360360
delete newHeaders["X-Frame-Options"];
@@ -363,7 +363,7 @@ if (lastChar == '/') { // If the last character is not a slash
363363
newHeaders["X-Frame-Options"] = "DENY";
364364

365365
if(datMap[currentURLhostNoTLD].fourOhFourFallback != null) {
366-
console.log(result);
366+
logToScreen(result);
367367

368368
newHeaders["Alt-Svc"] = "dat='dat://"+currentURLhostNoTLD+datPath+"'";
369369
newHeaders["Dat-Url"] = "dat://"+currentURLhostNoTLD+datPath;
@@ -373,13 +373,13 @@ if (lastChar == '/') { // If the last character is not a slash
373373
response.writeHead(404, newHeaders);
374374
response.end(result);
375375
} else {
376-
console.log(err);
376+
logToScreen(err);
377377
response.writeHead(204, newHeaders);
378378
response.end("Nothing");
379379
}
380380

381381
}
382-
if (err) {throw err; console.log(err);}
382+
if (err) {throw err; logToScreen(err);}
383383
});
384384

385385
}
@@ -390,8 +390,8 @@ if (lastChar == '/') { // If the last character is not a slash
390390

391391
} else if(request.method == 'GET' && currentTLD != 'dat_site' && currentTLD != 'datsite') {
392392

393-
console.log("Non Dat Site request "+request);
394-
console.log(request);
393+
logToScreen("Non Dat Site request "+request);
394+
logToScreen(request);
395395

396396
//var newHeaders;
397397
//newHeaders["location"] = "http://0.0.0.0/";
@@ -400,22 +400,22 @@ if (lastChar == '/') { // If the last character is not a slash
400400

401401
} else if(fs.existsSync(__dirname + "/../../dats/")) {
402402

403-
console.log(request.url);
403+
logToScreen(request.url);
404404

405405
var currentTLD = url.parse(request.url).hostname.split(".").pop();
406406

407407
var currentURLhostNoTLD = url.parse(request.url).hostname.split(".")[0];
408408

409409
var datPath = url.parse(request.url).pathname;
410410

411-
console.log(datPath);
411+
logToScreen(datPath);
412412

413-
console.log("TLD: " + currentTLD + " Hash: " + currentURLhostNoTLD);
413+
logToScreen("TLD: " + currentTLD + " Hash: " + currentURLhostNoTLD);
414414

415415
} else {
416416

417417
fs.mkdirSync(appPath + "/dats/");
418-
console.log(request.url);
418+
logToScreen(request.url);
419419

420420
}
421421

@@ -425,8 +425,8 @@ const server = http.createServer(requestHandler);
425425

426426
server.listen(port, (err) => {
427427
if (err) {
428-
return console.log('something bad happened', err);
428+
return logToScreen('something bad happened', err);
429429
}
430430

431-
console.log(`server is listening on ${port}`);
431+
logToScreen(`server is listening on ${port}`);
432432
});

electron app/resources/datpart/style.css

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ border-radius: 4px;
125125
width: calc(100% - 4px);
126126
background-color: #424242;
127127
color: #ffffff;
128+
129+
position: relative;
130+
top: 2px;
131+
margin-bottom: 3px;
128132
}
129133

130134
a, a:visited {
@@ -338,8 +342,8 @@ input.textbox {
338342
#version-notice {
339343
display: block;
340344
position: fixed;
341-
bottom: 0;
342-
left: 0;
345+
bottom: 2px;
346+
left: 4px;
343347
float: left;
344348
opacity: 0.5;
345349
}
@@ -352,4 +356,23 @@ input.textbox {
352356
font-size: 10px;
353357
color: rgba(255,255,255,0.5);
354358
z-index: -1;
359+
}
360+
361+
#logger {
362+
display: block;
363+
overflow: auto;
364+
overflow-y: auto;
365+
white-space: pre;
366+
-ms-word-break: break-all;
367+
word-break: break-all;
368+
word-break: break-word;
369+
overflow-wrap: break-word;
370+
word-wrap: break-word;
371+
-webkit-hyphens: auto;
372+
-ms-hyphens: auto;
373+
-moz-hyphens: auto;
374+
hyphens: auto;
375+
height: 250px;
376+
border-top: solid 1px #c6c6c6;
377+
border-bottom: solid 1px #c6c6c6;
355378
}

0 commit comments

Comments
 (0)