Ver código fonte

♻️ (dashboard-v6): 藏经阁地址统一由 libraryUrl() 拼接

五处「在藏经阁中打开」/ 术语分享链接各自拼
`VITE_APP_API_SERVER + /library/...`,收进 utils.ts 的 libraryUrl()。
仍以 VITE_APP_API_SERVER 为前缀(为空时是同域相对路径),
absolute=true 时补全为完整地址,供要复制给别人的链接用。
TermShare 的局部变量 libraryUrl 改名 libraryLink,避免与函数同名。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
visuddhinanda 20 horas atrás
pai
commit
22a893cd2d

+ 2 - 3
dashboard-v6/src/components/article/TypePali.tsx

@@ -28,7 +28,7 @@ import type { TTarget } from "../../types";
 import TocPath from "../tipitaka/TocPath";
 import ParagraphNode from "../tipitaka/ParagraphNode";
 import "./article.css";
-import { articlePath, fullUrl } from "../../utils";
+import { articlePath, fullUrl, libraryUrl } from "../../utils";
 
 import { useIntl } from "react-intl";
 
@@ -200,8 +200,7 @@ const TypePali = ({
                 if (key === "tpl") setTplOpen(true);
                 if (key === "library" && channels) {
                   window.open(
-                    import.meta.env.VITE_APP_API_SERVER +
-                      `/library/tipitaka/${id}/read?channel=${channels[0]}`,
+                    libraryUrl(`tipitaka/${id}/read?channel=${channels[0]}`),
                     "_blank",
                   );
                 }

+ 2 - 3
dashboard-v6/src/components/article/components/ArticleReaderToolbar.tsx

@@ -16,7 +16,7 @@ import { useAppSelector } from "../../../hooks";
 import { currentUser } from "../../../reducers/current-user";
 
 import { useState } from "react";
-import { articlePath, fullUrl } from "../../../utils";
+import { articlePath, fullUrl, libraryUrl } from "../../../utils";
 
 import type { TRole } from "../../../api/Auth";
 import { useIntl } from "react-intl";
@@ -135,8 +135,7 @@ const TypeArticleReaderToolbarWidget = ({
                     break;
                   case "open_in_library":
                     window.open(
-                      import.meta.env.VITE_APP_API_SERVER +
-                        `/library/anthology/${anthologyId}/read/${articleId}`,
+                      libraryUrl(`anthology/${anthologyId}/read/${articleId}`),
                       "_blank"
                     );
                     break;

+ 2 - 2
dashboard-v6/src/components/channel/ChannelMy.tsx

@@ -35,6 +35,7 @@ import TokenModal from "../token/TokenModal";
 import NissayaAlignerModal from "../nissaya/NissayaAlignerModal";
 import { useChannelProgress } from "./hooks/useChannelProgress";
 import type { IChannel, IChannelItem } from "../../api/channel";
+import { libraryUrl } from "../../utils";
 
 const { Search } = Input;
 
@@ -336,8 +337,7 @@ const ChannelMy = ({
                         break;
                       case "library":
                         window.open(
-                          import.meta.env.VITE_APP_API_SERVER +
-                            `/library/tipitaka?channel=${ch.id}`,
+                          libraryUrl(`tipitaka?channel=${ch.id}`),
                           "_blank"
                         );
                         break;

+ 4 - 4
dashboard-v6/src/components/term/TermShare.tsx

@@ -8,7 +8,7 @@ import {
   LinkOutlined,
 } from "@ant-design/icons";
 
-import { fullUrl } from "../../utils";
+import { fullUrl, libraryUrl } from "../../utils";
 
 const { Text } = Typography;
 
@@ -26,8 +26,8 @@ const TermShareWidget = ({ id, trigger, open, onClose }: IWidget) => {
   const isOpen = open ?? innerOpen;
 
   // 藏经阁(对外公开)访问链接
-  const libraryUrl = id
-    ? `${import.meta.env.VITE_APP_API_SERVER}/library/wiki/${intl.locale}/${id}`
+  const libraryLink = id
+    ? libraryUrl(`wiki/${intl.locale}/${id}`, true)
     : "";
   // 译经楼(工作台)访问链接
   const studioUrl = id ? fullUrl(`/workspace/term/${id}`) : "";
@@ -92,7 +92,7 @@ const TermShareWidget = ({ id, trigger, open, onClose }: IWidget) => {
       >
         {linkRow(
           intl.formatMessage({ id: "labels.library.access.link" }),
-          libraryUrl,
+          libraryLink,
           <GlobalOutlined />
         )}
         <Text

+ 2 - 2
dashboard-v6/src/pages/workspace/channel/show.tsx

@@ -7,7 +7,7 @@ import { ExportOutlined, TeamOutlined } from "@ant-design/icons";
 import ChapterInChannelList from "../../../components/channel/ChapterInChannelList";
 import ShareModal from "../../../components/share/ShareModal";
 
-import { articlePath, fullUrl } from "../../../utils";
+import { articlePath, fullUrl, libraryUrl } from "../../../utils";
 import type { IArticleParam } from "../../../types/article";
 import { EResType } from "../../../components/share/utils";
 import { fetchChannel } from "../../../api/channel";
@@ -39,7 +39,7 @@ const Widget = () => {
             <Space>
               <Button
                 icon={<ExportOutlined />}
-                href={`${import.meta.env.VITE_APP_API_SERVER}/library/tipitaka/channels/${channelId}`}
+                href={libraryUrl(`tipitaka/channels/${channelId}`)}
                 target="_blank"
               >
                 {intl.formatMessage({

+ 18 - 0
dashboard-v6/src/utils.ts

@@ -37,6 +37,24 @@ export function fullUrl(url: string): string {
   return path ? `${prefix}/${path}` : `${prefix}/`;
 }
 
+/**
+ * 藏经阁(Laravel library)地址:VITE_APP_API_SERVER + /library/<path>。
+ * library 不在 v6 的 BASE_URL 下,所以不能用 fullUrl()。
+ * VITE_APP_API_SERVER 为空时是同域的相对路径。
+ * @param path library 下的路径,如 `tipitaka?channel=xxx`(前导 "/" 可有可无)
+ * @param absolute 要复制给别人的链接传 true:VITE_APP_API_SERVER 不是完整地址时补上当前域名
+ */
+export function libraryUrl(path: string, absolute = false): string {
+  const server = (import.meta.env.VITE_APP_API_SERVER ?? "").replace(
+    /\/+$/,
+    ""
+  );
+  const url = `${server}/library/${path.replace(/^\/+/, "")}`;
+  return absolute && !/^https?:\/\//.test(url)
+    ? window.location.origin + url
+    : url;
+}
+
 export function PaliToEn(pali: string): string {
   let output: string = pali.toLowerCase();
   output = output.replaceAll("ā", "a");