@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.
Files changed (67) hide show
  1. package/dist/client/index.js +1 -1
  2. package/dist/client-v2/125.01d5562df948d974.js +10 -0
  3. package/dist/client-v2/229.bd72c2d7aa088310.js +10 -0
  4. package/dist/client-v2/336.1dd1b32466d0c778.js +10 -0
  5. package/dist/client-v2/43.eb45d53ba3e9828b.js +10 -0
  6. package/dist/client-v2/450.f590b4c220108742.js +10 -0
  7. package/dist/client-v2/929.d7e783304cc1f236.js +10 -0
  8. package/dist/client-v2/942.c10c97317af6dd02.js +10 -0
  9. package/dist/{client/StorageOptions.d.ts → client-v2/components/BaseUrlField.d.ts} +1 -1
  10. package/dist/client-v2/components/DefaultField.d.ts +18 -0
  11. package/dist/client-v2/{storageTypes/index.d.ts → components/FileSizeField.d.ts} +2 -2
  12. package/dist/client-v2/components/MimetypeField.d.ts +10 -0
  13. package/dist/client-v2/components/NameField.d.ts +10 -0
  14. package/dist/client-v2/components/ParanoidField.d.ts +10 -0
  15. package/dist/client-v2/components/PathField.d.ts +18 -0
  16. package/dist/client-v2/components/RenameModeField.d.ts +10 -0
  17. package/dist/client-v2/components/TitleField.d.ts +10 -0
  18. package/dist/client-v2/components/index.d.ts +17 -0
  19. package/dist/client-v2/index.d.ts +5 -0
  20. package/dist/client-v2/index.js +1 -1
  21. package/dist/client-v2/plugin.d.ts +47 -6
  22. package/dist/client-v2/storage-forms/AliOssStorageForm.d.ts +10 -0
  23. package/dist/client-v2/storage-forms/LocalStorageForm.d.ts +10 -0
  24. package/dist/client-v2/storage-forms/S3StorageForm.d.ts +10 -0
  25. package/dist/client-v2/storage-forms/TxCosStorageForm.d.ts +10 -0
  26. package/dist/externalVersion.js +10 -13
  27. package/dist/node_modules/@aws-sdk/client-s3/package.json +1 -1
  28. package/dist/node_modules/@aws-sdk/lib-storage/package.json +1 -1
  29. package/dist/node_modules/ali-oss/package.json +1 -1
  30. package/dist/node_modules/cos-nodejs-sdk-v5/.github/workflows/auto-changelog.yml +55 -0
  31. package/dist/node_modules/cos-nodejs-sdk-v5/.prettierrc +10 -0
  32. package/dist/node_modules/cos-nodejs-sdk-v5/.travis.yml +16 -0
  33. package/dist/node_modules/cos-nodejs-sdk-v5/LICENSE +21 -0
  34. package/dist/node_modules/cos-nodejs-sdk-v5/demo/crc64.js +9 -0
  35. package/dist/node_modules/cos-nodejs-sdk-v5/demo/demo-sts-scope.js +75 -0
  36. package/dist/node_modules/cos-nodejs-sdk-v5/demo/demo-sts.js +65 -0
  37. package/dist/node_modules/cos-nodejs-sdk-v5/demo/demo.js +4542 -0
  38. package/dist/node_modules/cos-nodejs-sdk-v5/demo/util.js +135 -0
  39. package/dist/node_modules/cos-nodejs-sdk-v5/index.d.ts +2610 -0
  40. package/dist/node_modules/{multer-cos → cos-nodejs-sdk-v5}/index.js +2 -2
  41. package/dist/node_modules/cos-nodejs-sdk-v5/package.json +1 -0
  42. package/dist/node_modules/cos-nodejs-sdk-v5/sdk/advance.js +1659 -0
  43. package/dist/node_modules/cos-nodejs-sdk-v5/sdk/async.js +59 -0
  44. package/dist/node_modules/cos-nodejs-sdk-v5/sdk/base.js +4404 -0
  45. package/dist/node_modules/cos-nodejs-sdk-v5/sdk/cos.js +137 -0
  46. package/dist/node_modules/cos-nodejs-sdk-v5/sdk/event.js +34 -0
  47. package/dist/node_modules/cos-nodejs-sdk-v5/sdk/select-stream.js +181 -0
  48. package/dist/node_modules/cos-nodejs-sdk-v5/sdk/session.js +126 -0
  49. package/dist/node_modules/cos-nodejs-sdk-v5/sdk/task.js +255 -0
  50. package/dist/node_modules/cos-nodejs-sdk-v5/sdk/util.js +776 -0
  51. package/dist/node_modules/cos-nodejs-sdk-v5/test/csp.js +1302 -0
  52. package/dist/node_modules/cos-nodejs-sdk-v5/test/test.js +6119 -0
  53. package/dist/node_modules/mime-match/package.json +1 -1
  54. package/dist/node_modules/mime-types/package.json +1 -1
  55. package/dist/node_modules/mkdirp/package.json +1 -1
  56. package/dist/node_modules/url-join/package.json +1 -1
  57. package/dist/server/storages/tx-cos.d.ts +16 -1
  58. package/dist/server/storages/tx-cos.js +111 -10
  59. package/dist/shared/previewer/filePreviewTypes.d.ts +1 -0
  60. package/dist/shared/previewer/filePreviewTypes.js +21 -0
  61. package/package.json +2 -3
  62. package/dist/client-v2/855.e7d2e24a0b457a89.js +0 -10
  63. package/dist/client-v2/storageTypes/types.d.ts +0 -26
  64. package/dist/node_modules/multer-cos/LICENSE +0 -24
  65. package/dist/node_modules/multer-cos/demo/index.js +0 -39
  66. package/dist/node_modules/multer-cos/demo/myMulter.js +0 -88
  67. package/dist/node_modules/multer-cos/package.json +0 -1
