Yuki Takei пре 7 месеци
родитељ
комит
1ceb723b64

+ 14 - 4
apps/app/src/pages/[[...path]]/page-data-props.ts

@@ -8,7 +8,10 @@ import type { CrowiRequest } from '~/interfaces/crowi-request';
 import type { PageModel } from '~/server/models/page';
 import type { IPageRedirect, PageRedirectModel } from '~/server/models/page-redirect';
 
-import type { InitialProps, SameRouteEachProps } from '../general-page';
+import type { CommonEachProps } from '../common-props';
+import type { InitialProps } from '../general-page';
+
+import type { EachProps } from './types';
 
 // Utility to resolve path, redirect, and identical path page check
 type PathResolutionResult = {
@@ -57,7 +60,8 @@ export async function getPageDataForInitial(
     context: GetServerSidePropsContext,
 ): Promise<GetServerSidePropsResult<
   Pick<InitialProps, 'pageWithMeta' | 'isNotFound' | 'isNotCreatable' | 'isForbidden' | 'skipSSR'> &
-  Pick<SameRouteEachProps, 'currentPathname' | 'isIdenticalPathPage'>
+  Pick<CommonEachProps, 'currentPathname'> &
+  EachProps
 >> {
   const req: CrowiRequest = context.req as CrowiRequest;
   const { crowi, user } = req;
@@ -74,7 +78,7 @@ export async function getPageDataForInitial(
   const pageId = _isPermalink(pathFromUrl) ? removeHeadingSlash(pathFromUrl) : null;
   const isPermalink = _isPermalink(pathFromUrl);
 
-  const { resolvedPathname, isIdenticalPathPage } = await resolvePathAndCheckIdentical(pathFromUrl, user);
+  const { resolvedPathname, isIdenticalPathPage, redirectFrom } = await resolvePathAndCheckIdentical(pathFromUrl, user);
 
   if (isIdenticalPathPage) {
     return {
@@ -86,6 +90,7 @@ export async function getPageDataForInitial(
         isNotCreatable: true,
         isForbidden: false,
         skipSSR: false,
+        redirectFrom,
       },
     };
   }
@@ -133,6 +138,7 @@ export async function getPageDataForInitial(
         isNotCreatable: false,
         isForbidden: false,
         skipSSR,
+        redirectFrom,
       },
     };
   }
@@ -151,6 +157,7 @@ export async function getPageDataForInitial(
       isNotCreatable: !isCreatablePage(resolvedPathname),
       isForbidden: count > 0,
       skipSSR: false,
+      redirectFrom,
     },
   };
 }
