mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-20 15:36:16 -04:00
Read only access works
This commit is contained in:
parent
1c1e035bf1
commit
93ccbaef3a
3 changed files with 82 additions and 10 deletions
|
@ -60,6 +60,15 @@ exports.getReadOnlyId = function (padId, callback)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns a the padId for a read only id
|
||||||
|
* @param {String} readOnlyId read only id
|
||||||
|
*/
|
||||||
|
exports.getPadId = function(readOnlyId, callback)
|
||||||
|
{
|
||||||
|
db.get("readonly2pad:" + readOnlyId, callback);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates a random String with the given length. Is needed to generate the read only ids
|
* Generates a random String with the given length. Is needed to generate the read only ids
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
*/
|
*/
|
||||||
var async = require("async");
|
var async = require("async");
|
||||||
var Changeset = require("../Changeset");
|
var Changeset = require("../Changeset");
|
||||||
|
var padManager = require("../PadManager");
|
||||||
|
|
||||||
|
|
||||||
function getPadPlainText(pad, revNum) {
|
function getPadPlainText(pad, revNum) {
|
||||||
|
@ -307,7 +308,15 @@ function _analyzeLine(text, aline, apool) {
|
||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPadHTMLDocument(pad, revNum, noDocType, callback) {
|
exports.getPadHTMLDocument = function(padId, revNum, noDocType, callback) {
|
||||||
|
padManager.getPad(padId, function(err, pad)
|
||||||
|
{
|
||||||
|
if(err)
|
||||||
|
{
|
||||||
|
callback(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var head = (noDocType?'':'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" '+
|
var head = (noDocType?'':'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" '+
|
||||||
'"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n')+
|
'"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n')+
|
||||||
'<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">\n'+
|
'<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">\n'+
|
||||||
|
@ -315,7 +324,9 @@ function getPadHTMLDocument(pad, revNum, noDocType, callback) {
|
||||||
'<head>\n'+
|
'<head>\n'+
|
||||||
'<meta http-equiv="Content-type" content="text/html; charset=utf-8" />\n'+
|
'<meta http-equiv="Content-type" content="text/html; charset=utf-8" />\n'+
|
||||||
'<meta http-equiv="Content-Language" content="en-us" />\n'+
|
'<meta http-equiv="Content-Language" content="en-us" />\n'+
|
||||||
'<title>'+'/'+pad.getId()+'</title>\n'+
|
'<style> * { font-family: Arial, sans-serif;\n'+
|
||||||
|
'font-size: 13px;\n'+
|
||||||
|
'line-height: 17px; }</style>\n' +
|
||||||
'</head>\n')+
|
'</head>\n')+
|
||||||
'<body>';
|
'<body>';
|
||||||
|
|
||||||
|
@ -324,6 +335,7 @@ function getPadHTMLDocument(pad, revNum, noDocType, callback) {
|
||||||
getPadHTML(pad, revNum, function (err, html) {
|
getPadHTML(pad, revNum, function (err, html) {
|
||||||
callback(err, head + html + foot);
|
callback(err, head + html + foot);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function _escapeHTML(s) {
|
function _escapeHTML(s) {
|
||||||
|
@ -410,7 +422,3 @@ function _findURLs(text) {
|
||||||
|
|
||||||
return urls;
|
return urls;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
exports.getPadHTML = getPadHTML;
|
|
||||||
exports.getPadHTMLDocument = getPadHTMLDocument;
|
|
|
@ -31,6 +31,8 @@ var async = require('async');
|
||||||
var express = require('express');
|
var express = require('express');
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var minify = require('./minify');
|
var minify = require('./minify');
|
||||||
|
var exporthtml;
|
||||||
|
var readOnlyManager;
|
||||||
|
|
||||||
//try to get the git version
|
//try to get the git version
|
||||||
var version = "";
|
var version = "";
|
||||||
|
@ -63,6 +65,10 @@ async.waterfall([
|
||||||
//create server
|
//create server
|
||||||
var app = express.createServer();
|
var app = express.createServer();
|
||||||
|
|
||||||
|
//load modules that needs a initalized db
|
||||||
|
readOnlyManager = require("./ReadOnlyManager");
|
||||||
|
exporthtml = require("./exporters/exporthtml");
|
||||||
|
|
||||||
//set logging
|
//set logging
|
||||||
if(settings.logHTTP)
|
if(settings.logHTTP)
|
||||||
app.use(express.logger({ format: ':date: :status, :method :url' }));
|
app.use(express.logger({ format: ':date: :status, :method :url' }));
|
||||||
|
@ -92,6 +98,55 @@ async.waterfall([
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//serve read only pad
|
||||||
|
app.get('/ro/:id', function(req, res)
|
||||||
|
{
|
||||||
|
res.header("Server", serverName);
|
||||||
|
|
||||||
|
var html;
|
||||||
|
var padId;
|
||||||
|
var pad;
|
||||||
|
|
||||||
|
async.series([
|
||||||
|
//translate the read only pad to a padId
|
||||||
|
function(callback)
|
||||||
|
{
|
||||||
|
readOnlyManager.getPadId(req.params.id, function(err, _padId)
|
||||||
|
{
|
||||||
|
padId = _padId;
|
||||||
|
callback(err);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
//render the html document
|
||||||
|
function(callback)
|
||||||
|
{
|
||||||
|
//return if the there is no padId
|
||||||
|
if(padId == null)
|
||||||
|
{
|
||||||
|
callback("notfound");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//render the html document
|
||||||
|
exporthtml.getPadHTMLDocument(padId, null, false, function(err, _html)
|
||||||
|
{
|
||||||
|
html = _html;
|
||||||
|
callback(err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
], function(err)
|
||||||
|
{
|
||||||
|
//throw any unexpected error
|
||||||
|
if(err && err != "notfound")
|
||||||
|
throw err;
|
||||||
|
|
||||||
|
if(err == "notfound")
|
||||||
|
res.send('404 - Not Found', 404);
|
||||||
|
else
|
||||||
|
res.send(html);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
//serve pad.html under /p
|
//serve pad.html under /p
|
||||||
app.get('/p/:pad', function(req, res, next)
|
app.get('/p/:pad', function(req, res, next)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue