@nocobase/plugin-file-manager 0.7.0-alpha.9 → 0.7.1-alpha.6

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 (68) hide show
  1. package/lib/actions/upload.js +237 -161
  2. package/lib/collections/attachments.js +55 -59
  3. package/lib/collections/storages.js +54 -60
  4. package/lib/constants.js +17 -9
  5. package/lib/index.js +29 -19
  6. package/lib/rules/index.js +14 -9
  7. package/lib/rules/mimetype.js +20 -9
  8. package/lib/server.js +91 -48
  9. package/lib/storages/ali-oss.js +36 -26
  10. package/lib/storages/index.js +22 -16
  11. package/lib/storages/local.d.ts +3 -0
  12. package/lib/storages/local.js +240 -119
  13. package/lib/storages/s3.js +77 -52
  14. package/lib/utils.js +43 -20
  15. package/package.json +6 -10
  16. package/esm/actions/upload.d.ts +0 -3
  17. package/esm/actions/upload.js +0 -143
  18. package/esm/actions/upload.js.map +0 -1
  19. package/esm/collections/attachments.d.ts +0 -3
  20. package/esm/collections/attachments.js +0 -59
  21. package/esm/collections/attachments.js.map +0 -1
  22. package/esm/collections/storages.d.ts +0 -3
  23. package/esm/collections/storages.js +0 -60
  24. package/esm/collections/storages.js.map +0 -1
  25. package/esm/constants.d.ts +0 -6
  26. package/esm/constants.js +0 -7
  27. package/esm/constants.js.map +0 -1
  28. package/esm/index.d.ts +0 -2
  29. package/esm/index.js +0 -3
  30. package/esm/index.js.map +0 -1
  31. package/esm/rules/index.d.ts +0 -1
  32. package/esm/rules/index.js +0 -3
  33. package/esm/rules/index.js.map +0 -1
  34. package/esm/rules/mimetype.d.ts +0 -1
  35. package/esm/rules/mimetype.js +0 -5
  36. package/esm/rules/mimetype.js.map +0 -1
  37. package/esm/server.d.ts +0 -7
  38. package/esm/server.js +0 -48
  39. package/esm/server.js.map +0 -1
  40. package/esm/storages/ali-oss.d.ts +0 -16
  41. package/esm/storages/ali-oss.js +0 -26
  42. package/esm/storages/ali-oss.js.map +0 -1
  43. package/esm/storages/index.d.ts +0 -8
  44. package/esm/storages/index.js +0 -12
  45. package/esm/storages/index.js.map +0 -1
  46. package/esm/storages/local.d.ts +0 -14
  47. package/esm/storages/local.js +0 -127
  48. package/esm/storages/local.js.map +0 -1
  49. package/esm/storages/s3.d.ts +0 -17
  50. package/esm/storages/s3.js +0 -53
  51. package/esm/storages/s3.js.map +0 -1
  52. package/esm/utils.d.ts +0 -2
  53. package/esm/utils.js +0 -16
  54. package/esm/utils.js.map +0 -1
  55. package/lib/actions/upload.js.map +0 -1
  56. package/lib/collections/attachments.js.map +0 -1
  57. package/lib/collections/storages.js.map +0 -1
  58. package/lib/constants.js.map +0 -1
  59. package/lib/index.js.map +0 -1
  60. package/lib/rules/index.js.map +0 -1
  61. package/lib/rules/mimetype.js.map +0 -1
  62. package/lib/server.js.map +0 -1
  63. package/lib/storages/ali-oss.js.map +0 -1
  64. package/lib/storages/index.js.map +0 -1
  65. package/lib/storages/local.js.map +0 -1
  66. package/lib/storages/s3.js.map +0 -1
  67. package/lib/utils.js.map +0 -1
  68. package/tsconfig.build.json +0 -9
