fsd-oss 0.12.0 → 0.13.1
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 +1 -1
- package/index.d.ts +10 -0
- package/lib/index.js +17 -1
- package/lib/simple-oss-client.js +6 -13
- package/package.json +4 -4
- package/simple-oss-client.d.ts +10 -2
package/LICENSE
CHANGED
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) {
|
package/lib/simple-oss-client.js
CHANGED
|
@@ -165,7 +165,11 @@ class SimpleOSSClient {
|
|
|
165
165
|
headers: response.headers
|
|
166
166
|
};
|
|
167
167
|
}
|
|
168
|
-
let data = await
|
|
168
|
+
let data = await xml2js.parseStringPromise(xml, {
|
|
169
|
+
trim: true,
|
|
170
|
+
explicitArray: false,
|
|
171
|
+
explicitRoot: false
|
|
172
|
+
});
|
|
169
173
|
if (data.Code) {
|
|
170
174
|
throw new Error(data.Message);
|
|
171
175
|
}
|
|
@@ -177,7 +181,7 @@ class SimpleOSSClient {
|
|
|
177
181
|
let expires = parseInt((Date.now() / 1000 + (options.expires || 3600)));
|
|
178
182
|
let response = options.response || {};
|
|
179
183
|
let url = `https://${this.config.bucket}.${this.endpoint}/${name}`;
|
|
180
|
-
let query = {};
|
|
184
|
+
let query = Object.assign({}, options.query);
|
|
181
185
|
if (options.trafficLimit) {
|
|
182
186
|
query['x-oss-traffic-limit'] = options.trafficLimit;
|
|
183
187
|
}
|
|
@@ -217,14 +221,3 @@ class SimpleOSSClient {
|
|
|
217
221
|
}
|
|
218
222
|
}
|
|
219
223
|
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.
|
|
3
|
+
"version": "0.13.1",
|
|
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.
|
|
15
|
+
"@alicloud/pop-core": "^1.7.13",
|
|
16
16
|
"akita": "^1.0.4",
|
|
17
17
|
"async": "*",
|
|
18
18
|
"crypto-js": "^4.1.1",
|
|
@@ -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.
|
|
23
|
+
"xml2js": "^0.6.2"
|
|
24
24
|
},
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "12ff02bfc634ba84c771ca433d33aae2dc881436"
|
|
26
26
|
}
|
package/simple-oss-client.d.ts
CHANGED
|
@@ -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;
|
|
@@ -163,5 +163,13 @@ export interface SignatureUrlOptions {
|
|
|
163
163
|
/**
|
|
164
164
|
* 返回头信息
|
|
165
165
|
*/
|
|
166
|
-
response?:
|
|
166
|
+
response?: {
|
|
167
|
+
[key: string]: string;
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* 其他查询参数
|
|
171
|
+
*/
|
|
172
|
+
query?: {
|
|
173
|
+
[key: string]: string;
|
|
174
|
+
};
|
|
167
175
|
}
|