@nocobase/plugin-file-manager 0.7.0-alpha.8 → 0.7.0-alpha.82
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/lib/actions/upload.js +236 -161
- package/lib/collections/attachments.js +53 -59
- package/lib/collections/storages.js +54 -60
- package/lib/constants.js +17 -9
- package/lib/index.js +29 -19
- package/lib/rules/index.js +14 -9
- package/lib/rules/mimetype.js +20 -9
- package/lib/server.js +91 -48
- package/lib/storages/ali-oss.js +36 -26
- package/lib/storages/index.js +22 -16
- package/lib/storages/local.d.ts +3 -0
- package/lib/storages/local.js +240 -119
- package/lib/storages/s3.js +77 -52
- package/lib/utils.js +43 -20
- package/package.json +6 -10
- package/esm/actions/upload.d.ts +0 -3
- package/esm/actions/upload.js +0 -143
- package/esm/actions/upload.js.map +0 -1
- package/esm/collections/attachments.d.ts +0 -3
- package/esm/collections/attachments.js +0 -59
- package/esm/collections/attachments.js.map +0 -1
- package/esm/collections/storages.d.ts +0 -3
- package/esm/collections/storages.js +0 -60
- package/esm/collections/storages.js.map +0 -1
- package/esm/constants.d.ts +0 -6
- package/esm/constants.js +0 -7
- package/esm/constants.js.map +0 -1
- package/esm/index.d.ts +0 -2
- package/esm/index.js +0 -3
- package/esm/index.js.map +0 -1
- package/esm/rules/index.d.ts +0 -1
- package/esm/rules/index.js +0 -3
- package/esm/rules/index.js.map +0 -1
- package/esm/rules/mimetype.d.ts +0 -1
- package/esm/rules/mimetype.js +0 -5
- package/esm/rules/mimetype.js.map +0 -1
- package/esm/server.d.ts +0 -7
- package/esm/server.js +0 -48
- package/esm/server.js.map +0 -1
- package/esm/storages/ali-oss.d.ts +0 -16
- package/esm/storages/ali-oss.js +0 -26
- package/esm/storages/ali-oss.js.map +0 -1
- package/esm/storages/index.d.ts +0 -8
- package/esm/storages/index.js +0 -12
- package/esm/storages/index.js.map +0 -1
- package/esm/storages/local.d.ts +0 -14
- package/esm/storages/local.js +0 -127
- package/esm/storages/local.js.map +0 -1
- package/esm/storages/s3.d.ts +0 -17
- package/esm/storages/s3.js +0 -53
- package/esm/storages/s3.js.map +0 -1
- package/esm/utils.d.ts +0 -2
- package/esm/utils.js +0 -16
- package/esm/utils.js.map +0 -1
- package/lib/actions/upload.js.map +0 -1
- package/lib/collections/attachments.js.map +0 -1
- package/lib/collections/storages.js.map +0 -1
- package/lib/constants.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/rules/index.js.map +0 -1
- package/lib/rules/mimetype.js.map +0 -1
- package/lib/server.js.map +0 -1
- package/lib/storages/ali-oss.js.map +0 -1
- package/lib/storages/index.js.map +0 -1
- package/lib/storages/local.js.map +0 -1
- package/lib/storages/s3.js.map +0 -1
- package/lib/utils.js.map +0 -1
- package/tsconfig.build.json +0 -9
package/lib/constants.js
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports.LIMIT_MAX_FILE_SIZE =
|
|
7
|
-
|
|
8
|
-
exports.
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.STORAGE_TYPE_S3 = exports.STORAGE_TYPE_LOCAL = exports.STORAGE_TYPE_ALI_OSS = exports.LIMIT_MAX_FILE_SIZE = exports.LIMIT_FILES = exports.FILE_FIELD_NAME = void 0;
|
|
7
|
+
const FILE_FIELD_NAME = 'file';
|
|
8
|
+
exports.FILE_FIELD_NAME = FILE_FIELD_NAME;
|
|
9
|
+
const LIMIT_FILES = 1;
|
|
10
|
+
exports.LIMIT_FILES = LIMIT_FILES;
|
|
11
|
+
const LIMIT_MAX_FILE_SIZE = 1024 * 1024 * 1024;
|
|
12
|
+
exports.LIMIT_MAX_FILE_SIZE = LIMIT_MAX_FILE_SIZE;
|
|
13
|
+
const STORAGE_TYPE_LOCAL = 'local';
|
|
14
|
+
exports.STORAGE_TYPE_LOCAL = STORAGE_TYPE_LOCAL;
|
|
15
|
+
const STORAGE_TYPE_ALI_OSS = 'ali-oss';
|
|
16
|
+
exports.STORAGE_TYPE_ALI_OSS = STORAGE_TYPE_ALI_OSS;
|
|
17
|
+
const STORAGE_TYPE_S3 = 's3';
|
|
18
|
+
exports.STORAGE_TYPE_S3 = STORAGE_TYPE_S3;
|
package/lib/index.js
CHANGED
|
@@ -1,20 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
})
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _exportNames = {};
|
|
7
|
+
Object.defineProperty(exports, "default", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function get() {
|
|
10
|
+
return _server.default;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
var _constants = require("./constants");
|
|
15
|
+
|
|
16
|
+
Object.keys(_constants).forEach(function (key) {
|
|
17
|
+
if (key === "default" || key === "__esModule") return;
|
|
18
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
19
|
+
if (key in exports && exports[key] === _constants[key]) return;
|
|
20
|
+
Object.defineProperty(exports, key, {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function get() {
|
|
23
|
+
return _constants[key];
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
var _server = _interopRequireDefault(require("./server"));
|
|
29
|
+
|
|
30
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
package/lib/rules/index.js
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "mimetype", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _mimetype.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
var _mimetype = _interopRequireDefault(require("./mimetype"));
|
|
14
|
+
|
|
15
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
package/lib/rules/mimetype.js
CHANGED
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = _default;
|
|
7
|
+
|
|
8
|
+
function _mimeMatch() {
|
|
9
|
+
const data = _interopRequireDefault(require("mime-match"));
|
|
10
|
+
|
|
11
|
+
_mimeMatch = function _mimeMatch() {
|
|
12
|
+
return data;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return data;
|
|
9
16
|
}
|
|
10
|
-
|
|
11
|
-
|
|
17
|
+
|
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
+
|
|
20
|
+
function _default(file, options = '*', ctx) {
|
|
21
|
+
return options.toString().split(',').some((0, _mimeMatch().default)(file.mimetype));
|
|
22
|
+
}
|
package/lib/server.js
CHANGED
|
@@ -1,51 +1,94 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
function _server() {
|
|
9
|
+
const data = require("@nocobase/server");
|
|
10
|
+
|
|
11
|
+
_server = function _server() {
|
|
12
|
+
return data;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function _path() {
|
|
19
|
+
const data = require("path");
|
|
20
|
+
|
|
21
|
+
_path = function _path() {
|
|
22
|
+
return data;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
return data;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
var _upload = require("./actions/upload");
|
|
29
|
+
|
|
30
|
+
var _constants = require("./constants");
|
|
31
|
+
|
|
32
|
+
var _storages = require("./storages");
|
|
33
|
+
|
|
34
|
+
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; }
|
|
35
|
+
|
|
36
|
+
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; }
|
|
37
|
+
|
|
38
|
+
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; }
|
|
39
|
+
|
|
40
|
+
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); } }
|
|
41
|
+
|
|
42
|
+
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); }); }; }
|
|
43
|
+
|
|
44
|
+
class PluginFileManager extends _server().Plugin {
|
|
45
|
+
storageType() {
|
|
46
|
+
return process.env.DEFAULT_STORAGE_TYPE;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
install() {
|
|
50
|
+
var _this = this;
|
|
51
|
+
|
|
52
|
+
return _asyncToGenerator(function* () {
|
|
53
|
+
const defaultStorageConfig = (0, _storages.getStorageConfig)(_this.storageType());
|
|
54
|
+
|
|
55
|
+
if (defaultStorageConfig) {
|
|
56
|
+
const Storage = _this.db.getCollection('storages');
|
|
57
|
+
|
|
58
|
+
yield Storage.repository.create({
|
|
59
|
+
values: _objectSpread(_objectSpread({}, defaultStorageConfig.defaults()), {}, {
|
|
60
|
+
type: _this.storageType(),
|
|
61
|
+
default: true
|
|
62
|
+
})
|
|
44
63
|
});
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
64
|
+
}
|
|
65
|
+
})();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
load() {
|
|
69
|
+
var _this2 = this;
|
|
70
|
+
|
|
71
|
+
return _asyncToGenerator(function* () {
|
|
72
|
+
yield _this2.db.import({
|
|
73
|
+
directory: (0, _path().resolve)(__dirname, 'collections')
|
|
74
|
+
}); // 暂时中间件只能通过 use 加进来
|
|
75
|
+
|
|
76
|
+
_this2.app.resourcer.use(_upload.middleware);
|
|
77
|
+
|
|
78
|
+
_this2.app.resourcer.registerActionHandler('upload', _upload.action);
|
|
79
|
+
|
|
80
|
+
if (process.env.APP_ENV !== 'production') {
|
|
81
|
+
yield (0, _storages.getStorageConfig)(_constants.STORAGE_TYPE_LOCAL).middleware(_this2.app);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
_this2.app.acl.allow('attachments', 'upload', 'loggedIn');
|
|
85
|
+
})();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
getName() {
|
|
89
|
+
return this.getPackageName(__dirname);
|
|
90
|
+
}
|
|
91
|
+
|
|
49
92
|
}
|
|
50
|
-
|
|
51
|
-
|
|
93
|
+
|
|
94
|
+
exports.default = PluginFileManager;
|
package/lib/storages/ali-oss.js
CHANGED
|
@@ -1,28 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
+
var _default = {
|
|
13
|
+
make(storage) {
|
|
14
|
+
const createAliOssStorage = require('multer-aliyun-oss');
|
|
15
|
+
|
|
16
|
+
return new createAliOssStorage({
|
|
17
|
+
config: storage.options,
|
|
18
|
+
filename: (0, _utils.cloudFilenameGetter)(storage)
|
|
19
|
+
});
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
defaults() {
|
|
23
|
+
return {
|
|
24
|
+
title: '阿里云对象存储',
|
|
25
|
+
type: _constants.STORAGE_TYPE_ALI_OSS,
|
|
26
|
+
name: 'ali-oss-1',
|
|
27
|
+
baseUrl: process.env.ALI_OSS_STORAGE_BASE_URL,
|
|
28
|
+
options: {
|
|
29
|
+
region: process.env.ALI_OSS_REGION,
|
|
30
|
+
accessKeyId: process.env.ALI_OSS_ACCESS_KEY_ID,
|
|
31
|
+
accessKeySecret: process.env.ALI_OSS_ACCESS_KEY_SECRET,
|
|
32
|
+
bucket: process.env.ALI_OSS_BUCKET
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
27
37
|
};
|
|
28
|
-
|
|
38
|
+
exports.default = _default;
|
package/lib/storages/index.js
CHANGED
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports.getStorageConfig =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getStorageConfig = getStorageConfig;
|
|
7
|
+
|
|
8
|
+
var _local = _interopRequireDefault(require("./local"));
|
|
9
|
+
|
|
10
|
+
var _aliOss = _interopRequireDefault(require("./ali-oss"));
|
|
11
|
+
|
|
12
|
+
var _s = _interopRequireDefault(require("./s3"));
|
|
13
|
+
|
|
14
|
+
var _constants = require("../constants");
|
|
15
|
+
|
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
+
|
|
11
18
|
const map = new Map();
|
|
12
|
-
map.set(
|
|
13
|
-
map.set(
|
|
14
|
-
map.set(
|
|
19
|
+
map.set(_constants.STORAGE_TYPE_LOCAL, _local.default);
|
|
20
|
+
map.set(_constants.STORAGE_TYPE_ALI_OSS, _aliOss.default);
|
|
21
|
+
map.set(_constants.STORAGE_TYPE_S3, _s.default);
|
|
22
|
+
|
|
15
23
|
function getStorageConfig(key) {
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
exports.getStorageConfig = getStorageConfig;
|
|
19
|
-
//# sourceMappingURL=index.js.map
|
|
24
|
+
return map.get(key);
|
|
25
|
+
}
|