Added uploads handler

This commit is contained in:
NGPixel 2016-09-17 00:26:02 -04:00
parent 1dcd11570a
commit 405e23f01e
7 changed files with 77 additions and 4 deletions

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,24 @@
let vueImage = new Vue({
el: '#modal-editor-image',
data: {
modeSelected: 'text'
},
methods: {
cancel: (ev) => {
mdeModalOpenState = false;
$('#modal-editor-image').slideUp();
},
insertImage: (ev) => {
if(mde.codemirror.doc.somethingSelected()) {
mde.codemirror.execCommand('singleSelection');
}
let codeBlockText = '\n```' + vueCodeBlock.modeSelected + '\n' + codeEditor.getValue() + '\n```\n';
mde.codemirror.doc.replaceSelection(codeBlockText);
vueCodeBlock.cancel();
}
}
});

View File

@ -8,6 +8,7 @@ if($('#mk-editor').length === 1) {
let mdeModalOpenState = false;
let mdeCurrentEditor = null;
//=include editor-image.js
//=include editor-codeblock.js
var mde = new SimpleMDE({
@ -88,7 +89,10 @@ if($('#mk-editor').length === 1) {
{
name: "image",
action: (editor) => {
$('#modal-editor-image').slideDown();
if(!mdeModalOpenState) {
mdeModalOpenState = true;
$('#modal-editor-image').slideDown();
}
},
className: "fa fa-image",
title: "Insert Image",

33
controllers/uploads.js Normal file
View File

@ -0,0 +1,33 @@
"use strict";
var express = require('express');
var router = express.Router();
var _ = require('lodash');
var validPathRe = new RegExp("^([a-z0-9\\/-]+\\.[a-z0-9]+)$");
// ==========================================
// SERVE UPLOADS FILES
// ==========================================
router.get('/*', (req, res, next) => {
let fileName = req.params[0];
if(!validPathRe.test(fileName)) {
return res.sendStatus(404).end();
}
//todo: Authentication-based access
res.sendFile(fileName, {
root: git.getRepoPath() + '/uploads/',
dotfiles: 'deny'
}, (err) => {
if (err) {
res.status(err.status).end();
}
});
});
module.exports = router;

View File

@ -125,6 +125,17 @@ module.exports = {
},
/**
* Gets the repo path.
*
* @return {String} The repo path.
*/
getRepoPath() {
return this._repo.path || path.join(ROOTPATH, 'repo');
},
/**
* Sync with the remote repository
*

View File

@ -145,8 +145,9 @@ app.use(mw.flash);
app.use('/', ctrl.auth);
app.use('/', ctrl.pages);
app.use('/uploads', ctrl.uploads);
app.use('/admin', mw.auth, ctrl.admin);
app.use('/', ctrl.pages);
// ----------------------------------------
// Error handling

View File

@ -23,7 +23,7 @@
p.control
a.button.is-warning.is-outlined(v-on:click="cancel") Cancel
p.control
a.button.is-primary.is-outlined(v-on:click="insertCode") Insert Image
a.button.is-primary.is-outlined(v-on:click="insertImage") Insert Image
.columns
.column.is-one-quarter(style={'max-width':'350px'})