Initial commit

This commit is contained in:
Flummi 2018-02-16 14:25:46 +01:00
commit d0ae0041e8
21 changed files with 732 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
node_modules
cfg/config.mjs
package-lock.json

10
db.txt Normal file
View File

@ -0,0 +1,10 @@
pastes:
id
uuid
datetime
language
title
paste
hidden
description
(owner)

17
package.json Normal file
View File

@ -0,0 +1,17 @@
{
"name": "fpaste",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node --experimental-modules src/fpaste.mjs"
},
"author": "Flummi",
"license": "ISC",
"dependencies": {
"express": "^4.16.2",
"express-handlebars": "^3.0.0",
"highlight": "^0.2.4",
"highlight.js": "^9.12.0"
}
}

Binary file not shown.

Binary file not shown.

125
public/css/code.css Normal file
View File

@ -0,0 +1,125 @@
div.formatedCode {
display: table;
margin: 5px 0 15px;
padding: 0;
}
div.formatedCode div.lineNumbers {
border-right: 1px solid #ccc;
text-align: right;
}
div.formatedCode div.lineNumbers a {
color: #aaa;
}
div.formatedCode div.lineNumbers,
div.formatedCode div.sourceCode {
display: table-cell;
}
div.formatedCode pre.plainText,
div.formatedCode div.lineNumbers pre,
div.formatedCode div.sourceCode pre {
padding: 0;
margin: 0 10px 0;
line-height: 12pt;
font-size: 10pt;
}
/*
github.com style (c) Vasily Polovnyov <vast@whiteants.net>
*/
.hljs {
display: block;
overflow-x: auto;
padding: 0.5em;
color: #333;
background: #f8f8f8;
}
.hljs-comment,
.hljs-quote {
color: #998;
font-style: italic;
}
.hljs-keyword,
.hljs-selector-tag,
.hljs-subst {
color: #333;
font-weight: bold;
}
.hljs-number,
.hljs-literal,
.hljs-variable,
.hljs-template-variable,
.hljs-tag .hljs-attr {
color: #008080;
}
.hljs-string,
.hljs-doctag {
color: #d14;
}
.hljs-title,
.hljs-section,
.hljs-selector-id {
color: #900;
font-weight: bold;
}
.hljs-subst {
font-weight: normal;
}
.hljs-type,
.hljs-class .hljs-title {
color: #458;
font-weight: bold;
}
.hljs-tag,
.hljs-name,
.hljs-attribute {
color: #000080;
font-weight: normal;
}
.hljs-regexp,
.hljs-link {
color: #009926;
}
.hljs-symbol,
.hljs-bullet {
color: #990073;
}
.hljs-built_in,
.hljs-builtin-name {
color: #0086b3;
}
.hljs-meta {
color: #999;
font-weight: bold;
}
.hljs-deletion {
background: #fdd;
}
.hljs-addition {
background: #dfd;
}
.hljs-emphasis {
font-style: italic;
}
.hljs-strong {
font-weight: bold;
}

17
public/css/fonts.css Normal file
View File

@ -0,0 +1,17 @@
@media screen {
@font-face {
font-family: 'Ubuntu';
font-style: normal;
font-weight: normal;
src: local('Ubuntu'), url('/css/Ubuntu-Regular.ttf') format('ttf');
}
}
@media screen {
@font-face {
font-family: 'Ubuntu';
font-style: normal;
font-weight: 500;
src: local('Ubuntu Medium'), local('Ubuntu-Medium'), url('/css/Ubuntu-Medium.ttf') format('ttf');
}
}

59
public/css/index.css Normal file
View File

