Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions data
Submodule data added at 7ea599
35 changes: 35 additions & 0 deletions lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var express = require("express"),
gravatar = require("gravatar"),
passport = require("passport"),
methodOverride = require("method-override"),
multer = require("multer"),
flash = require("express-flash");

var app;
Expand Down Expand Up @@ -179,6 +180,40 @@ module.exports.initialize = function (config) {
}
}

// 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 rep_file_name = req.body.rep_file_name;
var rep_file = app.locals.config.get("application").repository + "/uploads/" + rep_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/" + rep_file_name + "</pre>";
res.render("upload_status", {message: output_msg});
});
});
});
});

app.all("/pages/*", requireAuthentication);

if (!app.locals.config.get("authorization").anonRead) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"passport-local": "^1.0.0",
"semver": "^2.3.2",
"serve-favicon": "^2.1.7",
"multer": "*",
"transliteration": "^0.1.1"
},
"devDependencies": {
Expand Down
3 changes: 3 additions & 0 deletions public/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,9 @@ ul.doc-list > li .message {
.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;
Expand Down
Binary file added public/img/upload_16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 14 additions & 2 deletions public/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,13 @@
$('form.edit').submit();
},

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");
Expand All @@ -201,10 +208,12 @@

$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"));
<li title=\"Preview\" class=\"preview\"><span></span></li>\
</ul>").insertBefore($("form.edit textarea:first").closest("div"));

$("ul.toolbar").on("click", "span", function () {
$("ul.toolbar").on("click", "span", function() {
if (this.parentNode.className == "info") {
Jingo.markdownSyntax();
}
Expand All @@ -215,6 +224,9 @@
if (this.parentNode.className == "fullscreen") {
Jingo.toggleFullscreen();
}
if (this.parentNode.className == "upload") {
Jingo.upload();
}
});
},

Expand Down
9 changes: 9 additions & 0 deletions public/js/upload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
$(document).ready(function() {
$("#wiki_upload").ajaxForm(function(response) {
$('#upload_status').html(response);
});
$("input#wiki_file").change(function() {
var filename = $(this).val().replace(/^.*[\\\/]/, '')
$("input#rep_file_name").val(filename);
});
});
11 changes: 11 additions & 0 deletions public/vendor/jquery.form.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions routes/misc.js
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -8,6 +9,7 @@ models.use(Git);
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");
Expand All @@ -19,6 +21,20 @@ function _postPreview(req, res) {
});
}

function _getUploadForm(req, res) {
if (!res.locals.user) {
res.render("404", {
title: 'Modules'
});
return;
}

res.render("upload", {
config: app.locals.config.get("application").repository,
message: 'Ready to upload.'
});
}

function _getExistence(req, res) {

if (!req.query.data) {
Expand Down
Loading