Skip to content

Commit 28181e5

Browse files
Add user-agent to the request header (#79)
* fix: fixed icons of request params * feat: add user agent in headers --------- Co-authored-by: Jackson Tian <shyvo1987@gmail.com>
1 parent 47296b1 commit 28181e5

File tree

10 files changed

+208
-174
lines changed

10 files changed

+208
-174
lines changed

media/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"@vitejs/plugin-react": "^1.3.2",
4949
"autoprefixer": "^10.0.1",
5050
"eslint": "^8",
51-
"eslint-config-next": "14.2.3",
51+
"eslint-config-next": "14.1.4",
5252
"less": "^4.2.0",
5353
"postcss": "^8",
5454
"prettier": "^3.2.5",

media/src/components/APIPage/API.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,27 @@ export const API: React.FC<APIProps> = (props) => {
157157
<InnerSchemaTable
158158
name=""
159159
schema={selectedApi?.responses["200"]?.schema as any}
160+
renderExpandIcon={(node, onExpand) => {
161+
return (
162+
<div
163+
className="hover:bg-darken-3 relative flex cursor-pointer items-center justify-center rounded"
164+
style={{
165+
marginLeft: -23.5,
166+
width: 20,
167+
height: 20,
168+
marginRight: 3,
169+
textAlign: "center",
170+
}}
171+
onClick={() => {
172+
onExpand(node);
173+
}}
174+
>
175+
<i
176+
className={node.isExpanded ? "codicon codicon-chevron-down" : "codicon codicon-chevron-right"}
177+
></i>
178+
</div>
179+
);
180+
}}
160181
renderEmpty={() => {
161182
return (
162183
<tr>

media/src/components/APIPage/APIDocument/ApiErrorCode.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ export const ApiErrorCode: React.FC<ApiErrorCodeProps> = (props) => {
4747
| React.ReactElement<any, string | React.JSXElementConstructor<any>>
4848
| Iterable<React.ReactNode> // import isEmpty from 'lodash/isEmpty'
4949
| React.ReactPortal
50-
| React.PromiseLikeOfReactNode
5150
| null
5251
| undefined,
5352
index: any,

media/yarn.lock

Lines changed: 41 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -651,10 +651,10 @@
651651
resolved "https://registry.yarnpkg.com/@next/env/-/env-14.1.1.tgz#80150a8440eb0022a73ba353c6088d419b908bac"
652652
integrity sha512-7CnQyD5G8shHxQIIg3c7/pSeYFeMhsNbpU/bmvH7ZnDql7mNRgg8O2JZrhrc/soFnfBnKP4/xXNiiSIPn2w8gA==
653653

654-
"@next/eslint-plugin-next@14.2.3":
655-
version "14.2.3"
656-
resolved "https://registry.yarnpkg.com/@next/eslint-plugin-next/-/eslint-plugin-next-14.2.3.tgz#287ad8620e7061ba01e8d3313d464db6d217b6df"
657-
integrity sha512-L3oDricIIjgj1AVnRdRor21gI7mShlSwU/1ZGHmqM3LzHhXXhdkrfeNY5zif25Bi5Dd7fiJHsbhoZCHfXYvlAw==
654+
"@next/eslint-plugin-next@14.1.4":
655+
version "14.1.4"
656+
resolved "https://registry.npmmirror.com/@next/eslint-plugin-next/-/eslint-plugin-next-14.1.4.tgz#d7372b5ffede0e466af8af2ff534386418827fc8"
657+
integrity sha512-n4zYNLSyCo0Ln5b7qxqQeQ34OZKXwgbdcx6kmkQbywr+0k6M3Vinft0T72R6CDAcDrne2IAgSud4uWCzFgc5HA==
658658
dependencies:
659659
glob "10.3.10"
660660

@@ -930,50 +930,50 @@
930930
resolved "https://registry.npmmirror.com/@types/vscode/-/vscode-1.85.0.tgz#46beb07f0f626665b52d1e2294382b2bc63b602e"
931931
integrity sha512-CF/RBon/GXwdfmnjZj0WTUMZN5H6YITOfBCP4iEZlOtVQXuzw6t7Le7+cR+7JzdMrnlm7Mfp49Oj2TuSXIWo3g==
932932

933-
"@typescript-eslint/parser@^5.4.2 || ^6.0.0 || 7.0.0 - 7.2.0":
934-
version "7.2.0"
935-
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-7.2.0.tgz#44356312aea8852a3a82deebdacd52ba614ec07a"
936-
integrity sha512-5FKsVcHTk6TafQKQbuIVkXq58Fnbkd2wDL4LB7AURN7RUOu1utVP+G8+6u3ZhEroW3DF6hyo3ZEXxgKgp4KeCg==
933+
"@typescript-eslint/parser@^5.4.2 || ^6.0.0":
934+
version "6.21.0"
935+
resolved "https://registry.npmmirror.com/@typescript-eslint/parser/-/parser-6.21.0.tgz#af8fcf66feee2edc86bc5d1cf45e33b0630bf35b"
936+
integrity sha512-tbsV1jPne5CkFQCgPBcDOt30ItF7aJoZL997JSF7MhGQqOeT3svWRYxiqlfA5RUdlHN6Fi+EI9bxqbdyAUZjYQ==
937937
dependencies:
938-
"@typescript-eslint/scope-manager" "7.2.0"
939-
"@typescript-eslint/types" "7.2.0"
940-
"@typescript-eslint/typescript-estree" "7.2.0"
941-
"@typescript-eslint/visitor-keys" "7.2.0"
938+
"@typescript-eslint/scope-manager" "6.21.0"
939+
"@typescript-eslint/types" "6.21.0"
940+
"@typescript-eslint/typescript-estree" "6.21.0"
941+
"@typescript-eslint/visitor-keys" "6.21.0"
942942
debug "^4.3.4"
943943

944-
"@typescript-eslint/scope-manager@7.2.0":
945-
version "7.2.0"
946-
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-7.2.0.tgz#cfb437b09a84f95a0930a76b066e89e35d94e3da"
947-
integrity sha512-Qh976RbQM/fYtjx9hs4XkayYujB/aPwglw2choHmf3zBjB4qOywWSdt9+KLRdHubGcoSwBnXUH2sR3hkyaERRg==
944+
"@typescript-eslint/scope-manager@6.21.0":
945+
version "6.21.0"
946+
resolved "https://registry.npmmirror.com/@typescript-eslint/scope-manager/-/scope-manager-6.21.0.tgz#ea8a9bfc8f1504a6ac5d59a6df308d3a0630a2b1"
947+
integrity sha512-OwLUIWZJry80O99zvqXVEioyniJMa+d2GrqpUTqi5/v5D5rOrppJVBPa0yKCblcigC0/aYAzxxqQ1B+DS2RYsg==
948948
dependencies:
949-
"@typescript-eslint/types" "7.2.0"
950-
"@typescript-eslint/visitor-keys" "7.2.0"
949+
"@typescript-eslint/types" "6.21.0"
950+
"@typescript-eslint/visitor-keys" "6.21.0"
951951

952-
"@typescript-eslint/types@7.2.0":
953-
version "7.2.0"
954-
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-7.2.0.tgz#0feb685f16de320e8520f13cca30779c8b7c403f"
955-
integrity sha512-XFtUHPI/abFhm4cbCDc5Ykc8npOKBSJePY3a3s+lwumt7XWJuzP5cZcfZ610MIPHjQjNsOLlYK8ASPaNG8UiyA==
952+
"@typescript-eslint/types@6.21.0":
953+
version "6.21.0"
954+
resolved "https://registry.npmmirror.com/@typescript-eslint/types/-/types-6.21.0.tgz#205724c5123a8fef7ecd195075fa6e85bac3436d"
955+
integrity sha512-1kFmZ1rOm5epu9NZEZm1kckCDGj5UJEf7P1kliH4LKu/RkwpsfqqGmY2OOcUs18lSlQBKLDYBOGxRVtrMN5lpg==
956956

957-
"@typescript-eslint/typescript-estree@7.2.0":
958-
version "7.2.0"
959-
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-7.2.0.tgz#5beda2876c4137f8440c5a84b4f0370828682556"
960-
integrity sha512-cyxS5WQQCoBwSakpMrvMXuMDEbhOo9bNHHrNcEWis6XHx6KF518tkF1wBvKIn/tpq5ZpUYK7Bdklu8qY0MsFIA==
957+
"@typescript-eslint/typescript-estree@6.21.0":
958+
version "6.21.0"
959+
resolved "https://registry.npmmirror.com/@typescript-eslint/typescript-estree/-/typescript-estree-6.21.0.tgz#c47ae7901db3b8bddc3ecd73daff2d0895688c46"
960+
integrity sha512-6npJTkZcO+y2/kr+z0hc4HwNfrrP4kNYh57ek7yCNlrBjWQ1Y0OS7jiZTkgumrvkX5HkEKXFZkkdFNkaW2wmUQ==
961961
dependencies:
962-
"@typescript-eslint/types" "7.2.0"
963-
"@typescript-eslint/visitor-keys" "7.2.0"
962+
"@typescript-eslint/types" "6.21.0"
963+
"@typescript-eslint/visitor-keys" "6.21.0"
964964
debug "^4.3.4"
965965
globby "^11.1.0"
966966
is-glob "^4.0.3"
967967
minimatch "9.0.3"
968968
semver "^7.5.4"
969969
ts-api-utils "^1.0.1"
970970

971-
"@typescript-eslint/visitor-keys@7.2.0":
972-
version "7.2.0"
973-
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-7.2.0.tgz#5035f177752538a5750cca1af6044b633610bf9e"
974-
integrity sha512-c6EIQRHhcpl6+tO8EMR+kjkkV+ugUNXOmeASA1rlzkd8EPIriavpWoiEz1HR/VLhbVIdhqnV6E7JZm00cBDx2A==
971+
"@typescript-eslint/visitor-keys@6.21.0":
972+
version "6.21.0"
973+
resolved "https://registry.npmmirror.com/@typescript-eslint/visitor-keys/-/visitor-keys-6.21.0.tgz#87a99d077aa507e20e238b11d56cc26ade45fe47"
974+
integrity sha512-JJtkDduxLi9bivAB+cYOVMtbkqdPOhZ+ZI5LC47MIRrDV4Yn2o+ZnW10Nkmr28xRpSpdJ6Sm42Hjf2+REYXm0A==
975975
dependencies:
976-
"@typescript-eslint/types" "7.2.0"
976+
"@typescript-eslint/types" "6.21.0"
977977
eslint-visitor-keys "^3.4.1"
978978

979979
"@uiw/copy-to-clipboard@~1.0.12":
@@ -2312,14 +2312,14 @@ escape-string-regexp@^5.0.0:
23122312
resolved "https://registry.npmmirror.com/escape-string-regexp/-/escape-string-regexp-5.0.0.tgz#4683126b500b61762f2dbebace1806e8be31b1c8"
23132313
integrity sha512-/veY75JbMK4j1yjvuUxuVsiS/hr/4iHs9FTT6cgTexxdE0Ly/glccBAkloH/DofkjRbZU3bnoj38mOmhkZ0lHw==
23142314

2315-
eslint-config-next@14.2.3:
2316-
version "14.2.3"
2317-
resolved "https://registry.yarnpkg.com/eslint-config-next/-/eslint-config-next-14.2.3.tgz#2fb0f7c4eccda530a4b5054438162b2303786d4f"
2318-
integrity sha512-ZkNztm3Q7hjqvB1rRlOX8P9E/cXRL9ajRcs8jufEtwMfTVYRqnmtnaSu57QqHyBlovMuiB8LEzfLBkh5RYV6Fg==
2315+
eslint-config-next@14.1.4:
2316+
version "14.1.4"
2317+
resolved "https://registry.npmmirror.com/eslint-config-next/-/eslint-config-next-14.1.4.tgz#22f2ba4c0993e991249d863656a64c204bae542c"
2318+
integrity sha512-cihIahbhYAWwXJwZkAaRPpUi5t9aOi/HdfWXOjZeUOqNWXHD8X22kd1KG58Dc3MVaRx3HoR/oMGk2ltcrqDn8g==
23192319
dependencies:
2320-
"@next/eslint-plugin-next" "14.2.3"
2320+
"@next/eslint-plugin-next" "14.1.4"
23212321
"@rushstack/eslint-patch" "^1.3.3"
2322-
"@typescript-eslint/parser" "^5.4.2 || ^6.0.0 || 7.0.0 - 7.2.0"
2322+
"@typescript-eslint/parser" "^5.4.2 || ^6.0.0"
23232323
eslint-import-resolver-node "^0.3.6"
23242324
eslint-import-resolver-typescript "^3.5.2"
23252325
eslint-plugin-import "^2.28.1"
@@ -5643,16 +5643,7 @@ string-convert@^0.2.0:
56435643
resolved "https://registry.npmmirror.com/string-convert/-/string-convert-0.2.1.tgz#6982cc3049fbb4cd85f8b24568b9d9bf39eeff97"
56445644
integrity sha512-u/1tdPl4yQnPBjnVrmdLo9gtuLvELKsAoRapekWggdiQNvvvum+jYF329d84NAa660KQw7pB2n36KrIKVoXa3A==
56455645

5646-
"string-width-cjs@npm:string-width@^4.2.0":
5647-
version "4.2.3"
5648-
resolved "https://registry.npmmirror.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
5649-
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
5650-
dependencies:
5651-
emoji-regex "^8.0.0"
5652-
is-fullwidth-code-point "^3.0.0"
5653-
strip-ansi "^6.0.1"
5654-
5655-
string-width@^4.1.0:
5646+
"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0:
56565647
version "4.2.3"
56575648
resolved "https://registry.npmmirror.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
56585649
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@@ -5723,14 +5714,7 @@ string_decoder@^1.1.1:
57235714
dependencies:
57245715
safe-buffer "~5.2.0"
57255716

5726-
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
5727-
version "6.0.1"
5728-
resolved "https://registry.npmmirror.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
5729-
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
5730-
dependencies:
5731-
ansi-regex "^5.0.1"
5732-
5733-
strip-ansi@^6.0.0, strip-ansi@^6.0.1:
5717+
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
57345718
version "6.0.1"
57355719
resolved "https://registry.npmmirror.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
57365720
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,6 @@
284284
"@types/fs-extra": "^5.1.0",
285285
"@types/lodash": "^4.14.182",
286286
"@types/mocha": "^10.0.3",
287-
"@types/node": "18.x",
288287
"@types/react": "^18.3.3",
289288
"@types/react-dom": "^18.3.0",
290289
"@types/vscode": "^1.47.0",

src/Service.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { PontSpec } from "pontx-spec";
66
import { PontAPIExplorer, AlicloudApiExplorer } from "./explorer";
77
import { AlicloudApiCommands } from "./commands";
88
import * as _ from "lodash";
9-
import { batchDispose, getFormatValues, showProgress, VSCodeLogger } from "./utils";
9+
import { batchDispose, getFormatValues, getUserAgent, showProgress, VSCodeLogger } from "./utils";
1010
import { request } from "./openApiService/request/request";
1111
import fs from "fs";
1212
import fsx from "fs/promises";
@@ -145,19 +145,21 @@ export class AlicloudAPIService {
145145
* @description 根据 API 查询是否有 CodeSample
146146
*/
147147
async requestSamplesByAPI(product: string, version: string, api: string) {
148-
const resStr = await fetch(
149-
`https://api.aliyun.com/api/samples/product/${product}/version/${version}/api/${api}`,
150-
{},
151-
).then((res) => res.text());
148+
const resStr = await fetch(`https://api.aliyun.com/api/samples/product/${product}/version/${version}/api/${api}`, {
149+
headers: {
150+
"User-Agent": getUserAgent(),
151+
},
152+
}).then((res) => res.text());
152153
const res = JSON.parse(resStr);
153154
return res?.data || [];
154155
}
155156

156157
async requestEndpoints(product: string) {
157-
const resStr = await fetch(
158-
`https://api.aliyun.com/meta/v1/products/${product}/endpoints.json?language=zh-CN`,
159-
{},
160-
).then((res) => res.text());
158+
const resStr = await fetch(`https://api.aliyun.com/meta/v1/products/${product}/endpoints.json?language=zh-CN`, {
159+
headers: {
160+
"User-Agent": getUserAgent(),
161+
},
162+
}).then((res) => res.text());
161163
const res = JSON.parse(resStr);
162164
return res?.data?.endpoints || [];
163165
}
@@ -256,7 +258,10 @@ export class AlicloudAPIService {
256258
const resStr = await fetch(`https://api.aliyun.com/api/product/makeCode`, {
257259
method: "post",
258260
body: JSON.stringify(body),
259-
headers: { "Content-Type": "application/json" },
261+
headers: {
262+
"Content-Type": "application/json",
263+
"User-Agent": getUserAgent(),
264+
},
260265
}).then((res) => res.text());
261266
const res = JSON.parse(resStr);
262267
return res;

0 commit comments

Comments
 (0)