@ -0,0 +1,59 @@
section#main .settings {
background-color: #999;
border: 1px solid #666;
width: 650px;
margin: 0;
padding: 5px 1px 5px;
border-radius: 3px;
box-shadow: 3px 3px 10px #666;
}
section#main ul.settings {
list-style: none;
}
section#main ul.settings li {
display: inline;
margin-right: 15px;
}
section#main .settings p {
font-size: 11px;
color: white;
display: inline-block;
margin: 5px;
}
section#main input#desc,
section#main select#lang {
margin: 1px 0 1px;
font-size: 11px;
}
section#main input#desc {
min-width: 400px;
margin: 1px 0 1px;
}
section#main select#lang {
width: 100px;
text-align: left;
}
section#main input[type=checkbox] {
margin: 0;
position: relative;
top: 2px;
}
section#main textarea {
display: block;
margin: 5px 0 5px;
padding: 0;
width: 652px;
height: 400px;
}
section#main input#email {
display: none;
}

236
public/css/main.css Normal file
View File

@ -0,0 +1,236 @@
body {
margin: 0;
padding: 0;
background: #fff;
color: #666;
font-size: 12pt;
font-family: sans-serif;
}
h1,h2,h3,h4,h5,h6,header,menu {
font-family: 'Ubuntu', sans-serif;
}
a {
color: #088;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
li {
font-size: 9pt;
}
input.inputDesc {
color: #999;
}
section, menu, header, div {
margin: 0;
padding: 0;
}
pre {
line-height: 12pt;
font-size: 10pt;
}
form input[type=submit],
form input[type=reset] {
background-color: #777;
color: white;
border: 1px solid #666;
font-family: 'Ubuntu', sans-serif;
font-weight: bold;
padding: 10px;
margin: 5px 0 5px;
border-radius: 3px;
display: block;
box-shadow: 3px 3px 10px #666;
cursor: pointer;
}
form input[type=submit]:hover {
text-decoration: underline;
}
/* {{{ Logo */
header
{
margin: 100px auto 40px;
width: 500px;
font-size: 20pt;
}
header p#left a#n3
{
text-decoration: none;
position: relative;
left: 6px;
}
header p#left a#n3 sup
{
font-size: 12pt;
position: relative;
top: -4px;
right: 3px;
}
header p#left
{
padding: 0;
margin: 0;
display: inline-block;
font-weight: bold;
text-align: right;
width: 210px;
}
header p#center
{
padding: 0;
margin: 0;
display: inline-block;
text-align: center;
color: #999;
font-size: 22pt;
width: 68px; /* hmm... to align stuff correctly */
}
header p#right
{
padding: 0;
margin: 0;
display: inline-block;
text-align: left;
color: #999;
width: 210px;
}
header p#info
{
width: 500px;
text-align: center;
font-size: 12pt;
}
/* }}} */
/* {{{ Menu */
menu
{
float: left;
margin: 107px 20px auto;
padding: 40px 0 40px;
list-style-type: none;
position: fixed;
top: 100px;
left: 20px;
vertical-align: middle;
background-color: #666;
border-radius: 5px;
box-shadow: 3px 3px 10px #444;
}
menu li
{
padding: 5px;
width: 170px;
background-color: #666;
color: #ccc;
text-align: center;
}
menu li.highlight:hover,
menu li.active
{
background-color: #777;
}
menu li p
{
display: inline;
}
menu li a {
width: 100%;
display: inline-block;
color: #fff;
}
menu hr
{
margin: 0 auto 0;
width: 60%;
border: 0;
height: 1px;
background-color: #777;
}
menu ul.submenu
{
border-top: 1px dotted #aaa;
list-style-type: none;
margin: 4px auto 0;
padding: 0;
width: 60%;
}
menu ul.submenu li {
margin: 4px 2px 2px;
padding: 0;
font-size: 10px;
width: 100%;
background-color: #777;
}
menu ul.submenu li span.info {
color: #aaa;
}
menu ul.submenu li a {
color: #ddd;
}
/* }}} */
section#main
{
margin: 20px 20px 0 270px;
width: 760px;
}
section#main .error
{
font-weight: bold;
color: #c20;
}
section#main .warning
{
color: #c20;
}
section#main .success
{
color: #0a3;
}
section#main .info
{
font-weight: bold;
font-style: italic;
}
section#main p.moreless
{
text-align: right;
}

View File

@ -0,0 +1,30 @@
section#notifications {
position: absolute;
top: 0;
text-align: center;
width: 100%;
}
section#notifications p {
background-color: #999;
border: 1px solid #666;
box-shadow: 3px 3px 10px #666;
border-radius: 3px;
color: white;
font-size: 11px;
width: 50%;
margin-left: auto;
margin-right: auto;
padding: 5px 1px 5px;
}
section#notifications p a {
background-color: #666;
border-radius: 4px;
color: #ccc;
padding: 2px 5px 2px;
margin-left: 5px;
margin-right: 5px;
cursor: pointer;
display: inline-block;
}

