瀏覽代碼

Added uploads handler

NGPixel 8 年之前
父節點
當前提交
405e23f01e
共有 7 個文件被更改,包括 76 次插入3 次删除
  1. 0 0
      assets/js/app.js
  2. 24 0
      client/js/components/editor-image.js
  3. 5 1
      client/js/components/editor.js
  4. 33 0
      controllers/uploads.js
  5. 11 0
      models/git.js
  6. 2 1
      server.js
  7. 1 1
      views/modals/editor-image.pug

File diff suppressed because it is too large
+ 0 - 0
assets/js/app.js


+ 24 - 0
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();
+
+		}
+	}
+});

+ 5 - 1
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 - 0
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 - 0
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
 	 *

+ 2 - 1
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

+ 1 - 1
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'})

Some files were not shown because too many files changed in this diff