fsd-oss 0.13.0 → 0.13.2

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2018 郑州脉冲软件科技有限公司
3
+ Copyright (c) 2023 郑州渺漠信息科技有限公司
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -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);
@@ -147,12 +149,14 @@ class SimpleOSSClient {
147
149
  if (this.config.stsToken) {
148
150
  headers['x-oss-security-token'] = this.config.stsToken;
149
151
  }
150
- headers.authorization = this.getSign(method, `/${this.config.bucket}/${resource}`, headers);
152
+ let canonicalizedResource = this.createCanonicalizedResource(`/${this.config.bucket}/${resource}`, options.subres);
153
+ headers.authorization = this.getSign(method, canonicalizedResource, headers);
151
154
  let url = `https://${this.config.bucket}.${this.endpoint}/${resource}`;
155
+ let query = Object.assign({}, options.query, options.subres);
152
156
  return client.request(url, {
153
157
  method,
154
158
  headers,
155
- query: options.query,
159
+ query,
156
160
  body,
157
161
  timeout: options.timeout || this.config.timeout || 60000
158
162
  });
@@ -165,7 +169,11 @@ class SimpleOSSClient {
165
169
  headers: response.headers
166
170
  };
167
171
  }
168
- let data = await xml2data(xml);
172
+ let data = await xml2js.parseStringPromise(xml, {
173
+ trim: true,
174
+ explicitArray: false,
175
+ explicitRoot: false
176
+ });
169
177
  if (data.Code) {
170
178
  throw new Error(data.Message);
171
179
  }
@@ -197,6 +205,17 @@ class SimpleOSSClient {
197
205
  query.Expires = expires;
198
206
  return `${url}?${qs.stringify(query)}`;
199
207
  }
208
+ createCanonicalizedResource(resource, subres) {
209
+ if (!subres)
210
+ return resource;
211
+ let string = Object.keys(subres)
212
+ .sort()
213
+ .map((key) => `${key}=${subres[key]}`)
214
+ .join('&');
215
+ if (string)
216
+ return `${resource}?${string}`;
217
+ return resource;
218
+ }
200
219
  getSign(method, canonicalizedResource, headers) {
201
220
  headers = headers || {};
202
221
  let parts = [
@@ -217,14 +236,3 @@ class SimpleOSSClient {
217
236
  }
218
237
  }
219
238
  exports.default = SimpleOSSClient;
220
- function xml2data(xml) {
221
- return new Promise((resolve, reject) => {
222
- const opt = { trim: true, explicitArray: false, explicitRoot: false };
223
- xml2js.parseString(xml, opt, (error, result) => {
224
- if (error) {
225
- return reject(new Error('XMLDataError'));
226
- }
227
- resolve(result);
228
- });
229
- });
230
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fsd-oss",
3
- "version": "0.13.0",
3
+ "version": "0.13.2",
4
4
  "description": "Aliyun OSS adapter for fsd",
5
5
  "main": "lib/index.js",
6
6
  "types": "index.d.ts",
@@ -20,7 +20,7 @@
20
20
  "mime-types": "^2.1.35",
21
21
  "minimatch": "^3.1.2",
22
22
  "slash": "^3.0.0",
23
- "xml2js": "^0.5.0"
23
+ "xml2js": "^0.6.2"
24
24
  },
25
- "gitHead": "1548128573c0fd22977706a6704029ec3ca3bab6"
25
+ "gitHead": "f5aaaca713f514d3a8fb65bc2eecd1e8df8fd5c8"
26
26
  }
@@ -1,4 +1,4 @@
1
- import { Request } from 'akita';
1
+ import type { Request } from 'akita';
2
2
 
3
3
  export default class SimpleOSSClient {
4
4
  config: SimpleOSSClientConfig;
@@ -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 {