Fix issues caused by acts not using req.area

master
kts of kettek (muzukashi) 2016-06-22 23:51:11 -07:00
parent 879437b96e
commit 6161d963a3
8 changed files with 38 additions and 38 deletions

View File

@ -1,7 +1,7 @@
var fs = require('fs'); var fs = require('fs');
module.exports = function(qwiki) { module.exports = function(qwiki) {
qwiki.rule('', '@@CONTENT@@', function(req, res, instance, next) { qwiki.rule('', '@@CONTENT@@', function(req, res, instance, next) {
var area = req.url; var area = req.area;
if (area == '') { if (area == '') {
area = 'front'; area = 'front';
} }
@ -29,7 +29,7 @@ module.exports = function(qwiki) {
res.write(area + ': ' + err.code); res.write(area + ': ' + err.code);
next(); next();
} else { } else {
qwiki.convertAndSave(area, (req.url in qwiki.wiki_index.pages ? qwiki.wiki_index.pages[req.url].format : qwiki.getDefault('format')), data, function() { qwiki.convertAndSave(area, (req.area in qwiki.wiki_index.pages ? qwiki.wiki_index.pages[req.area].format : qwiki.getDefault('format')), data, function() {
qwiki.readFile(res, wiki_path, function(type, err) { qwiki.readFile(res, wiki_path, function(type, err) {
if (type == 'FNF') { if (type == 'FNF') {
res.write('error while creating cache'); res.write('error while creating cache');
@ -55,19 +55,19 @@ module.exports = function(qwiki) {
}); });
}); });
qwiki.rule('', '@@TITLE@@', function(req, res, instance, next) { qwiki.rule('', '@@TITLE@@', function(req, res, instance, next) {
res.write('qwiki ' + req.url); res.write('qwiki ' + req.area);
next(); next();
}); });
qwiki.rule('', '@@PAGE@@', function(req, res, instance, next) { qwiki.rule('', '@@PAGE@@', function(req, res, instance, next) {
res.write(req.url); res.write(req.area);
next(); next();
}); });
qwiki.rule('', '@@CONTROLS@@', function(req, res, instance, next) { qwiki.rule('', '@@CONTROLS@@', function(req, res, instance, next) {
res.write('<li><a href="'+req.url+'/edit"><img src="/edit.png">Edit</a></li><li><a href="'+req.url+'/new"><img src="/new.png">New Page</a></li><li><a href="'+req.url+'/upload"><img src="/upload.png">Upload</a></li><li><a href="./index"><img src="/file_dir.png">Index</a></li>'); res.write('<li><a href="'+req.area+'/edit"><img src="/edit.png">Edit</a></li><li><a href="'+req.area+'/new"><img src="/new.png">New Page</a></li><li><a href="'+req.area+'/upload"><img src="/upload.png">Upload</a></li><li><a href="./index"><img src="/file_dir.png">Index</a></li>');
next(); next();
}); });
qwiki.rule('', '@@CRUMBS@@', function(req, res, instance, next) { qwiki.rule('', '@@CRUMBS@@', function(req, res, instance, next) {
var parts = req.url.split('/'); var parts = req.area.split('/');
var path = ''; var path = '';
parts[0] = '>'; parts[0] = '>';
for (var i = 0; i < parts.length; i++) { for (var i = 0; i < parts.length; i++) {
@ -82,11 +82,11 @@ module.exports = function(qwiki) {
next(); next();
}); });
qwiki.act('', function(req, res) { qwiki.act('', function(req, res) {
var ext = qwiki.getExt(req.url); var ext = qwiki.getExt(req.area);
var mimetype = qwiki.getMIMEtype(qwiki.getExt(req.url)); var mimetype = qwiki.getMIMEtype(qwiki.getExt(req.area));
if (mimetype == '') mimetype = 'application/octet-stream'; if (mimetype == '') mimetype = 'application/octet-stream';
if (ext != '') { // write file on disk directly if (ext != '') { // write file on disk directly
var path = 'wiki/'+req.url; var path = 'wiki/'+req.area;
fs.stat(path, function(err, stat) { fs.stat(path, function(err, stat) {
if (err == null) { if (err == null) {
// TODO: etags should actually be based on binary data(CRC32, etc.), not last modified // TODO: etags should actually be based on binary data(CRC32, etc.), not last modified

View File

@ -9,7 +9,7 @@ module.exports = function(qwiki) {
next() next()
}); });
qwiki.act('delete', function(req, res) { qwiki.act('delete', function(req, res) {
var area = (req.url == '' ? 'front' : req.url.substr(1)); var area = (req.area == '' ? 'front' : req.area);
// handle POST // handle POST
if ('submit' in req.fields) { if ('submit' in req.fields) {
if (req.fields['submit'] == 'Yes') { if (req.fields['submit'] == 'Yes') {
@ -17,8 +17,8 @@ module.exports = function(qwiki) {
if (err == null) { if (err == null) {
qwiki.deletePage(area, function() { qwiki.deletePage(area, function() {
qwiki.deleteCache(area, function() { qwiki.deleteCache(area, function() {
console.log('redirecting to '+req.url); console.log('redirecting to '+req.area);
res.writeHead(302, {'Location': req.url}); res.writeHead(302, {'Location': req.area});
res.end(); res.end();
}); });
}); });
@ -49,7 +49,7 @@ module.exports = function(qwiki) {
}); });
return; return;
} else { } else {
res.writeHead(302, {'Location': req.url+'/edit'}); res.writeHead(302, {'Location': req.area+'/edit'});
res.end(); res.end();
} }
} else { } else {

View File

@ -1,7 +1,7 @@
var fs = require('fs'); var fs = require('fs');
module.exports = function(qwiki) { module.exports = function(qwiki) {
qwiki.rule('edit', '@@CONTENT@@', function(req, res, instance, next) { qwiki.rule('edit', '@@CONTENT@@', function(req, res, instance, next) {
var area = (req.url == '' ? 'front' : req.url.substr(1)); var area = (req.area == '' ? 'front' : req.area);
var path = 'wiki/'+area+'.qwk'; var path = 'wiki/'+area+'.qwk';
res.write('<form action="" method="POST"><div class="edit"><div><label for="page"><span>This is the page name that corresponds to the wiki URL, e.g., my_page => kettek.net/qwiki/my_page</span>Page</label> <input type="text" name="page" value="'+area+'"></div>'); res.write('<form action="" method="POST"><div class="edit"><div><label for="page"><span>This is the page name that corresponds to the wiki URL, e.g., my_page => kettek.net/qwiki/my_page</span>Page</label> <input type="text" name="page" value="'+area+'"></div>');
res.write('<div><label for="format"><span>This is the data format of content source, such as HTML or raw.</span>Format</label> <select name="format">'); res.write('<div><label for="format"><span>This is the data format of content source, such as HTML or raw.</span>Format</label> <select name="format">');
@ -21,11 +21,11 @@ module.exports = function(qwiki) {
}); });
}); });
qwiki.rule('edit', '@@CONTROLS@@', function(req, res, instance, next) { qwiki.rule('edit', '@@CONTROLS@@', function(req, res, instance, next) {
res.write('<li><a href="'+(req.url == '' ? '/' : req.url)+'"><img src="/view.png">View</a></li><li><a href="'+req.url+'/revisions"><img src="/revisions.png">Revisions</a></li><li><a href="'+req.url+'/delete"><img src="/delete.png">Delete</a></li>'); res.write('<li><a href="'+(req.area == '' ? '/' : req.area)+'"><img src="/view.png">View</a></li><li><a href="'+req.area+'/revisions"><img src="/revisions.png">Revisions</a></li><li><a href="'+req.area+'/delete"><img src="/delete.png">Delete</a></li>');
next(); next();
}); });
qwiki.act('edit', function(req, res) { qwiki.act('edit', function(req, res) {
var area = (req.url == '' ? 'front' : req.url.substr(1)); var area = (req.area == '' ? 'front' : req.area);
// handle POST // handle POST
if ('submit' in req.fields && req.fields['submit'] == 'save') { if ('submit' in req.fields && req.fields['submit'] == 'save') {
var old_area = area; var old_area = area;
@ -79,7 +79,7 @@ module.exports = function(qwiki) {
res.write(err.code); res.write(err.code);
res.end(); res.end();
} else { } else {
res.writeHead(302, {'Location': '/'+area+'/edit'}); res.writeHead(302, {'Location': req.url});
res.end(); res.end();
} }
}); });

View File

@ -2,12 +2,12 @@
var fs = require('fs'); var fs = require('fs');
module.exports = function(qwiki) { module.exports = function(qwiki) {
qwiki.rule('index', '@@CONTENT@@', function(req, res, instance, next) { qwiki.rule('index', '@@CONTENT@@', function(req, res, instance, next) {
var path = 'wiki/'+req.url; var path = 'wiki/'+req.area;
qwiki.readDirectory(path, function(err, files) { qwiki.readDirectory(path, function(err, files) {
if (err) { if (err) {
console.log('err: ' + err); console.log('err: ' + err);
if (err.errno == -2) { // ENOENT if (err.errno == -2) { // ENOENT
res.write('Cannot index "' + req.url + '" as it does not exist'); // FIXME: do actual errors res.write('Cannot index "' + req.area + '" as it does not exist'); // FIXME: do actual errors
} }
res.write('Error: ' + err); res.write('Error: ' + err);
next(); next();
@ -33,25 +33,25 @@ module.exports = function(qwiki) {
if (a_ext != 'qwk' && b_ext == 'qwk') return 1; if (a_ext != 'qwk' && b_ext == 'qwk') return 1;
else return 0; else return 0;
});*/ });*/
res.write('<h2>Index of '+req.url+'</h2>'); res.write('<h2>Index of '+req.area+'</h2>');
res.write('<ul id="act_index">') res.write('<ul id="act_index">')
if (req.url != '') { if (req.area != '') {
res.write('<li><a class="file_dir" href="'+req.url+'/../index">..</a></li>'); res.write('<li><a class="file_dir" href="'+req.area+'/../index">..</a></li>');
} }
for (var file in files) { for (var file in files) {
var name = ''; var name = '';
res.write('<li>'); res.write('<li>');
if (qwiki.getExt(files[file].name) == 'qwk') { if (qwiki.getExt(files[file].name) == 'qwk') {
name = files[file].name.slice(0, -4); name = files[file].name.slice(0, -4);
res.write('<a class="file_qwk" href="'+req.url+'/'+name+'">'+name+'</a>'); res.write('<a class="file_qwk" href="'+req.area+'/'+name+'">'+name+'</a>');
res.write (' <a class="file_delete" href="'+req.url+'/'+name+'/delete">Delete</a>'); res.write (' <a class="file_delete" href="'+req.area+'/'+name+'/delete">Delete</a>');
} else { } else {
name = files[file].name; name = files[file].name;
if (files[file].is_dir) { if (files[file].is_dir) {
res.write('<a class="file_dir" href="'+req.url+'/'+name+'/index">'+name+'/</a>'); res.write('<a class="file_dir" href="'+req.area+'/'+name+'/index">'+name+'/</a>');
} else { } else {
res.write('<a class="file_other" href="'+req.url+'/'+name+'">'+name+'</a>'); res.write('<a class="file_other" href="'+req.area+'/'+name+'">'+name+'</a>');
res.write (' <a class="file_delete" href="'+req.url+'/'+name+'/delete">Delete</a>'); res.write (' <a class="file_delete" href="'+req.area+'/'+name+'/delete">Delete</a>');
} }
} }
res.write('</li>'); res.write('</li>');
@ -61,7 +61,7 @@ module.exports = function(qwiki) {
}); });
}); });
qwiki.rule('index', '@@CONTROLS@@', function(req, res, instance, next) { qwiki.rule('index', '@@CONTROLS@@', function(req, res, instance, next) {
res.write('<li><a href="'+(req.url == '' ? '/' : req.url)+'"><img src="/view.png">View</a></li><li><a href="'+req.url+'/upload"><img src="/upload.png">Upload</a></li>'); res.write('<li><a href="'+(req.area == '' ? '/' : req.area)+'"><img src="/view.png">View</a></li><li><a href="'+req.area+'/upload"><img src="/upload.png">Upload</a></li>');
next(); next();
}); });
qwiki.act('index', function(req, res) { qwiki.act('index', function(req, res) {

View File

@ -1,12 +1,12 @@
module.exports = function(qwiki) { module.exports = function(qwiki) {
qwiki.rule('new', '@@CONTENT@@', function(req, res, instance, next) { qwiki.rule('new', '@@CONTENT@@', function(req, res, instance, next) {
var area = req.url; var area = req.area;
if (area == '') { if (area == '') {
area = 'new_page'; area = 'new_page';
} else { } else {
area = req.url.substr(1) + '/new_page'; area = req.area + '/new_page';
} }
var path = 'wiki/'+req.url+'.qwk'; var path = 'wiki/'+req.area+'.qwk';
res.write('<form action="" method="POST"><div class="edit"><div><label for="page"><span>This is the page name that corresponds to the wiki URL, e.g., my_page => kettek.net/qwiki/my_page</span>Page</label> <input type="text" name="page" value="'+area+'"></div>'); res.write('<form action="" method="POST"><div class="edit"><div><label for="page"><span>This is the page name that corresponds to the wiki URL, e.g., my_page => kettek.net/qwiki/my_page</span>Page</label> <input type="text" name="page" value="'+area+'"></div>');
res.write('</div><div class="prompt"><input type="submit" name="submit" value="edit"></div></form>'); res.write('</div><div class="prompt"><input type="submit" name="submit" value="edit"></div></form>');
next(); next();

View File

@ -1,8 +1,8 @@
module.exports = function(qwiki) { module.exports = function(qwiki) {
// **** REVISIONS // **** REVISIONS
qwiki.rule('revisions', '@@CONTENT@@', function(req, res, instance, next) { qwiki.rule('revisions', '@@CONTENT@@', function(req, res, instance, next) {
var path = 'wiki/'+req.url+'.qwk'; var path = 'wiki/'+req.area+'.qwk';
res.write('revisions for ' + req.url.substr(1)); res.write('revisions for ' + req.area);
next() next()
}); });
qwiki.act('revisions', function(req, res) { qwiki.act('revisions', function(req, res) {

View File

@ -11,7 +11,7 @@ module.exports = function(qwiki) {
res.write('<h2>Upload</h2>'); res.write('<h2>Upload</h2>');
var wiki_path = process.cwd() + '/wiki/'; var wiki_path = process.cwd() + '/wiki/';
if (typeof req.files.file !== 'undefined') { if (typeof req.files.file !== 'undefined') {
var loc_path = (typeof req.fields.location !== 'undefined' ? req.fields.location+'/' : req.url+'/'); var loc_path = (typeof req.fields.location !== 'undefined' ? req.fields.location+'/' : req.area+'/');
var total = 0; var total = 0;
if (req.files.file instanceof Array) { if (req.files.file instanceof Array) {
for (var i = 0, len = req.files.file.length; i < len; i++) { for (var i = 0, len = req.files.file.length; i < len; i++) {
@ -58,7 +58,7 @@ module.exports = function(qwiki) {
function end(req, res) { function end(req, res) {
res.write('<form enctype="multipart/form-data" action="" method="POST"><div class="edit">'); res.write('<form enctype="multipart/form-data" action="" method="POST"><div class="edit">');
res.write('<div><label for="file"><span>These are the file(s) to upload</span>File(s)</label> <input type="file" name="file" multiple></div>'); res.write('<div><label for="file"><span>These are the file(s) to upload</span>File(s)</label> <input type="file" name="file" multiple></div>');
res.write('<div><label for="location"><span>This is the target location to save the file(s) to</span>Location</label> <input type="text" name="location" value="'+req.url+'"></div>'); res.write('<div><label for="location"><span>This is the target location to save the file(s) to</span>Location</label> <input type="text" name="location" value="'+req.area+'"></div>');
res.write('</div>'); res.write('</div>');
res.write('<div class="prompt"><input type="submit" name="submit" value="Upload"></div>'); res.write('<div class="prompt"><input type="submit" name="submit" value="Upload"></div>');
res.write('</form>'); res.write('</form>');

View File

@ -1,10 +1,10 @@
module.exports = function(qwiki) { module.exports = function(qwiki) {
// **** VIEW // **** VIEW
qwiki.act('view', function(req, res) { qwiki.act('view', function(req, res) {
if (req.url == '') { if (req.area == '') {
req.url = 'index'; req.area = 'index';
} }
var path = 'wiki/'+req.url+'.qwk'; var path = 'wiki/'+req.area+'.qwk';
qwiki.readFile(res, path, function(type, err) { qwiki.readFile(res, path, function(type, err) {
if (type == 'FNF') { if (type == 'FNF') {