75
public/css/view.css Normal file
View File

@ -0,0 +1,75 @@
#main form#filter_form p {
display: inline-block;
margin-right: 20px;
}
#filter_form input[type=submit] {
padding: 4px;
margin-left: 20px;
display: inline-block;
}
div.pasteInfo {
background-color: #999;
border: 1px solid #666;
width: 650px;
padding: 5px;
margin-top: 16px;
border-radius: 3px;
color: white;
font-size: 11px;
box-shadow: 3px 3px 10px #666;
}
div.pasteInfo p {
margin: 0;
padding: 4px;
}
div.pasteInfo p a {
color: #055;
}
div.pasteInfo p.desc {
font-style: italic;
}
div.pasteInfo p.timestamp {
float: right;
width: 150px;
text-align: right;
}
div.pasteInfo p.language {
clear: right;
float: right;
width: 150px;
text-align: right;
}
div.pasteInfo p a {
margin-left: 5px;
margin-right: 5px;
color: #ccc;
background-color: #666;
padding: 2px 5px 2px;
border: 0;
border-radius: 4px;
font-size: 11px;
font-family: sans-serif;
font-weight: normal;
display: inline;
vertical-align: baseline;
cursor: pointer;
font-style: normal;
}
div.pasteInfo p.language a {
margin: 0;
}
div.formatedCode pre.plainText,
div.formatedCode div.lineNumbers pre,
div.formatedCode div.sourceCode pre {
max-width: 580px;
overflow-x: auto;
}

30
src/fpaste.mjs Normal file
View File

@ -0,0 +1,30 @@
import cfg from "../cfg/config";
import express from "express";
import exphbs from "express-handlebars";
import router from "./routes";
const hbs = exphbs.create({
defaultLayout: "main",
helpers: {
times: (n, block) => {
let rows = [];
for(var i = 0; i < n; ++i)
rows.push(block.fn(i+1));
return rows.join("<br />");
}
}
});
const app = express();
app
.engine("handlebars", hbs.engine)
.set("view engine", "handlebars")
.use(express.static("public", cfg.websrv.static_options))
.use("/", router.index)
.use("/v", router.view)
.use("/a", router.about)
.listen(cfg.websrv.port, () => {
console.log(`fpaste listening on port ${cfg.websrv.port}`);
});

10
src/routes/index.mjs Normal file
View File

@ -0,0 +1,10 @@
import index from "./r/index";
import view from "./r/view";
import about from "./r/about";
export default {
index: index,
view: view,
about: about
};

8
src/routes/r/about.mjs Normal file
View File

@ -0,0 +1,8 @@
import express from "express";
const router = express.Router();
router.get("/", (req, res) => {
res.render("about");
});
export default router;

8
src/routes/r/index.mjs Normal file
View File

@ -0,0 +1,8 @@
import express from "express";
const router = express.Router();
router.get("/", (req, res) => {
res.render("index");
});
export default router;

33
src/routes/r/view.mjs Normal file
View File

@ -0,0 +1,33 @@
import express from "express";
const router = express.Router();
import highlight from "highlight.js";
console.log(highlight.highlightAuto("<?php\necho 'blah';\n?>"));
router.get("/", (req, res) => {
const data = {
pastes: [
{
title: "title 01",
paste: highlight.highlightAuto("<?php\necho 'blah';\n?>").value,
language: "PHP",
rows: "<?php\necho 'blah';\n?>".split(/\n/).length
},
{
title: "title 02",
paste: highlight.highlightAuto("blub").value,
language: "Plaintext",
rows: "blub".split(/\n/).length
},
{
title: "title 03",
paste: highlight.highlightAuto("muh").value,
language: "Plaintext",
rows: "muh".split(/\n/).length
}
]
};
res.render("view", data);
});
export default router;

