fsd-oss 0.7.2 → 0.10.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 +1 -1
- package/index.d.ts +38 -1
- package/lib/index.js +44 -22
- package/package.json +8 -8
- package/tsconfig.json +0 -29
package/README.md
CHANGED
package/index.d.ts
CHANGED
|
@@ -18,4 +18,41 @@ export interface OSSAdapterOptions {
|
|
|
18
18
|
callbackUrl?: string; // 边缘上传回调地址
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
export
|
|
21
|
+
export interface UploadToken {
|
|
22
|
+
auth: {
|
|
23
|
+
accessKeyId: string;
|
|
24
|
+
accessKeySecret: string;
|
|
25
|
+
stsToken: string;
|
|
26
|
+
bucket: string;
|
|
27
|
+
endpoint: string;
|
|
28
|
+
};
|
|
29
|
+
path: string;
|
|
30
|
+
expiration: number;
|
|
31
|
+
callback?: any;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface UploadTokenWithAutoRefresh {
|
|
35
|
+
auth: {
|
|
36
|
+
accessKeyId: string;
|
|
37
|
+
accessKeySecret: string;
|
|
38
|
+
stsToken: string;
|
|
39
|
+
bucket: string;
|
|
40
|
+
endpoint: string;
|
|
41
|
+
refreshSTSToken: () => Promise<{
|
|
42
|
+
accessKeyId: string;
|
|
43
|
+
accessKeySecret: string;
|
|
44
|
+
stsToken: string;
|
|
45
|
+
}>;
|
|
46
|
+
};
|
|
47
|
+
path: string;
|
|
48
|
+
expiration: number;
|
|
49
|
+
callback?: any;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export default class OSSAdpter extends Adapter<OSSAdapterOptions> {
|
|
53
|
+
createUploadToken: (videoId: string, meta?: any) => Promise<UploadToken>;
|
|
54
|
+
createUploadTokenWithAutoRefresh: (
|
|
55
|
+
videoId: string,
|
|
56
|
+
meta?: any
|
|
57
|
+
) => Promise<UploadTokenWithAutoRefresh>;
|
|
58
|
+
}
|
package/lib/index.js
CHANGED
|
@@ -7,7 +7,6 @@ const minimatch = require("minimatch");
|
|
|
7
7
|
const Debugger = require("debug");
|
|
8
8
|
const eachLimit = require("async/eachLimit");
|
|
9
9
|
const RPC = require("@alicloud/pop-core");
|
|
10
|
-
const url_1 = require("url");
|
|
11
10
|
const stream_1 = require("stream");
|
|
12
11
|
const debug = Debugger('fsd-oss');
|
|
13
12
|
const CALLBACK_BODY = 'bucket=${bucket}&path=${object}&etag=${etag}&size=${size}&mimeType=${mimeType}&height=${imageInfo.height}&width=${imageInfo.width}&format=${imageInfo.format}';
|
|
@@ -96,6 +95,17 @@ class OSSAdapter {
|
|
|
96
95
|
}
|
|
97
96
|
return token;
|
|
98
97
|
};
|
|
98
|
+
this.createUploadTokenWithAutoRefresh = async (videoId, meta) => {
|
|
99
|
+
let token = await this.createUploadToken(videoId, meta);
|
|
100
|
+
let auth = token.auth;
|
|
101
|
+
auth = Object.assign({}, auth, {
|
|
102
|
+
refreshSTSToken: async () => {
|
|
103
|
+
let t = await this.createUploadToken(videoId, meta);
|
|
104
|
+
return t.auth;
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
return Object.assign({}, token, { auth });
|
|
108
|
+
};
|
|
99
109
|
}
|
|
100
110
|
async append(path, data) {
|
|
101
111
|
debug('append %s', path);
|
|
@@ -146,6 +156,7 @@ class OSSAdapter {
|
|
|
146
156
|
return stream;
|
|
147
157
|
}
|
|
148
158
|
async unlink(path) {
|
|
159
|
+
var _a;
|
|
149
160
|
debug('unlink %s', path);
|
|
150
161
|
const { root } = this._options;
|
|
151
162
|
let p = slash(Path.join(root, path)).substr(1);
|
|
@@ -158,10 +169,10 @@ class OSSAdapter {
|
|
|
158
169
|
'max-keys': 1000
|
|
159
170
|
}, {});
|
|
160
171
|
({ nextMarker } = list);
|
|
161
|
-
if (list.objects
|
|
172
|
+
if ((_a = list.objects) === null || _a === void 0 ? void 0 : _a.length) {
|
|
162
173
|
let objects = list.objects.map((o) => o.name);
|
|
163
174
|
await this._oss.deleteMulti(objects, {
|
|
164
|
-
|
|
175
|
+
quiet: true
|
|
165
176
|
});
|
|
166
177
|
}
|
|
167
178
|
} while (nextMarker);
|
|
@@ -170,10 +181,10 @@ class OSSAdapter {
|
|
|
170
181
|
await this._oss.delete(p);
|
|
171
182
|
}
|
|
172
183
|
}
|
|
173
|
-
async mkdir(path,
|
|
184
|
+
async mkdir(path, recursive) {
|
|
174
185
|
debug('mkdir %s', path);
|
|
175
186
|
let parent = Path.dirname(path);
|
|
176
|
-
if (
|
|
187
|
+
if (recursive && parent !== '/') {
|
|
177
188
|
parent += '/';
|
|
178
189
|
if (!(await this.exists(parent))) {
|
|
179
190
|
debug('mkdir prefix: %s', parent);
|
|
@@ -190,7 +201,7 @@ class OSSAdapter {
|
|
|
190
201
|
let delimiter = recursion ? '' : '/';
|
|
191
202
|
let pattern = '';
|
|
192
203
|
if (recursion === true) {
|
|
193
|
-
pattern = '
|
|
204
|
+
pattern = '**/*';
|
|
194
205
|
}
|
|
195
206
|
else if (recursion) {
|
|
196
207
|
pattern = recursion;
|
|
@@ -208,13 +219,29 @@ class OSSAdapter {
|
|
|
208
219
|
}, {});
|
|
209
220
|
debug('list: %O', list);
|
|
210
221
|
({ nextMarker } = list);
|
|
222
|
+
if (list.prefixes) {
|
|
223
|
+
list.prefixes.forEach((name) => {
|
|
224
|
+
let relative = slash(Path.relative(p, name));
|
|
225
|
+
if (!relative)
|
|
226
|
+
return;
|
|
227
|
+
results.push({
|
|
228
|
+
name: `${relative}/`,
|
|
229
|
+
metadata: {
|
|
230
|
+
size: 0,
|
|
231
|
+
lastModified: null
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
}
|
|
211
236
|
if (list.objects) {
|
|
212
237
|
list.objects.forEach((object) => {
|
|
213
238
|
let { name } = object;
|
|
214
239
|
let relative = slash(Path.relative(p, name));
|
|
215
240
|
if (!relative)
|
|
216
241
|
return;
|
|
217
|
-
if (
|
|
242
|
+
if (name.endsWith('/'))
|
|
243
|
+
relative += '/';
|
|
244
|
+
if (pattern && pattern !== '**/*' && !minimatch(relative, pattern))
|
|
218
245
|
return;
|
|
219
246
|
results.push({
|
|
220
247
|
name: relative,
|
|
@@ -242,11 +269,10 @@ class OSSAdapter {
|
|
|
242
269
|
return url;
|
|
243
270
|
}
|
|
244
271
|
async copy(path, dest) {
|
|
272
|
+
var _a;
|
|
245
273
|
debug('copy %s to %s', path, dest);
|
|
246
274
|
if (!(await this.exists(path)))
|
|
247
275
|
throw new Error('The source path is not exists!');
|
|
248
|
-
if (await this.exists(dest))
|
|
249
|
-
throw new Error('The dest path is already exists!');
|
|
250
276
|
const { root } = this._options;
|
|
251
277
|
let from = slash(Path.join(root, path)).substr(1);
|
|
252
278
|
let to = slash(Path.join(root, dest)).substr(1);
|
|
@@ -261,7 +287,7 @@ class OSSAdapter {
|
|
|
261
287
|
}, {});
|
|
262
288
|
debug('list result: %O', list);
|
|
263
289
|
({ nextMarker } = list);
|
|
264
|
-
if (list.objects
|
|
290
|
+
if ((_a = list.objects) === null || _a === void 0 ? void 0 : _a.length) {
|
|
265
291
|
await eachLimit(list.objects, 10, async (object) => {
|
|
266
292
|
let { name } = object;
|
|
267
293
|
debug(' -> copy %s', name);
|
|
@@ -353,18 +379,17 @@ class OSSAdapter {
|
|
|
353
379
|
let { uploadId } = res;
|
|
354
380
|
let files = [];
|
|
355
381
|
for (let i = 1; i <= partCount; i += 1) {
|
|
356
|
-
files.push(`task://${uploadId}
|
|
382
|
+
files.push(`task://${uploadId}?${i}`);
|
|
357
383
|
}
|
|
358
384
|
return files;
|
|
359
385
|
}
|
|
360
386
|
async writePart(path, partTask, data, size) {
|
|
361
387
|
debug('writePart %s, task: %s', path, partTask);
|
|
362
|
-
let p = slash(Path.join(this._options.root, path)).
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
let
|
|
367
|
-
let res = await this._oss._uploadPart(p, uploadId, info.search.substr(1), {
|
|
388
|
+
let p = slash(Path.join(this._options.root, path)).substring(1);
|
|
389
|
+
if (!partTask.startsWith('task://'))
|
|
390
|
+
throw new Error('Invalid part task id');
|
|
391
|
+
let [uploadId, no] = partTask.replace('task://', '').split('?');
|
|
392
|
+
let res = await this._oss._uploadPart(p, uploadId, parseInt(no), {
|
|
368
393
|
stream: data,
|
|
369
394
|
size
|
|
370
395
|
});
|
|
@@ -373,11 +398,8 @@ class OSSAdapter {
|
|
|
373
398
|
}
|
|
374
399
|
async completeMultipartUpload(path, parts) {
|
|
375
400
|
debug('completeMultipartUpload %s', path);
|
|
376
|
-
let
|
|
377
|
-
|
|
378
|
-
throw new Error('Invalid part pathname');
|
|
379
|
-
let uploadId = (info.hostname || '').toUpperCase();
|
|
380
|
-
let p = slash(Path.join(this._options.root, path)).substr(1);
|
|
401
|
+
let uploadId = parts[0].replace('part://', '').split('?')[0];
|
|
402
|
+
let p = slash(Path.join(this._options.root, path)).substring(1);
|
|
381
403
|
debug('update id: %s, target: %s', uploadId, p);
|
|
382
404
|
let datas = parts.map((item, key) => ({
|
|
383
405
|
etag: item.split('#')[1],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fsd-oss",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Aliyun OSS adapter for fsd",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -8,16 +8,16 @@
|
|
|
8
8
|
"build": "tsc",
|
|
9
9
|
"prepublish": "npm run build"
|
|
10
10
|
},
|
|
11
|
-
"repository": "https://github.com/
|
|
12
|
-
"author": "Liang <liang@
|
|
11
|
+
"repository": "https://github.com/liangxingchen/fsd/tree/master/packages/fsd-oss",
|
|
12
|
+
"author": "Liang <liang@miaomo.cc> (https://github.com/liangxingchen)",
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@alicloud/pop-core": "^1.7.10",
|
|
16
|
-
"ali-oss": "^6.
|
|
17
|
-
"async": "
|
|
18
|
-
"debug": "^4.3.
|
|
19
|
-
"minimatch": "^3.0.
|
|
16
|
+
"ali-oss": "^6.17.1",
|
|
17
|
+
"async": "*",
|
|
18
|
+
"debug": "^4.3.4",
|
|
19
|
+
"minimatch": "^3.0.5",
|
|
20
20
|
"slash": "^3.0.0"
|
|
21
21
|
},
|
|
22
|
-
"gitHead": "
|
|
22
|
+
"gitHead": "9820fd7263b6791a38e5568396bfac0f2d3e37e9"
|
|
23
23
|
}
|
package/tsconfig.json
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"module": "commonjs",
|
|
4
|
-
"allowSyntheticDefaultImports": true,
|
|
5
|
-
"noImplicitAny": true,
|
|
6
|
-
"noImplicitAny": true,
|
|
7
|
-
"removeComments": true,
|
|
8
|
-
"preserveConstEnums": true,
|
|
9
|
-
"outDir": "lib",
|
|
10
|
-
"moduleResolution": "node",
|
|
11
|
-
"baseUrl": ".",
|
|
12
|
-
"paths": {
|
|
13
|
-
"*": [
|
|
14
|
-
"../../packages/*",
|
|
15
|
-
"../../typings/*"
|
|
16
|
-
]
|
|
17
|
-
},
|
|
18
|
-
"target": "ES2017",
|
|
19
|
-
"lib": [
|
|
20
|
-
"ES2017"
|
|
21
|
-
]
|
|
22
|
-
},
|
|
23
|
-
"include": [
|
|
24
|
-
"src/**/*"
|
|
25
|
-
],
|
|
26
|
-
"exclude": [
|
|
27
|
-
"node_modules"
|
|
28
|
-
]
|
|
29
|
-
}
|