|
|
@@ -1,5 +1,6 @@
|
|
|
const logger = require('@alias/logger')('growi:routes:hackmd');
|
|
|
const path = require('path');
|
|
|
+const fs = require('graceful-fs');
|
|
|
const swig = require('swig-templates');
|
|
|
const axios = require('axios');
|
|
|
|
|
|
@@ -31,12 +32,10 @@ module.exports = function(crowi, app) {
|
|
|
}
|
|
|
|
|
|
const origin = `${req.protocol}://${req.get('host')}`;
|
|
|
- const styleFilePath = origin + manifest['styles/style-hackmd.css'];
|
|
|
|
|
|
// generate definitions to replace
|
|
|
const definitions = {
|
|
|
origin,
|
|
|
- styleFilePath,
|
|
|
};
|
|
|
// inject
|
|
|
const script = agentScriptContentTpl(definitions);
|
|
|
@@ -45,6 +44,24 @@ module.exports = function(crowi, app) {
|
|
|
res.send(script);
|
|
|
};
|
|
|
|
|
|
+ /**
|
|
|
+ * GET /_hackmd/load-styles
|
|
|
+ *
|
|
|
+ * loadStyles action
|
|
|
+ * This should be access from HackMD and send script to insert styles
|
|
|
+ *
|
|
|
+ * @param {object} req
|
|
|
+ * @param {object} res
|
|
|
+ */
|
|
|
+ const loadStyles = function(req, res) {
|
|
|
+ const styleFilePath = path.join(crowi.publicDir, manifest['styles/style-hackmd.css']);
|
|
|
+
|
|
|
+ const styles = fs.readFileSync(styleFilePath);
|
|
|
+
|
|
|
+ res.set('Content-Type', 'text/css');
|
|
|
+ res.send(styles);
|
|
|
+ };
|
|
|
+
|
|
|
const validateForApi = async function(req, res, next) {
|
|
|
// validate process.env.HACKMD_URI
|
|
|
const hackmdUri = process.env.HACKMD_URI;
|
|
|
@@ -145,6 +162,7 @@ module.exports = function(crowi, app) {
|
|
|
|
|
|
return {
|
|
|
loadAgent,
|
|
|
+ loadStyles,
|
|
|
validateForApi,
|
|
|
integrate,
|
|
|
saveOnHackmd,
|