2
0
Эх сурвалжийг харах

fix: enhance expired share link handling and update type definitions

Shun Miyazawa 4 сар өмнө
parent
commit
555caf0cb1

+ 17 - 12
apps/app/src/pages/share/[[...path]]/page-data-props.ts

@@ -55,18 +55,6 @@ export const getPageDataForInitial = async (
     return notFoundProps;
   }
 
-  // expired
-  if (shareLink.isExpired()) {
-    return {
-      props: {
-        isNotFound: false,
-        pageWithMeta: null,
-        isExpired: true,
-        shareLink: shareLink.toObject(),
-      },
-    };
-  }
-
   const pageId = getIdStringForRef(shareLink.relatedPage);
   const pageWithMeta = await pageService.findPageAndMetaDataByViewer(
     pageId,
@@ -80,6 +68,23 @@ export const getPageDataForInitial = async (
     return notFoundProps;
   }
 
+  // expired
+  if (shareLink.isExpired()) {
+    const populatedPage =
+      await pageWithMeta.data.populateDataToShowRevision(true); //shouldExcludeBody = false,
+    return {
+      props: {
+        isNotFound: false,
+        pageWithMeta: {
+          data: populatedPage,
+          meta: pageWithMeta.meta,
+        },
+        isExpired: true,
+        shareLink: shareLink.toObject(),
+      },
+    };
+  }
+
   // Handle existing page
   const ssrMaxRevisionBodyLength = configManager.getConfig(
     'app:ssrMaxRevisionBodyLength',

+ 4 - 1
apps/app/src/pages/share/[[...path]]/types.ts

@@ -16,18 +16,21 @@ export type ShareLinkPageStatesProps = Pick<
 > &
   (
     | {
+        // not found case
         pageWithMeta: IDataWithRequiredMeta<null, IPageNotFoundInfo>;
         isNotFound: true;
         isExpired: undefined;
         shareLink: undefined;
       }
     | {
-        pageWithMeta: null;
+        // expired case
+        pageWithMeta: IPageToShowRevisionWithMeta;
         isNotFound: false;
         isExpired: true;
         shareLink: IShareLinkHasId;
       }
     | {
+        // normal case
         pageWithMeta: IPageToShowRevisionWithMeta;
         isNotFound: false;
         isExpired: false;