|
|
@@ -169,9 +169,13 @@ module.exports = (crowi) => {
|
|
|
const globalNotificationService = crowi.getGlobalNotificationService();
|
|
|
const socketIoService = crowi.socketIoService;
|
|
|
const { Page, GlobalNotificationSetting } = crowi.models;
|
|
|
- const { exportService } = crowi;
|
|
|
+ const { pageService, exportService } = crowi;
|
|
|
|
|
|
const validator = {
|
|
|
+ getPage: [
|
|
|
+ query('id').if(value => value != null).isMongoId(),
|
|
|
+ query('path').if(value => value != null).isString(),
|
|
|
+ ],
|
|
|
likes: [
|
|
|
body('pageId').isString(),
|
|
|
body('bool').isBoolean(),
|
|
|
@@ -198,6 +202,70 @@ module.exports = (crowi) => {
|
|
|
],
|
|
|
};
|
|
|
|
|
|
+ /**
|
|
|
+ * @swagger
|
|
|
+ *
|
|
|
+ * /page:
|
|
|
+ * get:
|
|
|
+ * tags: [Page]
|
|
|
+ * operationId: getPage
|
|
|
+ * summary: /page
|
|
|
+ * description: get page by pagePath or pageId
|
|
|
+ * parameters:
|
|
|
+ * - name: pageId
|
|
|
+ * in: query
|
|
|
+ * description: page id
|
|
|
+ * schema:
|
|
|
+ * $ref: '#/components/schemas/Page/properties/_id'
|
|
|
+ * - name: path
|
|
|
+ * in: query
|
|
|
+ * description: page path
|
|
|
+ * schema:
|
|
|
+ * $ref: '#/components/schemas/Page/properties/path'
|
|
|
+ * responses:
|
|
|
+ * 200:
|
|
|
+ * description: Page data
|
|
|
+ * content:
|
|
|
+ * application/json:
|
|
|
+ * schema:
|
|
|
+ * $ref: '#/components/schemas/Page'
|
|
|
+ */
|
|
|
+ router.get('/', accessTokenParser, loginRequired, validator.getPage, apiV3FormValidator, async(req, res) => {
|
|
|
+ const { pageId, path } = req.query;
|
|
|
+
|
|
|
+ if (pageId == null && path == null) {
|
|
|
+ return res.apiv3Err(new ErrorV3('Parameter pagePath or pageId is required.', 'invalid-request'));
|
|
|
+ }
|
|
|
+
|
|
|
+ let result = {};
|
|
|
+ try {
|
|
|
+ result = await pageService.findPageAndMetaDataByViewer({ pageId, path, user: req.user });
|
|
|
+ }
|
|
|
+ catch (err) {
|
|
|
+ logger.error('get-page-failed', err);
|
|
|
+ return res.apiv3Err(err, 500);
|
|
|
+ }
|
|
|
+
|
|
|
+ const page = result.page;
|
|
|
+
|
|
|
+ if (page == null) {
|
|
|
+ return res.apiv3(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ page.initLatestRevisionField();
|
|
|
+
|
|
|
+ // populate
|
|
|
+ result.page = await page.populateDataToShowRevision();
|
|
|
+ }
|
|
|
+ catch (err) {
|
|
|
+ logger.error('populate-page-failed', err);
|
|
|
+ return res.apiv3Err(err, 500);
|
|
|
+ }
|
|
|
+
|
|
|
+ return res.apiv3(result);
|
|
|
+ });
|
|
|
+
|
|
|
/**
|
|
|
* @swagger
|
|
|
*
|