Skip to content

Add user-agent to the request header #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion media/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"@vitejs/plugin-react": "^1.3.2",
"autoprefixer": "^10.0.1",
"eslint": "^8",
"eslint-config-next": "14.2.3",
"eslint-config-next": "14.1.4",
"less": "^4.2.0",
"postcss": "^8",
"prettier": "^3.2.5",
Expand Down
21 changes: 21 additions & 0 deletions media/src/components/APIPage/API.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,27 @@ export const API: React.FC<APIProps> = (props) => {
<InnerSchemaTable
name=""
schema={selectedApi?.responses["200"]?.schema as any}
renderExpandIcon={(node, onExpand) => {
return (
<div
className="hover:bg-darken-3 relative flex cursor-pointer items-center justify-center rounded"
style={{
marginLeft: -23.5,
width: 20,
height: 20,
marginRight: 3,
textAlign: "center",
}}
onClick={() => {
onExpand(node);
}}
>
<i
className={node.isExpanded ? "codicon codicon-chevron-down" : "codicon codicon-chevron-right"}
></i>
</div>
);
}}
renderEmpty={() => {
return (
<tr>
Expand Down
1 change: 0 additions & 1 deletion media/src/components/APIPage/APIDocument/ApiErrorCode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export const ApiErrorCode: React.FC<ApiErrorCodeProps> = (props) => {
| React.ReactElement<any, string | React.JSXElementConstructor<any>>
| Iterable<React.ReactNode> // import isEmpty from 'lodash/isEmpty'
| React.ReactPortal
| React.PromiseLikeOfReactNode
| null
| undefined,
index: any,
Expand Down
98 changes: 41 additions & 57 deletions media/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -651,10 +651,10 @@
resolved "https://registry.yarnpkg.com/@next/env/-/env-14.1.1.tgz#80150a8440eb0022a73ba353c6088d419b908bac"
integrity sha512-7CnQyD5G8shHxQIIg3c7/pSeYFeMhsNbpU/bmvH7ZnDql7mNRgg8O2JZrhrc/soFnfBnKP4/xXNiiSIPn2w8gA==

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

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

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

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

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

"@typescript-eslint/typescript-estree@7.2.0":
version "7.2.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-7.2.0.tgz#5beda2876c4137f8440c5a84b4f0370828682556"
integrity sha512-cyxS5WQQCoBwSakpMrvMXuMDEbhOo9bNHHrNcEWis6XHx6KF518tkF1wBvKIn/tpq5ZpUYK7Bdklu8qY0MsFIA==
"@typescript-eslint/typescript-estree@6.21.0":
version "6.21.0"
resolved "https://registry.npmmirror.com/@typescript-eslint/typescript-estree/-/typescript-estree-6.21.0.tgz#c47ae7901db3b8bddc3ecd73daff2d0895688c46"
integrity sha512-6npJTkZcO+y2/kr+z0hc4HwNfrrP4kNYh57ek7yCNlrBjWQ1Y0OS7jiZTkgumrvkX5HkEKXFZkkdFNkaW2wmUQ==
dependencies:
"@typescript-eslint/types" "7.2.0"
"@typescript-eslint/visitor-keys" "7.2.0"
"@typescript-eslint/types" "6.21.0"
"@typescript-eslint/visitor-keys" "6.21.0"
debug "^4.3.4"
globby "^11.1.0"
is-glob "^4.0.3"
minimatch "9.0.3"
semver "^7.5.4"
ts-api-utils "^1.0.1"

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

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

eslint-config-next@14.2.3:
version "14.2.3"
resolved "https://registry.yarnpkg.com/eslint-config-next/-/eslint-config-next-14.2.3.tgz#2fb0f7c4eccda530a4b5054438162b2303786d4f"
integrity sha512-ZkNztm3Q7hjqvB1rRlOX8P9E/cXRL9ajRcs8jufEtwMfTVYRqnmtnaSu57QqHyBlovMuiB8LEzfLBkh5RYV6Fg==
eslint-config-next@14.1.4:
version "14.1.4"
resolved "https://registry.npmmirror.com/eslint-config-next/-/eslint-config-next-14.1.4.tgz#22f2ba4c0993e991249d863656a64c204bae542c"
integrity sha512-cihIahbhYAWwXJwZkAaRPpUi5t9aOi/HdfWXOjZeUOqNWXHD8X22kd1KG58Dc3MVaRx3HoR/oMGk2ltcrqDn8g==
dependencies:
"@next/eslint-plugin-next" "14.2.3"
"@next/eslint-plugin-next" "14.1.4"
"@rushstack/eslint-patch" "^1.3.3"
"@typescript-eslint/parser" "^5.4.2 || ^6.0.0 || 7.0.0 - 7.2.0"
"@typescript-eslint/parser" "^5.4.2 || ^6.0.0"
eslint-import-resolver-node "^0.3.6"
eslint-import-resolver-typescript "^3.5.2"
eslint-plugin-import "^2.28.1"
Expand Down Expand Up @@ -5643,16 +5643,7 @@ string-convert@^0.2.0:
resolved "https://registry.npmmirror.com/string-convert/-/string-convert-0.2.1.tgz#6982cc3049fbb4cd85f8b24568b9d9bf39eeff97"
integrity sha512-u/1tdPl4yQnPBjnVrmdLo9gtuLvELKsAoRapekWggdiQNvvvum+jYF329d84NAa660KQw7pB2n36KrIKVoXa3A==

"string-width-cjs@npm:string-width@^4.2.0":
version "4.2.3"
resolved "https://registry.npmmirror.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
dependencies:
emoji-regex "^8.0.0"
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"

string-width@^4.1.0:
"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0:
version "4.2.3"
resolved "https://registry.npmmirror.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
Expand Down Expand Up @@ -5723,14 +5714,7 @@ string_decoder@^1.1.1:
dependencies:
safe-buffer "~5.2.0"

"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
version "6.0.1"
resolved "https://registry.npmmirror.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"

strip-ansi@^6.0.0, strip-ansi@^6.0.1:
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.npmmirror.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@
"@types/fs-extra": "^5.1.0",
"@types/lodash": "^4.14.182",
"@types/mocha": "^10.0.3",
"@types/node": "18.x",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@types/vscode": "^1.47.0",
Expand Down
25 changes: 15 additions & 10 deletions src/Service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { PontSpec } from "pontx-spec";
import { PontAPIExplorer, AlicloudApiExplorer } from "./explorer";
import { AlicloudApiCommands } from "./commands";
import * as _ from "lodash";
import { batchDispose, getFormatValues, showProgress, VSCodeLogger } from "./utils";
import { batchDispose, getFormatValues, getUserAgent, showProgress, VSCodeLogger } from "./utils";
import { request } from "./openApiService/request/request";
import fs from "fs";
import fsx from "fs/promises";
Expand Down Expand Up @@ -145,19 +145,21 @@ export class AlicloudAPIService {
* @description 根据 API 查询是否有 CodeSample
*/
async requestSamplesByAPI(product: string, version: string, api: string) {
const resStr = await fetch(
`https://api.aliyun.com/api/samples/product/${product}/version/${version}/api/${api}`,
{},
).then((res) => res.text());
const resStr = await fetch(`https://api.aliyun.com/api/samples/product/${product}/version/${version}/api/${api}`, {
headers: {
"User-Agent": getUserAgent(),
},
}).then((res) => res.text());
const res = JSON.parse(resStr);
return res?.data || [];
}

async requestEndpoints(product: string) {
const resStr = await fetch(
`https://api.aliyun.com/meta/v1/products/${product}/endpoints.json?language=zh-CN`,
{},
).then((res) => res.text());
const resStr = await fetch(`https://api.aliyun.com/meta/v1/products/${product}/endpoints.json?language=zh-CN`, {
headers: {
"User-Agent": getUserAgent(),
},
}).then((res) => res.text());
const res = JSON.parse(resStr);
return res?.data?.endpoints || [];
}
Expand Down Expand Up @@ -256,7 +258,10 @@ export class AlicloudAPIService {
const resStr = await fetch(`https://api.aliyun.com/api/product/makeCode`, {
method: "post",
body: JSON.stringify(body),
headers: { "Content-Type": "application/json" },
headers: {
"Content-Type": "application/json",
"User-Agent": getUserAgent(),
},
}).then((res) => res.text());
const res = JSON.parse(resStr);
return res;
Expand Down
Loading
Loading