MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / configServer

Method configServer

contributed/modClock/main.js:387–663  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

385 }
386
387 configServer() {
388 this.suffixLine = "build: " + this.getbuildstring();
389
390 this.uiServer = new Server();
391 this.uiServer.clock = this;
392 this.uiServer.callback = function(message, value, v2) {
393 let clock = this.server.clock;
394 let name = clock.prefs.name;
395 let scriptServer = clock.connectionWasEstablished ? REMOTE_SCRIPTS : LOCAL_SCRIPTS;
396 switch (message) {
397 case Server.status:
398 global.needsReboot = 0;
399 this.userReq = [];
400 this.path = value;
401 this.redirect = 0;
402 break;
403
404 case Server.headersComplete:
405 return String;
406
407 case Server.requestComplete:
408 let postData = value.split("&");
409
410 this.userReq.dataValid = postData.length > 1;
411
412 for (let i=0; i<postData.length; i++) {
413 const equal = postData[i].indexOf("=");
414 if (equal < 0)
415 continue;
416 let name = postData[i].slice(0, equal);
417 let value = postData[i].slice(equal + 1);
418 value = value.split("+");
419 value = value.join(" ");
420 this.userReq[name] = value;
421 }
422 this.redirect = 1;
423 if (this.path == "/style") {
424 let newStyle = clock.styles.find(x => x.tag === this.userReq.style);
425 newStyle.options_response(this.userReq);
426 this.redirect = 1;
427
428 clock.prefs.style = this.userReq.style;
429 clock.styles.forEach(clock.prefs.savePref);
430
431 clock.prefs.brightness = parseInt(this.userReq.brightness);
432 }
433 else if (this.path == "/rescanSSID" || this.path.slice(0,19) == "/current_version.js")
434 this.redirect = 0;
435 else if (this.path == "/tail") {
436// this.redirect = 1;
437 clock.prefs.tail_brightness = parseInt(this.userReq.tail_brightness);
438 clock.prefs.tail_order = clock.checkFormat(clock.display.supportedFormats, this.userReq.tail_order);
439 clock.prefs.extra = parseInt(this.userReq.extra);
440 clock.prefs.tail_on = this.userReq.tail_on ? parseInt(this.userReq.tail_on) : 0;
441 clock.prefs.tail_sched = parseInt(this.userReq.tail_sched);
442 clock.prefs.tail_time_on = clock.parseTimeReq(this.userReq.tail_time_on);
443 clock.prefs.tail_time_off = clock.parseTimeReq(this.userReq.tail_time_off);
444 }

Callers 2

connectedMethod · 0.95
configAPMethod · 0.95

Calls 15

advertiseServerMethod · 0.95
checkboxValueFunction · 0.85
dstValueFunction · 0.85
findMethod · 0.80
options_responseMethod · 0.80
checkFormatMethod · 0.80
parseTimeReqMethod · 0.80
setTimeFromTextMethod · 0.80
checkNameMethod · 0.80
redirectHeadMethod · 0.80
bodyPrefixMethod · 0.80
bodySuffixMethod · 0.80

Tested by

no test coverage detected