patch allows nice pad urls server/padname and also the old form server/p/padname; first commit to my remote repository

This commit is contained in:
Wikinaut 2011-11-10 00:06:43 +01:00
parent bf0fe9377d
commit 2f0e45efe3
3 changed files with 41 additions and 38 deletions

View file

@ -197,23 +197,26 @@ async.waterfall([
}); });
}); });
//serve pad.html under /p //serve pad.html under / and /p for compatibility
app.get('/p/:pad', function(req, res, next) app.get( "(/p)?/:pad", function(req, res, next)
{ {
// ensure the padname is valid and the url doesn't end with a / // ensure the padname is valid and the url doesn't end with a /
if(!padManager.isValidPadId(req.params.pad) || /\/$/.test(req.url)) // and that reserved pathnames are served as files, not as pads
if( !padManager.isValidPadId(req.params.pad) || /\/+$/.test(req.url)) {
res.send('Such a padname is forbidden.', 404);
return;
} else if ( /(favicon\.ico|robots\.txt)/.test(req.url) )
{ {
res.send('Such a padname is forbidden', 404); next();
return; return;
} }
res.header("Server", serverName); res.header("Server", serverName);
var filePath = path.normalize(__dirname + "/../static/pad.html"); var filePath = path.normalize(__dirname + "/../static/pad.html");
res.sendfile(filePath, { maxAge: exports.maxAge }); res.sendfile(filePath, { maxAge: exports.maxAge });
}); });
//serve timeslider.html under /p/$padname/timeslider //serve timeslider.html under /$padname/timeslider
app.get('/p/:pad/timeslider', function(req, res, next) app.get('/:pad/timeslider', function(req, res, next)
{ {
//ensure the padname is valid and the url doesn't end with a / //ensure the padname is valid and the url doesn't end with a /
if(!padManager.isValidPadId(req.params.pad) || /\/$/.test(req.url)) if(!padManager.isValidPadId(req.params.pad) || /\/$/.test(req.url))
@ -227,8 +230,8 @@ async.waterfall([
res.sendfile(filePath, { maxAge: exports.maxAge }); res.sendfile(filePath, { maxAge: exports.maxAge });
}); });
//serve timeslider.html under /p/$padname/timeslider //serve export files under /$padname/export
app.get('/p/:pad/export/:type', function(req, res, next) app.get('/:pad/export/:type', function(req, res, next)
{ {
//ensure the padname is valid and the url doesn't end with a / //ensure the padname is valid and the url doesn't end with a /
if(!padManager.isValidPadId(req.params.pad) || /\/$/.test(req.url)) if(!padManager.isValidPadId(req.params.pad) || /\/$/.test(req.url))
@ -262,7 +265,7 @@ async.waterfall([
}); });
//handle import requests //handle import requests
app.post('/p/:pad/import', function(req, res, next) app.post('/:pad/import', function(req, res, next)
{ {
//ensure the padname is valid and the url doesn't end with a / //ensure the padname is valid and the url doesn't end with a /
if(!padManager.isValidPadId(req.params.pad) || /\/$/.test(req.url)) if(!padManager.isValidPadId(req.params.pad) || /\/$/.test(req.url))
@ -343,7 +346,7 @@ async.waterfall([
}); });
//serve robots.txt //serve robots.txt
app.get('/robots.txt', function(req, res) app.get( /.*\/robots.txt/, function(req, res)
{ {
res.header("Server", serverName); res.header("Server", serverName);
var filePath = path.normalize(__dirname + "/../static/robots.txt"); var filePath = path.normalize(__dirname + "/../static/robots.txt");
@ -351,7 +354,7 @@ async.waterfall([
}); });
//serve favicon.ico //serve favicon.ico
app.get('/favicon.ico', function(req, res) app.get( /.*\/favicon\.ico/, function(req, res)
{ {
res.header("Server", serverName); res.header("Server", serverName);
var filePath = path.normalize(__dirname + "/../static/custom/favicon.ico"); var filePath = path.normalize(__dirname + "/../static/custom/favicon.ico");

View file

@ -1,6 +1,6 @@
<!doctype html> <!doctype html>
<html> <html>
<title>Etherpad Lite</title> <title>Etherpad</title>
<style> <style>
*{ margin:0;padding:0; } *{ margin:0;padding:0; }
body { body {
@ -39,7 +39,7 @@
text-shadow: 0 -1px 0 rgba(0,0,0,.8); text-shadow: 0 -1px 0 rgba(0,0,0,.8);
height: 70px; height: 70px;
line-height: 70px; line-height: 70px;
width: 300px; width: 500px;
background: #555; background: #555;
background: -webkit-linear-gradient(#5F5F5F,#565656 50%,#4C4C4C 51%,#373737); background: -webkit-linear-gradient(#5F5F5F,#565656 50%,#4C4C4C 51%,#373737);
background: -moz-linear-gradient(#5F5F5F,#565656 50%,#4C4C4C 51%,#373737); background: -moz-linear-gradient(#5F5F5F,#565656 50%,#4C4C4C 51%,#373737);
@ -62,7 +62,7 @@
#label { #label {
text-align: left; text-align: left;
margin: 0 auto; margin: 0 auto;
width: 300px width: 500px
} }
input { input {
vertical-align: middle; vertical-align: middle;
@ -70,7 +70,7 @@
font-size: 15px font-size: 15px
} }
input[type="text"] { input[type="text"] {
width: 243px; width: 443px; /* 243px */
padding: 10px 47px 10px 10px; padding: 10px 47px 10px 10px;
background: #fff; background: #fff;
border: 1px solid #bbb; border: 1px solid #bbb;
@ -88,29 +88,22 @@
</style> </style>
<link href="static/custom/index.css" rel="stylesheet"> <link href="static/custom/index.css" rel="stylesheet">
<script src="static/custom/index.js"></script> <script src="static/custom/index.js"></script>
<div id="container">
<div id="button" onclick="go2Random()">New Pad</div><br><div id="label">or create/open a Pad with the name</div>
<form action="#" onsubmit="go2Name();return false;">
<input type="text" id="padname" autofocus>
<input type="submit" value="OK">
</form>
</div>
<script> <script>
function go2Name() function go2Name()
{ {
var padname = document.getElementById("padname").value; var padname = document.getElementById("padname").value;
padname.length > 0 ? window.location = "p/" + padname : alert("Please enter a name") padname.length > 0 ? window.location = /** "p/" + **/ padname : alert("Please enter a name")
} }
function go2Random() function go2Random()
{ {
window.location = "p/" + randomPadName(); window.location = /** "p/" + **/ randomPadName();
} }
function randomPadName() function randomPadName()
{ {
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; var chars = "23456789ABCDEFGHJKLMNPQRSTUWXYZabcdefghijkmnopqrstuwxyz";
var string_length = 10; var string_length = 16;
var randomstring = ''; var randomstring = '';
for (var i = 0; i < string_length; i++) for (var i = 0; i < string_length; i++)
{ {
@ -123,4 +116,11 @@
//start the costum js //start the costum js
if(typeof costumStart == "function") costumStart(); if(typeof costumStart == "function") costumStart();
</script> </script>
<div id="container">
<div id="button" onclick="go2Random()" title="open a new pad with a generated random name like 'B3GYd74mn2yBH6'">create new random pad</div><br><div id="label">open an existing pad or create a new pad with the name</div>
<form action="#" onsubmit="go2Name();return false;">
<input type="text" id="padname" autofocus>
<input type="submit" value="OK">
</form>
</div>
</html> </html>

File diff suppressed because one or more lines are too long