tiny-oss 0.5.0 → 1.0.0
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/README.md +459 -52
- package/UPGRADING.md +151 -0
- package/dist/aws.d.ts +208 -0
- package/dist/azure.d.ts +204 -0
- package/dist/cos.d.ts +208 -0
- package/dist/index.d.ts +209 -0
- package/dist/obs.d.ts +208 -0
- package/dist/protocol.d.ts +271 -0
- package/dist/tiny-oss.aws.es.js +1052 -0
- package/dist/tiny-oss.aws.es.js.map +1 -0
- package/dist/tiny-oss.azure.es.js +882 -0
- package/dist/tiny-oss.azure.es.js.map +1 -0
- package/dist/tiny-oss.cos.es.js +984 -0
- package/dist/tiny-oss.cos.es.js.map +1 -0
- package/dist/tiny-oss.es.js +965 -0
- package/dist/tiny-oss.es.js.map +1 -0
- package/dist/tiny-oss.obs.es.js +1048 -0
- package/dist/tiny-oss.obs.es.js.map +1 -0
- package/dist/tiny-oss.protocol.es.js +588 -0
- package/dist/tiny-oss.protocol.es.js.map +1 -0
- package/package.json +78 -64
- package/dist/tiny-oss.js +0 -1642
- package/dist/tiny-oss.js.map +0 -1
- package/dist/tiny-oss.min.js +0 -35
- package/dist/tiny-oss.min.js.map +0 -1
- package/es/TinyOSS.js +0 -209
- package/es/index.js +0 -1
- package/es/utils/ajax.js +0 -61
- package/es/utils/index.js +0 -188
- package/lib/TinyOSS.js +0 -218
- package/lib/index.js +0 -3
- package/lib/utils/ajax.js +0 -66
- package/lib/utils/index.js +0 -203
- package/types/index.d.ts +0 -89
- package/vendor/digest.js +0 -390
package/lib/utils/ajax.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
exports.__esModule = true;
|
|
4
|
-
exports["default"] = ajax;
|
|
5
|
-
|
|
6
|
-
function ajax(url, options) {
|
|
7
|
-
if (options === void 0) {
|
|
8
|
-
options = {};
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
return new Promise(function (resolve, reject) {
|
|
12
|
-
var _options = options,
|
|
13
|
-
_options$async = _options.async,
|
|
14
|
-
async = _options$async === void 0 ? true : _options$async,
|
|
15
|
-
_options$data = _options.data,
|
|
16
|
-
data = _options$data === void 0 ? null : _options$data,
|
|
17
|
-
_options$headers = _options.headers,
|
|
18
|
-
headers = _options$headers === void 0 ? {} : _options$headers,
|
|
19
|
-
_options$method = _options.method,
|
|
20
|
-
method = _options$method === void 0 ? 'get' : _options$method,
|
|
21
|
-
_options$timeout = _options.timeout,
|
|
22
|
-
timeout = _options$timeout === void 0 ? 0 : _options$timeout,
|
|
23
|
-
onprogress = _options.onprogress;
|
|
24
|
-
var xhr = new XMLHttpRequest();
|
|
25
|
-
var timerId;
|
|
26
|
-
|
|
27
|
-
if (timeout) {
|
|
28
|
-
timerId = setTimeout(function () {
|
|
29
|
-
reject(new Error("the request timeout " + timeout + "ms"));
|
|
30
|
-
}, timeout);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
xhr.onerror = function () {
|
|
34
|
-
reject(new Error('unknown error'));
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
if (xhr.upload) {
|
|
38
|
-
// Note: the progress event must be located before the xhr.open method
|
|
39
|
-
xhr.upload.onprogress = onprogress;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
xhr.onreadystatechange = function () {
|
|
43
|
-
if (xhr.readyState === 4) {
|
|
44
|
-
if (timeout) clearTimeout(timerId);
|
|
45
|
-
|
|
46
|
-
if (xhr.status >= 200 && xhr.status < 300) {
|
|
47
|
-
resolve(xhr.response, xhr);
|
|
48
|
-
} else {
|
|
49
|
-
var err = new Error('the request is error');
|
|
50
|
-
reject(err);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
xhr.open(method, url, async);
|
|
56
|
-
Object.keys(headers).forEach(function (key) {
|
|
57
|
-
xhr.setRequestHeader(key, headers[key]);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
try {
|
|
61
|
-
xhr.send(data);
|
|
62
|
-
} catch (err) {
|
|
63
|
-
reject(err);
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
}
|
package/lib/utils/index.js
DELETED
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
exports.__esModule = true;
|
|
6
|
-
exports.unix = unix;
|
|
7
|
-
exports.blobToBuffer = blobToBuffer;
|
|
8
|
-
exports.assertOptions = assertOptions;
|
|
9
|
-
exports.getContentMd5 = getContentMd5;
|
|
10
|
-
exports.getCanonicalizedOSSHeaders = getCanonicalizedOSSHeaders;
|
|
11
|
-
exports.getCanonicalizedResource = getCanonicalizedResource;
|
|
12
|
-
exports.getSignature = getSignature;
|
|
13
|
-
|
|
14
|
-
var _md = _interopRequireDefault(require("md5"));
|
|
15
|
-
|
|
16
|
-
var _base64Js = _interopRequireDefault(require("base64-js"));
|
|
17
|
-
|
|
18
|
-
var _digest = _interopRequireDefault(require("../../vendor/digest"));
|
|
19
|
-
|
|
20
|
-
function isDate(obj) {
|
|
21
|
-
return obj && Object.prototype.toString.call(obj) === '[object Date]' && obj.toString !== 'Invalid Date';
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function unix(date) {
|
|
25
|
-
var d;
|
|
26
|
-
|
|
27
|
-
if (date) {
|
|
28
|
-
d = new Date(date);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (!isDate(d)) {
|
|
32
|
-
d = new Date();
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return Math.round(d.getTime() / 1000);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function blobToBuffer(blob) {
|
|
39
|
-
return new Promise(function (resolve, reject) {
|
|
40
|
-
var fr = new FileReader();
|
|
41
|
-
|
|
42
|
-
fr.onload = function () {
|
|
43
|
-
var result = new Uint8Array(fr.result);
|
|
44
|
-
resolve(result);
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
fr.onerror = function () {
|
|
48
|
-
reject(fr.error);
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
fr.readAsArrayBuffer(blob);
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function assertOptions(options) {
|
|
56
|
-
var accessKeyId = options.accessKeyId,
|
|
57
|
-
accessKeySecret = options.accessKeySecret,
|
|
58
|
-
bucket = options.bucket,
|
|
59
|
-
endpoint = options.endpoint;
|
|
60
|
-
|
|
61
|
-
if (!accessKeyId) {
|
|
62
|
-
throw new Error('need accessKeyId');
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (!accessKeySecret) {
|
|
66
|
-
throw new Error('need accessKeySecret');
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (!bucket && !endpoint) {
|
|
70
|
-
throw new Error('need bucket or endpoint');
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function hexToBuffer(hex) {
|
|
75
|
-
var arr = [];
|
|
76
|
-
|
|
77
|
-
for (var i = 0; i < hex.length; i += 2) {
|
|
78
|
-
arr.push(parseInt(hex[i] + hex[i + 1], 16));
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return Uint8Array.from(arr);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function getContentMd5(buf) {
|
|
85
|
-
// md5 doesn't work for Uint8Array
|
|
86
|
-
var bytes = Array.prototype.slice.call(buf, 0);
|
|
87
|
-
var md5Buf = hexToBuffer((0, _md["default"])(bytes));
|
|
88
|
-
return _base64Js["default"].fromByteArray(md5Buf);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function getCanonicalizedOSSHeaders(headers) {
|
|
92
|
-
var result = '';
|
|
93
|
-
var headerNames = Object.keys(headers);
|
|
94
|
-
headerNames = headerNames.map(function (name) {
|
|
95
|
-
return name.toLowerCase();
|
|
96
|
-
});
|
|
97
|
-
headerNames.sort();
|
|
98
|
-
headerNames.forEach(function (name) {
|
|
99
|
-
if (name.indexOf('x-oss-') === 0) {
|
|
100
|
-
result += name + ":" + headers[name] + "\n";
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
return result;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function getCanonicalizedResource(bucket, objectName, parameters) {
|
|
107
|
-
if (bucket === void 0) {
|
|
108
|
-
bucket = '';
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
if (objectName === void 0) {
|
|
112
|
-
objectName = '';
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
var resourcePath = '';
|
|
116
|
-
|
|
117
|
-
if (bucket) {
|
|
118
|
-
resourcePath += "/" + bucket;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if (objectName) {
|
|
122
|
-
if (objectName.charAt(0) !== '/') {
|
|
123
|
-
resourcePath += '/';
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
resourcePath += objectName;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
var canonicalizedResource = "" + resourcePath;
|
|
130
|
-
var separatorString = '?';
|
|
131
|
-
|
|
132
|
-
if (parameters) {
|
|
133
|
-
var compareFunc = function compareFunc(entry1, entry2) {
|
|
134
|
-
if (entry1[0] > entry2[0]) {
|
|
135
|
-
return 1;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
if (entry1[0] < entry2[0]) {
|
|
139
|
-
return -1;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
return 0;
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
var processFunc = function processFunc(key) {
|
|
146
|
-
canonicalizedResource += separatorString + key;
|
|
147
|
-
|
|
148
|
-
if (parameters[key]) {
|
|
149
|
-
canonicalizedResource += "=" + parameters[key];
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
separatorString = '&';
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
Object.keys(parameters).sort(compareFunc).forEach(processFunc);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
return canonicalizedResource;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
function getSignature(options) {
|
|
162
|
-
if (options === void 0) {
|
|
163
|
-
options = {};
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
var _options = options,
|
|
167
|
-
_options$type = _options.type,
|
|
168
|
-
type = _options$type === void 0 ? 'header' : _options$type,
|
|
169
|
-
_options$verb = _options.verb,
|
|
170
|
-
verb = _options$verb === void 0 ? '' : _options$verb,
|
|
171
|
-
_options$contentMd = _options.contentMd5,
|
|
172
|
-
contentMd5 = _options$contentMd === void 0 ? '' : _options$contentMd,
|
|
173
|
-
_options$expires = _options.expires,
|
|
174
|
-
expires = _options$expires === void 0 ? unix() + 3600 : _options$expires,
|
|
175
|
-
bucket = _options.bucket,
|
|
176
|
-
objectName = _options.objectName,
|
|
177
|
-
accessKeySecret = _options.accessKeySecret,
|
|
178
|
-
_options$headers = _options.headers,
|
|
179
|
-
headers = _options$headers === void 0 ? {} : _options$headers,
|
|
180
|
-
subResource = _options.subResource;
|
|
181
|
-
var date = headers['x-oss-date'] || '';
|
|
182
|
-
var contentType = headers['Content-Type'] || '';
|
|
183
|
-
var data = [verb, contentMd5, contentType];
|
|
184
|
-
|
|
185
|
-
if (type === 'header') {
|
|
186
|
-
data.push(date);
|
|
187
|
-
} else {
|
|
188
|
-
data.push(expires);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
var canonicalizedOSSHeaders = getCanonicalizedOSSHeaders(headers);
|
|
192
|
-
var canonicalizedResource = getCanonicalizedResource(bucket, objectName, subResource);
|
|
193
|
-
data.push("" + canonicalizedOSSHeaders + canonicalizedResource);
|
|
194
|
-
var text = data.join('\n');
|
|
195
|
-
var hmac = new _digest["default"].HMAC_SHA1();
|
|
196
|
-
hmac.setKey(accessKeySecret);
|
|
197
|
-
hmac.update(text);
|
|
198
|
-
var hashBuf = new Uint8Array(hmac.finalize());
|
|
199
|
-
|
|
200
|
-
var signature = _base64Js["default"].fromByteArray(hashBuf);
|
|
201
|
-
|
|
202
|
-
return signature;
|
|
203
|
-
}
|
package/types/index.d.ts
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
// Type definitions for [Tiny-OSS] [0.4.1]
|
|
2
|
-
// Project: [Tiny-OSS]
|
|
3
|
-
|
|
4
|
-
export = TinyOSS;
|
|
5
|
-
|
|
6
|
-
declare class TinyOSS {
|
|
7
|
-
/**
|
|
8
|
-
*
|
|
9
|
-
* @param options see <link> https://github.com/ali-sdk/ali-oss#signatureurlname-options </link>
|
|
10
|
-
*/
|
|
11
|
-
constructor(options?: TinyOSS.TinyOSSOptions);
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* put object
|
|
15
|
-
*
|
|
16
|
-
* @param objectName object name
|
|
17
|
-
* @param blob data
|
|
18
|
-
* @param options put options
|
|
19
|
-
*/
|
|
20
|
-
put(objectName: string, blob: Blob, options?: PutOptions): Promise<XMLHttpRequest["response"]>;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* put symbol link
|
|
24
|
-
*
|
|
25
|
-
* @param objectName object name
|
|
26
|
-
* @param targetObjectName target object name
|
|
27
|
-
*/
|
|
28
|
-
putSymlink(
|
|
29
|
-
objectName: string,
|
|
30
|
-
targetObjectName: string
|
|
31
|
-
): Promise<XMLHttpRequest["response"]>;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* get signature url for an object
|
|
35
|
-
*
|
|
36
|
-
* @param objectName object name
|
|
37
|
-
* @param options signature options, see <link> https://github.com/ali-sdk/ali-oss#signatureurlname-options </link>
|
|
38
|
-
* @return signature url
|
|
39
|
-
*/
|
|
40
|
-
signatureUrl(
|
|
41
|
-
objectName: string,
|
|
42
|
-
options: TinyOSS.SignatureUrlOptions
|
|
43
|
-
): string;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
declare namespace TinyOSS {
|
|
47
|
-
export interface TinyOSSOptions {
|
|
48
|
-
accessKeyId: string; // access secret you create
|
|
49
|
-
accessKeySecret: string; // access secret you create
|
|
50
|
-
stsToken?: string; // used by temporary authorization
|
|
51
|
-
bucket?: string; // the default bucket you want to access If you don't have any bucket, please use putBucket() create one first.
|
|
52
|
-
endpoint?: string; // oss region domain. It takes priority over region.
|
|
53
|
-
region?: string; // the bucket data region location, please see Data Regions, default is oss-cn-hangzhou.
|
|
54
|
-
internal?: boolean; // access OSS with aliyun internal network or not, default is false. If your servers are running on aliyun too, you can set true to save lot of money.
|
|
55
|
-
secure?: boolean; // instruct OSS client to use HTTPS (secure: true) or HTTP (secure: false) protocol.
|
|
56
|
-
timeout?: string | number; // instance level timeout for all operations, default is 60s
|
|
57
|
-
cname?: boolean; // use custom domain name
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export type HTTPMethods = "GET" | "POST" | "DELETE" | "PUT";
|
|
61
|
-
|
|
62
|
-
export interface ResponseHeaderType {
|
|
63
|
-
"content-type"?: string;
|
|
64
|
-
"content-disposition"?: string;
|
|
65
|
-
"cache-control"?: string;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export interface ObjectCallback {
|
|
69
|
-
url: string; // After a file is uploaded successfully, the OSS sends a callback request to this URL.
|
|
70
|
-
host?: string; // The host header value for initiating callback requests.
|
|
71
|
-
body: string; // The value of the request body when a callback is initiated, for example, key=$(key)&etag=$(etag)&my_var=$(x:my_var).
|
|
72
|
-
contentType?: string; // The Content-Type of the callback requests initiatiated, It supports application/x-www-form-urlencoded and application/json, and the former is the default value.
|
|
73
|
-
customValue?: object;
|
|
74
|
-
headers?: object; // extra headers, detail see RFC 2616
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export interface PutOptions {
|
|
78
|
-
onprogress?(e: Event): void;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export interface SignatureUrlOptions {
|
|
82
|
-
expires?: number; // after expires seconds, the url will become invalid, default is 1800
|
|
83
|
-
method?: HTTPMethods; // the HTTP method, default is 'GET'
|
|
84
|
-
"Content-Type"?: string; // set the request content type
|
|
85
|
-
process?: string;
|
|
86
|
-
response?: ResponseHeaderType; // set the response headers for download
|
|
87
|
-
callback?: ObjectCallback;
|
|
88
|
-
}
|
|
89
|
-
}
|