fsd-oss 0.12.0 → 0.13.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/index.d.ts CHANGED
@@ -3,6 +3,9 @@ import { Adapter } from 'fsd';
3
3
  export interface OSSAdapterOptions {
4
4
  root?: string;
5
5
  urlPrefix?: string;
6
+ /**
7
+ * 是否公开读,默认为false
8
+ */
6
9
  publicRead?: boolean;
7
10
  // 以下为OSS驱动配置
8
11
  accessKeyId: string;
@@ -16,6 +19,13 @@ export interface OSSAdapterOptions {
16
19
  accountId?: string;
17
20
  roleName?: string;
18
21
  callbackUrl?: string; // 边缘上传回调地址
22
+ /**
23
+ * 缩略图配置
24
+ */
25
+ thumbs?: {
26
+ // name -> ?x-oss-process=style/stylename
27
+ [name: string]: string;
28
+ };
19
29
  }
20
30
 
21
31
  export interface UploadToken {
package/lib/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const Path = require("path");
4
+ const qs = require("qs");
4
5
  const slash = require("slash");
5
6
  const minimatch = require("minimatch");
6
7
  const Debugger = require("debug");
@@ -237,10 +238,25 @@ class OSSAdapter {
237
238
  }
238
239
  async createUrl(path, options) {
239
240
  debug('createUrl %s', path);
241
+ options = Object.assign({}, options);
240
242
  const { root, urlPrefix, publicRead } = this._options;
241
243
  let p = slash(Path.join(root, path));
244
+ let suffix = '';
245
+ if (options.thumb) {
246
+ if (options.thumb in this._options.thumbs) {
247
+ suffix = this._options.thumbs[options.thumb];
248
+ }
249
+ else {
250
+ throw new Error(`Unkown thumb name ${options.thumb}`);
251
+ }
252
+ }
242
253
  if (urlPrefix && publicRead) {
243
- return urlPrefix + p;
254
+ return urlPrefix + p + suffix;
255
+ }
256
+ if (suffix) {
257
+ if (suffix[0] === '?')
258
+ suffix = suffix.substring(1);
259
+ options.query = qs.parse(suffix);
244
260
  }
245
261
  let url = this._oss.signatureUrl(p.substring(1), options);
246
262
  if (urlPrefix) {
@@ -177,7 +177,7 @@ class SimpleOSSClient {
177
177
  let expires = parseInt((Date.now() / 1000 + (options.expires || 3600)));
178
178
  let response = options.response || {};
179
179
  let url = `https://${this.config.bucket}.${this.endpoint}/${name}`;
180
- let query = {};
180
+ let query = Object.assign({}, options.query);
181
181
  if (options.trafficLimit) {
182
182
  query['x-oss-traffic-limit'] = options.trafficLimit;
183
183
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fsd-oss",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "description": "Aliyun OSS adapter for fsd",
5
5
  "main": "lib/index.js",
6
6
  "types": "index.d.ts",
@@ -12,7 +12,7 @@
12
12
  "author": "Liang <liang@miaomo.cc> (https://github.com/liangxingchen)",
13
13
  "license": "MIT",
14
14
  "dependencies": {
15
- "@alicloud/pop-core": "^1.7.12",
15
+ "@alicloud/pop-core": "^1.7.13",
16
16
  "akita": "^1.0.4",
17
17
  "async": "*",
18
18
  "crypto-js": "^4.1.1",
@@ -22,5 +22,5 @@
22
22
  "slash": "^3.0.0",
23
23
  "xml2js": "^0.5.0"
24
24
  },
25
- "gitHead": "ad01afd0117496a9b857e566a404f0ececbd723d"
25
+ "gitHead": "1548128573c0fd22977706a6704029ec3ca3bab6"
26
26
  }
@@ -163,5 +163,13 @@ export interface SignatureUrlOptions {
163
163
  /**
164
164
  * 返回头信息
165
165
  */
166
- response?: Record<string, string>;
166
+ response?: {
167
+ [key: string]: string;
168
+ };
169
+ /**
170
+ * 其他查询参数
171
+ */
172
+ query?: {
173
+ [key: string]: string;
174
+ };
167
175
  }