Browse Source

Added uploads handler

pull/2/head
NGPixel 8 years ago
parent
commit
405e23f01e
7 changed files with 77 additions and 4 deletions
  1. 2
      assets/js/app.js
  2. 24
      client/js/components/editor-image.js
  3. 6
      client/js/components/editor.js
  4. 33
      controllers/uploads.js
  5. 11
      models/git.js
  6. 3
      server.js
  7. 2
      views/modals/editor-image.pug

2
assets/js/app.js
File diff suppressed because it is too large
View File

24
client/js/components/editor-image.js

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

6
client/js/components/editor.js

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

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

11
models/git.js

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

3
server.js

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

2
views/modals/editor-image.pug

@ -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'})

Loading…
Cancel
Save