Browse Source

Swap axios for async-request because of size

Wasi Master 3 years ago
parent
commit
1539e32456
5 changed files with 129 additions and 4274 deletions
  1. 107 4217
      dist/extension.js
  2. 0 0
      dist/extension.js.map
  3. 11 41
      package-lock.json
  4. 4 4
      package.json
  5. 7 12
      src/extension.ts

File diff suppressed because it is too large
+ 107 - 4217
dist/extension.js


File diff suppressed because it is too large
+ 0 - 0
dist/extension.js.map


+ 11 - 41
package-lock.json

@@ -9,7 +9,7 @@
       "version": "0.0.1",
       "license": "MIT",
       "dependencies": {
-        "axios": "^0.25.0",
+        "@endom8rix/async-request": "^1.1.0",
         "html-escaper": "^3.0.3",
         "markdown-escape": "^1.1.0"
       },
@@ -44,6 +44,11 @@
         "node": ">=10.0.0"
       }
     },
+    "node_modules/@endom8rix/async-request": {
+      "version": "1.1.0",
+      "resolved": "https://registry.npmjs.org/@endom8rix/async-request/-/async-request-1.1.0.tgz",
+      "integrity": "sha512-z1T0GxHdkK137njkpRjgEkLZO0lJNKWSvyxp/PBDsYJ09knKJhuM9pPYZEPRXN7/oC8JrblTYQsEWMJefhPESg=="
+    },
     "node_modules/@eslint/eslintrc": {
       "version": "1.0.5",
       "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-1.0.5.tgz",
@@ -742,14 +747,6 @@
         "node": ">=8"
       }
     },
-    "node_modules/axios": {
-      "version": "0.25.0",
-      "resolved": "https://registry.npmjs.org/axios/-/axios-0.25.0.tgz",
-      "integrity": "sha512-cD8FOb0tRH3uuEe6+evtAbgJtfxr7ly3fQjYcMcuPlgkwVS9xboaVIpcDV+cYQe+yGykgwZCs1pzjntcGa6l5g==",
-      "dependencies": {
-        "follow-redirects": "^1.14.7"
-      }
-    },
     "node_modules/balanced-match": {
       "version": "1.0.2",
       "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
@@ -1555,25 +1552,6 @@
       "integrity": "sha512-8/sOawo8tJ4QOBX8YlQBMxL8+RLZfxMQOif9o0KUKTNTjMYElWPE0r/m5VNFxTRd0NSw8qSy8dajrwX4RYI1Hw==",
       "dev": true
     },
-    "node_modules/follow-redirects": {
-      "version": "1.14.7",
-      "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.7.tgz",
-      "integrity": "sha512-+hbxoLbFMbRKDwohX8GkTataGqO6Jb7jGwpAlwgy2bIz25XtRm7KEzJM76R1WiNT5SwZkX4Y75SwBolkpmE7iQ==",
-      "funding": [
-        {
-          "type": "individual",
-          "url": "https://github.com/sponsors/RubenVerborgh"
-        }
-      ],
-      "engines": {
-        "node": ">=4.0"
-      },
-      "peerDependenciesMeta": {
-        "debug": {
-          "optional": true
-        }
-      }
-    },
     "node_modules/fs.realpath": {
       "version": "1.0.0",
       "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
@@ -3520,6 +3498,11 @@
       "integrity": "sha512-ws57AidsDvREKrZKYffXddNkyaF14iHNHm8VQnZH6t99E8gczjNN0GpvcGny0imC80yQ0tHz1xVUKk/KFQSUyA==",
       "dev": true
     },
+    "@endom8rix/async-request": {
+      "version": "1.1.0",
+      "resolved": "https://registry.npmjs.org/@endom8rix/async-request/-/async-request-1.1.0.tgz",
+      "integrity": "sha512-z1T0GxHdkK137njkpRjgEkLZO0lJNKWSvyxp/PBDsYJ09knKJhuM9pPYZEPRXN7/oC8JrblTYQsEWMJefhPESg=="
+    },
     "@eslint/eslintrc": {
       "version": "1.0.5",
       "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-1.0.5.tgz",
@@ -4057,14 +4040,6 @@
       "integrity": "sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==",
       "dev": true
     },
-    "axios": {
-      "version": "0.25.0",
-      "resolved": "https://registry.npmjs.org/axios/-/axios-0.25.0.tgz",
-      "integrity": "sha512-cD8FOb0tRH3uuEe6+evtAbgJtfxr7ly3fQjYcMcuPlgkwVS9xboaVIpcDV+cYQe+yGykgwZCs1pzjntcGa6l5g==",
-      "requires": {
-        "follow-redirects": "^1.14.7"
-      }
-    },
     "balanced-match": {
       "version": "1.0.2",
       "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
@@ -4678,11 +4653,6 @@
       "integrity": "sha512-8/sOawo8tJ4QOBX8YlQBMxL8+RLZfxMQOif9o0KUKTNTjMYElWPE0r/m5VNFxTRd0NSw8qSy8dajrwX4RYI1Hw==",
       "dev": true
     },