@@ -0,0 +1,255 @@
1
+ var session = require('./session');
2
+ var util = require('./util');
3
+
4
+ var originApiMap = {};
5
+ var transferToTaskMethod = function (apiMap, apiName) {
6
+ originApiMap[apiName] = apiMap[apiName];
7
+ apiMap[apiName] = function (params, callback) {
8
+ if (params.SkipTask) {
9
+ originApiMap[apiName].call(this, params, callback);
10
+ } else {
11
+ this._addTask(apiName, params, callback);
12
+ }
13
+ };
14
+ };
15
+
16
+ var initTask = function (cos) {
17
+ var queue = [];
18
+ var tasks = {};
19
+ var uploadingFileCount = 0;
20
+ var nextUploadIndex = 0;
21
+
22
+ // 接口返回简略的任务信息
23
+ var formatTask = function (task) {
24
+ var t = {
25
+ id: task.id,
26
+ Bucket: task.Bucket,
27
+ Region: task.Region,
28
+ Key: task.Key,
29
+ FilePath: task.FilePath,
30
+ state: task.state,
31
+ loaded: task.loaded,
32
+ size: task.size,
33
+ speed: task.speed,
34
+ percent: task.percent,
35
+ hashPercent: task.hashPercent,
36
+ error: task.error,
37
+ };
38
+ if (task.FilePath) t.FilePath = task.FilePath;
39
+ return t;
40
+ };
41
+
42
+ var emitListUpdate = (function () {
43
+ var timer;
44
+ var emit = function () {
45
+ timer = 0;
46
+ cos.emit('task-list-update', { list: util.map(queue, formatTask) });
47
+ cos.emit('list-update', { list: util.map(queue, formatTask) });
48
+ };
49
+ return function () {
50
+ if (!timer) timer = setTimeout(emit);
51
+ };
52
+ })();
53
+
54
+ var clearQueue = function () {
55
+ if (queue.length <= cos.options.UploadQueueSize) return;
56
+ for (
57
+ var i = 0;
58
+ i < nextUploadIndex && // 小于当前操作的 index 才清理
59
+ i < queue.length && // 大于队列才清理
60
+ queue.length > cos.options.UploadQueueSize; // 如果还太多,才继续清理
61
+
62
+ ) {
63
+ var isActive = queue[i].state === 'waiting' || queue[i].state === 'checking' || queue[i].state === 'uploading';
64
+ if (!queue[i] || !isActive) {
65
+ tasks[queue[i].id] && delete tasks[queue[i].id];
66
+ queue.splice(i, 1);
67
+ nextUploadIndex--;
68
+ } else {
69
+ i++;
70
+ }
71
+ }
72
+ emitListUpdate();
73
+ };
74
+
75
+ var startNextTask = function () {
76
+ // 检查是否允许增加执行进程
77
+ if (uploadingFileCount >= cos.options.FileParallelLimit) return;
78
+ // 跳过不可执行的任务
79
+ while (queue[nextUploadIndex] && queue[nextUploadIndex].state !== 'waiting') nextUploadIndex++;
80
+ // 检查是否已遍历结束
81
+ if (nextUploadIndex >= queue.length) return;
82
+ // 上传该遍历到的任务
83
+ var task = queue[nextUploadIndex];
84
+ nextUploadIndex++;
85
+ uploadingFileCount++;
86
+ task.state = 'checking';
87
+ task.params.onTaskStart && task.params.onTaskStart(formatTask(task));
88
+ !task.params.UploadData && (task.params.UploadData = {});
89
+ var apiParams = util.formatParams(task.api, task.params);
90
+ originApiMap[task.api].call(cos, apiParams, function (err, data) {
91
+ if (!cos._isRunningTask(task.id)) return;
92
+ if (task.state === 'checking' || task.state === 'uploading') {
93
+ task.state = err ? 'error' : 'success';
94
+ err && (task.error = err);
95
+ uploadingFileCount--;
96
+ emitListUpdate();
97
+ startNextTask();
98
+ task.callback && task.callback(err, data);
99
+ if (task.state === 'success') {
100
+ if (task.params) {
101
+ delete task.params.UploadData;
102
+ delete task.params.Body;
103
+ delete task.params;
104
+ }
105
+ delete task.callback;
106
+ }
107
+ }
108
+ clearQueue();
109
+ });
110
+ emitListUpdate();
111
+ // 异步执行下一个任务
112
+ setTimeout(startNextTask);
113
+ };
114
+
115
+ var killTask = function (id, switchToState) {
116
+ var task = tasks[id];
117
+ if (!task) return;
118
+ var waiting = task && task.state === 'waiting';
119
+ var running = task && (task.state === 'checking' || task.state === 'uploading');
120
+ if (
121
+ (switchToState === 'canceled' && task.state !== 'canceled') ||
122
+ (switchToState === 'paused' && waiting) ||
123
+ (switchToState === 'paused' && running)
124
+ ) {
125
+ if (switchToState === 'paused' && task.params.Body && typeof task.params.Body.pipe === 'function') {
126
+ console.error('stream not support pause');
127
+ return;
128
+ }
129
+ task.state = switchToState;
130
+ cos.emit('inner-kill-task', { TaskId: id, toState: switchToState });
131
+ try {
132
+ var UploadId = task && task.params && task.params.UploadData.UploadId;
133
+ } catch (e) {}
134
+ if (switchToState === 'canceled' && UploadId) session.removeUsing(UploadId);
135
+ emitListUpdate();
136
+ if (running) {
137
+ uploadingFileCount--;
138
+ startNextTask();
139
+ }
140
+ if (switchToState === 'canceled') {
141
+ if (task.params) {
142
+ delete task.params.UploadData;
143
+ delete task.params.Body;
144
+ delete task.params;
145
+ }
146
+ delete task.callback;
147
+ }
148
+ }
149
+ clearQueue();
150
+ };
151
+
152
+ cos._addTasks = function (taskList) {
153
+ util.each(taskList, function (task) {
154
+ cos._addTask(task.api, task.params, task.callback, true);
155
+ });
156
+ emitListUpdate();
157
+ };
158
+
159
+ var isTaskReadyWarning = true;
160
+ cos._addTask = function (api, params, callback, ignoreAddEvent) {
161
+ // 复制参数对象
162
+ params = util.formatParams(api, params);
163
+
164
+ // 生成 id
165
+ var id = util.uuid();
166
+ params.TaskId = id;
167
+ params.onTaskReady && params.onTaskReady(id);
168
+ if (params.TaskReady) {
169
+ params.TaskReady(id);
170
+ isTaskReadyWarning &&
171
+ console.warn('warning: Param "TaskReady" has been deprecated. Please use "onTaskReady" instead.');
172
+ isTaskReadyWarning = false;
173
+ }
174
+
175
+ var task = {
176
+ // env
177
+ params: params,
178
+ callback: callback,
179
+ api: api,
180
+ index: queue.length,
181
+ // task
182
+ id: id,
183
+ Bucket: params.Bucket,
184
+ Region: params.Region,
185
+ Key: params.Key,
186
+ FilePath: params.FilePath || '',
187
+ state: 'waiting',
188
+ loaded: 0,
189
+ size: 0,
190
+ speed: 0,
191
+ percent: 0,
192
+ hashPercent: 0,
193
+ error: null,
194
+ };
195
+ var onHashProgress = params.onHashProgress;
196
+ params.onHashProgress = function (info) {
197
+ if (!cos._isRunningTask(task.id)) return;
198
+ task.hashPercent = info.percent;
199
+ onHashProgress && onHashProgress(info);
200
+ emitListUpdate();
201
+ };
202
+ var onProgress = params.onProgress;
203
+ params.onProgress = function (info) {
204
+ if (!cos._isRunningTask(task.id)) return;
205
+ task.state === 'checking' && (task.state = 'uploading');
206
+ task.loaded = info.loaded;
207
+ task.speed = info.speed;
208
+ task.percent = info.percent;
209
+ onProgress && onProgress(info);
210
+ emitListUpdate();
211
+ };
212
+
213
+ // 异步获取 filesize
214
+ util.getFileSize(api, params, function (err, size) {
215
+ // 开始处理上传
216
+ if (err) return callback(util.error(err)); // 如果获取大小出错,不加入队列
217
+ // 获取完文件大小再把任务加入队列
218
+ tasks[id] = task;
219
+ queue.push(task);
220
+ task.size = size;
221
+ !ignoreAddEvent && emitListUpdate();
222
+ startNextTask();
223
+ clearQueue();
224
+ });
225
+ return id;
226
+ };
227
+ cos._isRunningTask = function (id) {
228
+ var task = tasks[id];
229
+ return !!(task && (task.state === 'checking' || task.state === 'uploading'));
230
+ };
231
+ cos.getTaskList = function () {
232
+ return util.map(queue, formatTask);
233
+ };
234
+ cos.cancelTask = function (id) {
235
+ killTask(id, 'canceled');
236
+ };
237
+ cos.pauseTask = function (id) {
238
+ killTask(id, 'paused');
239
+ };
240
+ cos.restartTask = function (id) {
241
+ var task = tasks[id];
242
+ if (task && (task.state === 'paused' || task.state === 'error')) {
243
+ task.state = 'waiting';
244
+ emitListUpdate();
245
+ nextUploadIndex = Math.min(nextUploadIndex, task.index);
246
+ startNextTask();
247
+ }
248
+ };
249
+ cos.isUploadRunning = function () {
250
+ return uploadingFileCount || nextUploadIndex < queue.length;
251
+ };
252
+ };
253
+
254
+ module.exports.transferToTaskMethod = transferToTaskMethod;
255
+ module.exports.init = initTask;