feat: 添加多项功能和修复
功能新增: - OSS 存储使用情况显示(文件页面) - OSS 当日流量统计(阿里云云监控API) - 分享页面路由修复(/s/xxx 格式支持) Bug修复: - 修复分享页面资源路径(相对路径改绝对路径) - 修复分享码获取逻辑(支持路径格式) - 修复OSS配额undefined显示问题 - 修复登录流程OSS配置检查 - 修复文件数为null时的显示问题 依赖更新: - 添加 @alicloud/cms20190101 云监控SDK - 添加 @alicloud/openapi-client Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
20
backend/node_modules/@alicloud/tea-util/ChangeLog.txt
generated
vendored
Normal file
20
backend/node_modules/@alicloud/tea-util/ChangeLog.txt
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
2024-07-08 Version 1.4.9
|
||||
1. Support extends query parameters
|
||||
|
||||
2024-05-13 Version 1.4.8
|
||||
1. Support extends parameters
|
||||
|
||||
2023-06-28 Version: 1.4.7
|
||||
1. Support static method `assertAsReadable()`
|
||||
|
||||
2023-06-26 Version: 1.4.6
|
||||
1. Support static method `assertAsInteger()`
|
||||
|
||||
2022-11-16 Version: 1.4.5
|
||||
1. Support ca params for server and client
|
||||
|
||||
2020-03-03 Version: 1.2.3
|
||||
1. Release version 1.2.3
|
||||
|
||||
2020-02-10 Version: 1.0.0
|
||||
1. Release version 1.0.0
|
||||
29
backend/node_modules/@alicloud/tea-util/README.md
generated
vendored
Normal file
29
backend/node_modules/@alicloud/tea-util/README.md
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
English | [简体中文](README-CN.md)
|
||||

