@bedelightful/upload-sdk 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +8 -0
- package/README.md +132 -0
- package/dist/es/Exception/BaseException.js +14 -0
- package/dist/es/Exception/BaseException.js.map +1 -0
- package/dist/es/Exception/DownloadException.js +40 -0
- package/dist/es/Exception/DownloadException.js.map +1 -0
- package/dist/es/Exception/HttpException.js +50 -0
- package/dist/es/Exception/HttpException.js.map +1 -0
- package/dist/es/Exception/InitException.js +49 -0
- package/dist/es/Exception/InitException.js.map +1 -0
- package/dist/es/Exception/UploadException.js +50 -0
- package/dist/es/Exception/UploadException.js.map +1 -0
- package/dist/es/index.d.ts +867 -0
- package/dist/es/index.js +162 -0
- package/dist/es/index.js.map +1 -0
- package/dist/es/modules/Kodo/defaultUpload.js +38 -0
- package/dist/es/modules/Kodo/defaultUpload.js.map +1 -0
- package/dist/es/modules/Kodo/index.js +8 -0
- package/dist/es/modules/Kodo/index.js.map +1 -0
- package/dist/es/modules/Local/index.js +31 -0
- package/dist/es/modules/Local/index.js.map +1 -0
- package/dist/es/modules/MinIO/MultipartUpload.js +335 -0
- package/dist/es/modules/MinIO/MultipartUpload.js.map +1 -0
- package/dist/es/modules/MinIO/STSUpload.js +10 -0
- package/dist/es/modules/MinIO/STSUpload.js.map +1 -0
- package/dist/es/modules/MinIO/defaultUpload.js +124 -0
- package/dist/es/modules/MinIO/defaultUpload.js.map +1 -0
- package/dist/es/modules/MinIO/index.js +16 -0
- package/dist/es/modules/MinIO/index.js.map +1 -0
- package/dist/es/modules/OBS/MultipartUpload.js +269 -0
- package/dist/es/modules/OBS/MultipartUpload.js.map +1 -0
- package/dist/es/modules/OBS/STSUpload.js +71 -0
- package/dist/es/modules/OBS/STSUpload.js.map +1 -0
- package/dist/es/modules/OBS/defaultUpload.js +59 -0
- package/dist/es/modules/OBS/defaultUpload.js.map +1 -0
- package/dist/es/modules/OBS/index.js +16 -0
- package/dist/es/modules/OBS/index.js.map +1 -0
- package/dist/es/modules/OBS/utils/index.js +25 -0
- package/dist/es/modules/OBS/utils/index.js.map +1 -0
- package/dist/es/modules/OSS/MultipartUpload.js +232 -0
- package/dist/es/modules/OSS/MultipartUpload.js.map +1 -0
- package/dist/es/modules/OSS/STSUpload.js +48 -0
- package/dist/es/modules/OSS/STSUpload.js.map +1 -0
- package/dist/es/modules/OSS/defaultUpload.js +53 -0
- package/dist/es/modules/OSS/defaultUpload.js.map +1 -0
- package/dist/es/modules/OSS/index.js +16 -0
- package/dist/es/modules/OSS/index.js.map +1 -0
- package/dist/es/modules/OSS/utils/helper.js +137 -0
- package/dist/es/modules/OSS/utils/helper.js.map +1 -0
- package/dist/es/modules/OSS/utils/signature.js +96 -0
- package/dist/es/modules/OSS/utils/signature.js.map +1 -0
- package/dist/es/modules/TOS/MultipartUpload.js +288 -0
- package/dist/es/modules/TOS/MultipartUpload.js.map +1 -0
- package/dist/es/modules/TOS/STSUpload.js +92 -0
- package/dist/es/modules/TOS/STSUpload.js.map +1 -0
- package/dist/es/modules/TOS/defaultUpload.js +65 -0
- package/dist/es/modules/TOS/defaultUpload.js.map +1 -0
- package/dist/es/modules/TOS/index.js +16 -0
- package/dist/es/modules/TOS/index.js.map +1 -0
- package/dist/es/modules/TOS/utils/TosClientError.js +15 -0
- package/dist/es/modules/TOS/utils/TosClientError.js.map +1 -0
- package/dist/es/modules/TOS/utils/index.js +38 -0
- package/dist/es/modules/TOS/utils/index.js.map +1 -0
- package/dist/es/modules/TOS/utils/signatureV4.js +269 -0
- package/dist/es/modules/TOS/utils/signatureV4.js.map +1 -0
- package/dist/es/modules/TOS/utils/signatureV4Credentials.js +21 -0
- package/dist/es/modules/TOS/utils/signatureV4Credentials.js.map +1 -0
- package/dist/es/modules/TOS/utils/universal/crypto.browser.js +56 -0
- package/dist/es/modules/TOS/utils/universal/crypto.browser.js.map +1 -0
- package/dist/es/modules/TOS/utils/utils.js +18 -0
- package/dist/es/modules/TOS/utils/utils.js.map +1 -0
- package/dist/es/modules/index.js +20 -0
- package/dist/es/modules/index.js.map +1 -0
- package/dist/es/types/Kodo.js +1 -0
- package/dist/es/types/Kodo.js.map +1 -0
- package/dist/es/types/Local.js +1 -0
- package/dist/es/types/Local.js.map +1 -0
- package/dist/es/types/MinIO.js +1 -0
- package/dist/es/types/MinIO.js.map +1 -0
- package/dist/es/types/OBS.js +8 -0
- package/dist/es/types/OBS.js.map +1 -0
- package/dist/es/types/OSS.js +1 -0
- package/dist/es/types/OSS.js.map +1 -0
- package/dist/es/types/TOS.js +1 -0
- package/dist/es/types/TOS.js.map +1 -0
- package/dist/es/types/error.js +1 -0
- package/dist/es/types/error.js.map +1 -0
- package/dist/es/types/index.js +13 -0
- package/dist/es/types/index.js.map +1 -0
- package/dist/es/types/log.js +1 -0
- package/dist/es/types/log.js.map +1 -0
- package/dist/es/types/request.js +1 -0
- package/dist/es/types/request.js.map +1 -0
- package/dist/es/utils/EventEmitter.js +32 -0
- package/dist/es/utils/EventEmitter.js.map +1 -0
- package/dist/es/utils/UploadManger.js +276 -0
- package/dist/es/utils/UploadManger.js.map +1 -0
- package/dist/es/utils/UploadTask.js +13 -0
- package/dist/es/utils/UploadTask.js.map +1 -0
- package/dist/es/utils/checkDataFormat.js +41 -0
- package/dist/es/utils/checkDataFormat.js.map +1 -0
- package/dist/es/utils/global.js +83 -0
- package/dist/es/utils/global.js.map +1 -0
- package/dist/es/utils/index.js +20 -0
- package/dist/es/utils/index.js.map +1 -0
- package/dist/es/utils/logPubSub.js +59 -0
- package/dist/es/utils/logPubSub.js.map +1 -0
- package/dist/es/utils/multipart.js +159 -0
- package/dist/es/utils/multipart.js.map +1 -0
- package/dist/es/utils/nanoid.js +10 -0
- package/dist/es/utils/nanoid.js.map +1 -0
- package/dist/es/utils/regExpUtil.js +21 -0
- package/dist/es/utils/regExpUtil.js.map +1 -0
- package/dist/es/utils/request.js +234 -0
- package/dist/es/utils/request.js.map +1 -0
- package/dist/es/utils/response.js +20 -0
- package/dist/es/utils/response.js.map +1 -0
- package/dist/index.d.ts +867 -0
- package/dist/index.js +60913 -0
- package/dist/index.js.map +1 -0
- package/dist/index.min.js +130 -0
- package/dist/index.min.js.map +1 -0
- package/dist/lib/Exception/BaseException.js +37 -0
- package/dist/lib/Exception/BaseException.js.map +1 -0
- package/dist/lib/Exception/DownloadException.js +65 -0
- package/dist/lib/Exception/DownloadException.js.map +1 -0
- package/dist/lib/Exception/HttpException.js +75 -0
- package/dist/lib/Exception/HttpException.js.map +1 -0
- package/dist/lib/Exception/InitException.js +73 -0
- package/dist/lib/Exception/InitException.js.map +1 -0
- package/dist/lib/Exception/UploadException.js +75 -0
- package/dist/lib/Exception/UploadException.js.map +1 -0
- package/dist/lib/index.d.cts +867 -0
- package/dist/lib/index.js +203 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/modules/Kodo/defaultUpload.js +61 -0
- package/dist/lib/modules/Kodo/defaultUpload.js.map +1 -0
- package/dist/lib/modules/Kodo/index.js +28 -0
- package/dist/lib/modules/Kodo/index.js.map +1 -0
- package/dist/lib/modules/Local/index.js +50 -0
- package/dist/lib/modules/Local/index.js.map +1 -0
- package/dist/lib/modules/MinIO/MultipartUpload.js +357 -0
- package/dist/lib/modules/MinIO/MultipartUpload.js.map +1 -0
- package/dist/lib/modules/MinIO/STSUpload.js +33 -0
- package/dist/lib/modules/MinIO/STSUpload.js.map +1 -0
- package/dist/lib/modules/MinIO/defaultUpload.js +158 -0
- package/dist/lib/modules/MinIO/defaultUpload.js.map +1 -0
- package/dist/lib/modules/MinIO/index.js +35 -0
- package/dist/lib/modules/MinIO/index.js.map +1 -0
- package/dist/lib/modules/OBS/MultipartUpload.js +296 -0
- package/dist/lib/modules/OBS/MultipartUpload.js.map +1 -0
- package/dist/lib/modules/OBS/STSUpload.js +104 -0
- package/dist/lib/modules/OBS/STSUpload.js.map +1 -0
- package/dist/lib/modules/OBS/defaultUpload.js +88 -0
- package/dist/lib/modules/OBS/defaultUpload.js.map +1 -0
- package/dist/lib/modules/OBS/index.js +45 -0
- package/dist/lib/modules/OBS/index.js.map +1 -0
- package/dist/lib/modules/OBS/utils/index.js +49 -0
- package/dist/lib/modules/OBS/utils/index.js.map +1 -0
- package/dist/lib/modules/OSS/MultipartUpload.js +259 -0
- package/dist/lib/modules/OSS/MultipartUpload.js.map +1 -0
- package/dist/lib/modules/OSS/STSUpload.js +71 -0
- package/dist/lib/modules/OSS/STSUpload.js.map +1 -0
- package/dist/lib/modules/OSS/defaultUpload.js +76 -0
- package/dist/lib/modules/OSS/defaultUpload.js.map +1 -0
- package/dist/lib/modules/OSS/index.js +35 -0
- package/dist/lib/modules/OSS/index.js.map +1 -0
- package/dist/lib/modules/OSS/utils/helper.js +173 -0
- package/dist/lib/modules/OSS/utils/helper.js.map +1 -0
- package/dist/lib/modules/OSS/utils/signature.js +132 -0
- package/dist/lib/modules/OSS/utils/signature.js.map +1 -0
- package/dist/lib/modules/TOS/MultipartUpload.js +315 -0
- package/dist/lib/modules/TOS/MultipartUpload.js.map +1 -0
- package/dist/lib/modules/TOS/STSUpload.js +125 -0
- package/dist/lib/modules/TOS/STSUpload.js.map +1 -0
- package/dist/lib/modules/TOS/defaultUpload.js +94 -0
- package/dist/lib/modules/TOS/defaultUpload.js.map +1 -0
- package/dist/lib/modules/TOS/index.js +45 -0
- package/dist/lib/modules/TOS/index.js.map +1 -0
- package/dist/lib/modules/TOS/utils/TosClientError.js +34 -0
- package/dist/lib/modules/TOS/utils/TosClientError.js.map +1 -0
- package/dist/lib/modules/TOS/utils/index.js +64 -0
- package/dist/lib/modules/TOS/utils/index.js.map +1 -0
- package/dist/lib/modules/TOS/utils/signatureV4.js +294 -0
- package/dist/lib/modules/TOS/utils/signatureV4.js.map +1 -0
- package/dist/lib/modules/TOS/utils/signatureV4Credentials.js +44 -0
- package/dist/lib/modules/TOS/utils/signatureV4Credentials.js.map +1 -0
- package/dist/lib/modules/TOS/utils/universal/crypto.browser.js +93 -0
- package/dist/lib/modules/TOS/utils/universal/crypto.browser.js.map +1 -0
- package/dist/lib/modules/TOS/utils/utils.js +42 -0
- package/dist/lib/modules/TOS/utils/utils.js.map +1 -0
- package/dist/lib/modules/index.js +50 -0
- package/dist/lib/modules/index.js.map +1 -0
- package/dist/lib/types/Kodo.js +17 -0
- package/dist/lib/types/Kodo.js.map +1 -0
- package/dist/lib/types/Local.js +17 -0
- package/dist/lib/types/Local.js.map +1 -0
- package/dist/lib/types/MinIO.js +17 -0
- package/dist/lib/types/MinIO.js.map +1 -0
- package/dist/lib/types/OBS.js +32 -0
- package/dist/lib/types/OBS.js.map +1 -0
- package/dist/lib/types/OSS.js +17 -0
- package/dist/lib/types/OSS.js.map +1 -0
- package/dist/lib/types/TOS.js +17 -0
- package/dist/lib/types/TOS.js.map +1 -0
- package/dist/lib/types/error.js +17 -0
- package/dist/lib/types/error.js.map +1 -0
- package/dist/lib/types/index.js +37 -0
- package/dist/lib/types/index.js.map +1 -0
- package/dist/lib/types/log.js +17 -0
- package/dist/lib/types/log.js.map +1 -0
- package/dist/lib/types/request.js +17 -0
- package/dist/lib/types/request.js.map +1 -0
- package/dist/lib/utils/EventEmitter.js +51 -0
- package/dist/lib/utils/EventEmitter.js.map +1 -0
- package/dist/lib/utils/UploadManger.js +309 -0
- package/dist/lib/utils/UploadManger.js.map +1 -0
- package/dist/lib/utils/UploadTask.js +32 -0
- package/dist/lib/utils/UploadTask.js.map +1 -0
- package/dist/lib/utils/checkDataFormat.js +70 -0
- package/dist/lib/utils/checkDataFormat.js.map +1 -0
- package/dist/lib/utils/global.js +106 -0
- package/dist/lib/utils/global.js.map +1 -0
- package/dist/lib/utils/index.js +44 -0
- package/dist/lib/utils/index.js.map +1 -0
- package/dist/lib/utils/logPubSub.js +78 -0
- package/dist/lib/utils/logPubSub.js.map +1 -0
- package/dist/lib/utils/multipart.js +197 -0
- package/dist/lib/utils/multipart.js.map +1 -0
- package/dist/lib/utils/nanoid.js +33 -0
- package/dist/lib/utils/nanoid.js.map +1 -0
- package/dist/lib/utils/regExpUtil.js +44 -0
- package/dist/lib/utils/regExpUtil.js.map +1 -0
- package/dist/lib/utils/request.js +264 -0
- package/dist/lib/utils/request.js.map +1 -0
- package/dist/lib/utils/response.js +43 -0
- package/dist/lib/utils/response.js.map +1 -0
- package/dist/package.json +120 -0
- package/package.json +120 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/modules/TOS/utils/TosClientError.ts"],"sourcesContent":["class TosClientError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message)\n\n\t\t// https://www.dannyguo.com/blog/how-to-fix-instanceof-not-working-for-custom-errors-in-typescript/\n\t\tObject.setPrototypeOf(this, TosClientError.prototype)\n\t}\n}\n\nexport default TosClientError\n\n\n\n\n"],"mappings":";;AAAC,MAAM,kBAAN,MAAM,wBAAuB,MAAM;AAAA,EACnC,YAAY,SAAiB;AAC5B,UAAM,OAAO;AAGb,WAAO,eAAe,MAAM,gBAAe,SAAS;AAAA,EACrD;AACD;AAPoC;AAAnC,IAAM,iBAAN;AASD,IAAO,yBAAQ;","names":[]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
const VOLCENGINE_MIN_PART_SIZE = 5 * 1024 * 1024;
|
|
4
|
+
const ignoreHeaders = ["host"];
|
|
5
|
+
function formatHeaders(optionHeaders) {
|
|
6
|
+
const reqHeaders = { ...optionHeaders };
|
|
7
|
+
Object.keys(reqHeaders).forEach((key) => {
|
|
8
|
+
if (ignoreHeaders.includes(key)) {
|
|
9
|
+
delete reqHeaders[key];
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
return reqHeaders;
|
|
13
|
+
}
|
|
14
|
+
__name(formatHeaders, "formatHeaders");
|
|
15
|
+
function removeProtocol(host) {
|
|
16
|
+
const idx = host.indexOf("://");
|
|
17
|
+
if (idx !== -1) {
|
|
18
|
+
return host.substring(idx + 3);
|
|
19
|
+
}
|
|
20
|
+
return host;
|
|
21
|
+
}
|
|
22
|
+
__name(removeProtocol, "removeProtocol");
|
|
23
|
+
function getAuthHeaders(signOpt, signers, expiredAt, credentials) {
|
|
24
|
+
const signatureHeaders = signers.signatureHeader(signOpt, expiredAt, credentials);
|
|
25
|
+
const optionHeaders = {};
|
|
26
|
+
signatureHeaders.forEach((value, mapKey) => {
|
|
27
|
+
optionHeaders[mapKey] = value;
|
|
28
|
+
});
|
|
29
|
+
return formatHeaders(optionHeaders);
|
|
30
|
+
}
|
|
31
|
+
__name(getAuthHeaders, "getAuthHeaders");
|
|
32
|
+
export {
|
|
33
|
+
VOLCENGINE_MIN_PART_SIZE,
|
|
34
|
+
formatHeaders,
|
|
35
|
+
getAuthHeaders,
|
|
36
|
+
removeProtocol
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/modules/TOS/utils/index.ts"],"sourcesContent":["import type { ISigCredentials, ISigOptions, SignersV4 } from \"./signatureV4\"\n\nexport const VOLCENGINE_MIN_PART_SIZE = 5 * 1024 * 1024\n\nconst ignoreHeaders = [\"host\"]\n\nexport function formatHeaders(optionHeaders: Record<string, string>) {\n\tconst reqHeaders = { ...optionHeaders }\n\tObject.keys(reqHeaders).forEach((key) => {\n\t\tif (ignoreHeaders.includes(key)) {\n\t\t\tdelete reqHeaders[key]\n\t\t}\n\t})\n\treturn reqHeaders\n}\n\nexport function removeProtocol(host: string) {\n\tconst idx = host.indexOf(\"://\")\n\tif (idx !== -1) {\n\t\treturn host.substring(idx + 3)\n\t}\n\treturn host\n}\n\nexport function getAuthHeaders(\n\tsignOpt: ISigOptions,\n\tsigners: SignersV4,\n\texpiredAt: number,\n\tcredentials?: ISigCredentials,\n) {\n\tconst signatureHeaders = signers.signatureHeader(signOpt, expiredAt, credentials)\n\tconst optionHeaders: Record<string, string> = {}\n\n\tsignatureHeaders.forEach((value, mapKey) => {\n\t\toptionHeaders[mapKey] = value\n\t})\n\n\treturn formatHeaders(optionHeaders)\n}\n\n\n\n\n"],"mappings":";;AAEO,MAAM,2BAA2B,IAAI,OAAO;AAEnD,MAAM,gBAAgB,CAAC,MAAM;AAEtB,SAAS,cAAc,eAAuC;AACpE,QAAM,aAAa,EAAE,GAAG,cAAc;AACtC,SAAO,KAAK,UAAU,EAAE,QAAQ,CAAC,QAAQ;AACxC,QAAI,cAAc,SAAS,GAAG,GAAG;AAChC,aAAO,WAAW,GAAG;AAAA,IACtB;AAAA,EACD,CAAC;AACD,SAAO;AACR;AARgB;AAUT,SAAS,eAAe,MAAc;AAC5C,QAAM,MAAM,KAAK,QAAQ,KAAK;AAC9B,MAAI,QAAQ,IAAI;AACf,WAAO,KAAK,UAAU,MAAM,CAAC;AAAA,EAC9B;AACA,SAAO;AACR;AANgB;AAQT,SAAS,eACf,SACA,SACA,WACA,aACC;AACD,QAAM,mBAAmB,QAAQ,gBAAgB,SAAS,WAAW,WAAW;AAChF,QAAM,gBAAwC,CAAC;AAE/C,mBAAiB,QAAQ,CAAC,OAAO,WAAW;AAC3C,kBAAc,MAAM,IAAI;AAAA,EACzB,CAAC;AAED,SAAO,cAAc,aAAa;AACnC;AAdgB;","names":[]}
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import { hashSha256, hmacSha256, parse, stringify } from "./universal/crypto.browser";
|
|
4
|
+
import { getSortedQueryString } from "./utils";
|
|
5
|
+
const SIG_QUERY = {
|
|
6
|
+
algorithm: "tos-algorithm",
|
|
7
|
+
expiration: "tos-expiration",
|
|
8
|
+
signame: "tos-signame",
|
|
9
|
+
signature: "tos-signature",
|
|
10
|
+
v4_algorithm: "X-Tos-Algorithm",
|
|
11
|
+
v4_credential: "X-Tos-Credential",
|
|
12
|
+
v4_date: "X-Tos-Date",
|
|
13
|
+
v4_expires: "X-Tos-Expires",
|
|
14
|
+
v4_signedHeaders: "X-Tos-SignedHeaders",
|
|
15
|
+
v4_security_token: "X-Tos-Security-Token",
|
|
16
|
+
v4_signature: "X-Tos-Signature",
|
|
17
|
+
v4_content_sha: "X-Tos-Content-Sha256",
|
|
18
|
+
v4_policy: "X-Tos-Policy"
|
|
19
|
+
};
|
|
20
|
+
function isDefaultPort(port) {
|
|
21
|
+
if (port && port !== 80 && port !== 443) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
__name(isDefaultPort, "isDefaultPort");
|
|
27
|
+
const v4Identifier = "request";
|
|
28
|
+
function getNeedSignedHeaders(headers) {
|
|
29
|
+
const needSignHeaders = [];
|
|
30
|
+
if (headers) {
|
|
31
|
+
Object.keys(headers).forEach((key) => {
|
|
32
|
+
if (key === "host" || key.startsWith("x-tos-")) {
|
|
33
|
+
if (headers[key] != null) {
|
|
34
|
+
needSignHeaders.push(key);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return needSignHeaders.sort();
|
|
40
|
+
}
|
|
41
|
+
__name(getNeedSignedHeaders, "getNeedSignedHeaders");
|
|
42
|
+
const _SignersV4 = class _SignersV4 {
|
|
43
|
+
constructor(opt, credentials) {
|
|
44
|
+
/**
|
|
45
|
+
* normal v4 signature
|
|
46
|
+
* */
|
|
47
|
+
// @ts-ignore
|
|
48
|
+
this.signature = /* @__PURE__ */ __name((opt, expiredAt, credentials) => {
|
|
49
|
+
if (!credentials) {
|
|
50
|
+
credentials = this.credentials;
|
|
51
|
+
}
|
|
52
|
+
const parts = [];
|
|
53
|
+
const datatime = opt.datetime;
|
|
54
|
+
const credString = this.credentialString(datatime);
|
|
55
|
+
parts.push(
|
|
56
|
+
`${this.options.algorithm} Credential=${credentials.GetAccessKey()}/${credString}`
|
|
57
|
+
);
|
|
58
|
+
parts.push(`SignedHeaders=${_SignersV4.signedHeaders(opt)}`);
|
|
59
|
+
parts.push(`Signature=${this.authorization(opt, credentials, 0)}`);
|
|
60
|
+
return parts.join(", ");
|
|
61
|
+
}, "signature");
|
|
62
|
+
this.signatureHeader = /* @__PURE__ */ __name((opt, expiredAt, credentials) => {
|
|
63
|
+
opt.datetime = _SignersV4.getDateTime();
|
|
64
|
+
const header = /* @__PURE__ */ new Map();
|
|
65
|
+
if (!opt.headers) {
|
|
66
|
+
const h = {};
|
|
67
|
+
opt.headers = h;
|
|
68
|
+
}
|
|
69
|
+
opt.headers.host = `${opt.host}`;
|
|
70
|
+
if (!isDefaultPort(opt.port)) {
|
|
71
|
+
opt.headers.host += `:${opt.port}`;
|
|
72
|
+
}
|
|
73
|
+
if (opt.endpoints) {
|
|
74
|
+
opt.headers.host = `${this.options.bucket}.${opt.endpoints}`;
|
|
75
|
+
}
|
|
76
|
+
header.set("host", opt.headers.host);
|
|
77
|
+
header.set("x-tos-date", opt.datetime);
|
|
78
|
+
header.set("x-tos-content-sha256", _SignersV4.hexEncodedBodyHash());
|
|
79
|
+
if (this.options.securityToken) {
|
|
80
|
+
header.set("x-tos-security-token", this.options.securityToken);
|
|
81
|
+
}
|
|
82
|
+
header.forEach((value, key) => {
|
|
83
|
+
if (key.startsWith("x-tos") && opt.headers) {
|
|
84
|
+
opt.headers[key] = value;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
opt.path = _SignersV4.getEncodePath(opt.path);
|
|
88
|
+
const sign = this.signature(opt, 0, credentials);
|
|
89
|
+
header.set("authorization", sign);
|
|
90
|
+
return header;
|
|
91
|
+
}, "signatureHeader");
|
|
92
|
+
this.getSignatureQuery = /* @__PURE__ */ __name((opt, expiredAt) => {
|
|
93
|
+
const queryOpt = {
|
|
94
|
+
...opt,
|
|
95
|
+
query: typeof opt.query === "string" ? {} : opt.query
|
|
96
|
+
};
|
|
97
|
+
queryOpt.datetime = _SignersV4.getDateTime();
|
|
98
|
+
if (!queryOpt.headers) {
|
|
99
|
+
queryOpt.headers = {};
|
|
100
|
+
}
|
|
101
|
+
queryOpt.headers.host = `${queryOpt.host}`;
|
|
102
|
+
if (!isDefaultPort(queryOpt.port)) {
|
|
103
|
+
queryOpt.headers.host += `:${queryOpt.port}`;
|
|
104
|
+
}
|
|
105
|
+
queryOpt.path = _SignersV4.getEncodePath(queryOpt.path);
|
|
106
|
+
if (queryOpt.endpoints) {
|
|
107
|
+
queryOpt.headers.host = `${this.options.bucket}.${queryOpt.endpoints}`;
|
|
108
|
+
}
|
|
109
|
+
queryOpt.headers[SIG_QUERY.v4_date] = queryOpt.datetime;
|
|
110
|
+
const credString = this.credentialString(queryOpt.datetime);
|
|
111
|
+
const res = {
|
|
112
|
+
...queryOpt.query || {},
|
|
113
|
+
[SIG_QUERY.v4_algorithm]: this.options.algorithm,
|
|
114
|
+
[SIG_QUERY.v4_content_sha]: _SignersV4.hexEncodedBodyHash(),
|
|
115
|
+
[SIG_QUERY.v4_credential]: `${this.credentials.GetAccessKey()}/${credString}`,
|
|
116
|
+
[SIG_QUERY.v4_date]: queryOpt.datetime,
|
|
117
|
+
[SIG_QUERY.v4_expires]: `${expiredAt}`,
|
|
118
|
+
[SIG_QUERY.v4_signedHeaders]: _SignersV4.signedHeaders(queryOpt)
|
|
119
|
+
};
|
|
120
|
+
if (this.options.securityToken) {
|
|
121
|
+
res[SIG_QUERY.v4_security_token] = this.options.securityToken;
|
|
122
|
+
}
|
|
123
|
+
const queryString = getSortedQueryString(res);
|
|
124
|
+
if (typeof opt.query === "string") {
|
|
125
|
+
opt.query = queryString;
|
|
126
|
+
} else {
|
|
127
|
+
opt.query = res;
|
|
128
|
+
}
|
|
129
|
+
res[SIG_QUERY.v4_signature] = this.authorization(queryOpt, this.credentials, expiredAt);
|
|
130
|
+
return res;
|
|
131
|
+
}, "getSignatureQuery");
|
|
132
|
+
this.getSignaturePolicyQuery = /* @__PURE__ */ __name((opt, expiredAt) => {
|
|
133
|
+
const policyOpt = {
|
|
134
|
+
...opt,
|
|
135
|
+
path: opt.path || "/",
|
|
136
|
+
method: opt.method || "POST",
|
|
137
|
+
datetime: _SignersV4.getDateTime()
|
|
138
|
+
};
|
|
139
|
+
const credString = this.credentialString(policyOpt.datetime);
|
|
140
|
+
const res = {
|
|
141
|
+
[SIG_QUERY.v4_algorithm]: this.options.algorithm,
|
|
142
|
+
[SIG_QUERY.v4_credential]: `${this.credentials.GetAccessKey()}/${credString}`,
|
|
143
|
+
[SIG_QUERY.v4_date]: policyOpt.datetime,
|
|
144
|
+
[SIG_QUERY.v4_expires]: `${expiredAt}`,
|
|
145
|
+
[SIG_QUERY.v4_policy]: stringify(parse(JSON.stringify(opt.policy), "utf-8"), "base64")
|
|
146
|
+
};
|
|
147
|
+
if (this.options.securityToken) {
|
|
148
|
+
res[SIG_QUERY.v4_security_token] = this.options.securityToken;
|
|
149
|
+
}
|
|
150
|
+
opt.query = getSortedQueryString(res);
|
|
151
|
+
res[SIG_QUERY.v4_signature] = this.authorization(policyOpt, this.credentials, expiredAt);
|
|
152
|
+
return res;
|
|
153
|
+
}, "getSignaturePolicyQuery");
|
|
154
|
+
// @ts-ignore
|
|
155
|
+
this.authorization = /* @__PURE__ */ __name((opt, credentials, expiredAt) => {
|
|
156
|
+
if (!opt.datetime) {
|
|
157
|
+
return "";
|
|
158
|
+
}
|
|
159
|
+
const signingKey = this.getSigningKey(credentials, opt.datetime.substr(0, 8));
|
|
160
|
+
return hmacSha256(signingKey, this.stringToSign(opt.datetime, opt), "hex");
|
|
161
|
+
}, "authorization");
|
|
162
|
+
this.credentialString = /* @__PURE__ */ __name((datetime) => {
|
|
163
|
+
return _SignersV4.createScope(
|
|
164
|
+
datetime.substr(0, 8),
|
|
165
|
+
this.options.region,
|
|
166
|
+
this.options.serviceName
|
|
167
|
+
);
|
|
168
|
+
}, "credentialString");
|
|
169
|
+
this.getSigningKey = /* @__PURE__ */ __name((credentials, date) => {
|
|
170
|
+
const kDate = hmacSha256(credentials.GetSecretKey(), date);
|
|
171
|
+
const kRegion = hmacSha256(kDate, this.options.region);
|
|
172
|
+
const kService = hmacSha256(kRegion, this.options.serviceName);
|
|
173
|
+
const signingKey = hmacSha256(kService, v4Identifier);
|
|
174
|
+
return signingKey;
|
|
175
|
+
}, "getSigningKey");
|
|
176
|
+
this.stringToSign = /* @__PURE__ */ __name((datetime, opt) => {
|
|
177
|
+
if (!this.options.algorithm) {
|
|
178
|
+
return "";
|
|
179
|
+
}
|
|
180
|
+
const parts = [];
|
|
181
|
+
parts.push(this.options.algorithm);
|
|
182
|
+
parts.push(datetime);
|
|
183
|
+
parts.push(this.credentialString(datetime));
|
|
184
|
+
const canonicalString = "policy" in opt ? _SignersV4.canonicalStringPolicy(opt) : _SignersV4.canonicalString(opt);
|
|
185
|
+
parts.push(_SignersV4.hexEncodedHash(canonicalString));
|
|
186
|
+
return parts.join("\n");
|
|
187
|
+
}, "stringToSign");
|
|
188
|
+
this.options = opt;
|
|
189
|
+
this.credentials = credentials;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* ! * ' () aren't transformed by encodeUrl, so they need be handled
|
|
193
|
+
*/
|
|
194
|
+
static getEncodePath(path, encodeAll = true) {
|
|
195
|
+
if (!path) {
|
|
196
|
+
return "";
|
|
197
|
+
}
|
|
198
|
+
let tmpPath = path;
|
|
199
|
+
if (encodeAll) {
|
|
200
|
+
tmpPath = path.replace(/%2F/g, "/");
|
|
201
|
+
}
|
|
202
|
+
tmpPath = tmpPath.replace(/\(/g, "%28");
|
|
203
|
+
tmpPath = tmpPath.replace(/\)/g, "%29");
|
|
204
|
+
tmpPath = tmpPath.replace(/!/g, "%21");
|
|
205
|
+
tmpPath = tmpPath.replace(/\*/g, "%2A");
|
|
206
|
+
tmpPath = tmpPath.replace(/'/g, "%27");
|
|
207
|
+
return tmpPath;
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
__name(_SignersV4, "SignersV4");
|
|
211
|
+
_SignersV4.hexEncodedBodyHash = /* @__PURE__ */ __name(() => {
|
|
212
|
+
return "UNSIGNED-PAYLOAD";
|
|
213
|
+
}, "hexEncodedBodyHash");
|
|
214
|
+
_SignersV4.getDateTime = /* @__PURE__ */ __name(() => {
|
|
215
|
+
const date = new Date((/* @__PURE__ */ new Date()).toUTCString());
|
|
216
|
+
return `${date.toISOString().replace(/\..+/, "").replace(/-/g, "").replace(/:/g, "")}Z`;
|
|
217
|
+
}, "getDateTime");
|
|
218
|
+
_SignersV4.createScope = /* @__PURE__ */ __name((date, region, serviceName) => {
|
|
219
|
+
return [date.substr(0, 8), region, serviceName, v4Identifier].join("/");
|
|
220
|
+
}, "createScope");
|
|
221
|
+
_SignersV4.hexEncodedHash = /* @__PURE__ */ __name((string) => {
|
|
222
|
+
return hashSha256(string, "hex");
|
|
223
|
+
}, "hexEncodedHash");
|
|
224
|
+
_SignersV4.canonicalString = /* @__PURE__ */ __name((opt) => {
|
|
225
|
+
const parts = [];
|
|
226
|
+
parts.push(opt.method);
|
|
227
|
+
parts.push(opt.path);
|
|
228
|
+
parts.push(_SignersV4.getEncodePath(opt.query, false));
|
|
229
|
+
parts.push(`${_SignersV4.canonicalHeaders(opt)}
|
|
230
|
+
`);
|
|
231
|
+
parts.push(_SignersV4.signedHeaders(opt));
|
|
232
|
+
parts.push(_SignersV4.hexEncodedBodyHash());
|
|
233
|
+
return parts.join("\n");
|
|
234
|
+
}, "canonicalString");
|
|
235
|
+
_SignersV4.canonicalStringPolicy = /* @__PURE__ */ __name((opt) => {
|
|
236
|
+
const parts = [];
|
|
237
|
+
parts.push(_SignersV4.getEncodePath(opt.query, false));
|
|
238
|
+
parts.push(_SignersV4.hexEncodedBodyHash());
|
|
239
|
+
return parts.join("\n");
|
|
240
|
+
}, "canonicalStringPolicy");
|
|
241
|
+
_SignersV4.canonicalHeaders = /* @__PURE__ */ __name((opt) => {
|
|
242
|
+
const parts = [];
|
|
243
|
+
const needSignHeaders = getNeedSignedHeaders(opt.headers);
|
|
244
|
+
for (const key of needSignHeaders) {
|
|
245
|
+
const value = opt.headers?.[key];
|
|
246
|
+
parts.push(
|
|
247
|
+
`${key.toLowerCase()}:${_SignersV4.canonicalHeaderValues(value?.toString() || "")}`
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
return parts.join("\n");
|
|
251
|
+
}, "canonicalHeaders");
|
|
252
|
+
_SignersV4.canonicalHeaderValues = /* @__PURE__ */ __name((values) => {
|
|
253
|
+
return values.replace(/\s+/g, " ").replace(/^\s+|\s+$/g, "");
|
|
254
|
+
}, "canonicalHeaderValues");
|
|
255
|
+
_SignersV4.signedHeaders = /* @__PURE__ */ __name((opt) => {
|
|
256
|
+
const keys = [];
|
|
257
|
+
const needSignHeaders = getNeedSignedHeaders(opt.headers);
|
|
258
|
+
for (const key of needSignHeaders) {
|
|
259
|
+
keys.push(key.toLowerCase());
|
|
260
|
+
}
|
|
261
|
+
return keys.sort().join(";");
|
|
262
|
+
}, "signedHeaders");
|
|
263
|
+
let SignersV4 = _SignersV4;
|
|
264
|
+
export {
|
|
265
|
+
SIG_QUERY,
|
|
266
|
+
SignersV4,
|
|
267
|
+
isDefaultPort
|
|
268
|
+
};
|
|
269
|
+
//# sourceMappingURL=signatureV4.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/modules/TOS/utils/signatureV4.ts"],"sourcesContent":["import { hashSha256, hmacSha256, parse, stringify } from \"./universal/crypto.browser\"\nimport { getSortedQueryString } from \"./utils\"\n\nexport interface ISign {\n\tsignature(opt: ISigOptions, expiredAt: number, credentials?: ISigCredentials): string\n\n\tsignatureHeader(\n\t\topt: ISigOptions,\n\t\texpiredAt?: number,\n\t\tcredentials?: ISigCredentials,\n\t): Map<string, string>\n\n\tgetSignatureQuery(opt: ISigOptions, expiredAt: number): { [key: string]: any }\n}\n\nexport interface ISigCredentials {\n\tGetSecretKey(): string\n\n\tGetAccessKey(): string\n}\n\nexport interface ISigPolicyQuery {\n\tpolicy: {\n\t\tconditions: (string[] | { bucket: string } | { key: string })[]\n\t}\n\tdatetime?: string\n\tquery?: string\n\tpath?: string\n\tmethod?: string\n\theaders?: { [key: string]: string | undefined }\n}\n\nexport interface ISigOptions {\n\tsigName?: string\n\tendpoints?: string\n\tbucket?: string\n\theaders?: { [key: string]: string | undefined }\n\tregion?: string\n\tserviceName?: string\n\talgorithm?: string\n\tpath: string\n\tmethod: string\n\tquery?: string | Record<string, any>\n\tdatetime?: string\n\thost?: string\n\tport?: number\n}\n\nexport interface ISigQueryOptions extends Omit<ISigOptions, \"query\"> {\n\tquery?: Record<string, any>\n}\n\nexport const SIG_QUERY = {\n\talgorithm: \"tos-algorithm\",\n\texpiration: \"tos-expiration\",\n\tsigname: \"tos-signame\",\n\tsignature: \"tos-signature\",\n\n\tv4_algorithm: \"X-Tos-Algorithm\",\n\tv4_credential: \"X-Tos-Credential\",\n\tv4_date: \"X-Tos-Date\",\n\tv4_expires: \"X-Tos-Expires\",\n\tv4_signedHeaders: \"X-Tos-SignedHeaders\",\n\tv4_security_token: \"X-Tos-Security-Token\",\n\tv4_signature: \"X-Tos-Signature\",\n\tv4_content_sha: \"X-Tos-Content-Sha256\",\n\tv4_policy: \"X-Tos-Policy\",\n}\n\nexport function isDefaultPort(port?: number) {\n\tif (port && port !== 80 && port !== 443) {\n\t\treturn false\n\t}\n\treturn true\n}\n\n/**\n * @api private\n */\nconst v4Identifier = \"request\"\n\ninterface ISignV4Opt {\n\talgorithm?: string\n\tregion?: string\n\tserviceName?: string\n\tsecurityToken?: string\n\tbucket: string\n}\n\nfunction getNeedSignedHeaders(headers: Record<string, unknown> | undefined) {\n\tconst needSignHeaders: string[] = []\n\tif (headers) {\n\t\tObject.keys(headers).forEach((key: string) => {\n\t\t\tif (key === \"host\" || key.startsWith(\"x-tos-\")) {\n\t\t\t\tif (headers[key] != null) {\n\t\t\t\t\tneedSignHeaders.push(key)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\treturn needSignHeaders.sort()\n}\n\n/**\n * @api private\n */\nexport class SignersV4 implements ISign {\n\tprivate options: ISignV4Opt\n\n\tprivate credentials: ISigCredentials\n\n\tconstructor(opt: ISignV4Opt, credentials: ISigCredentials) {\n\t\tthis.options = opt\n\t\tthis.credentials = credentials\n\t}\n\n\t/**\n\t * normal v4 signature\n\t * */\n\t// @ts-ignore\n\tpublic signature = (opt: ISigOptions, expiredAt: number, credentials?: ISigCredentials) => {\n\t\tif (!credentials) {\n\t\t\tcredentials = this.credentials\n\t\t}\n\t\tconst parts: string[] = []\n\t\tconst datatime = opt.datetime as string\n\t\tconst credString = this.credentialString(datatime)\n\t\tparts.push(\n\t\t\t`${this.options.algorithm} Credential=${credentials.GetAccessKey()}/${credString}`,\n\t\t)\n\n\t\tparts.push(`SignedHeaders=${SignersV4.signedHeaders(opt)}`)\n\t\tparts.push(`Signature=${this.authorization(opt, credentials, 0)}`)\n\t\treturn parts.join(\", \")\n\t}\n\n\tpublic signatureHeader = (\n\t\topt: ISigOptions,\n\t\t// @ts-ignore\n\t\texpiredAt?: number,\n\t\tcredentials?: ISigCredentials,\n\t): Map<string, string> => {\n\t\t// const datetime = (new Date(new Date().toUTCString())).Format(\"yyyyMMddTHHmmssZ\")\n\t\topt.datetime = SignersV4.getDateTime()\n\t\tconst header = new Map<string, string>()\n\t\t/* istanbul ignore if */\n\t\tif (!opt.headers) {\n\t\t\tconst h: { [key: string]: string } = {}\n\t\t\topt.headers = h\n\t\t}\n\n\t\topt.headers.host = `${opt.host}`\n\t\t/* istanbul ignore if */\n\t\tif (!isDefaultPort(opt.port)) {\n\t\t\topt.headers.host += `:${opt.port}`\n\t\t}\n\t\t/* istanbul ignore if */\n\t\tif (opt.endpoints) {\n\t\t\topt.headers.host = `${this.options.bucket}.${opt.endpoints}`\n\t\t}\n\n\t\theader.set(\"host\", opt.headers.host)\n\t\theader.set(\"x-tos-date\", opt.datetime)\n\t\theader.set(\"x-tos-content-sha256\", SignersV4.hexEncodedBodyHash())\n\t\tif (this.options.securityToken) {\n\t\t\theader.set(\"x-tos-security-token\", this.options.securityToken)\n\t\t}\n\t\t// x-tos- must to be signatured\n\t\theader.forEach((value, key) => {\n\t\t\tif (key.startsWith(\"x-tos\") && opt.headers) {\n\t\t\t\topt.headers[key] = value\n\t\t\t}\n\t\t})\n\t\topt.path = SignersV4.getEncodePath(opt.path)\n\t\tconst sign = this.signature(opt, 0, credentials)\n\t\theader.set(\"authorization\", sign)\n\n\t\treturn header\n\t}\n\n\tpublic getSignatureQuery = (opt: ISigOptions, expiredAt: number): { [key: string]: any } => {\n\t\tconst queryOpt: ISigQueryOptions = {\n\t\t\t...opt,\n\t\t\tquery: typeof opt.query === \"string\" ? {} : (opt.query as Record<string, any>),\n\t\t}\n\t\tqueryOpt.datetime = SignersV4.getDateTime()\n\t\tif (!queryOpt.headers) {\n\t\t\tqueryOpt.headers = {}\n\t\t}\n\n\t\tqueryOpt.headers.host = `${queryOpt.host}`\n\t\tif (!isDefaultPort(queryOpt.port)) {\n\t\t\tqueryOpt.headers.host += `:${queryOpt.port}`\n\t\t}\n\n\t\tqueryOpt.path = SignersV4.getEncodePath(queryOpt.path)\n\t\tif (queryOpt.endpoints) {\n\t\t\tqueryOpt.headers.host = `${this.options.bucket}.${queryOpt.endpoints}`\n\t\t\t// opt.path = `${opt.path}`;\n\t\t}\n\n\t\tqueryOpt.headers[SIG_QUERY.v4_date] = queryOpt.datetime\n\t\tconst credString = this.credentialString(queryOpt.datetime as string)\n\t\tconst res = {\n\t\t\t...(queryOpt.query || {}),\n\t\t\t[SIG_QUERY.v4_algorithm]: this.options.algorithm,\n\t\t\t[SIG_QUERY.v4_content_sha]: SignersV4.hexEncodedBodyHash(),\n\t\t\t[SIG_QUERY.v4_credential]: `${this.credentials.GetAccessKey()}/${credString}`,\n\t\t\t[SIG_QUERY.v4_date]: queryOpt.datetime,\n\t\t\t[SIG_QUERY.v4_expires]: `${expiredAt}`,\n\t\t\t[SIG_QUERY.v4_signedHeaders]: SignersV4.signedHeaders(queryOpt),\n\t\t}\n\t\tif (this.options.securityToken) {\n\t\t\tres[SIG_QUERY.v4_security_token] = this.options.securityToken\n\t\t}\n\n\t\tconst queryString = getSortedQueryString(res)\n\t\t// Keep the original opt query type\n\t\tif (typeof opt.query === \"string\") {\n\t\t\topt.query = queryString\n\t\t} else {\n\t\t\topt.query = res\n\t\t}\n\n\t\tres[SIG_QUERY.v4_signature] = this.authorization(queryOpt, this.credentials, expiredAt)\n\t\treturn res\n\t}\n\n\tpublic getSignaturePolicyQuery = (\n\t\topt: ISigPolicyQuery,\n\t\texpiredAt: number,\n\t): { [key: string]: any } => {\n\t\t// Add required ISigOptions properties\n\t\tconst policyOpt: ISigOptions = {\n\t\t\t...(opt as any),\n\t\t\tpath: opt.path || \"/\",\n\t\t\tmethod: opt.method || \"POST\",\n\t\t\tdatetime: SignersV4.getDateTime(),\n\t\t}\n\n\t\tconst credString = this.credentialString(policyOpt.datetime as string)\n\t\tconst res = {\n\t\t\t[SIG_QUERY.v4_algorithm]: this.options.algorithm,\n\t\t\t[SIG_QUERY.v4_credential]: `${this.credentials.GetAccessKey()}/${credString}`,\n\t\t\t[SIG_QUERY.v4_date]: policyOpt.datetime,\n\t\t\t[SIG_QUERY.v4_expires]: `${expiredAt}`,\n\t\t\t[SIG_QUERY.v4_policy]: stringify(parse(JSON.stringify(opt.policy), \"utf-8\"), \"base64\"),\n\t\t}\n\t\tif (this.options.securityToken) {\n\t\t\tres[SIG_QUERY.v4_security_token] = this.options.securityToken\n\t\t}\n\n\t\t// Ensure opt has a query property\n\t\topt.query = getSortedQueryString(res)\n\n\t\tres[SIG_QUERY.v4_signature] = this.authorization(policyOpt, this.credentials, expiredAt)\n\t\treturn res\n\t}\n\n\tstatic hexEncodedBodyHash = () => {\n\t\treturn \"UNSIGNED-PAYLOAD\"\n\t}\n\n\t// @ts-ignore\n\tprivate authorization = (opt: ISigOptions, credentials: ISigCredentials, expiredAt: number) => {\n\t\t/* istanbul ignore if */\n\t\tif (!opt.datetime) {\n\t\t\treturn \"\"\n\t\t}\n\n\t\tconst signingKey = this.getSigningKey(credentials, opt.datetime.substr(0, 8))\n\t\t// console.log(\n\t\t// 'signingKey:',\n\t\t// signingKey,\n\t\t// 'sign:',\n\t\t// this.stringToSign(opt.datetime, opt)\n\t\t// );\n\t\treturn hmacSha256(signingKey, this.stringToSign(opt.datetime, opt), \"hex\")\n\t}\n\n\tstatic getDateTime = () => {\n\t\tconst date = new Date(new Date().toUTCString())\n\t\treturn `${date.toISOString().replace(/\\..+/, \"\").replace(/-/g, \"\").replace(/:/g, \"\")}Z`\n\t}\n\n\tprivate credentialString = (datetime: string) => {\n\t\treturn SignersV4.createScope(\n\t\t\tdatetime.substr(0, 8),\n\t\t\tthis.options.region,\n\t\t\tthis.options.serviceName,\n\t\t)\n\t}\n\n\tstatic createScope = (date: string, region?: string, serviceName?: string) => {\n\t\treturn [date.substr(0, 8), region, serviceName, v4Identifier].join(\"/\")\n\t}\n\n\tprivate getSigningKey = (credentials: ISigCredentials, date: string) => {\n\t\tconst kDate = hmacSha256(credentials.GetSecretKey(), date)\n\t\tconst kRegion = hmacSha256(kDate, this.options.region as string)\n\t\tconst kService = hmacSha256(kRegion, this.options.serviceName as string)\n\t\tconst signingKey = hmacSha256(kService, v4Identifier)\n\n\t\treturn signingKey\n\t}\n\n\tprivate stringToSign = (datetime: string, opt: ISigOptions) => {\n\t\t/* istanbul ignore if */\n\t\tif (!this.options.algorithm) {\n\t\t\treturn \"\"\n\t\t}\n\n\t\tconst parts: string[] = []\n\t\tparts.push(this.options.algorithm)\n\t\tparts.push(datetime)\n\t\tparts.push(this.credentialString(datetime))\n\t\tconst canonicalString =\n\t\t\t\"policy\" in opt ? SignersV4.canonicalStringPolicy(opt) : SignersV4.canonicalString(opt)\n\t\tparts.push(SignersV4.hexEncodedHash(canonicalString))\n\t\treturn parts.join(\"\\n\")\n\t}\n\n\tstatic hexEncodedHash = (string: string) => {\n\t\treturn hashSha256(string, \"hex\")\n\t}\n\n\tstatic canonicalString = (opt: ISigOptions) => {\n\t\tconst parts: any[] = []\n\t\tparts.push(opt.method)\n\t\tparts.push(opt.path)\n\t\tparts.push(SignersV4.getEncodePath(opt.query as string, false))\n\t\tparts.push(`${SignersV4.canonicalHeaders(opt)}\\n`)\n\t\tparts.push(SignersV4.signedHeaders(opt))\n\t\tparts.push(SignersV4.hexEncodedBodyHash())\n\t\treturn parts.join(\"\\n\")\n\t}\n\n\tstatic canonicalStringPolicy = (opt: ISigOptions) => {\n\t\tconst parts: any[] = []\n\t\tparts.push(SignersV4.getEncodePath(opt.query as string, false))\n\t\tparts.push(SignersV4.hexEncodedBodyHash())\n\t\treturn parts.join(\"\\n\")\n\t}\n\n\tstatic canonicalHeaders = (opt: ISigOptions) => {\n\t\tconst parts: string[] = []\n\t\tconst needSignHeaders = getNeedSignedHeaders(opt.headers)\n\n\t\t// eslint-disable-next-line no-restricted-syntax\n\t\tfor (const key of needSignHeaders) {\n\t\t\tconst value = opt.headers?.[key]\n\t\t\tparts.push(\n\t\t\t\t`${key.toLowerCase()}:${SignersV4.canonicalHeaderValues(value?.toString() || \"\")}`,\n\t\t\t)\n\t\t}\n\n\t\treturn parts.join(\"\\n\")\n\t}\n\n\tstatic canonicalHeaderValues = (values: string) => {\n\t\treturn values.replace(/\\s+/g, \" \").replace(/^\\s+|\\s+$/g, \"\")\n\t}\n\n\tstatic signedHeaders = (opt: ISigOptions) => {\n\t\tconst keys: string[] = []\n\t\tconst needSignHeaders = getNeedSignedHeaders(opt.headers)\n\n\t\t// eslint-disable-next-line no-restricted-syntax\n\t\tfor (const key of needSignHeaders) {\n\t\t\tkeys.push(key.toLowerCase())\n\t\t}\n\n\t\treturn keys.sort().join(\";\")\n\t}\n\n\t/**\n\t * ! * ' () aren't transformed by encodeUrl, so they need be handled\n\t */\n\tstatic getEncodePath(path: string, encodeAll: boolean = true): string {\n\t\tif (!path) {\n\t\t\treturn \"\"\n\t\t}\n\n\t\tlet tmpPath = path\n\t\tif (encodeAll) {\n\t\t\ttmpPath = path.replace(/%2F/g, \"/\")\n\t\t}\n\t\ttmpPath = tmpPath.replace(/\\(/g, \"%28\")\n\t\ttmpPath = tmpPath.replace(/\\)/g, \"%29\")\n\t\ttmpPath = tmpPath.replace(/!/g, \"%21\")\n\t\ttmpPath = tmpPath.replace(/\\*/g, \"%2A\")\n\t\ttmpPath = tmpPath.replace(/'/g, \"%27\")\n\t\treturn tmpPath\n\t}\n}\n\n\n\n\n"],"mappings":";;AAAC,SAAS,YAAY,YAAY,OAAO,iBAAiB;AAC1D,SAAS,4BAA4B;AAmD9B,MAAM,YAAY;AAAA,EACxB,WAAW;AAAA,EACX,YAAY;AAAA,EACZ,SAAS;AAAA,EACT,WAAW;AAAA,EAEX,cAAc;AAAA,EACd,eAAe;AAAA,EACf,SAAS;AAAA,EACT,YAAY;AAAA,EACZ,kBAAkB;AAAA,EAClB,mBAAmB;AAAA,EACnB,cAAc;AAAA,EACd,gBAAgB;AAAA,EAChB,WAAW;AACZ;AAEO,SAAS,cAAc,MAAe;AAC5C,MAAI,QAAQ,SAAS,MAAM,SAAS,KAAK;AACxC,WAAO;AAAA,EACR;AACA,SAAO;AACR;AALgB;AAUhB,MAAM,eAAe;AAUrB,SAAS,qBAAqB,SAA8C;AAC3E,QAAM,kBAA4B,CAAC;AACnC,MAAI,SAAS;AACZ,WAAO,KAAK,OAAO,EAAE,QAAQ,CAAC,QAAgB;AAC7C,UAAI,QAAQ,UAAU,IAAI,WAAW,QAAQ,GAAG;AAC/C,YAAI,QAAQ,GAAG,KAAK,MAAM;AACzB,0BAAgB,KAAK,GAAG;AAAA,QACzB;AAAA,MACD;AAAA,IACD,CAAC;AAAA,EACF;AACA,SAAO,gBAAgB,KAAK;AAC7B;AAZS;AAiBF,MAAM,aAAN,MAAM,WAA2B;AAAA,EAKvC,YAAY,KAAiB,aAA8B;AAS3D;AAAA;AAAA;AAAA;AAAA,SAAO,YAAY,wBAAC,KAAkB,WAAmB,gB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,SAAO,MAAM,KAAK,IAAI;AACvB,GAL+B;AAvOnB,WA8OL,mBAAmB,wBAAC,QAAqB;AAC/C,QAAM,QAAkB,CAAC;AACzB,QAAM,kBAAkB,qBAAqB,IAAI,OAAO;AAGxD,aAAW,OAAO,iBAAiB;AAClC,UAAM,QAAQ,IAAI,UAAU,GAAG;AAC/B,UAAM;AAAA,MACL,GAAG,IAAI,YAAY,CAAC,IAAI,WAAU,sBAAsB,OAAO,SAAS,KAAK,EAAE,CAAC;AAAA,IACjF;AAAA,EACD;AAEA,SAAO,MAAM,KAAK,IAAI;AACvB,GAb0B;AA9Od,WA6PL,wBAAwB,wBAAC,WAAmB;AAClD,SAAO,OAAO,QAAQ,QAAQ,GAAG,EAAE,QAAQ,cAAc,EAAE;AAC5D,GAF+B;AA7PnB,WAiQL,gBAAgB,wBAAC,QAAqB;AAC5C,QAAM,OAAiB,CAAC;AACxB,QAAM,kBAAkB,qBAAqB,IAAI,OAAO;AAGxD,aAAW,OAAO,iBAAiB;AAClC,SAAK,KAAK,IAAI,YAAY,CAAC;AAAA,EAC5B;AAEA,SAAO,KAAK,KAAK,EAAE,KAAK,GAAG;AAC5B,GAVuB;AAjQjB,IAAM,YAAN;","names":[]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
const _SignatureV4Credentials = class _SignatureV4Credentials {
|
|
4
|
+
constructor(securityToken, secretAccessKey, accessKeyId) {
|
|
5
|
+
this.accessKeyId = accessKeyId;
|
|
6
|
+
this.secretAccessKey = secretAccessKey;
|
|
7
|
+
this.securityToken = securityToken;
|
|
8
|
+
}
|
|
9
|
+
GetAccessKey() {
|
|
10
|
+
return this.accessKeyId;
|
|
11
|
+
}
|
|
12
|
+
GetSecretKey() {
|
|
13
|
+
return this.secretAccessKey;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
__name(_SignatureV4Credentials, "SignatureV4Credentials");
|
|
17
|
+
let SignatureV4Credentials = _SignatureV4Credentials;
|
|
18
|
+
export {
|
|
19
|
+
SignatureV4Credentials
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=signatureV4Credentials.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/modules/TOS/utils/signatureV4Credentials.ts"],"sourcesContent":["import type { ISigCredentials } from \"./signatureV4\"\n\nexport class SignatureV4Credentials implements ISigCredentials {\n\tpublic securityToken: string\n\n\tpublic secretAccessKey: string\n\n\tpublic accessKeyId: string\n\n\tconstructor(securityToken?: string, secretAccessKey?: string, accessKeyId?: string) {\n\t\tthis.accessKeyId = accessKeyId as string\n\t\tthis.secretAccessKey = secretAccessKey as string\n\t\tthis.securityToken = securityToken as string\n\t}\n\n\tpublic GetAccessKey(): string {\n\t\treturn this.accessKeyId\n\t}\n\n\tpublic GetSecretKey(): string {\n\t\treturn this.secretAccessKey\n\t}\n}\n\n\n\n\n"],"mappings":";;AAEO,MAAM,0BAAN,MAAM,wBAAkD;AAAA,EAO9D,YAAY,eAAwB,iBAA0B,aAAsB;AACnF,SAAK,cAAc;AACnB,SAAK,kBAAkB;AACvB,SAAK,gBAAgB;AAAA,EACtB;AAAA,EAEO,eAAuB;AAC7B,WAAO,KAAK;AAAA,EACb;AAAA,EAEO,eAAuB;AAC7B,WAAO,KAAK;AAAA,EACb;AACD;AApB+D;AAAxD,IAAM,yBAAN;","names":[]}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import cryptoEncBase64 from "crypto-js/enc-base64";
|
|
4
|
+
import cryptoEncHex from "crypto-js/enc-hex";
|
|
5
|
+
import cryptoEncUtf8 from "crypto-js/enc-utf8";
|
|
6
|
+
import cryptoHmacSha256 from "crypto-js/hmac-sha256";
|
|
7
|
+
import cryptoHashMd5 from "crypto-js/md5";
|
|
8
|
+
import cryptoHashSha256 from "crypto-js/sha256";
|
|
9
|
+
import TosClientError from "../TosClientError";
|
|
10
|
+
import { isBuffer } from "../utils";
|
|
11
|
+
function getEnc(coding) {
|
|
12
|
+
switch (coding) {
|
|
13
|
+
case "utf-8":
|
|
14
|
+
return cryptoEncUtf8;
|
|
15
|
+
case "base64":
|
|
16
|
+
return cryptoEncBase64;
|
|
17
|
+
case "hex":
|
|
18
|
+
return cryptoEncHex;
|
|
19
|
+
default:
|
|
20
|
+
throw new TosClientError("The coding is not supported");
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
__name(getEnc, "getEnc");
|
|
24
|
+
function decode(v, decoding) {
|
|
25
|
+
if (!decoding) {
|
|
26
|
+
return v;
|
|
27
|
+
}
|
|
28
|
+
return v.toString(getEnc(decoding));
|
|
29
|
+
}
|
|
30
|
+
__name(decode, "decode");
|
|
31
|
+
const hmacSha256 = /* @__PURE__ */ __name(function hmacSha2562(key, message, decoding) {
|
|
32
|
+
return decode(cryptoHmacSha256(message, key), decoding);
|
|
33
|
+
}, "hmacSha256");
|
|
34
|
+
const hashSha256 = /* @__PURE__ */ __name(function hashSha2562(message, decoding) {
|
|
35
|
+
return decode(cryptoHashSha256(message), decoding);
|
|
36
|
+
}, "hashSha256");
|
|
37
|
+
const hashMd5 = /* @__PURE__ */ __name(function hashMd52(message, decoding) {
|
|
38
|
+
if (isBuffer(message)) {
|
|
39
|
+
throw new TosClientError("not support buffer in browser environment");
|
|
40
|
+
}
|
|
41
|
+
return decode(cryptoHashMd5(message), decoding);
|
|
42
|
+
}, "hashMd5");
|
|
43
|
+
const parse = /* @__PURE__ */ __name(function parse2(str, encoding) {
|
|
44
|
+
return getEnc(encoding).parse(str);
|
|
45
|
+
}, "parse");
|
|
46
|
+
const stringify = /* @__PURE__ */ __name(function stringify2(str, decoding) {
|
|
47
|
+
return getEnc(decoding).stringify(str);
|
|
48
|
+
}, "stringify");
|
|
49
|
+
export {
|
|
50
|
+
hashMd5,
|
|
51
|
+
hashSha256,
|
|
52
|
+
hmacSha256,
|
|
53
|
+
parse,
|
|
54
|
+
stringify
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=crypto.browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/modules/TOS/utils/universal/crypto.browser.ts"],"sourcesContent":["import cryptoEncBase64 from \"crypto-js/enc-base64\"\nimport cryptoEncHex from \"crypto-js/enc-hex\"\nimport cryptoEncUtf8 from \"crypto-js/enc-utf8\"\nimport cryptoHmacSha256 from \"crypto-js/hmac-sha256\"\nimport cryptoHashMd5 from \"crypto-js/md5\"\nimport cryptoHashSha256 from \"crypto-js/sha256\"\nimport TosClientError from \"../TosClientError\"\nimport { isBuffer } from \"../utils\"\n\nfunction getEnc(coding: \"utf-8\" | \"base64\" | \"hex\") {\n\tswitch (coding) {\n\t\tcase \"utf-8\":\n\t\t\treturn cryptoEncUtf8\n\t\tcase \"base64\":\n\t\t\treturn cryptoEncBase64\n\t\tcase \"hex\":\n\t\t\treturn cryptoEncHex\n\t\tdefault:\n\t\t\tthrow new TosClientError(\"The coding is not supported\")\n\t}\n}\n\nfunction decode(v: any, decoding?: \"base64\" | \"hex\"): string {\n\tif (!decoding) {\n\t\treturn v\n\t}\n\n\treturn v.toString(getEnc(decoding))\n}\n\nexport const hmacSha256 = function hmacSha256(\n\tkey: string,\n\tmessage: string,\n\tdecoding?: \"base64\" | \"hex\",\n) {\n\treturn decode(cryptoHmacSha256(message, key), decoding)\n}\n\nexport const hashSha256 = function hashSha256(message: string, decoding?: \"base64\" | \"hex\") {\n\treturn decode(cryptoHashSha256(message), decoding)\n}\n\nexport const hashMd5 = function hashMd5(message: string | Buffer, decoding?: \"base64\" | \"hex\") {\n\tif (isBuffer(message)) {\n\t\tthrow new TosClientError(\"not support buffer in browser environment\")\n\t}\n\n\treturn decode(cryptoHashMd5(message), decoding)\n}\n\nexport const parse = function parse(str: string, encoding: \"utf-8\" | \"base64\" | \"hex\") {\n\treturn getEnc(encoding).parse(str)\n}\n\nexport const stringify = function stringify(\n\tstr: CryptoJS.lib.WordArray,\n\tdecoding: \"utf-8\" | \"base64\" | \"hex\",\n) {\n\treturn getEnc(decoding).stringify(str)\n}\n\n\n\n\n"],"mappings":";;AAAC,OAAO,qBAAqB;AAC7B,OAAO,kBAAkB;AACzB,OAAO,mBAAmB;AAC1B,OAAO,sBAAsB;AAC7B,OAAO,mBAAmB;AAC1B,OAAO,sBAAsB;AAC7B,OAAO,oBAAoB;AAC3B,SAAS,gBAAgB;AAEzB,SAAS,OAAO,QAAoC;AACnD,UAAQ,QAAQ;AAAA,IACf,KAAK;AACJ,aAAO;AAAA,IACR,KAAK;AACJ,aAAO;AAAA,IACR,KAAK;AACJ,aAAO;AAAA,IACR;AACC,YAAM,IAAI,eAAe,6BAA6B;AAAA,EACxD;AACD;AAXS;AAaT,SAAS,OAAO,GAAQ,UAAqC;AAC5D,MAAI,CAAC,UAAU;AACd,WAAO;AAAA,EACR;AAEA,SAAO,EAAE,SAAS,OAAO,QAAQ,CAAC;AACnC;AANS;AAQF,MAAM,aAAa,gCAASA,YAClC,KACA,SACA,UACC;AACD,SAAO,OAAO,iBAAiB,SAAS,GAAG,GAAG,QAAQ;AACvD,GAN0B;AAQnB,MAAM,aAAa,gCAASC,YAAW,SAAiB,UAA6B;AAC3F,SAAO,OAAO,iBAAiB,OAAO,GAAG,QAAQ;AAClD,GAF0B;AAInB,MAAM,UAAU,gCAASC,SAAQ,SAA0B,UAA6B;AAC9F,MAAI,SAAS,OAAO,GAAG;AACtB,UAAM,IAAI,eAAe,2CAA2C;AAAA,EACrE;AAEA,SAAO,OAAO,cAAc,OAAO,GAAG,QAAQ;AAC/C,GANuB;AAQhB,MAAM,QAAQ,gCAASC,OAAM,KAAa,UAAsC;AACtF,SAAO,OAAO,QAAQ,EAAE,MAAM,GAAG;AAClC,GAFqB;AAId,MAAM,YAAY,gCAASC,WACjC,KACA,UACC;AACD,SAAO,OAAO,QAAQ,EAAE,UAAU,GAAG;AACtC,GALyB;","names":["hmacSha256","hashSha256","hashMd5","parse","stringify"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
const getSortedQueryString = /* @__PURE__ */ __name((query) => {
|
|
4
|
+
const searchParts = [];
|
|
5
|
+
Object.keys(query).sort().forEach((key) => {
|
|
6
|
+
searchParts.push(`${encodeURIComponent(key)}=${encodeURIComponent(query[key])}`);
|
|
7
|
+
});
|
|
8
|
+
return searchParts.join("&");
|
|
9
|
+
}, "getSortedQueryString");
|
|
10
|
+
function isBuffer(obj) {
|
|
11
|
+
return typeof Buffer !== "undefined" && obj instanceof Buffer;
|
|
12
|
+
}
|
|
13
|
+
__name(isBuffer, "isBuffer");
|
|
14
|
+
export {
|
|
15
|
+
getSortedQueryString,
|
|
16
|
+
isBuffer
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/modules/TOS/utils/utils.ts"],"sourcesContent":["export const getSortedQueryString = (query: Record<string, any>) => {\n\tconst searchParts: string[] = []\n\tObject.keys(query)\n\t\t.sort()\n\t\t.forEach((key) => {\n\t\t\tsearchParts.push(`${encodeURIComponent(key)}=${encodeURIComponent(query[key])}`)\n\t\t})\n\treturn searchParts.join(\"&\")\n}\n\nexport function isBuffer(obj: unknown): obj is Buffer {\n\treturn typeof Buffer !== \"undefined\" && obj instanceof Buffer\n}\n\n\n\n\n"],"mappings":";;AAAQ,MAAM,uBAAuB,wBAAC,UAA+B;AACpE,QAAM,cAAwB,CAAC;AAC/B,SAAO,KAAK,KAAK,EACf,KAAK,EACL,QAAQ,CAAC,QAAQ;AACjB,gBAAY,KAAK,GAAG,mBAAmB,GAAG,CAAC,IAAI,mBAAmB,MAAM,GAAG,CAAC,CAAC,EAAE;AAAA,EAChF,CAAC;AACF,SAAO,YAAY,KAAK,GAAG;AAC5B,GARqC;AAU9B,SAAS,SAAS,KAA6B;AACrD,SAAO,OAAO,WAAW,eAAe,eAAe;AACxD;AAFgB;","names":[]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { PlatformType } from "../types";
|
|
2
|
+
import OSSUpload from "./OSS";
|
|
3
|
+
import OBSUpload from "./OBS";
|
|
4
|
+
import KodoUpload from "./Kodo";
|
|
5
|
+
import TOSUpload from "./TOS";
|
|
6
|
+
import LocalUpload from "./Local";
|
|
7
|
+
import MinIOUpload from "./MinIO";
|
|
8
|
+
const PlatformModules = {
|
|
9
|
+
[PlatformType.OSS]: OSSUpload,
|
|
10
|
+
[PlatformType.Kodo]: KodoUpload,
|
|
11
|
+
[PlatformType.TOS]: TOSUpload,
|
|
12
|
+
[PlatformType.OBS]: OBSUpload,
|
|
13
|
+
[PlatformType.Local]: LocalUpload,
|
|
14
|
+
[PlatformType.Minio]: MinIOUpload
|
|
15
|
+
};
|
|
16
|
+
var modules_default = PlatformModules;
|
|
17
|
+
export {
|
|
18
|
+
modules_default as default
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/modules/index.ts"],"sourcesContent":["import type {\n\tPlatformMultipartUploadOption,\n\tPlatformRequest,\n\tPlatformSimpleUploadOption,\n} from \"../types\"\nimport { PlatformType } from \"../types\"\nimport type { OSS } from \"../types/OSS\"\nimport type { OBS } from \"../types/OBS\"\nimport type { Kodo } from \"../types/Kodo\"\nimport type { TOS } from \"../types/TOS\"\nimport type { Local } from \"../types/Local\"\nimport type { MinIO } from \"../types/MinIO\"\nimport OSSUpload from \"./OSS\"\nimport OBSUpload from \"./OBS\"\nimport KodoUpload from \"./Kodo\"\nimport TOSUpload from \"./TOS\"\nimport LocalUpload from \"./Local\"\nimport MinIOUpload from \"./MinIO\"\n\nconst PlatformModules: Record<\n\tPlatformType,\n\tRecord<\n\t\tstring,\n\t\t| PlatformRequest<OSS.AuthParams, PlatformSimpleUploadOption>\n\t\t| PlatformRequest<OSS.STSAuthParams, PlatformMultipartUploadOption>\n\t\t| PlatformRequest<Kodo.AuthParams, PlatformSimpleUploadOption>\n\t\t| PlatformRequest<TOS.AuthParams, PlatformMultipartUploadOption>\n\t\t| PlatformRequest<TOS.STSAuthParams, PlatformMultipartUploadOption>\n\t\t| PlatformRequest<OBS.STSAuthParams, PlatformMultipartUploadOption>\n\t\t| PlatformRequest<OBS.AuthParams, PlatformMultipartUploadOption>\n\t\t| PlatformRequest<Local.AuthParams, PlatformSimpleUploadOption>\n\t\t| PlatformRequest<MinIO.AuthParams, PlatformSimpleUploadOption>\n\t\t| PlatformRequest<MinIO.STSAuthParams, PlatformMultipartUploadOption>\n\t>\n> = {\n\t[PlatformType.OSS]: OSSUpload,\n\t[PlatformType.Kodo]: KodoUpload,\n\t[PlatformType.TOS]: TOSUpload,\n\t[PlatformType.OBS]: OBSUpload,\n\t[PlatformType.Local]: LocalUpload,\n\t[PlatformType.Minio]: MinIOUpload,\n}\n\nexport default PlatformModules\n\n\n\n\n"],"mappings":"AAKA,SAAS,oBAAoB;AAO7B,OAAO,eAAe;AACtB,OAAO,eAAe;AACtB,OAAO,gBAAgB;AACvB,OAAO,eAAe;AACtB,OAAO,iBAAiB;AACxB,OAAO,iBAAiB;AAExB,MAAM,kBAeF;AAAA,EACH,CAAC,aAAa,GAAG,GAAG;AAAA,EACpB,CAAC,aAAa,IAAI,GAAG;AAAA,EACrB,CAAC,aAAa,GAAG,GAAG;AAAA,EACpB,CAAC,aAAa,GAAG,GAAG;AAAA,EACpB,CAAC,aAAa,KAAK,GAAG;AAAA,EACtB,CAAC,aAAa,KAAK,GAAG;AACvB;AAEA,IAAO,kBAAQ;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=Kodo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=Local.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=MinIO.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
var OBSUploadFileEventType = /* @__PURE__ */ ((OBSUploadFileEventType2) => {
|
|
2
|
+
OBSUploadFileEventType2["initiateMultipartUploadSucceed"] = "initiateMultipartUploadSucceed";
|
|
3
|
+
return OBSUploadFileEventType2;
|
|
4
|
+
})(OBSUploadFileEventType || {});
|
|
5
|
+
export {
|
|
6
|
+
OBSUploadFileEventType
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=OBS.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/types/OBS.ts"],"sourcesContent":["import type { DonePart, PlatformMultipartUploadOption } from \"./index\"\nimport type { DataWrapperWithHeaders } from \"./request\"\n\nexport const enum OBSUploadFileEventType {\n\tinitiateMultipartUploadSucceed = \"initiateMultipartUploadSucceed\",\n}\n\nexport namespace OBS {\n\texport interface UploadFileEventResponse {\n\t\t[OBSUploadFileEventType.initiateMultipartUploadSucceed]: InitMultipartUploadResponse\n\t}\n\n\texport interface AuthParams {\n\t\tAccessKeyId: string\n\t\thost: string\n\t\tpolicy: string\n\t\tsignature: string\n\t\tdir: string\n\t\t\"content-type\": string\n\t}\n\n\texport interface STSAuthParams {\n\t\thost: string\n\t\tregion: string\n\t\tendpoint: string\n\t\tcredentials: {\n\t\t\taccess: string\n\t\t\tsecret: string\n\t\t\tsecurity_token: string\n\t\t\texpires_at: string\n\t\t}\n\t\tbucket: string\n\t\tdir: string\n\t\texpires: number\n\t\tcallback: string\n\t}\n\n\texport interface PartInfo {\n\t\tcontent: Buffer\n\t\tsize: number\n\t}\n\n\texport interface InitMultipartUploadOption extends PlatformMultipartUploadOption {\n\t\tmime?: string | null\n\t}\n\n\texport interface CommonResponse<I> {\n\t\tCommonMsg: {\n\t\t\tStatus: number\n\t\t\tCode: string\n\t\t\tMessage: string\n\t\t\tHostId: string\n\t\t\tRequestId: string\n\t\t\tInterfaceResult: null\n\t\t\tId2: string\n\t\t}\n\t\tInterfaceResult: I\n\t}\n\n\texport interface InitMultipartUploadResponse {\n\t\tInitiateMultipartUploadResult: {\n\t\t\tBucket: string\n\t\t\tKey: string\n\t\t\tUploadId: string\n\t\t}\n\t}\n\n\texport interface InitMultipartUploadResult {\n\t\tres: unknown\n\t\tbucket: string\n\t\tname: string\n\t\tUploadId: string\n\t}\n\n\texport type UploadPartResponse = DataWrapperWithHeaders<null>\n\n\texport interface UploadPartResult {\n\t\tname: string\n\t\tetag: string\n\t\tres: UploadPartResponse\n\t}\n\n\texport type CompleteMultipartUploadResponse = CommonResponse<{\n\t\tContentLength: string\n\t\tDate: string\n\t\tRequestId: string\n\t\tId2: string\n\t\tLocation: string\n\t\tBucket: string\n\t\tKey: string\n\t\tETag: string\n\t}>\n\n\texport type UploadPart = DonePart\n\n\texport type PutResponseData = CommonResponse<{\n\t\tContentLength: \"0\"\n\t\tRequestId: \"0000018C63BA1641B01B419F482B8B1E\"\n\t\tETag: '\"e00ca89591de6668570981e97c9663ea\"'\n\t}>\n}\n\n\n\n\n"],"mappings":"AAGO,IAAW,yBAAX,kBAAWA,4BAAX;AACN,EAAAA,wBAAA,oCAAiC;AADhB,SAAAA;AAAA,GAAA;","names":["OBSUploadFileEventType"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=OSS.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=TOS.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
var PlatformType = /* @__PURE__ */ ((PlatformType2) => {
|
|
2
|
+
PlatformType2["OSS"] = "aliyun";
|
|
3
|
+
PlatformType2["Kodo"] = "qiniu";
|
|
4
|
+
PlatformType2["TOS"] = "tos";
|
|
5
|
+
PlatformType2["OBS"] = "obs";
|
|
6
|
+
PlatformType2["Local"] = "local";
|
|
7
|
+
PlatformType2["Minio"] = "minio";
|
|
8
|
+
return PlatformType2;
|
|
9
|
+
})(PlatformType || {});
|
|
10
|
+
export {
|
|
11
|
+
PlatformType
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/types/index.ts"],"sourcesContent":["import type { OSS } from \"./OSS\"\nimport type { ErrorType } from \"./error\"\nimport type { Kodo } from \"./Kodo\"\nimport type { Local } from \"./Local\"\nimport type { Method } from \"./request\"\nimport type { TOS } from \"./TOS\"\nimport type { OBS } from \"./OBS\"\nimport type { MinIO } from \"./MinIO\"\n\n/** Request type */\nexport type MethodType = Method\n\n/**\n * @description Unified success response\n * @param code 1000 for successful request\n * @param message Request status information\n * @param data Return data payload\n */\nexport interface NormalSuccessResponse {\n\tcode: number\n\tmessage: string\n\theaders: Record<string, string>\n\tdata: {\n\t\tplatform: PlatformType\n\t\tpath: string\n\t}\n}\n\n/**\n * @param url Request URL\n * @param method Request method\n * @param headers Request headers\n * @param body Request body\n */\nexport interface Request {\n\turl: string\n\tmethod: Method\n\theaders?: Record<string, string>\n\tbody?: any\n}\n\n/**\n * @description: Image processing configuration\n * @param type // Image processing type, e.g.: resize, watermark\n * @param params Image processing parameters, refer to: https://help.aliyun.com/document_detail/144582.html\n */\nexport interface TransformImageConfig {\n\ttype:\n\t\t| \"resize\"\n\t\t| \"watermark\"\n\t\t| \"crop\"\n\t\t| \"quality\"\n\t\t| \"format\"\n\t\t| \"auto-orient\"\n\t\t| \"circle\"\n\t\t| \"indexcrop\"\n\t\t| \"rounded-corners\"\n\t\t| \"blur\"\n\t\t| \"rotate\"\n\t\t| \"interlace\"\n\t\t| \"bright\"\n\t\t| \"sharpen\"\n\t\t| \"contrast\"\n\tparams: Record<string, any>\n}\n\n/**\n * @description: Download configuration\n * @param url Request URL\n * @param method Request method\n * @param headers Request headers\n * @param body Request body\n */\nexport interface DownloadConfig extends Request {\n\toption?: {\n\t\timage?: TransformImageConfig[]\n\t}\n}\n\ntype UploadConfigOption = UploadCommonOption &\n\tPlatformSimpleUploadOption &\n\tPlatformMultipartUploadOption\n\n/**\n * @description: Common upload configuration\n * @param rewriteFileName Whether to rename the file\n */\nexport interface UploadCommonOption {\n\trewriteFileName?: boolean\n}\n\n/**\n * @description: Custom upload credential configuration\n * @param platform Platform type\n * @param credentials Credential information\n * @param expire Expiration timestamp (optional)\n */\nexport interface CustomCredentials {\n\tplatform: PlatformType\n\ttemporary_credential: PlatformParams\n\texpire?: number\n}\n\n/**\n * @description: Upload configuration, requires developers to configure upload credential request, SDK handles upload request internally\n * @param url Request upload credential - URL (optional when using custom credentials)\n * @param method Request upload credential - request method (optional when using custom credentials)\n * @param headers Request upload credential - request headers (optional when using custom credentials)\n * @param body Request upload credential - request body (optional when using custom credentials)\n * @param {File | Blob} file File to be uploaded\n * @param fileName File name\n * @param option Optional upload configuration\n * @param customCredentials Custom upload credentials (optional, will skip credential request when provided)\n */\nexport interface UploadConfig {\n\turl?: string\n\tmethod?: Method\n\theaders?: Record<string, string>\n\tbody?: any\n\tfile: File | Blob\n\tfileName: string\n\toption?: UploadConfigOption\n\tcustomCredentials?: CustomCredentials\n}\n\n/** Upload callback */\nexport interface UploadCallBack extends TaskCallBack {}\n\nexport type DonePart = { number: number; etag: string }\n\nexport interface Checkpoint {\n\t/** The file object selected by the user, if the browser is restarted, it needs the user to manually trigger the settings */\n\tfile: any\n\t/** object key */\n\tname: string\n\tfileSize: number\n\tpartSize: number\n\tUploadId: string\n\tdoneParts: DonePart[]\n}\n\n/** percent: percentage progress loaded: bytes uploaded total: total bytes checkpoint: upload checkpoint information */\nexport type Progress = (\n\tpercent: number,\n\tloaded: number,\n\ttotal: number,\n\tcheckpoint: Checkpoint | null,\n) => void\n\n/** PlatformType cloud storage provider enum type */\nexport enum PlatformType {\n\tOSS = \"aliyun\",\n\tKodo = \"qiniu\",\n\tTOS = \"tos\",\n\tOBS = \"obs\",\n\tLocal = \"local\",\n\tMinio = \"minio\",\n}\n\n/** Aggregated platform parameters */\nexport type PlatformParams =\n\t| OSS.AuthParams\n\t| OSS.STSAuthParams\n\t| Kodo.AuthParams\n\t| Local.AuthParams\n\t| TOS.AuthParams\n\t| TOS.STSAuthParams\n\t| OBS.AuthParams\n\t| OBS.STSAuthParams\n\t| MinIO.AuthParams\n\t| MinIO.STSAuthParams\n\n/** Request temporary credentials, return data template */\nexport interface UploadSource<T extends PlatformParams> {\n\tplatform: PlatformType\n\ttemporary_credential: T\n\texpire: number\n}\n\n/** Global variables */\nexport type GlobalCache<T extends PlatformParams> = Record<string, UploadSource<T>>\n\n/** Object storage platform base Option */\ninterface PlatformOption {\n\theaders?: Record<string, string>\n\ttaskId?: TaskId\n\tprogress?: Progress\n\treUploadedCount?: number\n}\n\n/** Multipart upload Option optional fields */\nexport interface PlatformMultipartUploadOption extends PlatformOption {\n\tparallel?: number\n\tpartSize?: number\n\tcheckpoint?: OSS.Checkpoint\n\tmime?: string | null\n}\n\n/** Simple upload Option optional fields */\nexport interface PlatformSimpleUploadOption extends PlatformOption {}\n\n/** Upload file implementation interface for different object storage platforms */\nexport type PlatformRequest<P, O> = (\n\tfile: File | Blob,\n\tkey: string,\n\tparams: P,\n\toption: O,\n) => Promise<NormalSuccessResponse>\n\n/** Object storage platform module */\nexport interface PlatformModule {\n\tupload: PlatformRequest<\n\t\tPlatformParams,\n\t\tPlatformSimpleUploadOption | PlatformMultipartUploadOption\n\t>\n}\n\n/** A TaskId is generated when a file upload starts */\nexport type TaskId = string\n\n/** Upload progress callback parameters */\nexport interface ProgressCallbackProps {\n\tpercent?: number\n\tloaded?: number\n\ttotal?: number\n\tcheckpoint?: OSS.Checkpoint | null\n}\n\n/** Success hook callback */\nexport type SuccessCallback = (response?: NormalSuccessResponse) => void\n\n/** Failure hook callback */\nexport type FailCallback = (err?: ErrorType.UploadError) => void\n\n/** Progress hook callback */\nexport type ProgressCallback = (\n\tpercent?: ProgressCallbackProps[\"percent\"],\n\tloaded?: ProgressCallbackProps[\"loaded\"],\n\ttotal?: ProgressCallbackProps[\"total\"],\n\tcheckpoint?: ProgressCallbackProps[\"checkpoint\"],\n) => void\n\n/** Upload task callbacks */\nexport interface TaskCallBack {\n\t// Upload succeeded\n\tsuccess?: (callback: SuccessCallback) => void\n\t// Upload errored\n\tfail?: (callback: FailCallback) => void\n\t// Progress\n\tprogress?: (callback: ProgressCallback) => void\n\t// Cancel\n\tcancel?: () => void\n\t// Pause\n\tpause?: () => void\n\t// Resume\n\tresume?: () => void\n}\n\n/** Task object */\nexport interface Task {\n\t// Upload succeeded\n\tsuccess?: SuccessCallback\n\t// Upload errored\n\tfail?: FailCallback\n\t// Progress\n\tprogress?: ProgressCallback\n\t// Cancel\n\tcancel?: () => void\n\t// Pause\n\tpause?: () => void\n\t// Resume\n\tresume?: () => void\n\t/** File progress info while paused */\n\tpauseInfo?: {\n\t\tisPause: boolean\n\t\tcheckpoint: OSS.Checkpoint\n\t}\n}\n\n\n\n\n"],"mappings":"AAsJO,IAAK,eAAL,kBAAKA,kBAAL;AACN,EAAAA,cAAA,SAAM;AACN,EAAAA,cAAA,UAAO;AACP,EAAAA,cAAA,SAAM;AACN,EAAAA,cAAA,SAAM;AACN,EAAAA,cAAA,WAAQ;AACR,EAAAA,cAAA,WAAQ;AANG,SAAAA;AAAA,GAAA;","names":["PlatformType"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=log.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=request.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|