@@ -158,7 +165,10 @@ export async function getPageDataForInitial(
 // Page data retrieval for same-route navigation
 export async function getPageDataForSameRoute(
     context: GetServerSidePropsContext,
-): Promise<GetServerSidePropsResult<Pick<SameRouteEachProps, 'currentPathname' | 'isIdenticalPathPage' | 'redirectFrom'>>> {
+): Promise<GetServerSidePropsResult<
+    Pick<CommonEachProps, 'currentPathname'> &
+    EachProps
+>> {
   const req: CrowiRequest = context.req as CrowiRequest;
   const { user } = req;
 

+ 7 - 6
apps/app/src/pages/[[...path]]/server-side-props.ts

@@ -1,18 +1,19 @@
 import type { GetServerSidePropsContext, GetServerSidePropsResult } from 'next';
 
 import {
-  getServerSideI18nProps, getServerSideUserUISettingsProps, getServerSideCommonInitialProps, getServerSideCommonEachProps,
+  getServerSideI18nProps, getServerSideUserUISettingsProps, getServerSideCommonInitialProps, getServerSideCommonEachProps, isValidCommonEachRouteProps,
 } from '../common-props';
-import type { InitialProps, SameRouteEachProps } from '../general-page';
+import type { InitialProps } from '../general-page';
 import {
   getServerSideConfigurationProps, getServerSideRendererConfigProps, getServerSideSidebarConfigProps,
-  getActivityAction, isValidInitialAndSameRouteProps, isValidSameRouteProps,
+  getActivityAction, isValidInitialAndSameRouteProps,
 } from '../general-page';
 import { addActivity } from '../utils/activity';
 import { mergeGetServerSidePropsResults } from '../utils/server-side-props';
 
 import { NEXT_JS_ROUTING_PAGE } from './consts';
 import { getPageDataForInitial, getPageDataForSameRoute } from './page-data-props';
+import type { EachProps } from './types';
 
 
 const nextjsRoutingProps = {
@@ -21,7 +22,7 @@ const nextjsRoutingProps = {
   },
 };
 
-export async function getServerSidePropsForInitial(context: GetServerSidePropsContext): Promise<GetServerSidePropsResult<InitialProps & SameRouteEachProps>> {
+export async function getServerSidePropsForInitial(context: GetServerSidePropsContext): Promise<GetServerSidePropsResult<InitialProps & EachProps>> {
   //
   // STAGE 1
   //
@@ -91,7 +92,7 @@ export async function getServerSidePropsForInitial(context: GetServerSidePropsCo
   return mergedResult;
 }
 
-export async function getServerSidePropsForSameRoute(context: GetServerSidePropsContext): Promise<GetServerSidePropsResult<SameRouteEachProps>> {
+export async function getServerSidePropsForSameRoute(context: GetServerSidePropsContext): Promise<GetServerSidePropsResult<EachProps>> {
   //
   // STAGE 1
   //
@@ -130,7 +131,7 @@ export async function getServerSidePropsForSameRoute(context: GetServerSideProps
   }
 
   // Validate the merged props have all required properties
-  if (!isValidSameRouteProps(mergedResult.props)) {
+  if (!isValidCommonEachRouteProps(mergedResult.props)) {
     throw new Error('Invalid same route props structure');
   }
 

+ 6 - 6
apps/app/src/pages/common-props/commons.ts

@@ -61,7 +61,7 @@ export type CommonEachProps = {
  */
 export function isValidCommonEachRouteProps(props: unknown): props is CommonEachProps {
   if (typeof props !== 'object' || props === null) {
-    logger.warn('isValidSameRouteProps: props is not an object or is null');
+    logger.warn('isValidCommonEachRouteProps: props is not an object or is null');
     return false;
   }
 
@@ -69,23 +69,23 @@ export function isValidCommonEachRouteProps(props: unknown): props is CommonEach
 
   // Essential properties validation
   if (typeof p.nextjsRoutingPage !== 'string' && p.nextjsRoutingPage !== null) {
-    logger.warn('isValidSameRouteProps: nextjsRoutingPage is not a string or null', { nextjsRoutingPage: p.nextjsRoutingPage });
+    logger.warn('isValidCommonEachRouteProps: nextjsRoutingPage is not a string or null', { nextjsRoutingPage: p.nextjsRoutingPage });
     return false;
   }
   if (typeof p.currentPathname !== 'string') {
-    logger.warn('isValidSameRouteProps: currentPathname is not a string', { currentPathname: p.currentPathname });
+    logger.warn('isValidCommonEachRouteProps: currentPathname is not a string', { currentPathname: p.currentPathname });
     return false;
   }
   if (typeof p.csrfToken !== 'string') {
-    logger.warn('isValidSameRouteProps: csrfToken is not a string', { csrfToken: p.csrfToken });
+    logger.warn('isValidCommonEachRouteProps: csrfToken is not a string', { csrfToken: p.csrfToken });
     return false;
   }
   if (typeof p.isMaintenanceMode !== 'boolean') {
-    logger.warn('isValidSameRouteProps: isMaintenanceMode is not a boolean', { isMaintenanceMode: p.isMaintenanceMode });
+    logger.warn('isValidCommonEachRouteProps: isMaintenanceMode is not a boolean', { isMaintenanceMode: p.isMaintenanceMode });
     return false;
   }
   if (typeof p.isIdenticalPathPage !== 'boolean') {
-    logger.warn('isValidSameRouteProps: isIdenticalPathPage is not a boolean', { isIdenticalPathPage: p.isIdenticalPathPage });
+    logger.warn('isValidCommonEachRouteProps: isIdenticalPathPage is not a boolean', { isIdenticalPathPage: p.isIdenticalPathPage });
     return false;
   }