-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added http server for loading modules in v5
- Loading branch information
Showing
7 changed files
with
714 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
const { app } = require('electron') | ||
const express = require('express') | ||
const { networkInterfaces } = require('os') | ||
const path = require('path') | ||
class http { | ||
get ipaddr() { | ||
return this.app.locals.ip | ||
} | ||
get port() { | ||
return this.app.locals.port | ||
} | ||
|
||
constructor(filename,code,name) { | ||
this.app = express() | ||
this.app.locals.filename = filename | ||
this.app.locals.code = code | ||
this.app.locals.name = name | ||
|
||
this.app.get('/:filename', function(req,res) { | ||
if (req.params.filename != path.basename(req.app.locals.filename)) { | ||
res.sendStatus(404) | ||
} else { | ||
res.setHeader('Content-Disposition',`attachment; filename=${path.basename(req.app.locals.filename)}`) | ||
.sendFile(filename,()=>{}) | ||
} | ||
}) | ||
|
||
this.app.get('/', function(req,res) { | ||
res.contentType('application/json') | ||
.send(JSON.stringify( | ||
{ | ||
"id": code, | ||
"name": name, | ||
"type": "module", | ||
"version": app.getVersion(), | ||
"description": `EncounterLog Export of ${name}`, | ||
"download": `http://${req.app.locals.ip}:${req.app.locals.port}/${path.basename(req.app.locals.filename)}` | ||
} | ||
) | ||
) | ||
}) | ||
|
||
this.server = new Promise((resolve,reject)=>{ | ||
try{ | ||
let server = this.app.listen(0,'::',()=>{ | ||
console.log("Server started.") | ||
const nets = networkInterfaces() | ||
for (const net of Object.keys(nets)) { | ||
for(const ip of nets[net]) { | ||
if (ip.family == 'IPv4' && !ip.internal) { | ||
this.app.locals.ip = ip.address | ||
break; | ||
} | ||
} | ||
if (this.app.locals.ip) break; | ||
} | ||
console.log(server.address()) | ||
this.app.locals.port = server.address()?.port | ||
resolve(server) | ||
}) | ||
} catch(e) { | ||
reject(e) | ||
} | ||
}) | ||
} | ||
} | ||
module.exports = http; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
<html xmlns="http://www.w3.org/1999/xhtml"> | ||
<head> | ||
<title>EncounterLog</title> | ||
<style type="text/css"> | ||
img { max-height: 100%; max-width: 100%; } | ||
.spinner { | ||
position: fixed; | ||
bottom: 15px; | ||
left: 0px; | ||
width: 100%; | ||
text-align: center; | ||
z-index: 999; | ||
} | ||
.loader { | ||
width: 48px; | ||
height: 48px; | ||
border-radius: 50%; | ||
display: inline-block; | ||
border-top: 4px solid #FFF; | ||
border-right: 4px solid transparent; | ||
box-sizing: border-box; | ||
animation: rotation 1s linear infinite; | ||
} | ||
.loader::after { | ||
content: ''; | ||
box-sizing: border-box; | ||
position: absolute; | ||
left: 0; | ||
top: 0; | ||
width: 48px; | ||
height: 48px; | ||
border-radius: 50%; | ||
border-left: 4px solid #FF0000; | ||
border-bottom: 4px solid transparent; | ||
animation: rotation 0.5s linear infinite reverse; | ||
} | ||
@keyframes rotation { | ||
0% { | ||
transform: rotate(0deg); | ||
} | ||
100% { | ||
transform: rotate(360deg); | ||
} | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div> | ||
<img src="icon.png"> | ||
</div> | ||
<div class="spinner"> | ||
<span class="loader"></span> | ||
</div> | ||
</body> |
Oops, something went wrong.