Created
September 19, 2015 07:48
-
-
Save czenzel/5c3c54c85207d85c1f15 to your computer and use it in GitHub Desktop.
Add File Uploads to Jingo Node.JS Wiki
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Only in jingo-uploads: .DS_Store | |
Only in jingo-master: .git | |
Only in jingo-uploads/lib: .DS_Store | |
diff -crB jingo-master/lib/app.js jingo-uploads/lib/app.js | |
*** jingo-master/lib/app.js 2015-09-19 03:43:52.000000000 -0400 | |
--- jingo-uploads/lib/app.js 2015-09-19 02:57:35.000000000 -0400 | |
*************** | |
*** 24,29 **** | |
--- 24,30 ---- | |
gravatar = require("gravatar"), | |
passport = require("passport"), | |
methodOverride = require("method-override"), | |
+ multer = require("multer"), | |
flash = require("express-flash") | |
; | |
*************** | |
*** 170,175 **** | |
--- 172,211 ---- | |
} | |
} | |
+ // File Uploads | |
+ var upload = multer({ dest: app.locals.config.get("application").repository + '/uploads/' }); | |
+ | |
+ app.use('/uploads', express.static(app.locals.config.get("application").repository + '/uploads')); | |
+ | |
+ app.post('/uploadFile', upload.single('wiki_file'), function (req, res, next) { | |
+ if (!res.locals.user) { | |
+ return; | |
+ } | |
+ | |
+ var file_name = req.file.originalname; | |
+ var rep_file = app.locals.config.get("application").repository + '/uploads/' + file_name; | |
+ | |
+ var temp_file = req.file.path; | |
+ var output_msg = ""; | |
+ | |
+ var fs = require('fs'); | |
+ | |
+ fs.unlink(rep_file, function(err) { | |
+ }); | |
+ | |
+ fs.readFile(temp_file, function(err, data) { | |
+ fs.writeFile(rep_file, data, function(err) { | |
+ fs.unlink(temp_file, function() { | |
+ var git_msg = req.body.file_message; | |
+ Git.add(rep_file, git_msg, req.user.asGitAuthor, function(err) { | |
+ }); | |
+ output_msg = 'File uploaded to: <pre>/uploads/' + file_name + '</pre>'; | |
+ res.render('upload_status', {message: output_msg}); | |
+ }); | |
+ }); | |
+ }); | |
+ }); | |
+ | |
app.all("/pages/*", requireAuthentication); | |
if (!app.locals.config.get("authorization").anonRead) { | |
Only in jingo-uploads/public: .DS_Store | |
diff -crB jingo-master/public/css/style.css jingo-uploads/public/css/style.css | |
*** jingo-master/public/css/style.css 2015-09-19 03:43:52.000000000 -0400 | |
--- jingo-uploads/public/css/style.css 2015-09-19 00:03:47.000000000 -0400 | |
*************** | |
*** 460,465 **** | |
--- 460,468 ---- | |
.toolbar li.preview span { | |
background-image:url(../img/preview_16.png); | |
} | |
+ .toolbar li.upload span { | |
+ background-image:url(../img/upload_16.png); | |
+ } | |
.toolbar.fullscreen { | |
position: fixed; | |
Only in jingo-uploads/public/img: upload_16.png | |
diff -crB jingo-master/public/js/app.js jingo-uploads/public/js/app.js | |
*** jingo-master/public/js/app.js 2015-09-19 03:43:52.000000000 -0400 | |
--- jingo-uploads/public/js/app.js 2015-09-19 02:46:04.000000000 -0400 | |
*************** | |
*** 165,170 **** | |
--- 165,177 ---- | |
}); | |
}, | |
+ upload: function() { | |
+ $("#upload").modal({keyboard: true, show: true, backdrop: false}); | |
+ $.get("/misc/upload", function(data) { | |
+ $("#upload .modal-body").html(data).get(0).scrollTop = 0; | |
+ }); | |
+ }, | |
+ | |
toggleFullscreen: function() { | |
var isFullscreen = Jingo.cmInstance.getOption("fullScreen"); | |
*************** | |
*** 179,186 **** | |
$toolbar = $("<ul class='toolbar'>"); | |
$toolbar.append("<li title=\"Toggle fullscreen (Ctrl/Cmd+Enter)\" class=\"fullscreen\"><span></span></li>\ | |
<li title=\"Syntax help\" class=\"info\"><span></span></li>\ | |
! <li title=\"Preview\" class=\"preview\"><span></span></li></ul>").insertBefore($("form.edit textarea:first").closest("div")); | |
$("ul.toolbar").on("click", "span", function() { | |
if (this.parentNode.className == "info") { | |
--- 186,195 ---- | |
$toolbar = $("<ul class='toolbar'>"); | |
$toolbar.append("<li title=\"Toggle fullscreen (Ctrl/Cmd+Enter)\" class=\"fullscreen\"><span></span></li>\ | |
+ <li title=\"Upload\" class=\"upload\"><span></span></li>\ | |
<li title=\"Syntax help\" class=\"info\"><span></span></li>\ | |
! <li title=\"Preview\" class=\"preview\"><span></span></li>\ | |
! </ul>").insertBefore($("form.edit textarea:first").closest("div")); | |
$("ul.toolbar").on("click", "span", function() { | |
if (this.parentNode.className == "info") { | |
*************** | |
*** 193,198 **** | |
--- 202,210 ---- | |
if (this.parentNode.className == "fullscreen") { | |
Jingo.toggleFullscreen(); | |
} | |
+ if (this.parentNode.className == "upload") { | |
+ Jingo.upload(); | |
+ } | |
}); | |
}, | |
Only in jingo-uploads/public/vendor: .DS_Store | |
Only in jingo-uploads/public/vendor: jquery.form.min.js | |
Only in jingo-uploads/public/vendor/markitup: .DS_Store | |
diff -crB jingo-master/routes/misc.js jingo-uploads/routes/misc.js | |
*** jingo-master/routes/misc.js 2015-09-19 03:43:52.000000000 -0400 | |
--- jingo-uploads/routes/misc.js 2015-09-19 02:34:02.000000000 -0400 | |
*************** | |
*** 1,4 **** | |
--- 1,5 ---- | |
var router = require("express").Router(), | |
+ app = require("../lib/app").getInstance(), | |
renderer = require('../lib/renderer'), | |
fs = require("fs"), | |
models = require("../lib/models"); | |
*************** | |
*** 8,13 **** | |
--- 9,15 ---- | |
router.get("/misc/syntax-reference", _getSyntaxReference); | |
router.post("/misc/preview", _postPreview); | |
router.get("/misc/existence", _getExistence); | |
+ router.get("/misc/upload", _getUploadForm); | |
function _getSyntaxReference(req, res) { | |
res.render('syntax'); | |
*************** | |
*** 19,24 **** | |
--- 21,33 ---- | |
}); | |
} | |
+ function _getUploadForm(req, res) { | |
+ res.render('upload', { | |
+ config: app.locals.config.get("application").repository, | |
+ message: 'Ready to upload.' | |
+ }); | |
+ } | |
+ | |
function _getExistence(req, res) { | |
if (!req.query.data) { | |
diff -crB jingo-master/routes/wiki.js jingo-uploads/routes/wiki.js | |
*** jingo-master/routes/wiki.js 2015-09-19 03:43:52.000000000 -0400 | |
--- jingo-uploads/routes/wiki.js 2015-09-18 23:51:58.000000000 -0400 | |
*************** | |
*** 89,95 **** | |
res.render("show", { | |
page: page, | |
title: app.locals.config.get("application").title + " – " + page.title, | |
! content: renderer.render("#" + page.title + "\n" + page.content) | |
}); | |
} | |
else { | |
--- 89,95 ---- | |
res.render("show", { | |
page: page, | |
title: app.locals.config.get("application").title + " – " + page.title, | |
! content: renderer.render("# " + page.title + "\n" + page.content) | |
}); | |
} | |
else { | |
Only in jingo-uploads/views: .DS_Store | |
diff -crB jingo-master/views/create.jade jingo-uploads/views/create.jade | |
*** jingo-master/views/create.jade 2015-09-19 03:43:52.000000000 -0400 | |
--- jingo-uploads/views/create.jade 2015-09-19 01:08:42.000000000 -0400 | |
*************** | |
*** 25,30 **** | |
--- 25,33 ---- | |
#preview(tabindex="-1",role="dialog",aria-hidden="true").modal | |
mixin dialogBox("Page preview") | |
+ #upload(tabindex="-1",role="dialog",aria-hidden="true").modal | |
+ mixin dialogBox("Upload a file") | |
+ | |
#syntax-reference(tabindex="-1",role="dialog",aria-hidden="true").modal | |
mixin dialogBox("Markdown cheatsheet") | |
diff -crB jingo-master/views/edit.jade jingo-uploads/views/edit.jade | |
*** jingo-master/views/edit.jade 2015-09-19 03:43:52.000000000 -0400 | |
--- jingo-uploads/views/edit.jade 2015-09-19 01:08:32.000000000 -0400 | |
*************** | |
*** 32,37 **** | |
--- 32,40 ---- | |
#preview(tabindex="-1",role="dialog",aria-hidden="true").modal | |
mixin dialogBox("Page preview") | |
+ #upload(tabindex="-1",role="dialog",aria-hidden="true").modal | |
+ mixin dialogBox("Upload a file") | |
+ | |
#syntax-reference(tabindex="-1",role="dialog",aria-hidden="true").modal | |
mixin dialogBox("Markdown cheatsheet") | |
diff -crB jingo-master/views/mixins/form.jade jingo-uploads/views/mixins/form.jade | |
*** jingo-master/views/mixins/form.jade 2015-09-19 03:43:52.000000000 -0400 | |
--- jingo-uploads/views/mixins/form.jade 2015-09-19 02:44:05.000000000 -0400 | |
*************** | |
*** 64,69 **** | |
--- 64,70 ---- | |
if hasFeature('markitup') | |
script(src="/vendor/jquery-migrate-1.1.0.min.js") | |
script(src="/vendor/markitup/jquery.markitup.js") | |
+ script(src="/vendor/jquery.form.min.js") | |
script(src="/vendor/markitup/sets/markdown/set.js") | |
script(src="/vendor/widearea/widearea.min.js") | |
script. | |
Only in jingo-uploads/views: upload.jade | |
Only in jingo-uploads/views: upload_status.jade |
You will also need a copy of jQuery.form.min.js
from: http://jquery.malsup.com/form/. Make sure you upload it to /vendor
in the scripts directory.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello everyone,
Here are some fixes and features I added within a few hours tonight to the Jingo Node.JS based wiki software package available on GitHub. These changes are based on the master branch located at https://github.com/claudioc/jingo.
Fixes:
Features:
Required Directories to be Created in the Repository:
Required Node.JS Modules to Install:
Required Icons:
/vendor/img
- upload_16I hope you find these fixes and features useful! Let me know!
Thanks,
Chris Zenzel