Added uploads handler

pull/2/head
NGPixel 8 years ago
parent 1dcd11570a
commit 405e23f01e

File diff suppressed because one or more lines are too long

@ -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();
}
}
});

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

@ -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;

@ -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 * Sync with the remote repository
* *

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

@ -23,7 +23,7 @@
p.control p.control
a.button.is-warning.is-outlined(v-on:click="cancel") Cancel a.button.is-warning.is-outlined(v-on:click="cancel") Cancel
p.control 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 .columns
.column.is-one-quarter(style={'max-width':'350px'}) .column.is-one-quarter(style={'max-width':'350px'})

Loading…
Cancel
Save