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

fix: refactor listPages to use getExcludedPaths function for better clarity

Shun Miyazawa 2 месяцев назад
Родитель
Сommit
c104709e85

+ 2 - 2
packages/remark-lsx/src/server/index.ts

@@ -57,7 +57,7 @@ const middleware = (crowi: any, app: any): void => {
     loginRequiredFallback,
   );
   const accessTokenParser = crowi.accessTokenParser;
-  const excludedPaths = crowi.pageService.getExcludedPathsBySystem();
+  const getExcludedPaths = () => crowi.pageService.getExcludedPathsBySystem();
 
   app.get(
     '/_api/lsx',
@@ -65,7 +65,7 @@ const middleware = (crowi: any, app: any): void => {
     loginRequired,
     lsxValidator,
     paramValidator,
-    listPages({ excludedPaths }),
+    listPages({ getExcludedPaths }),
   );
 };
 

+ 6 - 1
packages/remark-lsx/src/server/routes/list-pages/index.ts

@@ -66,7 +66,11 @@ interface IListPagesRequest
   user: IUser;
 }
 
-export const listPages = ({ excludedPaths }: { excludedPaths: string[] }) => {
+export const listPages = ({
+  getExcludedPaths,
+}: {
+  getExcludedPaths: () => string[];
+}) => {
   return async (req: IListPagesRequest, res: Response): Promise<Response> => {
     const params: LsxApiParams = {
       pagePath: removeTrailingSlash(req.query.pagePath),
@@ -92,6 +96,7 @@ export const listPages = ({ excludedPaths }: { excludedPaths: string[] }) => {
       const builder = await generateBaseQuery(params.pagePath, user);
       let query = builder.query;
 
+      const excludedPaths = getExcludedPaths();
       if (excludedPaths.length > 0) {
         const escapedPaths = excludedPaths.map((p) => {
           const cleanPath = p.startsWith('/') ? p.substring(1) : p;