modified: package.json

new file:   s/index.tpl.html
	new file:   s/item.tpl.html
	new file:   s/mp3.png
	new file:   s/style.css
	modified:   src/main.js
This commit is contained in:
Flummi 2016-08-16 13:29:32 +02:00
parent 7e192acae0
commit 244fa1053f
6 changed files with 136 additions and 37 deletions

View File

@ -6,7 +6,8 @@
"coffea": "^0.4.24",
"fs-extra": "^0.30.0",
"mysql": "^2.11.1",
"repl": "^0.1.3"
"repl": "^0.1.3",
"swig": "^1.4.2"
},
"repository": {
"type": "git",

13
s/index.tpl.html Normal file
View File

@ -0,0 +1,13 @@
<!DOCTYPE blah>
<html>
<head>
<title>f0ck me!</title>
<link rel="stylesheet" type="text/css" href="./s/style.css">
<link rel="favicon" type="image/png" href="./s/faviconf0ck.png" />
</head>
<body>
{% for item in items %}
<div class="mrhankyisteinneger"><a href="./{{ item }}"><img src="./t/{{ item }}.png" /></a></div>
{% endfor %}
</html>
</body>

32
s/item.tpl.html Normal file
View File

@ -0,0 +1,32 @@
<!DOCTYPE blah>
<html>
<head>
<title>{{ id }} - f0ck.me</title>
<link rel="stylesheet" type="text/css" href="./s/style.css">
<link rel="favicon" type="image/png" href="./s/faviconf0ck.png" />
</head>
<body>
<h4><a href="/">f0ck.me</a></h4>
<div class="id">[ID: {{ id }} | by: {{ username }}]</div>
<div class="medium">
{% if item == "video" %}
<video src="{{ dest }}" style="max-width: 1024px" autoplay controls loop></video>
{% endif %}
{% if item == "audio" %}
<audio controls src="{{ dest }}" type="audio/mp3" autoplay></audio>
{% endif %}
{% if item == "image" %}
<img src="{{ dest }}" style="max-width: 1024px" />
{% endif %}
</div>
<div class="controls">controls f&uuml;r vor und zur&uuml;ck :^)</div>
<div class="info">
<span class="src">src: <a href="{{ src }}" target="_blank">{{ src }}</a></span><br />
<span class="dest">dest: {{ dest }}</span><br />
<span class="mime">mime: {{ mime }}</span>&nbsp;
<span class="size">size: {{ size }}</span><br />
<span class="channel">channel: {{ userchannel }}</span>&nbsp;
<span class="network">network: {{ usernetwork }}</span>
</div>
</body>
</html>

BIN
s/mp3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

48
s/style.css Normal file
View File

@ -0,0 +1,48 @@
body {
background-color: #262626;
color: #fff;
font-family: Monospace;
}
a > img {
max-height: 128px;
max-width: 128px;
border: 2px solid #4c4a4a;
margin: 0;
}
a {
color: #9f0;
}
a:hover {
color: #74c100;
}
.medium {
display: flex;
justify-content: center;
align-items: center;
}
.info {
text-align: center;
}
.id {
text-align: center;
padding-bottom: 10px;
}
.mrhankyisteinneger {
padding: 0;
display: block;
margin: 0 0 4px 5px;
float: left;
}
.mrhankyisteinneger:hover {
opacity: 0.7;
}
.controls {
text-align: center;
}

View File