5
views/about.handlebars Normal file
View File

@ -0,0 +1,5 @@
<h1><a name="about">About fpaste.cc</a></h1>
<p>fpaste.cc is here in it&#39;s 1st version and it&#39;s better than expected! A completly written backend in NodeJS makes it possible to develop new features faster than ever before.</p>
<p>With the <a href="http://www.mariadb.org/">MariaDB</a> database backend fpaste.cc is even more reliable and the <a href="http://expressjs.com">express</a> webserver library offers a powerfull framework.</p>
<p>The <a href="https://github.com/andris9/highlight">highlight highlighting engine</a> offers great support for a variety of programming languages.</p>
<p>If you&#39;re interested in the source code of fpaste.cc, take a look at <a href="http://github.com/mcmaniac/npaste.de">github.com</a>. If you have any questions/suggestions or would like to contribute to fpaste.cc feel free to <a href="/a/contact">contact me</a>.</p>

11
views/index.handlebars Normal file
View File

@ -0,0 +1,11 @@
<h1>New paste</h1>
<form method="post" action="/">
<div class="settings"><p>Description:</p><input id="desc" type="text" name="desc" value=""></div>
<textarea id="content" name="content"></textarea>
<ul class="settings">
<li><p>Language:</p><select id="lang" name="lang"><option value="Plaintext">Plaintext</option><option value="ABAP">ABAP</option><option value="ActionScript">ActionScript</option><option value="ActionScript 3">ActionScript 3</option><option value="Ada">Ada</option><option value="ApacheConf">ApacheConf</option><option value="AppleScript">AppleScript</option><option value="Asymptote">Asymptote</option><option value="Atomo">Atomo</option><option value="autohotkey">autohotkey</option><option value="Bash">Bash</option><option value="Batchfile">Batchfile</option><option value="Befunge">Befunge</option><option value="BlitzMax">BlitzMax</option><option value="Boo">Boo</option><option value="Brainfuck">Brainfuck</option><option value="C">C</option><option value="Clojure">Clojure</option><option value="CMake">CMake</option><option value="CoffeeScript">CoffeeScript</option><option value="Common Lisp">Common Lisp</option><option value="C++">C++</option><option value="CSS">CSS</option><option value="Cython">Cython</option><option value="D">D</option><option value="Darcs Patch">Darcs Patch</option><option value="Debian Control file">Debian Control file</option><option value="Diff">Diff</option><option value="Duel">Duel</option><option value="Dylan">Dylan</option><option value="Erlang">Erlang</option><option value="Factor">Factor</option><option value="Felix">Felix</option><option value="Fortran">Fortran</option><option value="GAS">GAS</option><option value="Gettext Catalog">Gettext Catalog</option><option value="Gherkin">Gherkin</option><option value="GLSL">GLSL</option><option value="Gnuplot">Gnuplot</option><option value="Go">Go</option><option value="GoodData-CL">GoodData-CL</option><option value="Groff">Groff</option><option value="Haskell">Haskell</option><option value="haXe">haXe</option><option value="HTML">HTML</option><option value="Hybris">Hybris</option><option value="INI">INI</option><option value="Io">Io</option><option value="Ioke">Ioke</option><option value="IRC logs">IRC logs</option><option value="Java">Java</option><option value="JavaScript">JavaScript</option><option value="LLVM">LLVM</option><option value="Logtalk">Logtalk</option><option value="Lua">Lua</option><option value="Mako">Mako</option><option value="MAQL">MAQL</option><option value="Matlab">Matlab</option><option value="MiniD">MiniD</option><option value="Modelica">Modelica</option><option value="Modula-2">Modula-2</option><option value="MOOCode">MOOCode</option><option value="MuPAD">MuPAD</option><option value="MXML">MXML</option><option value="NASM">NASM</option><option value="Newspeak">Newspeak</option><option value="objdump">objdump</option><option value="Objective-C">Objective-C</option><option value="Objective-J">Objective-J</option><option value="OCaml">OCaml</option><option value="Ooc">Ooc</option><option value="Perl">Perl</option><option value="PHP">PHP</option><option value="PostScript">PostScript</option><option value="POVRay">POVRay</option><option value="Prolog">Prolog</option><option value="Properties">Properties</option><option value="Protocol Buffer">Protocol Buffer</option><option value="Python">Python</option><option value="Python 3.0 Traceback">Python 3.0 Traceback</option><option value="Python Traceback">Python Traceback</option><option value="Embedded Ragel">Embedded Ragel</option><option value="Redcode">Redcode</option><option value="S">S</option><option value="Scala">Scala</option><option value="Scheme">Scheme</option><option value="SCSS">SCSS</option><option value="Smalltalk">Smalltalk</option><option value="Smarty">Smarty</option><option value="Debian Sourcelist">Debian Sourcelist</option><option value="SQL">SQL</option><option value="SquidConf">SquidConf</option><option value="Tcl">Tcl</option><option value="Tcsh">Tcsh</option><option value="TeX">TeX</option><option value="Vala">Vala</option><option value="VB.net">VB.net</option><option value="Velocity">Velocity</option><option value="verilog">verilog</option><option value="VimL">VimL</option><option value="XML">XML</option><option value="XSLT">XSLT</option></select></li>
<li><p>Hide from recent pastes:</p><input type="checkbox" id="hidden" name="hidden"></li>
</ul>
<input id="email" type="text" name="email">
<input type="submit" value="Add paste">
</form>

