itizawa 5 лет назад
Родитель
Сommit
43faeef25d
2 измененных файлов с 31 добавлено и 0 удалено
  1. 2 0
      src/server/routes/index.js
  2. 29 0
      src/server/routes/page.js

+ 2 - 0
src/server/routes/index.js

@@ -180,6 +180,8 @@ module.exports = function(crowi, app) {
   app.post('/_api/hackmd.discard'        , accessTokenParser , loginRequiredStrictly , csrf, hackmd.validateForApi, hackmd.discard);
   app.post('/_api/hackmd.discard'        , accessTokenParser , loginRequiredStrictly , csrf, hackmd.validateForApi, hackmd.discard);
   app.post('/_api/hackmd.saveOnHackmd'   , accessTokenParser , loginRequiredStrictly , csrf, hackmd.validateForApi, hackmd.saveOnHackmd);
   app.post('/_api/hackmd.saveOnHackmd'   , accessTokenParser , loginRequiredStrictly , csrf, hackmd.validateForApi, hackmd.saveOnHackmd);
 
 
+  app.get('/share/:path', page.showSharePage);
+
   app.get('/*/$'                   , loginRequired , page.showPageWithEndOfSlash, page.notFound);
   app.get('/*/$'                   , loginRequired , page.showPageWithEndOfSlash, page.notFound);
   app.get('/*'                     , loginRequired , page.showPage, page.notFound);
   app.get('/*'                     , loginRequired , page.showPage, page.notFound);
 
 

+ 29 - 0
src/server/routes/page.js

@@ -439,6 +439,35 @@ module.exports = function(crowi, app) {
     return showPageForGrowiBehavior(req, res, next);
     return showPageForGrowiBehavior(req, res, next);
   };
   };
 
 
+  actions.showSharePage = async function(req, res, next) {
+    const { path } = req.params;
+
+    const layoutName = configManager.getConfig('crowi', 'customize:layout');
+    let view = `layout-${layoutName}/page`;
+
+    // TODO
+    const page = {};
+
+    const limit = 50;
+    const offset = parseInt(req.query.offset) || 0;
+    const renderVars = {};
+
+    addRendarVarsForPage(renderVars, page);
+    addRendarVarsForScope(renderVars, page);
+
+    await addRenderVarsForSlack(renderVars, page);
+    await addRenderVarsForDescendants(renderVars, path, req.user, offset, limit, true);
+
+    if (isUserPage(page.path)) {
+      // change template
+      view = `layout-${layoutName}/user_page`;
+      await addRenderVarsForUserPage(renderVars, page, req.user);
+    }
+
+    await interceptorManager.process('beforeRenderPage', req, res, renderVars);
+    return res.render(view, renderVars);
+  };
+
   /**
   /**
    * switch action by behaviorType
    * switch action by behaviorType
    */
    */