Shun Miyazawa 3 лет назад
Родитель
Сommit
ff6fa70aaa

+ 7 - 4
packages/app/src/server/routes/apiv3/page-listing.ts

@@ -1,3 +1,5 @@
+import { type } from 'os';
+
 import { ErrorV3 } from '@growi/core';
 import express, { Request, Router } from 'express';
 import { query, oneOf } from 'express-validator';
@@ -35,7 +37,7 @@ const validator = {
     query('path').isString(),
   ], 'id or path is required'),
   pageIdsOrPathRequired: oneOf([
-    query('pageIds').isArray(),
+    query('pageIds').isString(),
     query('path').isString(),
   ], 'pageIds or path is required'),
   infoParams: [
@@ -108,7 +110,6 @@ const routerFactory = (crowi: Crowi): Router => {
     const {
       pageIds, path, attachBookmarkCount: attachBookmarkCountParam, attachShortBody: attachShortBodyParam,
     } = req.query;
-
     const attachBookmarkCount: boolean = attachBookmarkCountParam === 'true';
     const attachShortBody: boolean = attachShortBodyParam === 'true';
 
@@ -118,8 +119,10 @@ const routerFactory = (crowi: Crowi): Router => {
     const pageService: PageService = crowi.pageService!;
 
     try {
-      const pages = pageIds != null
-        ? await Page.findByIdsAndViewer(pageIds as string[], req.user, null, true)
+      const parsedPageIds = JSON.parse(pageIds as string);
+
+      const pages = parsedPageIds != null && parsedPageIds.length > 0
+        ? await Page.findByIdsAndViewer(parsedPageIds as string[], req.user, null, true)
         : await Page.findByPathAndViewer(path as string, req.user, null, false, true);
 
       const foundIds = pages.map(page => page._id);

+ 4 - 3
packages/app/src/stores/page-listing.tsx

@@ -102,12 +102,13 @@ export const useSWRxPageInfoForList = (
 ): SWRResponse<Record<string, IPageInfoForListing>, Error> & PageInfoInjector => {
 
   const shouldFetch = (pageIds != null && pageIds.length > 0) || path != null;
+  const stringifiedPageIds = JSON.stringify(pageIds);
 
   const swrResult = useSWRImmutable(
-    shouldFetch ? ['/page-listing/info', pageIds, path, attachBookmarkCount, attachShortBody] : null,
-    ([endpoint, pageIds, path, attachBookmarkCount, attachShortBody]) => {
+    shouldFetch ? ['/page-listing/info', stringifiedPageIds, path, attachBookmarkCount, attachShortBody] : null,
+    ([endpoint, stringifiedPageIds, path, attachBookmarkCount, attachShortBody]) => {
       return apiv3Get(endpoint, {
-        pageIds, path, attachBookmarkCount, attachShortBody,
+        pageIds: stringifiedPageIds, path, attachBookmarkCount, attachShortBody,
       }).then(response => response.data);
     },
   );