-    "follow-redirects": {
-      "version": "1.14.7",
-      "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.7.tgz",
-      "integrity": "sha512-+hbxoLbFMbRKDwohX8GkTataGqO6Jb7jGwpAlwgy2bIz25XtRm7KEzJM76R1WiNT5SwZkX4Y75SwBolkpmE7iQ=="
-    },
     "fs.realpath": {
       "version": "1.0.0",
       "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",

+ 4 - 4
package.json

@@ -1,7 +1,7 @@
 {
   "name": "wikipedia-hyperlinker",
   "author": "Wasi Master <arianmollik323@gmail.com> (https://wasi-master.github.io)",
-  "publisher":"WasiMaster",
+  "publisher": "WasiMaster",
   "displayName": "Wikipedia Hyperlinker",
   "description": "Adds hyperlinks to markdown and HTML files with articles gotten from Wikipedia",
   "homepage": "https://github.com/wasi-master/wikipedia-hyperlinker#readme",
@@ -12,7 +12,7 @@
   },
   "repository": {
     "type": "git",
-    "url":"https://github.com/wasi-master/wikipedia-hyperlinker"
+    "url": "https://github.com/wasi-master/wikipedia-hyperlinker"
   },
   "engines": {
     "vscode": "^1.63.0"
@@ -27,7 +27,7 @@
     "wiki",
     "insert"
   ],
-  "badges":[
+  "badges": [
     {
       "url": "https://img.shields.io/github/stars/wasi-master/vscode-wikipedia-hyperlink?style=social",
       "href": "https://github.com/wasi-master/vscode-wikipedia-hyperlink",
@@ -82,7 +82,7 @@
     "webpack-cli": "^4.9.1"
   },
   "dependencies": {
-    "axios": "^0.25.0",
+    "@endom8rix/async-request": "^1.1.0",
     "html-escaper": "^3.0.3",
     "markdown-escape": "^1.1.0"
   }

+ 7 - 12
src/extension.ts

@@ -1,8 +1,8 @@
 // The module 'vscode' contains the VS Code extensibility API
 // Import the module and reference it with the alias vscode in your code below
 import * as vscode from 'vscode';
-import axios from 'axios';
 import { escape as htmlEscape } from 'html-escaper';
+import request = require('@endom8rix/async-request');
 import markdownEscape = require("markdown-escape");
 
 // this method is called when your extension is activated
@@ -34,11 +34,12 @@ export function activate(context: vscode.ExtensionContext) {
 				progress.report({ increment: 0 });
 				// Make a request to wikipedia to get short description
 				try {
-					const response = await axios.get(`https://en.wikipedia.org/w/api.php?format=json&action=query&prop=info|extracts&exintro&explaintext&&inprop=url&redirects=1`, { 'params': { 'titles': text } });
+					const response = await request(`https://en.wikipedia.org/w/api.php?format=json&action=query&prop=info|extracts&exintro&explaintext&&inprop=url&redirects=1&titles=${encodeURIComponent(text)}`);
+					const body = JSON.parse(response.body);
 					progress.report({ increment: 100 });
 					console.log(response);
-					const summary: string = response.data['query']['pages'][Object.keys(response.data['query']['pages'])[0]]['extract'];
-					const url: string = response.data['query']['pages'][Object.keys(response.data['query']['pages'])[0]]['fullurl'];
+					const summary: string = body['query']['pages'][Object.keys(body['query']['pages'])[0]]['extract'];
+					const url: string = body['query']['pages'][Object.keys(body['query']['pages'])[0]]['fullurl'];
 					if (summary.includes("may refer to:")) {
 						vscode.window
 							.showInformationMessage(
@@ -89,14 +90,8 @@ export function activate(context: vscode.ExtensionContext) {
 						});
 					}
 				} catch (error) {
-					if (axios.isAxiosError(error) && error.response) {
-						console.error(error.response);
-						vscode.window.showErrorMessage(`Request failed with HTTP Code ${error.response.status}`);
-					} else if (axios.isAxiosError(error) && error.request) {
-						vscode.window.showErrorMessage(`Request failed`);
-					} else {
-						console.error(error);
-					}
+					vscode.window.showErrorMessage(`Request failed`);
+					console.error(error);
 				}
 
 			});

Some files were not shown because too many files changed in this diff