|
@@ -2,7 +2,7 @@ import path from 'path';
|
|
|
import { type Readable } from 'stream';
|
|
import { type Readable } from 'stream';
|
|
|
import { pipeline } from 'stream/promises';
|
|
import { pipeline } from 'stream/promises';
|
|
|
|
|
|
|
|
-import type { IPage } from '@growi/core';
|
|
|
|
|
|
|
+import type { IPage, IRevision } from '@growi/core';
|
|
|
import {
|
|
import {
|
|
|
AllSubscriptionStatusType, PageGrant, SubscriptionStatusType,
|
|
AllSubscriptionStatusType, PageGrant, SubscriptionStatusType,
|
|
|
getIdForRef,
|
|
getIdForRef,
|
|
@@ -157,7 +157,7 @@ module.exports = (crowi) => {
|
|
|
],
|
|
],
|
|
|
export: [
|
|
export: [
|
|
|
query('format').isString().isIn(['md', 'pdf']),
|
|
query('format').isString().isIn(['md', 'pdf']),
|
|
|
- query('revisionId').isString(),
|
|
|
|
|
|
|
+ query('revisionId').optional().isMongoId(),
|
|
|
],
|
|
],
|
|
|
archive: [
|
|
archive: [
|
|
|
body('rootPagePath').isString(),
|
|
body('rootPagePath').isString(),
|
|
@@ -844,8 +844,10 @@ module.exports = (crowi) => {
|
|
|
*/
|
|
*/
|
|
|
router.get('/export/:pageId', loginRequiredStrictly, validator.export, async(req, res) => {
|
|
router.get('/export/:pageId', loginRequiredStrictly, validator.export, async(req, res) => {
|
|
|
const pageId: string = req.params.pageId;
|
|
const pageId: string = req.params.pageId;
|
|
|
- const { format, revisionId = null } = req.query;
|
|
|
|
|
- let revision;
|
|
|
|
|
|
|
+ const format: 'md' | 'pdf' = req.query.format ?? 'md';
|
|
|
|
|
+ const revisionId: string | undefined = req.query.revisionId;
|
|
|
|
|
+
|
|
|
|
|
+ let revision: HydratedDocument<IRevision> | null;
|
|
|
let pagePath;
|
|
let pagePath;
|
|
|
|
|
|
|
|
const Page = mongoose.model<HydratedDocument<PageDocument>, PageModel>('Page');
|
|
const Page = mongoose.model<HydratedDocument<PageDocument>, PageModel>('Page');
|
|
@@ -878,9 +880,17 @@ module.exports = (crowi) => {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
- const revisionIdForFind = revisionId ?? page.revision;
|
|
|
|
|
|
|
+ const targetId = revisionId ?? (page.revision != null ? getIdForRef(page.revision) : null);
|
|
|
|
|
+ if (targetId == null) {
|
|
|
|
|
+ throw new Error('revisionId is not specified');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const revisionIdForFind = new mongoose.Types.ObjectId(targetId);
|
|
|
|
|
+ revision = await Revision.findById(revisionIdForFind);
|
|
|
|
|
+ if (revision == null) {
|
|
|
|
|
+ throw new Error('Revision is not found');
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- revision = await Revision.findOne({ id: { $eq: revisionIdForFind } });
|
|
|
|
|
pagePath = page.path;
|
|
pagePath = page.path;
|
|
|
|
|
|
|
|
// Error if pageId and revison's pageIds do not match
|
|
// Error if pageId and revison's pageIds do not match
|