@ -9,6 +9,10 @@ var crypto = require('crypto');
var path = require('path');
var exec = require('child_process').exec;
var swig = require('swig');
var templates = {};
var sql;
var haDC = () => {
sql = mysql.createConnection(cfg.mysql);
@ -168,9 +172,7 @@ http.createServer((req, res) => {
var url = req.url.split("/")[1];
if(filePath == './')
filePath = './index.html';
console.log('request ', filePath);
var extname = String(path.extname(filePath)).toLowerCase();
var contentType = 'text/html';
var mimeTypes = {
@ -185,60 +187,61 @@ http.createServer((req, res) => {
'.webm': 'video/webm',
'.css': 'text/css'
};
if(filePath == "./index.html") { // mainpage
var tpl = swig.compile(templates.index);
var data = { items: [] };
sql.query("select * from `f0ck`.`items` order by `id` desc", (err, rows, fields) => {
var tmpres = "<!DOCTYPE blah><html><head><title>f0ck me!</title><link rel=\"stylesheet\" type=\"text/css\" href=\"./s/style.css\"></head><body>";
rows.forEach((e,i,a) => {
tmpres += "<div class='mrhankyisteinneger'><a href='./"+e.id+"'><img src='./t/"+e.id+".png' /></a></div>\n";
data.items.push( e.id );
});
tmpres += "</body></html>";
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(tmpres, 'utf-8');
res.end(tpl(data), 'utf-8');
});
}
else if(Number.isInteger(parseInt(url))) { // itempage
sql.query("select * from `f0ck`.`items` where `id` = ? limit 1", url, (err, rows, fields) => {
var tmpres = "";
var tpl = swig.compile(templates.item);
var data = {
id: '',
username: '',
item: '',
src: '',
dest: '',
mime: '',
size: '',
userchannel: '',
usernetwork: ''
};
rows.forEach((e,i,a) => {
tmpres = "<!DOCTYPE blah>\n<html>\n<head>\n<title>"+url+" - f0ck.me</title>\n<link rel=\"stylesheet\" type=\"text/css\" href=\"./s/style.css\">\n</head>\n<body>\n<h4><a href='/'>f0ck.me</a></h4>\n";
tmpres += "<div class='id'>[ID: "+e.id+" | by: "+e.username+"]</div>\n";
tmpres += "<div class='medium'>";
switch(e.mime) {
case "image/png":
case "image/jpeg":
case "image/gif":
tmpres += "<img src='"+e.dest+"' style='max-width: 1024px' />";
data.item = 'image';
break;
case "video/webm":
case "video/mp4":
tmpres += "<video src='"+e.dest+"' style='max-width: 1024px' autoplay controls loop></video>";
data.item = 'video';
break;
case "audio/mpeg":
tmpres += "<audio controls src='"+e.dest+"' type='audio/mp3' autoplay></audio>";
data.item = 'audio';
break;
}
tmpres += "</div><br />\n";
tmpres += "<div class='controls'>controls f&uuml;r vor und zur&uuml;ck :^)</div><br />\n";
tmpres += "<div class='info'>";
tmpres += "<span class='src'>src: <a href='"+e.src+"' target='_blank'>"+e.src+"</a></span><br />";
tmpres += "<span class='dest'>dest: "+e.dest+"</span><br />";
tmpres += "<span class='mime'>mime: "+e.mime+"</span>&nbsp;";
tmpres += "<span class='size'>size: "+formatSize(e.size)+"</span><br />";
tmpres += "<span class='channel'>channel: "+e.userchannel+"</span>&nbsp;";
tmpres += "<span class='network'>network: "+e.usernetwork+"</span>";
tmpres += "</div>\n</body>\n</html>";
data.id = e.id;
data.username = e.username;
data.src = e.src;
data.dest = e.dest;
data.mime = e.mime;
data.size = formatSize(e.size);
data.userchannel = e.userchannel;
data.usernetwork = e.usernetwork;
});
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(tmpres, 'utf-8');
res.end(tpl(data), 'utf-8');
});
}
else if(filePath.match(/^\.\/(b|s|t)\/.*/)) { // file
contentType = mimeTypes[extname] || 'application/octect-stream';
switch(contentType) {
case "video/webm":
case "video/mp4":
@ -258,12 +261,9 @@ http.createServer((req, res) => {
'Content-Type':contentType,
'Content-Length':end - start,
'Content-Range':'bytes '+start+'-'+end+'/'+stat.size,
// 'Accept-Ranges':'bytes',
// 'Server':'CustomStreamer/0.0.1',
'Transfer-Encoding':'chunked'
});
var stream = fs.createReadStream(filePath,
{ flags: 'r', start: start, end: end});
var stream = fs.createReadStream(filePath, { flags: 'r', start: start, end: end});
stream.pipe(res);
break;
default:
@ -286,8 +286,6 @@ http.createServer((req, res) => {
});
break;
}
fs.readFile(filePath, (error, content) => {
if(error) {
if(error.code == 'ENOENT') {
@ -311,6 +309,13 @@ http.createServer((req, res) => {
}
}).listen(cfg.webserver.port);
var getTpls = () => {
templates = {
"index": fs.readFileSync("./s/index.tpl.html", "utf-8"),
"item": fs.readFileSync("./s/item.tpl.html", "utf-8")
};
};
getTpls();
// Thumbnailbackgroundworker