Просмотр исходного кода

Revert "Pass JSON.stringified pageIds"

This reverts commit ff6fa70aaac2335a8eeab6150ad899c673eb7c67.
Shun Miyazawa 3 лет назад
Родитель
Сommit
87ed0f3499

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

@@ -1,5 +1,3 @@
-import { type } from 'os';
-
 import { ErrorV3 } from '@growi/core';
 import express, { Request, Router } from 'express';
 import { query, oneOf } from 'express-validator';
@@ -37,7 +35,7 @@ const validator = {
     query('path').isString(),
   ], 'id or path is required'),
   pageIdsOrPathRequired: oneOf([
-    query('pageIds').isString(),
+    query('pageIds').isArray(),
     query('path').isString(),
   ], 'pageIds or path is required'),
   infoParams: [
@@ -110,6 +108,7 @@ const routerFactory = (crowi: Crowi): Router => {
     const {
       pageIds, path, attachBookmarkCount: attachBookmarkCountParam, attachShortBody: attachShortBodyParam,
     } = req.query;
+
     const attachBookmarkCount: boolean = attachBookmarkCountParam === 'true';
     const attachShortBody: boolean = attachShortBodyParam === 'true';
 
@@ -119,12 +118,8 @@ const routerFactory = (crowi: Crowi): Router => {
     const pageService: PageService = crowi.pageService!;
 
     try {
-      // see: https://github.com/expressjs/body-parser/issues/289
-      // If an array of 20 or more is included in req.query, it is converted to an object with the index as a key, so the client passes JSON.stringify values
-      const parsedPageIds = JSON.parse(pageIds as string);
-
-      const pages = parsedPageIds != null && parsedPageIds.length > 0
-        ? await Page.findByIdsAndViewer(parsedPageIds as string[], req.user, null, true)
+      const pages = pageIds != null
+        ? await Page.findByIdsAndViewer(pageIds as string[], req.user, null, true)
         : await Page.findByPathAndViewer(path as string, req.user, null, false, true);
 
       const foundIds = pages.map(page => page._id);

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

@@ -102,13 +102,12 @@ 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', stringifiedPageIds, path, attachBookmarkCount, attachShortBody] : null,
-    ([endpoint, stringifiedPageIds, path, attachBookmarkCount, attachShortBody]) => {
+    shouldFetch ? ['/page-listing/info', pageIds, path, attachBookmarkCount, attachShortBody] : null,
+    ([endpoint, pageIds, path, attachBookmarkCount, attachShortBody]) => {
       return apiv3Get(endpoint, {
-        pageIds: stringifiedPageIds, path, attachBookmarkCount, attachShortBody,
+        pageIds, path, attachBookmarkCount, attachShortBody,
       }).then(response => response.data);
     },
   );