fsd-oss 0.13.1 → 0.13.3

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/lib/index.js CHANGED
@@ -204,8 +204,10 @@ class OSSAdapter {
204
204
  }
205
205
  const { root } = this._options;
206
206
  let p = slash(Path.join(root, path)).substring(1);
207
- let results = [];
207
+ let results = Object.create(null);
208
208
  let continuationToken = '';
209
+ let hasContents = false;
210
+ let hasCommonPrefixes = false;
209
211
  do {
210
212
  let list = await this._oss.list({
211
213
  prefix: p,
@@ -216,6 +218,7 @@ class OSSAdapter {
216
218
  debug('list: %O', list);
217
219
  continuationToken = list.NextContinuationToken;
218
220
  if (list.Contents) {
221
+ hasContents = true;
219
222
  list.Contents.forEach((object) => {
220
223
  let relative = slash(Path.relative(p, object.Key));
221
224
  if (!relative)
@@ -224,17 +227,34 @@ class OSSAdapter {
224
227
  relative += '/';
225
228
  if (pattern && pattern !== '**/*' && !minimatch(relative, pattern))
226
229
  return;
227
- results.push({
230
+ results[relative] = {
228
231
  name: relative,
229
232
  metadata: {
230
233
  size: object.Size,
231
234
  lastModified: new Date(object.LastModified)
232
235
  }
233
- });
236
+ };
237
+ });
238
+ }
239
+ if (list.CommonPrefixes) {
240
+ hasCommonPrefixes = true;
241
+ list.CommonPrefixes.forEach((prefix) => {
242
+ let relative = slash(Path.relative(p, prefix.Prefix));
243
+ if (!relative)
244
+ return;
245
+ relative += '/';
246
+ results[relative] = {
247
+ name: relative
248
+ };
234
249
  });
235
250
  }
236
251
  } while (continuationToken);
237
- return results;
252
+ if (hasContents && hasCommonPrefixes) {
253
+ return Object.keys(results)
254
+ .sort()
255
+ .map((key) => results[key]);
256
+ }
257
+ return Object.values(results);
238
258
  }
239
259
  async createUrl(path, options) {
240
260
  debug('createUrl %s', path);
@@ -57,6 +57,7 @@ class SimpleOSSClient {
57
57
  let query = {
58
58
  'list-type': '2'
59
59
  };
60
+ let subres = {};
60
61
  if (options.prefix)
61
62
  query.prefix = options.prefix;
62
63
  if (options.delimiter)
@@ -64,14 +65,15 @@ class SimpleOSSClient {
64
65
  if (options.startAfter)
65
66
  query['start-after'] = options.startAfter;
66
67
  if (options.continuationToken)
67
- query['continuation-token'] = options.continuationToken;
68
+ subres['continuation-token'] = options.continuationToken;
68
69
  if (options.maxKeys)
69
- query['max-keys'] = options.maxKeys;
70
+ query['max-keys'] = String(options.maxKeys);
70
71
  if (options.encodingType)
71
72
  query['encoding-type'] = options.encodingType;
72
73
  if (options.fetchOwner)
73
- query['fetch-owner'] = options.fetchOwner;
74
+ query['fetch-owner'] = String(options.fetchOwner);
74
75
  options.query = query;
76
+ options.subres = subres;
75
77
  let res = await this.requestData('GET', '', null, options);
76
78
  res.KeyCount = parseInt(res.KeyCount);
77
79
  res.MaxKeys = parseInt(res.MaxKeys);
@@ -84,6 +86,10 @@ class SimpleOSSClient {
84
86
  content.Size = parseInt(content.Size);
85
87
  });
86
88
  }
89
+ if (res.CommonPrefixes) {
90
+ if (!Array.isArray(res.CommonPrefixes))
91
+ res.CommonPrefixes = [res.CommonPrefixes];
92
+ }
87
93
  return res;
88
94
  }
89
95
  del(name, options) {
@@ -147,12 +153,14 @@ class SimpleOSSClient {
147
153
  if (this.config.stsToken) {
148
154
  headers['x-oss-security-token'] = this.config.stsToken;
149
155
  }
150
- headers.authorization = this.getSign(method, `/${this.config.bucket}/${resource}`, headers);
156
+ let canonicalizedResource = this.createCanonicalizedResource(`/${this.config.bucket}/${resource}`, options.subres);
157
+ headers.authorization = this.getSign(method, canonicalizedResource, headers);
151
158
  let url = `https://${this.config.bucket}.${this.endpoint}/${resource}`;
159
+ let query = Object.assign({}, options.query, options.subres);
152
160
  return client.request(url, {
153
161
  method,
154
162
  headers,
155
- query: options.query,
163
+ query,
156
164
  body,
157
165
  timeout: options.timeout || this.config.timeout || 60000
158
166
  });
@@ -201,6 +209,17 @@ class SimpleOSSClient {
201
209
  query.Expires = expires;
202
210
  return `${url}?${qs.stringify(query)}`;
203
211
  }
212
+ createCanonicalizedResource(resource, subres) {
213
+ if (!subres)
214
+ return resource;
215
+ let string = Object.keys(subres)
216
+ .sort()
217
+ .map((key) => `${key}=${subres[key]}`)
218
+ .join('&');
219
+ if (string)
220
+ return `${resource}?${string}`;
221
+ return resource;
222
+ }
204
223
  getSign(method, canonicalizedResource, headers) {
205
224
  headers = headers || {};
206
225
  let parts = [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fsd-oss",
3
- "version": "0.13.1",
3
+ "version": "0.13.3",
4
4
  "description": "Aliyun OSS adapter for fsd",
5
5
  "main": "lib/index.js",
6
6
  "types": "index.d.ts",
@@ -15,12 +15,12 @@
15
15
  "@alicloud/pop-core": "^1.7.13",
16
16
  "akita": "^1.0.4",
17
17
  "async": "*",
18
- "crypto-js": "^4.1.1",
18
+ "crypto-js": "^4.2.0",
19
19
  "debug": "^4.3.4",
20
20
  "mime-types": "^2.1.35",
21
21
  "minimatch": "^3.1.2",
22
22
  "slash": "^3.0.0",
23
23
  "xml2js": "^0.6.2"
24
24
  },
25
- "gitHead": "12ff02bfc634ba84c771ca433d33aae2dc881436"
25
+ "gitHead": "035c0e59b51166498ce13f66fc1316099fe77566"
26
26
  }
@@ -64,6 +64,7 @@ export interface RequestOptions {
64
64
  meta?: UserMeta;
65
65
  headers?: Record<string, string>;
66
66
  query?: Record<string, string>;
67
+ subres?: Record<string, string>;
67
68
  }
68
69
 
69
70
  export interface Result {
@@ -104,6 +105,7 @@ export interface ListResult extends Result {
104
105
  KeyCount: number;
105
106
  NextContinuationToken?: string;
106
107
  Contents: ListResultContent[];
108
+ CommonPrefixes: ListResultCommonPrefixes[];
107
109
  }
108
110
 
109
111
  export interface ListResultContent {
@@ -118,6 +120,10 @@ export interface ListResultContent {
118
120
  };
119
121
  }
120
122
 
123
+ export interface ListResultCommonPrefixes {
124
+ Prefix: string;
125
+ }
126
+
121
127
  export interface DeleteMultiOptions extends RequestOptions {
122
128
  quiet?: boolean;
123
129
  }