@@ -1,132 +1,253 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const koa_static_1 = __importDefault(require("koa-static"));
16
- const mkdirp_1 = __importDefault(require("mkdirp"));
17
- const multer_1 = __importDefault(require("multer"));
18
- const path_1 = __importDefault(require("path"));
19
- const url_1 = require("url");
20
- const constants_1 = require("../constants");
21
- const utils_1 = require("../utils");
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ function _koaStatic() {
9
+ const data = _interopRequireDefault(require("koa-static"));
10
+
11
+ _koaStatic = function _koaStatic() {
12
+ return data;
13
+ };
14
+
15
+ return data;
16
+ }
17
+
18
+ function _mkdirp() {
19
+ const data = _interopRequireDefault(require("mkdirp"));
20
+
21
+ _mkdirp = function _mkdirp() {
22
+ return data;
23
+ };
24
+
25
+ return data;
26
+ }
27
+
28
+ function _multer() {
29
+ const data = _interopRequireDefault(require("multer"));
30
+
31
+ _multer = function _multer() {
32
+ return data;
33
+ };
34
+
35
+ return data;
36
+ }
37
+
38
+ function _path() {
39
+ const data = _interopRequireDefault(require("path"));
40
+
41
+ _path = function _path() {
42
+ return data;
43
+ };
44
+
45
+ return data;
46
+ }
47
+
48
+ function _url() {
49
+ const data = require("url");
50
+
51
+ _url = function _url() {
52
+ return data;
53
+ };
54
+
55
+ return data;
56
+ }
57
+
58
+ var _constants = require("../constants");
59
+
60
+ var _utils = require("../utils");
61
+
62
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
63
+
64
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
65
+
66
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
67
+
68
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
69
+
70
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
71
+
72
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
73
+
22
74
  // use koa-mount match logic
23
75
  function match(basePath, pathname) {
24
- if (!pathname.startsWith(basePath)) {
25
- return false;
26
- }
27
- const newPath = pathname.replace(basePath, '') || '/';
28
- if (basePath.slice(-1) === '/') {
29
- return true;
30
- }
31
- return newPath[0] === '/';
76
+ if (!pathname.startsWith(basePath)) {
77
+ return false;
78
+ }
79
+
80
+ const newPath = pathname.replace(basePath, '') || '/';
81
+
82
+ if (basePath.slice(-1) === '/') {
83
+ return true;
84
+ }
85
+
86
+ return newPath[0] === '/';
32
87
  }
