Browse Source

add fetch version.txt

visuddhinanda 2 years ago
parent
commit
a84dbf9336
1 changed files with 64 additions and 13 deletions
  1. 64 13
      dashboard/src/pages/library/download/Download.tsx

+ 64 - 13
dashboard/src/pages/library/download/Download.tsx

@@ -1,26 +1,77 @@
-import { Divider, Typography } from "antd";
+import { Button, Card, Divider, Typography } from "antd";
+
+import { useEffect, useState } from "react";
 import { Link } from "react-router-dom";
+import { GithubOutlined } from "@ant-design/icons";
+
 import bg_png from "../../../assets/library/images/download_bg.png";
+import Marked from "../../../components/general/Marked";
 const { Paragraph } = Typography;
 
 const ChapterNewWidget = () => {
+  const [github, setGithub] = useState<string>("loading");
+  const githubLink =
+    "https://raw.githubusercontent.com/ariyamaggika/wikipali-app/master/version.txt";
+  const giteeLink =
+    "https://gitee.com/wolf96/wikipali-app/raw/main/version.txt";
+  const giteeRelease = "https://gitee.com/wolf96/wikipali-app/releases";
+  useEffect(() => {
+    fetch(githubLink, {
+      method: "GET",
+      mode: "cors",
+    })
+      .then((res) => {
+        return res.text();
+      })
+      .then((text) => {
+        console.log("获取的结果", text);
+        const link = text.replace(
+          /https(.+?)\.apk/g,
+          "- [https$1.apk](https$1.apk)"
+        );
+        setGithub(link.replaceAll("\n", "\n\n"));
+        return text;
+      })
+      .catch((err) => {
+        console.log("请求错误", err);
+      });
+  }, []);
   return (
     <Paragraph>
       <div>
         <img alt="code" src={bg_png} />
       </div>
-      <Divider>中国大陆</Divider>
-      <Paragraph>
-        <Link to="https://gitee.com/" target="_blank">
-          Gitee
-        </Link>
-      </Paragraph>
-      <Divider>其他地区</Divider>
-      <Paragraph>
-        <Link to="https://github.com/gohugoio/hugo/releases" target="_blank">
-          Github
-        </Link>
-      </Paragraph>
+      <Card
+        title={"中国大陆"}
+        style={{ margin: 10, borderRadius: 8 }}
+        hoverable
+      >
+        <Paragraph>
+          <Link to={giteeRelease} target="_blank">
+            Gitee
+          </Link>
+        </Paragraph>
+      </Card>
+      <Card
+        title={"其他地区"}
+        style={{ margin: 10, borderRadius: 8 }}
+        hoverable
+      >
+        <Paragraph>
+          <Button icon={<GithubOutlined />} type="text">
+            <Link
+              to="https://github.com/gohugoio/hugo/releases"
+              target="_blank"
+            >
+              Github
+            </Link>
+          </Button>
+        </Paragraph>
+
+        <Paragraph>
+          <Marked text={github} />
+        </Paragraph>
+      </Card>
     </Paragraph>
   );
 };