@nocobase/plugin-file-manager 2.1.0-beta.30 → 2.1.0-beta.33
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/dist/client/index.js +1 -1
- package/dist/client-v2/125.01d5562df948d974.js +10 -0
- package/dist/client-v2/229.bd72c2d7aa088310.js +10 -0
- package/dist/client-v2/336.1dd1b32466d0c778.js +10 -0
- package/dist/client-v2/43.eb45d53ba3e9828b.js +10 -0
- package/dist/client-v2/450.f590b4c220108742.js +10 -0
- package/dist/client-v2/929.d7e783304cc1f236.js +10 -0
- package/dist/client-v2/942.c10c97317af6dd02.js +10 -0
- package/dist/{client/StorageOptions.d.ts → client-v2/components/BaseUrlField.d.ts} +1 -1
- package/dist/client-v2/components/DefaultField.d.ts +18 -0
- package/dist/client-v2/{storageTypes/index.d.ts → components/FileSizeField.d.ts} +2 -2
- package/dist/client-v2/components/MimetypeField.d.ts +10 -0
- package/dist/client-v2/components/NameField.d.ts +10 -0
- package/dist/client-v2/components/ParanoidField.d.ts +10 -0
- package/dist/client-v2/components/PathField.d.ts +18 -0
- package/dist/client-v2/components/RenameModeField.d.ts +10 -0
- package/dist/client-v2/components/TitleField.d.ts +10 -0
- package/dist/client-v2/components/index.d.ts +17 -0
- package/dist/client-v2/index.d.ts +5 -0
- package/dist/client-v2/index.js +1 -1
- package/dist/client-v2/plugin.d.ts +47 -6
- package/dist/client-v2/storage-forms/AliOssStorageForm.d.ts +10 -0
- package/dist/client-v2/storage-forms/LocalStorageForm.d.ts +10 -0
- package/dist/client-v2/storage-forms/S3StorageForm.d.ts +10 -0
- package/dist/client-v2/storage-forms/TxCosStorageForm.d.ts +10 -0
- package/dist/externalVersion.js +10 -13
- package/dist/node_modules/@aws-sdk/client-s3/package.json +1 -1
- package/dist/node_modules/@aws-sdk/lib-storage/package.json +1 -1
- package/dist/node_modules/ali-oss/package.json +1 -1
- package/dist/node_modules/cos-nodejs-sdk-v5/.github/workflows/auto-changelog.yml +55 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/.prettierrc +10 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/.travis.yml +16 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/LICENSE +21 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/demo/crc64.js +9 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/demo/demo-sts-scope.js +75 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/demo/demo-sts.js +65 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/demo/demo.js +4542 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/demo/util.js +135 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/index.d.ts +2610 -0
- package/dist/node_modules/{multer-cos → cos-nodejs-sdk-v5}/index.js +2 -2
- package/dist/node_modules/cos-nodejs-sdk-v5/package.json +1 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/sdk/advance.js +1659 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/sdk/async.js +59 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/sdk/base.js +4404 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/sdk/cos.js +137 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/sdk/event.js +34 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/sdk/select-stream.js +181 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/sdk/session.js +126 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/sdk/task.js +255 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/sdk/util.js +776 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/test/csp.js +1302 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/test/test.js +6119 -0
- package/dist/node_modules/mime-match/package.json +1 -1
- package/dist/node_modules/mime-types/package.json +1 -1
- package/dist/node_modules/mkdirp/package.json +1 -1
- package/dist/node_modules/url-join/package.json +1 -1
- package/dist/server/storages/tx-cos.d.ts +16 -1
- package/dist/server/storages/tx-cos.js +111 -10
- package/dist/shared/previewer/filePreviewTypes.d.ts +1 -0
- package/dist/shared/previewer/filePreviewTypes.js +21 -0
- package/package.json +2 -3
- package/dist/client-v2/855.e7d2e24a0b457a89.js +0 -10
- package/dist/client-v2/storageTypes/types.d.ts +0 -26
- package/dist/node_modules/multer-cos/LICENSE +0 -24
- package/dist/node_modules/multer-cos/demo/index.js +0 -39
- package/dist/node_modules/multer-cos/demo/myMulter.js +0 -88
- package/dist/node_modules/multer-cos/package.json +0 -1
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var util = require('./util');
|
|
4
|
+
var event = require('./event');
|
|
5
|
+
var task = require('./task');
|
|
6
|
+
var base = require('./base');
|
|
7
|
+
var advance = require('./advance');
|
|
8
|
+
var pkg = require('../package.json');
|
|
9
|
+
|
|
10
|
+
var defaultOptions = {
|
|
11
|
+
AppId: '', // AppId 已废弃,请拼接到 Bucket 后传入,例如:test-1250000000
|
|
12
|
+
SecretId: '',
|
|
13
|
+
SecretKey: '',
|
|
14
|
+
SecurityToken: '', // 使用临时密钥需要注意自行刷新 Token
|
|
15
|
+
ChunkRetryTimes: 2,
|
|
16
|
+
FileParallelLimit: 3,
|
|
17
|
+
ChunkParallelLimit: 3,
|
|
18
|
+
ChunkSize: 1024 * 1024,
|
|
19
|
+
SliceSize: 1024 * 1024,
|
|
20
|
+
CopyChunkParallelLimit: 20,
|
|
21
|
+
CopyChunkSize: 1024 * 1024 * 10,
|
|
22
|
+
CopySliceSize: 1024 * 1024 * 10,
|
|
23
|
+
MaxPartNumber: 10000,
|
|
24
|
+
ProgressInterval: 1000,
|
|
25
|
+
Domain: '',
|
|
26
|
+
ServiceDomain: '',
|
|
27
|
+
Protocol: '',
|
|
28
|
+
CompatibilityMode: false,
|
|
29
|
+
ForcePathStyle: false,
|
|
30
|
+
UseRawKey: false,
|
|
31
|
+
Timeout: 0, // 单位毫秒,0 代表不设置超时时间
|
|
32
|
+
CorrectClockSkew: true,
|
|
33
|
+
SystemClockOffset: 0, // 单位毫秒,ms
|
|
34
|
+
UploadCheckContentMd5: false,
|
|
35
|
+
UploadQueueSize: 1000,
|
|
36
|
+
UploadIdCacheLimit: 500,
|
|
37
|
+
Proxy: '',
|
|
38
|
+
Tunnel: undefined,
|
|
39
|
+
Ip: '',
|
|
40
|
+
StrictSsl: true,
|
|
41
|
+
KeepAlive: true,
|
|
42
|
+
FollowRedirect: false,
|
|
43
|
+
UseAccelerate: false,
|
|
44
|
+
UserAgent: '',
|
|
45
|
+
ConfCwd: '',
|
|
46
|
+
ForceSignHost: true, // 默认将host加入签名计算,关闭后可能导致越权风险,建议保持为true
|
|
47
|
+
// 动态秘钥,优先级Credentials > SecretId/SecretKey。注意Cred内是小写的secretId、secretKey
|
|
48
|
+
Credentials: {
|
|
49
|
+
secretId: '',
|
|
50
|
+
secretKey: '',
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const watch = (obj, name, callback) => {
|
|
55
|
+
let value = obj[name];
|
|
56
|
+
Object.defineProperty(obj, name, {
|
|
57
|
+
get() {
|
|
58
|
+
return value;
|
|
59
|
+
},
|
|
60
|
+
set(newValue) {
|
|
61
|
+
value = newValue;
|
|
62
|
+
callback();
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// 对外暴露的类
|
|
68
|
+
var COS = function (options) {
|
|
69
|
+
this.options = util.extend(util.clone(defaultOptions), options || {});
|
|
70
|
+
this.options.FileParallelLimit = Math.max(1, this.options.FileParallelLimit);
|
|
71
|
+
this.options.ChunkParallelLimit = Math.max(1, this.options.ChunkParallelLimit);
|
|
72
|
+
this.options.ChunkRetryTimes = Math.max(0, this.options.ChunkRetryTimes);
|
|
73
|
+
this.options.ChunkSize = Math.max(1024 * 1024, this.options.ChunkSize);
|
|
74
|
+
this.options.CopyChunkParallelLimit = Math.max(1, this.options.CopyChunkParallelLimit);
|
|
75
|
+
this.options.CopyChunkSize = Math.max(1024 * 1024, this.options.CopyChunkSize);
|
|
76
|
+
this.options.CopySliceSize = Math.max(0, this.options.CopySliceSize);
|
|
77
|
+
this.options.MaxPartNumber = Math.max(1024, Math.min(10000, this.options.MaxPartNumber));
|
|
78
|
+
this.options.Timeout = Math.max(0, this.options.Timeout);
|
|
79
|
+
if (this.options.AppId) {
|
|
80
|
+
console.warn(
|
|
81
|
+
'warning: AppId has been deprecated, Please put it at the end of parameter Bucket(E.g: "test-1250000000").'
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
// 云API SDK 用小写密钥,这里兼容并 warning
|
|
85
|
+
if (this.options.secretId || this.options.secretKey) {
|
|
86
|
+
if (this.options.secretId && !this.options.SecretId) this.options.SecretId = this.options.secretId;
|
|
87
|
+
if (this.options.secretKey && !this.options.SecretKey) this.options.SecretKey = this.options.secretKey;
|
|
88
|
+
console.warn('warning: Please change options secretId/secretKey to SecretId/SecretKey.');
|
|
89
|
+
}
|
|
90
|
+
// 支持外部传入Cred动态秘钥
|
|
91
|
+
if (this.options.Credentials.secretId && this.options.Credentials.secretKey) {
|
|
92
|
+
this.options.SecretId = this.options.Credentials.secretId || '';
|
|
93
|
+
this.options.SecretKey = this.options.Credentials.secretKey || '';
|
|
94
|
+
}
|
|
95
|
+
if (this.options.SecretId && this.options.SecretId.indexOf(' ') > -1) {
|
|
96
|
+
console.error('error: SecretId格式错误,请检查');
|
|
97
|
+
console.error('error: SecretId format is incorrect. Please check');
|
|
98
|
+
}
|
|
99
|
+
if (this.options.SecretKey && this.options.SecretKey.indexOf(' ') > -1) {
|
|
100
|
+
console.error('error: SecretKey格式错误,请检查');
|
|
101
|
+
console.error('error: SecretKey format is incorrect. Please check');
|
|
102
|
+
}
|
|
103
|
+
if (util.isWeb()) {
|
|
104
|
+
console.warn(
|
|
105
|
+
'warning: cos-nodejs-sdk-v5 不支持浏览器使用,请改用 cos-js-sdk-v5,参考文档: https://cloud.tencent.com/document/product/436/11459'
|
|
106
|
+
);
|
|
107
|
+
console.warn(
|
|
108
|
+
'warning: cos-nodejs-sdk-v5 does not support browsers. Please use cos-js-sdk-v5 instead, See: https://cloud.tencent.com/document/product/436/11459'
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
event.init(this);
|
|
112
|
+
task.init(this);
|
|
113
|
+
|
|
114
|
+
// 支持动态秘钥,监听到cred里secretId、secretKey变化时,主动给cos替换秘钥
|
|
115
|
+
watch(this.options.Credentials, 'secretId', () => {
|
|
116
|
+
console.log('Credentials secretId changed');
|
|
117
|
+
this.options.SecretId = this.options.Credentials.secretId;
|
|
118
|
+
});
|
|
119
|
+
watch(this.options.Credentials, 'secretKey', () => {
|
|
120
|
+
console.log('Credentials secretKey changed');
|
|
121
|
+
this.options.SecretKey = this.options.Credentials.secretKey;
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
base.init(COS, task);
|
|
126
|
+
advance.init(COS, task);
|
|
127
|
+
|
|
128
|
+
COS.util = {
|
|
129
|
+
md5: util.md5,
|
|
130
|
+
xml2json: util.xml2json,
|
|
131
|
+
json2xml: util.json2xml,
|
|
132
|
+
encodeBase64: util.encodeBase64,
|
|
133
|
+
};
|
|
134
|
+
COS.getAuthorization = util.getAuth;
|
|
135
|
+
COS.version = pkg.version;
|
|
136
|
+
|
|
137
|
+
module.exports = COS;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
var initEvent = function (cos) {
|
|
2
|
+
var listeners = {};
|
|
3
|
+
var getList = function (action) {
|
|
4
|
+
!listeners[action] && (listeners[action] = []);
|
|
5
|
+
return listeners[action];
|
|
6
|
+
};
|
|
7
|
+
cos.on = function (action, callback) {
|
|
8
|
+
if (action === 'task-list-update') {
|
|
9
|
+
console.warn('warning: Event "' + action + '" has been deprecated. Please use "list-update" instead.');
|
|
10
|
+
}
|
|
11
|
+
getList(action).push(callback);
|
|
12
|
+
};
|
|
13
|
+
cos.off = function (action, callback) {
|
|
14
|
+
var list = getList(action);
|
|
15
|
+
for (var i = list.length - 1; i >= 0; i--) {
|
|
16
|
+
callback === list[i] && list.splice(i, 1);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
cos.emit = function (action, data) {
|
|
20
|
+
var list = getList(action).map(function (cb) {
|
|
21
|
+
return cb;
|
|
22
|
+
});
|
|
23
|
+
for (var i = 0; i < list.length; i++) {
|
|
24
|
+
list[i](data);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
var EventProxy = function () {
|
|
30
|
+
initEvent(this);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
module.exports.init = initEvent;
|
|
34
|
+
module.exports.EventProxy = EventProxy;
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
var { Transform } = require('stream');
|
|
2
|
+
var sysUtil = require('util');
|
|
3
|
+
var util = require('./util');
|
|
4
|
+
|
|
5
|
+
function SelectStream(options) {
|
|
6
|
+
if (!(this instanceof SelectStream)) return new SelectStream(options);
|
|
7
|
+
Transform.call(this, options);
|
|
8
|
+
Object.assign(this, {
|
|
9
|
+
totalLength: 0, // current message block's total length
|
|
10
|
+
headerLength: 0, // current message block's header length
|
|
11
|
+
payloadRestLength: 0, // current message block's rest payload length
|
|
12
|
+
header: null, // current message block's header
|
|
13
|
+
chunk: Buffer.alloc(0), // the data chunk being parsed
|
|
14
|
+
callback: null, // current _transform function's callback
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
SelectStream.prototype = {
|
|
18
|
+
/**
|
|
19
|
+
* process data chunk
|
|
20
|
+
* concat the last chunk and current chunk
|
|
21
|
+
* try to parse current message block's totalLength and headerLength
|
|
22
|
+
* try to parse current message block's header
|
|
23
|
+
* try to parse current message block's payload
|
|
24
|
+
*/
|
|
25
|
+
processChunk(chunk, encoding, callback) {
|
|
26
|
+
Object.assign(this, {
|
|
27
|
+
chunk: Buffer.concat([this.chunk, chunk], this.chunk.length + chunk.length),
|
|
28
|
+
encoding,
|
|
29
|
+
callback,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
this.parseLength();
|
|
33
|
+
this.parseHeader();
|
|
34
|
+
this.parsePayload();
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* try to parse current message block's totalLength and headerLength
|
|
39
|
+
*/
|
|
40
|
+
parseLength() {
|
|
41
|
+
if (!this.callback) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (this.totalLength && this.headerLength) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (this.chunk.length >= 12) {
|
|
50
|
+
this.totalLength = this.chunk.readInt32BE(0);
|
|
51
|
+
this.headerLength = this.chunk.readInt32BE(4);
|
|
52
|
+
this.payloadRestLength = this.totalLength - this.headerLength - 16;
|
|
53
|
+
this.chunk = this.chunk.slice(12);
|
|
54
|
+
} else {
|
|
55
|
+
this.callback();
|
|
56
|
+
this.callback = null;
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* try to parse current message block's header
|
|
62
|
+
* if header[':message-type'] is error, callback the error, emit error to next stream
|
|
63
|
+
*/
|
|
64
|
+
parseHeader() {
|
|
65
|
+
if (!this.callback) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (!this.headerLength || this.header) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (this.chunk.length >= this.headerLength) {
|
|
74
|
+
var header = {};
|
|
75
|
+
var offset = 0;
|
|
76
|
+
while (offset < this.headerLength) {
|
|
77
|
+
var headerNameLength = this.chunk[offset] * 1;
|
|
78
|
+
var headerName = this.chunk.toString('ascii', offset + 1, offset + 1 + headerNameLength);
|
|
79
|
+
var headerValueLength = this.chunk.readInt16BE(offset + headerNameLength + 2);
|
|
80
|
+
var headerValue = this.chunk.toString(
|
|
81
|
+
'ascii',
|
|
82
|
+
offset + headerNameLength + 4,
|
|
83
|
+
offset + headerNameLength + 4 + headerValueLength
|
|
84
|
+
);
|
|
85
|
+
header[headerName] = headerValue;
|
|
86
|
+
offset += headerNameLength + 4 + headerValueLength;
|
|
87
|
+
}
|
|
88
|
+
this.header = header;
|
|
89
|
+
this.chunk = this.chunk.slice(this.headerLength);
|
|
90
|
+
this.checkErrorHeader();
|
|
91
|
+
} else {
|
|
92
|
+
this.callback();
|
|
93
|
+
this.callback = null;
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* try to parse current message block's payload
|
|
99
|
+
*/
|
|
100
|
+
parsePayload() {
|
|
101
|
+
var self = this;
|
|
102
|
+
if (!this.callback) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (this.chunk.length <= this.payloadRestLength) {
|
|
107
|
+
this.payloadRestLength -= this.chunk.length;
|
|
108
|
+
this.pushData(this.chunk);
|
|
109
|
+
this.chunk = Buffer.alloc(0);
|
|
110
|
+
} else if (this.chunk.length < this.payloadRestLength + 4) {
|
|
111
|
+
this.pushData(this.chunk.slice(0, this.payloadRestLength));
|
|
112
|
+
this.chunk = this.chunk.slice(this.payloadRestLength);
|
|
113
|
+
this.payloadRestLength = 0;
|
|
114
|
+
} else {
|
|
115
|
+
this.pushData(this.chunk.slice(0, this.payloadRestLength));
|
|
116
|
+
this.chunk = this.chunk.slice(this.payloadRestLength + 4);
|
|
117
|
+
this.totalLength = 0;
|
|
118
|
+
this.headerLength = 0;
|
|
119
|
+
this.payloadRestLength = 0;
|
|
120
|
+
this.header = null;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (this.chunk.length && !(this.payloadRestLength === 0 && this.chunk.length < 4)) {
|
|
124
|
+
process.nextTick(function () {
|
|
125
|
+
self.processChunk(Buffer.alloc(0), self.encoding, self.callback);
|
|
126
|
+
});
|
|
127
|
+
} else {
|
|
128
|
+
this.callback();
|
|
129
|
+
this.callback = null;
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* if header[':event-type'] is Records, pipe payload to next stream
|
|
135
|
+
*/
|
|
136
|
+
pushData(content) {
|
|
137
|
+
if (this.header[':event-type'] === 'Records') {
|
|
138
|
+
this.push(content);
|
|
139
|
+
this.emit('message:records', content);
|
|
140
|
+
} else if (this.header[':event-type'] === 'Progress') {
|
|
141
|
+
var progress = util.xml2json(content.toString()).Progress;
|
|
142
|
+
this.emit('message:progress', progress);
|
|
143
|
+
} else if (this.header[':event-type'] === 'Stats') {
|
|
144
|
+
var stats = util.xml2json(content.toString()).Stats;
|
|
145
|
+
this.emit('message:stats', stats);
|
|
146
|
+
} else if (this.header[':event-type'] === 'error') {
|
|
147
|
+
var errCode = this.header[':error-code'];
|
|
148
|
+
var errMessage = this.header[':error-message'];
|
|
149
|
+
var err = new Error(errMessage);
|
|
150
|
+
err.message = errMessage;
|
|
151
|
+
err.name = err.code = errCode;
|
|
152
|
+
this.emit('message:error', err);
|
|
153
|
+
} else {
|
|
154
|
+
// 'Continuation', 'End'
|
|
155
|
+
this.emit('message:' + this.header[':event-type'].toLowerCase());
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* if header[':message-type'] is error, callback the error, emit error to next stream
|
|
161
|
+
*/
|
|
162
|
+
checkErrorHeader() {
|
|
163
|
+
if (this.header[':message-type'] === 'error') {
|
|
164
|
+
this.callback(this.header);
|
|
165
|
+
this.callback = null;
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Transform Stream's implementations
|
|
171
|
+
*/
|
|
172
|
+
_transform(chunk, encoding, callback) {
|
|
173
|
+
this.processChunk(chunk, encoding, callback);
|
|
174
|
+
},
|
|
175
|
+
_flush(callback) {
|
|
176
|
+
this.processChunk(Buffer.alloc(0), this.encoding, callback);
|
|
177
|
+
},
|
|
178
|
+
};
|
|
179
|
+
sysUtil.inherits(SelectStream, Transform);
|
|
180
|
+
|
|
181
|
+
module.exports = SelectStream;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
var util = require('./util');
|
|
2
|
+
// 按照文件特征值,缓存 UploadId
|
|
3
|
+
var cacheKey = 'cos_sdk_upload_cache';
|
|
4
|
+
var expires = 30 * 24 * 3600;
|
|
5
|
+
var store;
|
|
6
|
+
var cache;
|
|
7
|
+
var timer;
|
|
8
|
+
|
|
9
|
+
var getCache = function () {
|
|
10
|
+
var val,
|
|
11
|
+
opt = { configName: 'cos-nodejs-sdk-v5-storage' };
|
|
12
|
+
if (this.options.ConfCwd) opt.cwd = this.options.ConfCwd;
|
|
13
|
+
try {
|
|
14
|
+
var Conf = require('conf');
|
|
15
|
+
store = new Conf(opt);
|
|
16
|
+
val = store.get(cacheKey);
|
|
17
|
+
} catch (e) {}
|
|
18
|
+
if (!val || !(val instanceof Array)) val = [];
|
|
19
|
+
cache = val;
|
|
20
|
+
};
|
|
21
|
+
var setCache = function () {
|
|
22
|
+
try {
|
|
23
|
+
if (cache.length) store.set(cacheKey, cache);
|
|
24
|
+
else store.delete(cacheKey);
|
|
25
|
+
} catch (e) {}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
var init = function () {
|
|
29
|
+
if (cache) return;
|
|
30
|
+
getCache.call(this);
|
|
31
|
+
// 清理太老旧的数据
|
|
32
|
+
var changed = false;
|
|
33
|
+
var now = Math.round(Date.now() / 1000);
|
|
34
|
+
for (var i = cache.length - 1; i >= 0; i--) {
|
|
35
|
+
var mtime = cache[i][2];
|
|
36
|
+
if (!mtime || mtime + expires < now) {
|
|
37
|
+
cache.splice(i, 1);
|
|
38
|
+
changed = true;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
changed && setCache();
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// 把缓存存到本地
|
|
45
|
+
var save = function () {
|
|
46
|
+
if (timer) return;
|
|
47
|
+
timer = setTimeout(function () {
|
|
48
|
+
setCache();
|
|
49
|
+
timer = null;
|
|
50
|
+
}, 400);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
var mod = {
|
|
54
|
+
using: {},
|
|
55
|
+
// 标记 UploadId 正在使用
|
|
56
|
+
setUsing: function (uuid) {
|
|
57
|
+
mod.using[uuid] = true;
|
|
58
|
+
},
|
|
59
|
+
// 标记 UploadId 已经没在使用
|
|
60
|
+
removeUsing: function (uuid) {
|
|
61
|
+
delete mod.using[uuid];
|
|
62
|
+
},
|
|
63
|
+
// 用上传参数生成哈希值
|
|
64
|
+
getFileId: function (FileStat, ChunkSize, Bucket, Key) {
|
|
65
|
+
if (FileStat && FileStat.FilePath && FileStat.size && FileStat.ctime && FileStat.mtime && ChunkSize) {
|
|
66
|
+
return (
|
|
67
|
+
util.md5([FileStat.FilePath].join('::')) +
|
|
68
|
+
'-' +
|
|
69
|
+
util.md5([FileStat.size, FileStat.ctime, FileStat.mtime, ChunkSize, Bucket, Key].join('::'))
|
|
70
|
+
);
|
|
71
|
+
} else {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
// 用上传参数生成哈希值
|
|
76
|
+
getCopyFileId: function (copySource, sourceHeaders, ChunkSize, Bucket, Key) {
|
|
77
|
+
var size = sourceHeaders['content-length'];
|
|
78
|
+
var etag = sourceHeaders.etag || '';
|
|
79
|
+
var lastModified = sourceHeaders['last-modified'];
|
|
80
|
+
if (copySource && ChunkSize) {
|
|
81
|
+
return util.md5([copySource, size, etag, lastModified, ChunkSize, Bucket, Key].join('::'));
|
|
82
|
+
} else {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
// 获取文件对应的 UploadId 列表
|
|
87
|
+
getUploadIdList: function (uuid) {
|
|
88
|
+
if (!uuid) return null;
|
|
89
|
+
init.call(this);
|
|
90
|
+
var list = [];
|
|
91
|
+
for (var i = 0; i < cache.length; i++) {
|
|
92
|
+
if (cache[i][0] === uuid) list.push(cache[i][1]);
|
|
93
|
+
}
|
|
94
|
+
return list.length ? list : null;
|
|
95
|
+
},
|
|
96
|
+
// 缓存 UploadId
|
|
97
|
+
saveUploadId: function (uuid, UploadId, limit) {
|
|
98
|
+
init.call(this);
|
|
99
|
+
if (!uuid) return;
|
|
100
|
+
// 清理没用的 UploadId
|
|
101
|
+
var part1 = uuid.substr(0, uuid.indexOf('-') + 1);
|
|
102
|
+
for (var i = cache.length - 1; i >= 0; i--) {
|
|
103
|
+
var item = cache[i];
|
|
104
|
+
if (item[0] === uuid && item[1] === UploadId) {
|
|
105
|
+
cache.splice(i, 1);
|
|
106
|
+
} else if (uuid !== item[0] && item[0].indexOf(part1) === 0) {
|
|
107
|
+
// 文件路径相同,但其他信息不同,说明文件改变了或上传参数(存储桶、路径、分片大小)变了,直接清理掉
|
|
108
|
+
cache.splice(i, 1);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
cache.unshift([uuid, UploadId, Math.round(Date.now() / 1000)]);
|
|
112
|
+
if (cache.length > limit) cache.splice(limit);
|
|
113
|
+
save();
|
|
114
|
+
},
|
|
115
|
+
// UploadId 已用完,移除掉
|
|
116
|
+
removeUploadId: function (UploadId) {
|
|
117
|
+
init.call(this);
|
|
118
|
+
delete mod.using[UploadId];
|
|
119
|
+
for (var i = cache.length - 1; i >= 0; i--) {
|
|
120
|
+
if (cache[i][1] === UploadId) cache.splice(i, 1);
|
|
121
|
+
}
|
|
122
|
+
save();
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
module.exports = mod;
|