33
- function update(app, storages) {
34
- return __awaiter(this, void 0, void 0, function* () {
35
- const Storage = app.db.getCollection('storages');
36
- const items = yield Storage.repository.find({
37
- filter: {
38
- type: constants_1.STORAGE_TYPE_LOCAL,
39
- },
40
- });
41
- const primaryKey = Storage.model.primaryKeyAttribute;
42
- storages.clear();
43
- for (const storage of items) {
44
- storages.set(storage[primaryKey], storage);
45
- }
88
+
89
+ function update(_x, _x2) {
90
+ return _update.apply(this, arguments);
91
+ }
92
+
93
+ function _update() {
94
+ _update = _asyncToGenerator(function* (app, storages) {
95
+ const Storage = app.db.getCollection('storages');
96
+ const items = yield Storage.repository.find({
97
+ filter: {
98
+ type: _constants.STORAGE_TYPE_LOCAL
99
+ }
46
100
  });
101
+ const primaryKey = Storage.model.primaryKeyAttribute;
102
+ storages.clear();
103
+
104
+ var _iterator = _createForOfIteratorHelper(items),
105
+ _step;
106
+
107
+ try {
108
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
109
+ const storage = _step.value;
110
+ storages.set(storage[primaryKey], storage);
111
+ }
112
+ } catch (err) {
113
+ _iterator.e(err);
114
+ } finally {
115
+ _iterator.f();
116
+ }
117
+ });
118
+ return _update.apply(this, arguments);
47
119
  }
120
+
48
121
  function createLocalServerUpdateHook(app, storages) {
49
- return function (row) {
50
- return __awaiter(this, void 0, void 0, function* () {
51
- if (row.get('type') === constants_1.STORAGE_TYPE_LOCAL) {
52
- yield update(app, storages);
53
- }
54
- });
122
+ return /*#__PURE__*/function () {
123
+ var _ref = _asyncToGenerator(function* (row) {
124
+ if (row.get('type') === _constants.STORAGE_TYPE_LOCAL) {
125
+ yield update(app, storages);
126
+ }
127
+ });
128
+
129
+ return function (_x3) {
130
+ return _ref.apply(this, arguments);
55
131
  };
132
+ }();
56
133
  }
134
+
57
135
  function getDocumentRoot(storage) {
58
- const { documentRoot = 'uploads' } = storage.options || {};
59
- // TODO(feature): 后面考虑以字符串模板的方式使用,可注入 req/action 相关变量,以便于区分文件夹
60
- return path_1.default.resolve(path_1.default.isAbsolute(documentRoot) ? documentRoot : path_1.default.join(process.cwd(), documentRoot));
136
+ const _ref2 = storage.options || {},
137
+ _ref2$documentRoot = _ref2.documentRoot,
138
+ documentRoot = _ref2$documentRoot === void 0 ? 'uploads' : _ref2$documentRoot; // TODO(feature): 后面考虑以字符串模板的方式使用,可注入 req/action 相关变量,以便于区分文件夹
139
+
140
+
141
+ return _path().default.resolve(_path().default.isAbsolute(documentRoot) ? documentRoot : _path().default.join(process.cwd(), documentRoot));
61
142
  }
62
- function middleware(app, options) {
63
- return __awaiter(this, void 0, void 0, function* () {
64
- const LOCALHOST = `http://localhost:${process.env.SERVER_PORT || '13002'}`;
65
- const Storage = app.db.getCollection('storages');
66
- const storages = new Map();
67
- const localServerUpdateHook = createLocalServerUpdateHook(app, storages);
68
- Storage.model.addHook('afterCreate', localServerUpdateHook);
69
- Storage.model.addHook('afterUpdate', localServerUpdateHook);
70
- Storage.model.addHook('afterDestroy', localServerUpdateHook);
71
- app.on('beforeStart', () => __awaiter(this, void 0, void 0, function* () {
72
- yield update(app, storages);
73
- }));
74
- app.use(function (ctx, next) {
75
- var _a;
76
- return __awaiter(this, void 0, void 0, function* () {
77
- for (const storage of storages.values()) {
78
- const baseUrl = storage.get('baseUrl');
79
- let url;
80
- try {
81
- url = new url_1.URL(baseUrl);
82
- }
83
- catch (e) {
84
- url = {
85
- pathname: baseUrl,
86
- };
87
- }
88
- // 以下情况才认为当前进程所应该提供静态服务
89
- // 否则都忽略,交给其他 server 来提供(如 nginx/cdn 等)
90
- if (url.origin && ((_a = storage === null || storage === void 0 ? void 0 : storage.options) === null || _a === void 0 ? void 0 : _a.serve) === false) {
91
- continue;
92
- }
93
- const basePath = url.pathname.startsWith('/') ? url.pathname : `/${url.pathname}`;
94
- if (!match(basePath, ctx.path)) {
95
- continue;
96
- }
97
- return (0, koa_static_1.default)(getDocumentRoot(storage), {
98
- // for handle files after any api handlers
99
- defer: true,
100
- })(ctx, () => __awaiter(this, void 0, void 0, function* () {
101
- if (ctx.path.startsWith(basePath)) {
102
- ctx.path = ctx.path.replace(basePath, '');
103
- }
104
- yield next();
105
- }));
106
- }
107
- yield next();
108
- });
109
- });
110
- });
143
+
144
+ function middleware(_x4, _x5) {
145
+ return _middleware.apply(this, arguments);
111
146
  }
112
- exports.default = {
113
- middleware,
114
- make(storage) {
115
- return multer_1.default.diskStorage({
116
- destination: function (req, file, cb) {
117
- const destPath = path_1.default.join(getDocumentRoot(storage), storage.path);
118
- (0, mkdirp_1.default)(destPath, (err) => cb(err, destPath));
119
- },
120
- filename: utils_1.getFilename,
121
- });
122
- },
123
- defaults() {
124
- return {
125
- title: '本地存储',
126
- type: constants_1.STORAGE_TYPE_LOCAL,
127
- name: `local`,
128
- baseUrl: process.env.LOCAL_STORAGE_BASE_URL || `http://localhost:${process.env.SERVER_PORT || '13002'}/uploads`,
129
- };
130
- },
147
+
148
+ function _middleware() {
149
+ _middleware = _asyncToGenerator(function* (app, options) {
150
+ const LOCALHOST = `http://localhost:${process.env.APP_PORT || '13000'}`;
151
+ const Storage = app.db.getCollection('storages');
152
+ const storages = new Map();
153
+ const localServerUpdateHook = createLocalServerUpdateHook(app, storages);
154
+ Storage.model.addHook('afterCreate', localServerUpdateHook);
155
+ Storage.model.addHook('afterUpdate', localServerUpdateHook);
156
+ Storage.model.addHook('afterDestroy', localServerUpdateHook);
157
+ app.on('beforeStart', /*#__PURE__*/_asyncToGenerator(function* () {
158
+ yield update(app, storages);
159
+ }));
160
+ app.use( /*#__PURE__*/function () {
161
+ var _ref4 = _asyncToGenerator(function* (ctx, next) {
162
+ var _iterator2 = _createForOfIteratorHelper(storages.values()),
163
+ _step2;
164
+
165
+ try {
166
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
167
+ var _storage$options;
168
+
169
+ const storage = _step2.value;
170
+ const baseUrl = storage.get('baseUrl');
171
+ let url;
172
+
173
+ try {
174
+ url = new (_url().URL)(baseUrl);
175
+ } catch (e) {
176
+ url = {
177
+ pathname: baseUrl
178
+ };
179
+ } // 以下情况才认为当前进程所应该提供静态服务
180
+ // 否则都忽略,交给其他 server 来提供(如 nginx/cdn 等)
181
+
182
+
183
+ if (url.origin && (storage === null || storage === void 0 ? void 0 : (_storage$options = storage.options) === null || _storage$options === void 0 ? void 0 : _storage$options.serve) === false) {
184
+ continue;
185
+ }
186
+
187
+ const basePath = url.pathname.startsWith('/') ? url.pathname : `/${url.pathname}`;
188
+
189
+ if (!match(basePath, ctx.path)) {
190
+ continue;
191
+ }
192
+
193
+ return (0, _koaStatic().default)(getDocumentRoot(storage), {
194
+ // for handle files after any api handlers
195
+ defer: true
196
+ })(ctx, /*#__PURE__*/_asyncToGenerator(function* () {
197
+ if (ctx.path.startsWith(basePath)) {
198
+ ctx.path = ctx.path.replace(basePath, '');
199
+ }
200
+
201
+ yield next();
202
+ }));
203
+ }
204
+ } catch (err) {
205
+ _iterator2.e(err);
206
+ } finally {
207
+ _iterator2.f();
208
+ }
209
+
210
+ yield next();
211
+ });
212
+
213
+ return function (_x6, _x7) {
214
+ return _ref4.apply(this, arguments);
215
+ };
216
+ }());
217
+ });
218
+ return _middleware.apply(this, arguments);
219
+ }
220
+
221
+ var _default = {
222
+ middleware,
223
+
224
+ make(storage) {
225
+ return _multer().default.diskStorage({
226
+ destination: function destination(req, file, cb) {
227
+ const destPath = _path().default.join(getDocumentRoot(storage), storage.path);
228
+
229
+ (0, _mkdirp().default)(destPath, err => cb(err, destPath));
230
+ },
231
+ filename: _utils.getFilename
232
+ });
233
+ },
234
+
235
+ defaults() {
236
+ const _process$env = process.env,
237
+ LOCAL_STORAGE_DEST = _process$env.LOCAL_STORAGE_DEST,
238
+ LOCAL_STORAGE_BASE_URL = _process$env.LOCAL_STORAGE_BASE_URL,
239
+ APP_PORT = _process$env.APP_PORT;
240
+ const documentRoot = LOCAL_STORAGE_DEST || 'uploads';
241
+ return {
242
+ title: '本地存储',
243
+ type: _constants.STORAGE_TYPE_LOCAL,
244
+ name: `local`,
245
+ baseUrl: LOCAL_STORAGE_BASE_URL || `http://localhost:${APP_PORT || '13000'}/${documentRoot}`,
246
+ options: {
247
+ documentRoot
248
+ }
249
+ };
250
+ }
251
+
131
252
  };
132
- //# sourceMappingURL=local.js.map
253
+ exports.default = _default;
@@ -1,55 +1,80 @@
1
1
  "use strict";
2
- var __rest = (this && this.__rest) || function (s, e) {
3
- var t = {};
4
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
- t[p] = s[p];
6
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
- t[p[i]] = s[p[i]];
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _constants = require("../constants");
9
+
10
+ var _utils = require("../utils");
11
+
12
+ const _excluded = ["accessKeyId", "secretAccessKey", "bucket", "acl"];
13
+
14
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
15
+
16
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
17
+
18
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
19
+
20
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
21
+
22
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
23
+
24
+ var _default = {
25
+ filenameKey: 'key',
26
+
27
+ make(storage) {
28
+ const S3Client = require('aws-sdk/clients/s3');
29
+
30
+ const multerS3 = require('multer-s3');
31
+
32
+ const _storage$options = storage.options,
33
+ accessKeyId = _storage$options.accessKeyId,
34
+ secretAccessKey = _storage$options.secretAccessKey,
35
+ bucket = _storage$options.bucket,
36
+ _storage$options$acl = _storage$options.acl,
37
+ acl = _storage$options$acl === void 0 ? 'public-read' : _storage$options$acl,
38
+ options = _objectWithoutProperties(_storage$options, _excluded);
39
+
40
+ const s3 = new S3Client(_objectSpread(_objectSpread({}, options), {}, {
41
+ credentials: {
42
+ accessKeyId,
43
+ secretAccessKey
44
+ }
45
+ }));
46
+ return multerS3({
47
+ s3,
48
+ bucket,
49
+ acl,
50
+
51
+ contentType(req, file, cb) {
52
+ if (file.mimetype) {
53
+ cb(null, file.mimetype);
54
+ return;
10
55
  }
11
- return t;
56
+
57
+ multerS3.AUTO_CONTENT_TYPE(req, file, cb);
58
+ },
59
+
60
+ key: (0, _utils.cloudFilenameGetter)(storage)
61
+ });
62
+ },
63
+
64
+ defaults() {
65
+ return {
66
+ title: 'AWS S3',
67
+ name: 'aws-s3',
68
+ type: _constants.STORAGE_TYPE_S3,
69
+ baseUrl: process.env.AWS_S3_STORAGE_BASE_URL,
70
+ options: {
71
+ region: process.env.AWS_S3_REGION,
72
+ accessKeyId: process.env.AWS_ACCESS_KEY_ID,
73
+ secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
74
+ bucket: process.env.AWS_S3_BUCKET
75
+ }
76
+ };
77
+ }
78
+
12
79
  };
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- const constants_1 = require("../constants");
15
- const utils_1 = require("../utils");
16
- exports.default = {
17
- filenameKey: 'key',
18
- make(storage) {
19
- const S3Client = require('aws-sdk/clients/s3');
20
- const multerS3 = require('multer-s3');
21
- const _a = storage.options, { accessKeyId, secretAccessKey, bucket, acl = 'public-read' } = _a, options = __rest(_a, ["accessKeyId", "secretAccessKey", "bucket", "acl"]);
22
- const s3 = new S3Client(Object.assign(Object.assign({}, options), { credentials: {
23
- accessKeyId,
24
- secretAccessKey,
25
- } }));
26
- return multerS3({
27
- s3,
28
- bucket,
29
- acl,
30
- contentType(req, file, cb) {
31
- if (file.mimetype) {
32
- cb(null, file.mimetype);
33
- return;
34
- }
35
- multerS3.AUTO_CONTENT_TYPE(req, file, cb);
36
- },
37
- key: (0, utils_1.cloudFilenameGetter)(storage),
38
- });
39
- },
40
- defaults() {
41
- return {
42
- title: 'AWS S3',
43
- name: 'aws-s3',
44
- type: constants_1.STORAGE_TYPE_S3,
45
- baseUrl: process.env.AWS_S3_STORAGE_BASE_URL,
46
- options: {
47
- region: process.env.AWS_S3_REGION,
48
- accessKeyId: process.env.AWS_ACCESS_KEY_ID,
49
- secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
50
- bucket: process.env.AWS_S3_BUCKET,
51
- },
52
- };
53
- },
54
- };
55
- //# sourceMappingURL=s3.js.map
80
+ exports.default = _default;
package/lib/utils.js CHANGED
@@ -1,24 +1,47 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.cloudFilenameGetter = exports.getFilename = void 0;
7
- const crypto_1 = __importDefault(require("crypto"));
8
- const path_1 = __importDefault(require("path"));
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.cloudFilenameGetter = void 0;
7
+ exports.getFilename = getFilename;
8
+
9
+ function _crypto() {
10
+ const data = _interopRequireDefault(require("crypto"));
11
+
12
+ _crypto = function _crypto() {
13
+ return data;
14
+ };
15
+
16
+ return data;
17
+ }
18
+
19
+ function _path() {
20
+ const data = _interopRequireDefault(require("path"));
21
+
22
+ _path = function _path() {
23
+ return data;
24
+ };
25
+
26
+ return data;
27
+ }
28
+
29
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
30
+
9
31
  function getFilename(req, file, cb) {
10
- crypto_1.default.pseudoRandomBytes(16, function (err, raw) {
11
- cb(err, err ? undefined : `${raw.toString('hex')}${path_1.default.extname(file.originalname)}`);
12
- });
32
+ _crypto().default.pseudoRandomBytes(16, function (err, raw) {
33
+ cb(err, err ? undefined : `${raw.toString('hex')}${_path().default.extname(file.originalname)}`);
34
+ });
13
35
  }
14
- exports.getFilename = getFilename;
15
- const cloudFilenameGetter = (storage) => (req, file, cb) => {
16
- getFilename(req, file, (err, filename) => {
17
- if (err) {
18
- return cb(err);
19
- }
20
- cb(null, `${storage.path ? `${storage.path}/` : ''}${filename}`);
21
- });
36
+
37
+ const cloudFilenameGetter = storage => (req, file, cb) => {
38
+ getFilename(req, file, (err, filename) => {
39
+ if (err) {
40
+ return cb(err);
41
+ }
42
+
43
+ cb(null, `${storage.path ? `${storage.path}/` : ''}${filename}`);
44
+ });
22
45
  };
23
- exports.cloudFilenameGetter = cloudFilenameGetter;
24
- //# sourceMappingURL=utils.js.map
46
+
47
+ exports.cloudFilenameGetter = cloudFilenameGetter;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/plugin-file-manager",
3
- "version": "0.7.0-alpha.9",
3
+ "version": "0.7.1-alpha.6",
4
4
  "main": "lib/index.js",
5
5
  "license": "Apache-2.0",
6
6
  "licenses": [
@@ -9,25 +9,21 @@
9
9
  "url": "http://www.apache.org/licenses/LICENSE-2.0"
10
10
  }
11
11
  ],
12
- "scripts": {
13
- "build": "rimraf -rf lib esm dist && npm run build:cjs && npm run build:esm",
14
- "build:cjs": "tsc --project tsconfig.build.json",
15
- "build:esm": "tsc --project tsconfig.build.json --module es2015 --outDir esm"
16
- },
17
12
  "dependencies": {
18
13
  "@koa/multer": "^3.0.0",
19
- "@nocobase/server": "0.7.0-alpha.9",
14
+ "@nocobase/server": "0.7.1-alpha.6",
20
15
  "aws-sdk": "^2.2.32",
21
16
  "koa-static": "^5.0.0",
22
17
  "mime-match": "^1.0.2",
18
+ "mkdirp": "~0.5.4",
23
19
  "multer": "^1.4.2",
24
- "multer-aliyun-oss": "1.1.1",
20
+ "multer-aliyun-oss": "2.1.1",
25
21
  "multer-s3": "^2.10.0"
26
22
  },
27
23
  "devDependencies": {
28
- "@nocobase/test": "0.7.0-alpha.9",
24
+ "@nocobase/test": "0.7.1-alpha.6",
29
25
  "@types/koa-multer": "^1.0.1",
30
26
  "@types/multer": "^1.4.5"
31
27
  },
32
- "gitHead": "79d5b309fb92148162bfedfb7e304b4673faf568"
28
+ "gitHead": "b6f96c97020d278ae597bf05553442d7516b2216"
33
29
  }
@@ -1,3 +0,0 @@
1
- import { Context, Next } from '@nocobase/actions';
2
- export declare function middleware(ctx: Context, next: Next): Promise<any>;
3
- export declare function action(ctx: Context, next: Next): Promise<never>;