|
||||
|
||||
## Alibaba Cloud Tea Util SDK for TypeScript/Node.js
|
||||
|
||||
## Prerequisite
|
||||
|
||||
Node.js >= 8.x
|
||||
|
||||
## Installation
|
||||
If you use `npm` to manage your dependence, you can use the following command to install it and write into package.json dependences:
|
||||
|
||||
```sh
|
||||
$ npm install @alicloud/tea-util -S
|
||||
```
|
||||
|
||||
## Issues
|
||||
[Opening an Issue](https://github.com/aliyun/tea-util/issues/new), Issues not conforming to the guidelines may be closed immediately.
|
||||
|
||||
## Changelog
|
||||
Detailed changes for each release are documented in the [release notes](./ChangeLog.txt).
|
||||
|
||||
## References
|
||||
* [Latest Release](https://github.com/aliyun/tea-util/tree/master/ts)
|
||||
|
||||
## License
|
||||
[Apache-2.0](http://www.apache.org/licenses/LICENSE-2.0)
|
||||
|
||||
Copyright (c) 2009-present, Alibaba Cloud All rights reserved.
|
||||
108
backend/node_modules/@alicloud/tea-util/dist/client.d.ts
generated
vendored
Normal file
108
backend/node_modules/@alicloud/tea-util/dist/client.d.ts
generated
vendored
Normal file
@@ -0,0 +1,108 @@
|
||||
/// <reference types="node" />
|
||||
import { Readable } from 'stream';
|
||||
import * as $tea from '@alicloud/tea-typescript';
|
||||
export declare class ExtendsParameters extends $tea.Model {
|
||||
headers?: {
|
||||
[key: string]: string;
|
||||
};
|
||||
queries?: {
|
||||
[key: string]: string;
|
||||
};
|
||||
static names(): {
|
||||
[key: string]: string;
|
||||
};
|
||||
static types(): {
|
||||
[key: string]: any;
|
||||
};
|
||||
constructor(map?: {
|
||||
[key: string]: any;
|
||||
});
|
||||
}
|
||||
export declare class RuntimeOptions extends $tea.Model {
|
||||
autoretry?: boolean;
|
||||
ignoreSSL?: boolean;
|
||||
key?: string;
|
||||
cert?: string;
|
||||
ca?: string;
|
||||
maxAttempts?: number;
|
||||
backoffPolicy?: string;
|
||||
backoffPeriod?: number;
|
||||
readTimeout?: number;
|
||||
connectTimeout?: number;
|
||||
httpProxy?: string;
|
||||
httpsProxy?: string;
|
||||
noProxy?: string;
|
||||
maxIdleConns?: number;
|
||||
keepAlive?: boolean;
|
||||
extendsParameters?: ExtendsParameters;
|
||||
static names(): {
|
||||
[key: string]: string;
|
||||
};
|
||||
static types(): {
|
||||
[key: string]: any;
|
||||
};
|
||||
constructor(map?: {
|
||||
[key: string]: any;
|
||||
});
|
||||
}
|
||||
export default class Client {
|
||||
static toString(buff: Buffer): string;
|
||||
static parseJSON(text: string): any;
|
||||
static readAsBytes(stream: Readable): Promise<Buffer>;
|
||||
static readAsString(stream: Readable): Promise<string>;
|
||||
static readAsJSON(stream: Readable): Promise<any>;
|
||||
static getNonce(): string;
|
||||
static getDateUTCString(): string;
|
||||
static defaultString(real: string, defaultValue: string): string;
|
||||
static defaultNumber(real: number, defaultValue: number): number;
|
||||
static toFormString(val: {
|
||||
[key: string]: any;
|
||||
}): string;
|
||||
static toJSONString(val: any): string;
|
||||
static toBytes(val: string): Buffer;
|
||||
static empty(val: string): boolean;
|
||||
static equalString(val1: string, val2: string): boolean;
|
||||
static equalNumber(val1: number, val2: number): boolean;
|
||||
static isUnset(value: any): boolean;
|
||||
static stringifyMapValue(m: {
|
||||
[key: string]: any;
|
||||
}): {
|
||||
[key: string]: string;
|
||||
};
|
||||
static anyifyMapValue(m: {
|
||||
[key: string]: string;
|
||||
}): {
|
||||
[key: string]: any;
|
||||
};
|
||||
static assertAsBoolean(value: any): boolean;
|
||||
static assertAsString(value: any): string;
|
||||
static assertAsNumber(value: any): number;
|
||||
/**
|
||||
* Assert a value, if it is a integer, return it, otherwise throws
|
||||
* @return the integer value
|
||||
*/
|
||||
static assertAsInteger(value: any): number;
|
||||
static assertAsMap(value: any): {
|
||||
[key: string]: any;
|
||||
};
|
||||
static assertAsArray(value: any): any[];
|
||||
static assertAsBytes(value: any): Buffer;
|
||||
static getUserAgent(userAgent: string): string;
|
||||
static is2xx(code: number): boolean;
|
||||
static is3xx(code: number): boolean;
|
||||
static is4xx(code: number): boolean;
|
||||
static is5xx(code: number): boolean;
|
||||
static validateModel(m: $tea.Model): void;
|
||||
static toMap(inputModel: $tea.Model): {
|
||||
[key: string]: any;
|
||||
};
|
||||
static sleep(millisecond: number): Promise<void>;
|
||||
static toArray(input: any): {
|
||||
[key: string]: any;
|
||||
}[];
|
||||
/**
|
||||
* Assert a value, if it is a readable, return it, otherwise throws
|
||||
* @return the readable value
|
||||
*/
|
||||
static assertAsReadable(value: any): Readable;
|
||||
}
|
||||
301
backend/node_modules/@alicloud/tea-util/dist/client.js
generated
vendored
Normal file
301
backend/node_modules/@alicloud/tea-util/dist/client.js
generated
vendored
Normal file
@@ -0,0 +1,301 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.RuntimeOptions = exports.ExtendsParameters = void 0;
|
||||
const stream_1 = require("stream");
|
||||
const $tea = __importStar(require("@alicloud/tea-typescript"));
|
||||
const kitx = __importStar(require("kitx"));
|
||||
const querystring_1 = __importDefault(require("querystring"));
|
||||
const os_1 = require("os");
|
||||
const DEFAULT_USER_AGENT = `AlibabaCloud (${os_1.platform()}; ${os_1.arch()}) Node.js/${process.version} Core/1.0.1 TeaDSL/1`;
|
||||
class ExtendsParameters extends $tea.Model {
|
||||
constructor(map) {
|
||||
super(map);
|
||||
}
|
||||
static names() {
|
||||
return {
|
||||
headers: 'headers',
|
||||
queries: 'queries',
|
||||
};
|
||||
}
|
||||
static types() {
|
||||
return {
|
||||
headers: { 'type': 'map', 'keyType': 'string', 'valueType': 'string' },
|
||||
queries: { 'type': 'map', 'keyType': 'string', 'valueType': 'string' },
|
||||
};
|
||||
}
|
||||
}
|
||||
exports.ExtendsParameters = ExtendsParameters;
|
||||
class RuntimeOptions extends $tea.Model {
|
||||
constructor(map) {
|
||||
super(map);
|
||||
}
|
||||
static names() {
|
||||
return {
|
||||
autoretry: 'autoretry',
|
||||
ignoreSSL: 'ignoreSSL',
|
||||
key: 'key',
|
||||
cert: 'cert',
|
||||
ca: 'ca',
|
||||
maxAttempts: 'max_attempts',
|
||||
backoffPolicy: 'backoff_policy',
|
||||
backoffPeriod: 'backoff_period',
|
||||
readTimeout: 'readTimeout',
|
||||
connectTimeout: 'connectTimeout',
|
||||
httpProxy: 'httpProxy',
|
||||
httpsProxy: 'httpsProxy',
|
||||
noProxy: 'noProxy',
|
||||
maxIdleConns: 'maxIdleConns',
|
||||
keepAlive: 'keepAlive',
|
||||
extendsParameters: 'extendsParameters',
|
||||
};
|
||||
}
|
||||
static types() {
|
||||
return {
|
||||
autoretry: 'boolean',
|
||||
ignoreSSL: 'boolean',
|
||||
key: 'string',
|
||||
cert: 'string',
|
||||
ca: 'string',
|
||||
maxAttempts: 'number',
|
||||
backoffPolicy: 'string',
|
||||
backoffPeriod: 'number',
|
||||
readTimeout: 'number',
|
||||
connectTimeout: 'number',
|
||||
httpProxy: 'string',
|
||||
httpsProxy: 'string',
|
||||
noProxy: 'string',
|
||||
maxIdleConns: 'number',
|
||||
keepAlive: 'boolean',
|
||||
extendsParameters: ExtendsParameters,
|
||||
};
|
||||
}
|
||||
}
|
||||
exports.RuntimeOptions = RuntimeOptions;
|
||||
function read(readable) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let onData, onError, onEnd;
|
||||
var cleanup = function () {
|
||||
// cleanup
|
||||
readable.removeListener('error', onError);
|
||||
readable.removeListener('data', onData);
|
||||
readable.removeListener('end', onEnd);
|
||||
};
|
||||
var bufs = [];
|
||||
var size = 0;
|
||||
onData = function (buf) {
|
||||
bufs.push(buf);
|
||||
size += buf.length;
|
||||
};
|
||||
onError = function (err) {
|
||||
cleanup();
|
||||
reject(err);
|
||||
};
|
||||
onEnd = function () {
|
||||
cleanup();
|
||||
resolve(Buffer.concat(bufs, size));
|
||||
};
|
||||
readable.on('error', onError);
|
||||
readable.on('data', onData);
|
||||
readable.on('end', onEnd);
|
||||
});
|
||||
}
|
||||
class Client {
|
||||
static toString(buff) {
|
||||
return buff.toString();
|
||||
}
|
||||
static parseJSON(text) {
|
||||
return JSON.parse(text);
|
||||
}
|
||||
static async readAsBytes(stream) {
|
||||
return await read(stream);
|
||||
}
|
||||
static async readAsString(stream) {
|
||||
let buff = await Client.readAsBytes(stream);
|
||||
return Client.toString(buff);
|
||||
}
|
||||
static async readAsJSON(stream) {
|
||||
return Client.parseJSON(await Client.readAsString(stream));
|
||||
}
|
||||
static getNonce() {
|
||||
return kitx.makeNonce();
|
||||
}
|
||||
static getDateUTCString() {
|
||||
const now = new Date();
|
||||
return now.toUTCString();
|
||||
}
|
||||
static defaultString(real, defaultValue) {
|
||||
return real || defaultValue;
|
||||
}
|
||||
static defaultNumber(real, defaultValue) {
|
||||
return real || defaultValue;
|
||||
}
|
||||
static toFormString(val) {
|
||||
return querystring_1.default.stringify(val);
|
||||
}
|
||||
static toJSONString(val) {
|
||||
if (typeof val === 'string') {
|
||||
return val;
|
||||
}
|
||||
return JSON.stringify(val);
|
||||
}
|
||||
static toBytes(val) {
|
||||
return Buffer.from(val);
|
||||
}
|
||||
static empty(val) {
|
||||
return !val;
|
||||
}
|
||||
static equalString(val1, val2) {
|
||||
return val1 === val2;
|
||||
}
|
||||
static equalNumber(val1, val2) {
|
||||
return val1 === val2;
|
||||
}
|
||||
static isUnset(value) {
|
||||
if (typeof value === 'undefined') {
|
||||
return true;
|
||||
}
|
||||
if (value === null) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
static stringifyMapValue(m) {
|
||||
if (!m) {
|
||||
return m;
|
||||
}
|
||||
const result = {};
|
||||
for (const [key, value] of Object.entries(m)) {
|
||||
if (typeof value === 'undefined' || value === null) {
|
||||
continue;
|
||||
}
|
||||
result[key] = String(value);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
static anyifyMapValue(m) {
|
||||
return m;
|
||||
}
|
||||
static assertAsBoolean(value) {
|
||||
if (typeof value === 'boolean') {
|
||||
return value;
|
||||
}
|
||||
throw new Error(`The value is not a boolean`);
|
||||
}
|
||||
static assertAsString(value) {
|
||||
if (typeof value === 'string') {
|
||||
return value;
|
||||
}
|
||||
throw new Error(`The value is not a string`);
|
||||
}
|
||||
static assertAsNumber(value) {
|
||||
if (typeof value === 'number') {
|
||||
return value;
|
||||
}
|
||||
throw new Error(`The value is not a number`);
|
||||
}
|
||||
/**
|
||||
* Assert a value, if it is a integer, return it, otherwise throws
|
||||
* @return the integer value
|
||||
*/
|
||||
static assertAsInteger(value) {
|
||||
if (Number.isInteger(value)) {
|
||||
return value;
|
||||
}
|
||||
throw new Error(`The value is not a int number`);
|
||||
}
|
||||
static assertAsMap(value) {
|
||||
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
||||
return value;
|
||||
}
|
||||
throw new Error(`The value is not a object`);
|
||||
}
|
||||
static assertAsArray(value) {
|
||||
if (Array.isArray(value)) {
|
||||
return value;
|
||||
}
|
||||
throw new Error(`The value is not array`);
|
||||
}
|
||||
static assertAsBytes(value) {
|
||||
if (Buffer.isBuffer(value)) {
|
||||
return value;
|
||||
}
|
||||
throw new Error(`The value is not bytes`);
|
||||
}
|
||||
static getUserAgent(userAgent) {
|
||||
if (!userAgent || !userAgent.length) {
|
||||
return DEFAULT_USER_AGENT;
|
||||
}
|
||||
return DEFAULT_USER_AGENT + " " + userAgent;
|
||||
}
|
||||
static is2xx(code) {
|
||||
return code >= 200 && code < 300;
|
||||
}
|
||||
static is3xx(code) {
|
||||
return code >= 300 && code < 400;
|
||||
}
|
||||
static is4xx(code) {
|
||||
return code >= 400 && code < 500;
|
||||
}
|
||||
static is5xx(code) {
|
||||
return code >= 500 && code < 600;
|
||||
}
|
||||
static validateModel(m) {
|
||||
}
|
||||
static toMap(inputModel) {
|
||||
return $tea.toMap(inputModel);
|
||||
}
|
||||
static async sleep(millisecond) {
|
||||
return new Promise(resolve => {
|
||||
setTimeout(() => {
|
||||
resolve();
|
||||
}, millisecond);
|
||||
});
|
||||
}
|
||||
static toArray(input) {
|
||||
if (!(input instanceof Array)) {
|
||||
return null;
|
||||
}
|
||||
let ret = [];
|
||||
input.forEach((model) => {
|
||||
if (!model) {
|
||||
return;
|
||||
}
|
||||
ret.push($tea.toMap(model));
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
/**
|
||||
* Assert a value, if it is a readable, return it, otherwise throws
|
||||
* @return the readable value
|
||||
*/
|
||||
static assertAsReadable(value) {
|
||||
if (value instanceof stream_1.Readable) {
|
||||
return value;
|
||||
}
|
||||
throw new Error(`The value is not a readable`);
|
||||
}
|
||||
}
|
||||
exports.default = Client;
|
||||
//# sourceMappingURL=client.js.map
|
||||
1
backend/node_modules/@alicloud/tea-util/dist/client.js.map
generated
vendored
Normal file
1
backend/node_modules/@alicloud/tea-util/dist/client.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
32
backend/node_modules/@alicloud/tea-util/package.json
generated
vendored
Normal file
32
backend/node_modules/@alicloud/tea-util/package.json
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"name": "@alicloud/tea-util",
|
||||
"version": "1.4.9",
|
||||
"description": "",
|
||||
"main": "dist/client.js",
|
||||
"scripts": {
|
||||
"test": "mocha -r ts-node/register -r source-map-support/register test/**/*.spec.ts",
|
||||
"test-cov": "nyc -e .ts -r=html -r=text -r=lcov npm run test",
|
||||
"build": "tsc",
|
||||
"prepublishOnly": "tsc"
|
||||
},
|
||||
"author": "Jackson Tian",
|
||||
"license": "Apache-2.0",
|
||||
"devDependencies": {
|
||||
"@types/mocha": "^7.0.1",
|
||||
"@types/node": "^12.12.26",
|
||||
"mocha": "^7.0.1",
|
||||
"nyc": "^15.0.0",
|
||||
"source-map-support": "^0.5.16",
|
||||
"ts-node": "^8.6.2",
|
||||
"typescript": "^3.7.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"@alicloud/tea-typescript": "^1.5.1",
|
||||
"kitx": "^2.0.0"
|
||||
},
|
||||
"files": [
|
||||
"dist",
|
||||
"src"
|
||||
],
|
||||
"repository": "git@github.com:aliyun/tea-util.git"
|
||||
}
|
||||
343
backend/node_modules/@alicloud/tea-util/src/client.ts
generated
vendored
Normal file
343
backend/node_modules/@alicloud/tea-util/src/client.ts
generated
vendored
Normal file
@@ -0,0 +1,343 @@
|
||||
import { Readable } from 'stream';
|
||||
import * as $tea from '@alicloud/tea-typescript';
|
||||
import * as kitx from 'kitx';
|
||||
import querystring from 'querystring';
|
||||
import { platform, arch } from 'os';
|
||||
const DEFAULT_USER_AGENT = `AlibabaCloud (${platform()}; ${arch()}) Node.js/${process.version} Core/1.0.1 TeaDSL/1`;
|
||||
|
||||
export class ExtendsParameters extends $tea.Model {
|
||||
headers?: { [key: string]: string };
|
||||
queries?: { [key: string]: string };
|
||||
static names(): { [key: string]: string } {
|
||||
return {
|
||||
headers: 'headers',
|
||||
queries: 'queries',
|
||||
};
|
||||
}
|
||||
|
||||
static types(): { [key: string]: any } {
|
||||
return {
|
||||
headers: { 'type': 'map', 'keyType': 'string', 'valueType': 'string' },
|
||||
queries: { 'type': 'map', 'keyType': 'string', 'valueType': 'string' },
|
||||
};
|
||||
}
|
||||
|
||||
constructor(map?: { [key: string]: any }) {
|
||||
super(map);
|
||||
}
|
||||
}
|
||||
|
||||
export class RuntimeOptions extends $tea.Model {
|
||||
autoretry?: boolean;
|
||||
ignoreSSL?: boolean;
|
||||
key?: string;
|
||||
cert?: string;
|
||||
ca?: string;
|
||||
maxAttempts?: number;
|
||||
backoffPolicy?: string;
|
||||
backoffPeriod?: number;
|
||||
readTimeout?: number;
|
||||
connectTimeout?: number;
|
||||
httpProxy?: string;
|
||||
httpsProxy?: string;
|
||||
noProxy?: string;
|
||||
maxIdleConns?: number;
|
||||
keepAlive?: boolean;
|
||||
extendsParameters?: ExtendsParameters;
|
||||
static names(): { [key: string]: string } {
|
||||
return {
|
||||
autoretry: 'autoretry',
|
||||
ignoreSSL: 'ignoreSSL',
|
||||
key: 'key',
|
||||
cert: 'cert',
|
||||
ca: 'ca',
|
||||
maxAttempts: 'max_attempts',
|
||||
backoffPolicy: 'backoff_policy',
|
||||
backoffPeriod: 'backoff_period',
|
||||
readTimeout: 'readTimeout',
|
||||
connectTimeout: 'connectTimeout',
|
||||
httpProxy: 'httpProxy',
|
||||
httpsProxy: 'httpsProxy',
|
||||
noProxy: 'noProxy',
|
||||
maxIdleConns: 'maxIdleConns',
|
||||
keepAlive: 'keepAlive',
|
||||
extendsParameters: 'extendsParameters',
|
||||
};
|
||||
}
|
||||
|
||||
static types(): { [key: string]: any } {
|
||||
return {
|
||||
autoretry: 'boolean',
|
||||
ignoreSSL: 'boolean',
|
||||
key: 'string',
|
||||
cert: 'string',
|
||||
ca: 'string',
|
||||
maxAttempts: 'number',
|
||||
backoffPolicy: 'string',
|
||||
backoffPeriod: 'number',
|
||||
readTimeout: 'number',
|
||||
connectTimeout: 'number',
|
||||
httpProxy: 'string',
|
||||
httpsProxy: 'string',
|
||||
noProxy: 'string',
|
||||
maxIdleConns: 'number',
|
||||
keepAlive: 'boolean',
|
||||
extendsParameters: ExtendsParameters,
|
||||
};
|
||||
}
|
||||
|
||||
constructor(map?: { [key: string]: any }) {
|
||||
super(map);
|
||||
}
|
||||
}
|
||||
|
||||
function read(readable: Readable): Promise<Buffer> {
|
||||
return new Promise((resolve, reject) => {
|
||||
let onData, onError, onEnd;
|
||||
var cleanup = function () {
|
||||
// cleanup
|
||||
readable.removeListener('error', onError);
|
||||
readable.removeListener('data', onData);
|
||||
readable.removeListener('end', onEnd);
|
||||
};
|
||||
|
||||
var bufs = [];
|
||||
var size = 0;
|
||||
|
||||
onData = function (buf) {
|
||||
bufs.push(buf);
|
||||
size += buf.length;
|
||||
};
|
||||
|
||||
onError = function (err) {
|
||||
cleanup();
|
||||
reject(err);
|
||||
};
|
||||
|
||||
onEnd = function () {
|
||||
cleanup();
|
||||
resolve(Buffer.concat(bufs, size));
|
||||
};
|
||||
|
||||
readable.on('error', onError);
|
||||
readable.on('data', onData);
|
||||
readable.on('end', onEnd);
|
||||
});
|
||||
}
|
||||
|
||||
export default class Client {
|
||||
|
||||
static toString(buff: Buffer): string {
|
||||
return buff.toString();
|
||||
}
|
||||
|
||||
static parseJSON(text: string): any {
|
||||
return JSON.parse(text);
|
||||
}
|
||||
|
||||
static async readAsBytes(stream: Readable): Promise<Buffer> {
|
||||
return await read(stream);
|
||||
}
|
||||
|
||||
static async readAsString(stream: Readable): Promise<string> {
|
||||
let buff = await Client.readAsBytes(stream);
|
||||
return Client.toString(buff);
|
||||
}
|
||||
|
||||
static async readAsJSON(stream: Readable): Promise<any> {
|
||||
return Client.parseJSON(await Client.readAsString(stream));
|
||||
}
|
||||
|
||||
static getNonce(): string {
|
||||
return kitx.makeNonce();
|
||||
}
|
||||
|
||||
static getDateUTCString(): string {
|
||||
const now = new Date();
|
||||
return now.toUTCString();
|
||||
}
|
||||
|
||||
static defaultString(real: string, defaultValue: string): string {
|
||||
return real || defaultValue;
|
||||
}
|
||||
|
||||
static defaultNumber(real: number, defaultValue: number): number {
|
||||
return real || defaultValue;
|
||||
}
|
||||
|
||||
static toFormString(val: { [key: string]: any }): string {
|
||||
return querystring.stringify(val);
|
||||
}
|
||||
|
||||
static toJSONString(val: any): string {
|
||||
if (typeof val === 'string') {
|
||||
return val;
|
||||
}
|
||||
return JSON.stringify(val);
|
||||
}
|
||||
|
||||
static toBytes(val: string): Buffer {
|
||||
return Buffer.from(val);
|
||||
}
|
||||
|
||||
static empty(val: string): boolean {
|
||||
return !val;
|
||||
}
|
||||
|
||||
static equalString(val1: string, val2: string): boolean {
|
||||
return val1 === val2;
|
||||
}
|
||||
|
||||
static equalNumber(val1: number, val2: number): boolean {
|
||||
return val1 === val2;
|
||||
}
|
||||
|
||||
static isUnset(value: any): boolean {
|
||||
if (typeof value === 'undefined') {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (value === null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static stringifyMapValue(m: { [key: string]: any }): { [key: string]: string } {
|
||||
if (!m) {
|
||||
return m;
|
||||
}
|
||||
|
||||
const result: { [key: string]: string } = {};
|
||||
for (const [key, value] of Object.entries(m)) {
|
||||
if (typeof value === 'undefined' || value === null) {
|
||||
continue;
|
||||
}
|
||||
result[key] = String(value);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static anyifyMapValue(m: { [key: string]: string }): { [key: string]: any } {
|
||||
return m;
|
||||
}
|
||||
|
||||
static assertAsBoolean(value: any): boolean {
|
||||
if (typeof value === 'boolean') {
|
||||
return value;
|
||||
}
|
||||
throw new Error(`The value is not a boolean`);
|
||||
}
|
||||
|
||||
static assertAsString(value: any): string {
|
||||
if (typeof value === 'string') {
|
||||
return value;
|
||||
}
|
||||
throw new Error(`The value is not a string`);
|
||||
}
|
||||
|
||||
static assertAsNumber(value: any): number {
|
||||
if (typeof value === 'number') {
|
||||
return value;
|
||||
}
|
||||
throw new Error(`The value is not a number`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert a value, if it is a integer, return it, otherwise throws
|
||||
* @return the integer value
|
||||
*/
|
||||
static assertAsInteger(value: any): number {
|
||||
if (Number.isInteger(value)) {
|
||||
return value;
|
||||
}
|
||||
throw new Error(`The value is not a int number`);
|
||||
}
|
||||
|
||||
static assertAsMap(value: any): { [key: string]: any } {
|
||||
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
||||
return value as { [key: string]: any };
|
||||
}
|
||||
throw new Error(`The value is not a object`);
|
||||
}
|
||||
|
||||
static assertAsArray(value: any): any[] {
|
||||
if (Array.isArray(value)) {
|
||||
return value;
|
||||
}
|
||||
throw new Error(`The value is not array`);
|
||||
}
|
||||
|
||||
static assertAsBytes(value: any): Buffer {
|
||||
if (Buffer.isBuffer(value)) {
|
||||
return value;
|
||||
}
|
||||
throw new Error(`The value is not bytes`);
|
||||
}
|
||||
|
||||
static getUserAgent(userAgent: string): string {
|
||||
if (!userAgent || !userAgent.length) {
|
||||
return DEFAULT_USER_AGENT;
|
||||
}
|
||||
return DEFAULT_USER_AGENT + " " + userAgent;
|
||||
}
|
||||
|
||||
static is2xx(code: number): boolean {
|
||||
return code >= 200 && code < 300;
|
||||
}
|
||||
|
||||
static is3xx(code: number): boolean {
|
||||
return code >= 300 && code < 400;
|
||||
}
|
||||
|
||||
static is4xx(code: number): boolean {
|
||||
return code >= 400 && code < 500;
|
||||
}
|
||||
|
||||
static is5xx(code: number): boolean {
|
||||
return code >= 500 && code < 600;
|
||||
}
|
||||
static validateModel(m: $tea.Model): void {
|
||||
|
||||
}
|
||||
|
||||
static toMap(inputModel: $tea.Model): { [key: string]: any } {
|
||||
return $tea.toMap(inputModel);
|
||||
}
|
||||
|
||||
static async sleep(millisecond: number): Promise<void> {
|
||||
return new Promise(resolve => {
|
||||
setTimeout(() => {
|
||||
resolve();
|
||||
}, millisecond)
|
||||
})
|
||||
}
|
||||
|
||||
static toArray(input: any): { [key: string]: any }[] {
|
||||
if (!(input instanceof Array)) {
|
||||
return null;
|
||||
}
|
||||
let ret = [];
|
||||
input.forEach((model) => {
|
||||
if (!model) {
|
||||
return;
|
||||
}
|
||||
ret.push($tea.toMap(model));
|
||||
})
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert a value, if it is a readable, return it, otherwise throws
|
||||
* @return the readable value
|
||||
*/
|
||||
static assertAsReadable(value: any): Readable {
|
||||
if (value instanceof Readable) {
|
||||
return value;
|
||||
}
|
||||
throw new Error(`The value is not a readable`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user