View File

@ -0,0 +1,30 @@
<!doctype blah>
<html>
<head>
<title>fpaste</title>
<link rel="stylesheet" type="text/css" href="/css/main.css" />
<link rel="stylesheet" type="text/css" href="/css/notifications.css" />
<link rel="stylesheet" type="text/css" href="/css/code.css" />
<link rel="stylesheet" type="text/css" href="/css/view.css" />
<link rel="stylesheet" type="text/css" href="/css/index.css" />
<link rel="stylesheet" type="text/css" href="/css/fonts.css" />
</head>
<body>
<header>
<p id="left"><a id="n3" href="/a">f&nbsp;<sup>3,5</sup></a>paste.cc</p><p id="center">::</p><p id="right">Pudding</p>
<p id="info">a javascript pastebin</p>
</header>
<menu>
<li class="active highlight"><a href="/">New paste</a></li>
<li class="highlight"><a href="/v">View pastes</a></li>
<li><hr></li>
<li class="highlight"><a href="/u">Login</a></li>
<li><hr></li>
<li class="highlight"><a href="/a">About</a></li>
</menu>
<section id="notifications"></section>
<section id="main">
{{{body}}}
</section>
</body>
</html>

View File

@ -0,0 +1,17 @@
{{#each this}}
<div class="pasteInfo">
<p class="timestamp">15:13 - Thu 2017.06.15</p>
<p class="language"><a href="/v/lang/{{language}}">{{language}}</a></p>
<p>Paste: <a href="/nNm/">/nNm/</a><a href="/v/id/nNm">Show related</a></p>
<p class="desc">{{title}}</p>
</div>
<div class="formatedCode">
<div class="lineNumbers">
<pre class="lineNumbers">{{#times rows}}<a href="/nNm/#{{this}}" name="{{this}}">{{this}}</a>{{/times}}</pre>
</div>
<div class="sourceCode">
<pre>
{{{paste}}}</pre>
</div>
</div>
{{/each}}

8
views/view.handlebars Normal file
View File

@ -0,0 +1,8 @@
{{!-- pasteview inside views/partials --}}
<h1>Most recent pastes</h1>
<form method="post" action="/v" id="filter_form">
<p>Filter pastes (<a href="/a/howto#filter">help</a>):</p><input type="text" name="filter"><input type="submit">
</form>
<div id="paste_list">
{{> pasteview pastes }}
</div>