Sfoglia il codice sorgente

Use pako.js to decompress gzip response.

Oleksandr Korniienko 3 anni fa
parent
commit
f7d05034be
3 ha cambiato i file con 20 aggiunte e 3 eliminazioni
  1. 2 0
      package.json
  2. 8 3
      src/components/ValidatorReport/index.tsx
  3. 10 0
      yarn.lock

+ 2 - 0
package.json

@@ -14,6 +14,7 @@
     "d3-timeline-chart": "^1.3.0",
     "htmr": "^0.9.2",
     "interactjs": "^1.10.2",
+    "pako": "^2.0.4",
     "react": "^17.0.1",
     "react-bootstrap": "^1.4.0",
     "react-calendar-timeline": "^0.27.0",
@@ -59,6 +60,7 @@
     "@types/jest": "^26.0.15",
     "@types/node": "^12.0.0",
     "@types/node-fetch": "^2.5.7",
+    "@types/pako": "^1.0.2",
     "@types/react": "^16.9.53",
     "@types/react-bootstrap": "^0.32.25",
     "@types/react-calendar-timeline": "^0.26.3",

+ 8 - 3
src/components/ValidatorReport/index.tsx

@@ -30,6 +30,7 @@ import Alert from "@material-ui/lab/Alert";
 import Tabs from "@material-ui/core/Tabs";
 import Backdrop from "@material-ui/core/Backdrop";
 import "./index.css";
+import pako from "pako";
 import { alternativeBackendApis } from "../../config";
 
 config();
@@ -58,7 +59,7 @@ const useStyles = makeStyles((theme: Theme) =>
 );
 
 const oldChainStatsLocation =
-  "https://joystreamstats.live/static/validators-old-testnet.json";
+  "https://joystreamstats.live/static/validators-old-testnet.json.gz";
 const ValidatorReport = () => {
   const dateFormat = "yyyy-MM-DD";
   const [oldChainLastDate, setOldChainLastDate] = useState(moment());
@@ -209,10 +210,14 @@ const ValidatorReport = () => {
   useEffect(() => {
     setIsLoading(true);
     axios
-      .get(oldChainStatsLocation)
+      .get(oldChainStatsLocation, {
+        responseType: "arraybuffer",
+      })
       .then((response) => {
         try {
-          const oldStats = response.data;
+          var binData = new Uint8Array(response.data);
+          var data = pako.inflate(binData);
+          const oldStats = JSON.parse(new TextDecoder().decode(data));
           setOldChainStats(oldStats as ValidatorsJSResponse);
           setOldChainLastDate(
             moment(

+ 10 - 0
yarn.lock

@@ -2236,6 +2236,11 @@
   resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.1.tgz#d3357479a0fdfdd5907fe67e17e0a85c906e1301"
   integrity sha512-Gj7cI7z+98M282Tqmp2K5EIsoouUEzbBJhQQzDE3jSIRk6r9gsz0oUokqIUR4u1R3dMHo0pDHM7sNOHyhulypw==
 
+"@types/pako@^1.0.2":
+  version "1.0.2"
+  resolved "https://registry.yarnpkg.com/@types/pako/-/pako-1.0.2.tgz#17c9b136877f33d9ecc8e73cd26944f1f6dd39a1"
+  integrity sha512-8UJl2MjkqqS6ncpLZqRZ5LmGiFBkbYxocD4e4jmBqGvfRG1RS23gKsBQbdtV9O9GvRyjFTiRHRByjSlKCLlmZw==
+
 "@types/parse-json@^4.0.0":
   version "4.0.0"
   resolved "https://registry.yarnpkg.com/@types/parse-json/-/parse-json-4.0.0.tgz#2f8bb441434d163b35fb8ffdccd7138927ffb8c0"
@@ -9201,6 +9206,11 @@ p-try@^2.0.0:
   resolved "https://registry.yarnpkg.com/p-try/-/p-try-2.2.0.tgz#cb2868540e313d61de58fafbe35ce9004d5540e6"
   integrity sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==
 
+pako@^2.0.4:
+  version "2.0.4"
+  resolved "https://registry.yarnpkg.com/pako/-/pako-2.0.4.tgz#6cebc4bbb0b6c73b0d5b8d7e8476e2b2fbea576d"
+  integrity sha512-v8tweI900AUkZN6heMU/4Uy4cXRc2AYNRggVmTR+dEncawDJgCdLMximOVA2p4qO57WMynangsfGRb5WD6L1Bg==
+
 pako@~1.0.5:
   version "1.0.11"
   resolved "https://registry.yarnpkg.com/pako/-/pako-1.0.11.tgz#6c9599d340d54dfd3946380252a35705a6b992bf"