@nocobase/plugin-file-manager 0.9.1-alpha.2 → 0.9.2-alpha.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/lib/client/FileStorage.js +3 -49
- package/lib/client/FileStorageShortcut.js +5 -35
- package/lib/client/StorageOptions.js +10 -24
- package/lib/client/hooks/index.d.ts +1 -0
- package/lib/client/hooks/index.js +16 -0
- package/lib/client/hooks/useUploadFiles.d.ts +8 -0
- package/lib/client/hooks/useUploadFiles.js +78 -0
- package/lib/client/index.js +40 -16
- package/lib/client/initializers/UploadActionInitializer.d.ts +1 -0
- package/lib/client/initializers/UploadActionInitializer.js +67 -0
- package/lib/client/initializers/index.d.ts +1 -0
- package/lib/client/initializers/index.js +16 -0
- package/lib/client/locale/index.d.ts +2 -0
- package/lib/client/locale/index.js +29 -0
- package/lib/client/locale/zh-CN.d.ts +10 -0
- package/lib/client/locale/zh-CN.js +17 -0
- package/lib/client/schemas/storage.js +3 -12
- package/lib/client/templates/file.d.ts +2 -0
- package/lib/client/templates/file.js +164 -0
- package/lib/client/templates/index.d.ts +1 -0
- package/lib/client/templates/index.js +16 -0
- package/lib/index.js +0 -2
- package/lib/server/actions/upload.d.ts +2 -1
- package/lib/server/actions/upload.js +91 -125
- package/lib/server/collections/attachments.js +5 -4
- package/lib/server/collections/storages.js +3 -2
- package/lib/server/index.js +0 -4
- package/lib/server/rules/index.js +0 -2
- package/lib/server/rules/mimetype.js +0 -5
- package/lib/server/server.js +13 -38
- package/lib/server/storages/ali-oss.js +0 -6
- package/lib/server/storages/index.js +0 -8
- package/lib/server/storages/local.js +12 -66
- package/lib/server/storages/s3.js +10 -26
- package/lib/server/storages/tx-cos.js +0 -7
- package/lib/server/utils.js +0 -11
- package/package.json +7 -6
|
@@ -4,19 +4,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = _default;
|
|
7
|
-
|
|
8
7
|
function _mimeMatch() {
|
|
9
8
|
const data = _interopRequireDefault(require("mime-match"));
|
|
10
|
-
|
|
11
9
|
_mimeMatch = function _mimeMatch() {
|
|
12
10
|
return data;
|
|
13
11
|
};
|
|
14
|
-
|
|
15
12
|
return data;
|
|
16
13
|
}
|
|
17
|
-
|
|
18
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
-
|
|
20
15
|
function _default(file, options = '*', ctx) {
|
|
21
16
|
return options.toString().split(',').some((0, _mimeMatch().default)(file.mimetype));
|
|
22
17
|
}
|
package/lib/server/server.js
CHANGED
|
@@ -4,57 +4,47 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
function _server() {
|
|
9
8
|
const data = require("@nocobase/server");
|
|
10
|
-
|
|
11
9
|
_server = function _server() {
|
|
12
10
|
return data;
|
|
13
11
|
};
|
|
14
|
-
|
|
15
12
|
return data;
|
|
16
13
|
}
|
|
17
|
-
|
|
18
14
|
function _path() {
|
|
19
15
|
const data = require("path");
|
|
20
|
-
|
|
21
16
|
_path = function _path() {
|
|
22
17
|
return data;
|
|
23
18
|
};
|
|
24
|
-
|
|
25
19
|
return data;
|
|
26
20
|
}
|
|
27
|
-
|
|
28
21
|
var _upload = require("./actions/upload");
|
|
29
|
-
|
|
30
22
|
var _constants = require("./constants");
|
|
31
|
-
|
|
32
23
|
var _storages = require("./storages");
|
|
33
|
-
|
|
34
24
|
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
25
|
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
|
|
39
|
-
|
|
26
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
27
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
28
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
40
29
|
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
30
|
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
31
|
class PluginFileManager extends _server().Plugin {
|
|
45
32
|
storageType() {
|
|
46
33
|
return process.env.DEFAULT_STORAGE_TYPE;
|
|
47
34
|
}
|
|
48
|
-
|
|
49
35
|
install() {
|
|
50
36
|
var _this = this;
|
|
51
|
-
|
|
52
37
|
return _asyncToGenerator(function* () {
|
|
53
38
|
const defaultStorageConfig = (0, _storages.getStorageConfig)(_this.storageType());
|
|
54
|
-
|
|
55
39
|
if (defaultStorageConfig) {
|
|
56
40
|
const Storage = _this.db.getCollection('storages');
|
|
57
|
-
|
|
41
|
+
if (yield Storage.repository.findOne({
|
|
42
|
+
filter: {
|
|
43
|
+
name: defaultStorageConfig.defaults().name
|
|
44
|
+
}
|
|
45
|
+
})) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
58
48
|
yield Storage.repository.create({
|
|
59
49
|
values: _objectSpread(_objectSpread({}, defaultStorageConfig.defaults()), {}, {
|
|
60
50
|
type: _this.storageType(),
|
|
@@ -64,31 +54,22 @@ class PluginFileManager extends _server().Plugin {
|
|
|
64
54
|
}
|
|
65
55
|
})();
|
|
66
56
|
}
|
|
67
|
-
|
|
68
57
|
load() {
|
|
69
58
|
var _this2 = this;
|
|
70
|
-
|
|
71
59
|
return _asyncToGenerator(function* () {
|
|
72
60
|
yield _this2.importCollections((0, _path().resolve)(__dirname, './collections'));
|
|
73
|
-
|
|
74
61
|
_this2.app.acl.registerSnippet({
|
|
75
62
|
name: `pm.${_this2.name}.storages`,
|
|
76
63
|
actions: ['storages:*']
|
|
77
64
|
});
|
|
78
|
-
|
|
79
|
-
_this2.app.acl.allow('attachments', 'upload', 'loggedIn'); // 暂时中间件只能通过 use 加进来
|
|
80
|
-
|
|
81
|
-
|
|
65
|
+
_this2.app.acl.allow('attachments', 'upload', 'loggedIn');
|
|
82
66
|
_this2.app.resourcer.use(_upload.middleware);
|
|
83
|
-
|
|
84
|
-
_this2.app.resourcer.registerActionHandler('upload', _upload.
|
|
85
|
-
|
|
67
|
+
_this2.app.resourcer.use(_upload.createAction);
|
|
68
|
+
_this2.app.resourcer.registerActionHandler('upload', _upload.uploadAction);
|
|
86
69
|
if (process.env.APP_ENV !== 'production') {
|
|
87
70
|
yield (0, _storages.getStorageConfig)(_constants.STORAGE_TYPE_LOCAL).middleware(_this2.app);
|
|
88
71
|
}
|
|
89
|
-
|
|
90
72
|
const defaultStorageName = (0, _storages.getStorageConfig)(_this2.storageType()).defaults().name;
|
|
91
|
-
|
|
92
73
|
_this2.app.acl.addFixedParams('storages', 'destroy', () => {
|
|
93
74
|
return {
|
|
94
75
|
filter: {
|
|
@@ -96,7 +77,6 @@ class PluginFileManager extends _server().Plugin {
|
|
|
96
77
|
}
|
|
97
78
|
};
|
|
98
79
|
});
|
|
99
|
-
|
|
100
80
|
const ownMerger = () => {
|
|
101
81
|
return {
|
|
102
82
|
filter: {
|
|
@@ -104,15 +84,10 @@ class PluginFileManager extends _server().Plugin {
|
|
|
104
84
|
}
|
|
105
85
|
};
|
|
106
86
|
};
|
|
107
|
-
|
|
108
87
|
_this2.app.acl.addFixedParams('attachments', 'update', ownMerger);
|
|
109
|
-
|
|
110
88
|
_this2.app.acl.addFixedParams('attachments', 'create', ownMerger);
|
|
111
|
-
|
|
112
89
|
_this2.app.acl.addFixedParams('attachments', 'destroy', ownMerger);
|
|
113
90
|
})();
|
|
114
91
|
}
|
|
115
|
-
|
|
116
92
|
}
|
|
117
|
-
|
|
118
93
|
exports.default = PluginFileManager;
|
|
@@ -4,21 +4,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _constants = require("../constants");
|
|
9
|
-
|
|
10
8
|
var _utils = require("../utils");
|
|
11
|
-
|
|
12
9
|
var _default = {
|
|
13
10
|
make(storage) {
|
|
14
11
|
const createAliOssStorage = require('multer-aliyun-oss');
|
|
15
|
-
|
|
16
12
|
return new createAliOssStorage({
|
|
17
13
|
config: storage.options,
|
|
18
14
|
filename: (0, _utils.cloudFilenameGetter)(storage)
|
|
19
15
|
});
|
|
20
16
|
},
|
|
21
|
-
|
|
22
17
|
defaults() {
|
|
23
18
|
return {
|
|
24
19
|
title: '阿里云对象存储',
|
|
@@ -33,6 +28,5 @@ var _default = {
|
|
|
33
28
|
}
|
|
34
29
|
};
|
|
35
30
|
}
|
|
36
|
-
|
|
37
31
|
};
|
|
38
32
|
exports.default = _default;
|
|
@@ -4,25 +4,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getStorageConfig = getStorageConfig;
|
|
7
|
-
|
|
8
7
|
var _local = _interopRequireDefault(require("./local"));
|
|
9
|
-
|
|
10
8
|
var _aliOss = _interopRequireDefault(require("./ali-oss"));
|
|
11
|
-
|
|
12
9
|
var _s = _interopRequireDefault(require("./s3"));
|
|
13
|
-
|
|
14
10
|
var _txCos = _interopRequireDefault(require("./tx-cos"));
|
|
15
|
-
|
|
16
11
|
var _constants = require("../constants");
|
|
17
|
-
|
|
18
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
-
|
|
20
13
|
const map = new Map();
|
|
21
14
|
map.set(_constants.STORAGE_TYPE_LOCAL, _local.default);
|
|
22
15
|
map.set(_constants.STORAGE_TYPE_ALI_OSS, _aliOss.default);
|
|
23
16
|
map.set(_constants.STORAGE_TYPE_S3, _s.default);
|
|
24
17
|
map.set(_constants.STORAGE_TYPE_TX_COS, _txCos.default);
|
|
25
|
-
|
|
26
18
|
function getStorageConfig(key) {
|
|
27
19
|
return map.get(key);
|
|
28
20
|
}
|
|
@@ -4,92 +4,63 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
function _koaStatic() {
|
|
9
8
|
const data = _interopRequireDefault(require("koa-static"));
|
|
10
|
-
|
|
11
9
|
_koaStatic = function _koaStatic() {
|
|
12
10
|
return data;
|
|
13
11
|
};
|
|
14
|
-
|
|
15
12
|
return data;
|
|
16
13
|
}
|
|
17
|
-
|
|
18
14
|
function _mkdirp() {
|
|
19
15
|
const data = _interopRequireDefault(require("mkdirp"));
|
|
20
|
-
|
|
21
16
|
_mkdirp = function _mkdirp() {
|
|
22
17
|
return data;
|
|
23
18
|
};
|
|
24
|
-
|
|
25
19
|
return data;
|
|
26
20
|
}
|
|
27
|
-
|
|
28
21
|
function _multer() {
|
|
29
22
|
const data = _interopRequireDefault(require("multer"));
|
|
30
|
-
|
|
31
23
|
_multer = function _multer() {
|
|
32
24
|
return data;
|
|
33
25
|
};
|
|
34
|
-
|
|
35
26
|
return data;
|
|
36
27
|
}
|
|
37
|
-
|
|
38
28
|
function _path() {
|
|
39
29
|
const data = _interopRequireDefault(require("path"));
|
|
40
|
-
|
|
41
30
|
_path = function _path() {
|
|
42
31
|
return data;
|
|
43
32
|
};
|
|
44
|
-
|
|
45
33
|
return data;
|
|
46
34
|
}
|
|
47
|
-
|
|
48
35
|
function _url() {
|
|
49
36
|
const data = require("url");
|
|
50
|
-
|
|
51
37
|
_url = function _url() {
|
|
52
38
|
return data;
|
|
53
39
|
};
|
|
54
|
-
|
|
55
40
|
return data;
|
|
56
41
|
}
|
|
57
|
-
|
|
58
42
|
var _constants = require("../constants");
|
|
59
|
-
|
|
60
43
|
var _utils = require("../utils");
|
|
61
|
-
|
|
62
44
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
63
|
-
|
|
64
45
|
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
46
|
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
47
|
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
48
|
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
49
|
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
|
-
|
|
74
50
|
// use koa-mount match logic
|
|
75
51
|
function match(basePath, pathname) {
|
|
76
52
|
if (!pathname.startsWith(basePath)) {
|
|
77
53
|
return false;
|
|
78
54
|
}
|
|
79
|
-
|
|
80
55
|
const newPath = pathname.replace(basePath, '') || '/';
|
|
81
|
-
|
|
82
56
|
if (basePath.slice(-1) === '/') {
|
|
83
57
|
return true;
|
|
84
58
|
}
|
|
85
|
-
|
|
86
59
|
return newPath[0] === '/';
|
|
87
60
|
}
|
|
88
|
-
|
|
89
61
|
function refresh(_x, _x2, _x3) {
|
|
90
62
|
return _refresh.apply(this, arguments);
|
|
91
63
|
}
|
|
92
|
-
|
|
93
64
|
function _refresh() {
|
|
94
65
|
_refresh = _asyncToGenerator(function* (app, storages, options) {
|
|
95
66
|
const Storage = app.db.getCollection('storages');
|
|
@@ -101,10 +72,8 @@ function _refresh() {
|
|
|
101
72
|
});
|
|
102
73
|
const primaryKey = Storage.model.primaryKeyAttribute;
|
|
103
74
|
storages.clear();
|
|
104
|
-
|
|
105
75
|
var _iterator = _createForOfIteratorHelper(items),
|
|
106
|
-
|
|
107
|
-
|
|
76
|
+
_step;
|
|
108
77
|
try {
|
|
109
78
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
110
79
|
const storage = _step.value;
|
|
@@ -118,7 +87,6 @@ function _refresh() {
|
|
|
118
87
|
});
|
|
119
88
|
return _refresh.apply(this, arguments);
|
|
120
89
|
}
|
|
121
|
-
|
|
122
90
|
function createLocalServerUpdateHook(app, storages) {
|
|
123
91
|
return /*#__PURE__*/function () {
|
|
124
92
|
var _ref = _asyncToGenerator(function* (row, options) {
|
|
@@ -126,26 +94,21 @@ function createLocalServerUpdateHook(app, storages) {
|
|
|
126
94
|
yield refresh(app, storages, options);
|
|
127
95
|
}
|
|
128
96
|
});
|
|
129
|
-
|
|
130
97
|
return function (_x4, _x5) {
|
|
131
98
|
return _ref.apply(this, arguments);
|
|
132
99
|
};
|
|
133
100
|
}();
|
|
134
101
|
}
|
|
135
|
-
|
|
136
102
|
function getDocumentRoot(storage) {
|
|
137
103
|
const _ref2 = storage.options || {},
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
104
|
+
_ref2$documentRoot = _ref2.documentRoot,
|
|
105
|
+
documentRoot = _ref2$documentRoot === void 0 ? 'uploads' : _ref2$documentRoot;
|
|
106
|
+
// TODO(feature): 后面考虑以字符串模板的方式使用,可注入 req/action 相关变量,以便于区分文件夹
|
|
142
107
|
return _path().default.resolve(_path().default.isAbsolute(documentRoot) ? documentRoot : _path().default.join(process.cwd(), documentRoot));
|
|
143
108
|
}
|
|
144
|
-
|
|
145
109
|
function middleware(_x6) {
|
|
146
110
|
return _middleware.apply(this, arguments);
|
|
147
111
|
}
|
|
148
|
-
|
|
149
112
|
function _middleware() {
|
|
150
113
|
_middleware = _asyncToGenerator(function* (app) {
|
|
151
114
|
const Storage = app.db.getCollection('storages');
|
|
@@ -159,50 +122,40 @@ function _middleware() {
|
|
|
159
122
|
app.use( /*#__PURE__*/function () {
|
|
160
123
|
var _ref4 = _asyncToGenerator(function* (ctx, next) {
|
|
161
124
|
var _iterator2 = _createForOfIteratorHelper(storages.values()),
|
|
162
|
-
|
|
163
|
-
|
|
125
|
+
_step2;
|
|
164
126
|
try {
|
|
165
127
|
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
166
128
|
var _storage$options;
|
|
167
|
-
|
|
168
129
|
const storage = _step2.value;
|
|
169
130
|
const baseUrl = storage.get('baseUrl').trim();
|
|
170
|
-
|
|
171
131
|
if (!baseUrl) {
|
|
172
|
-
console.error('"baseUrl" is not configured');
|
|
173
|
-
|
|
132
|
+
console.error('"baseUrl" is not configured');
|
|
133
|
+
// return ctx.throw(500);
|
|
174
134
|
continue;
|
|
175
135
|
}
|
|
176
|
-
|
|
177
136
|
let url;
|
|
178
|
-
|
|
179
137
|
try {
|
|
180
138
|
url = new (_url().URL)(baseUrl);
|
|
181
139
|
} catch (e) {
|
|
182
140
|
url = {
|
|
183
141
|
pathname: baseUrl
|
|
184
142
|
};
|
|
185
|
-
}
|
|
143
|
+
}
|
|
144
|
+
// 以下情况才认为当前进程所应该提供静态服务
|
|
186
145
|
// 否则都忽略,交给其他 server 来提供(如 nginx/cdn 等)
|
|
187
|
-
|
|
188
|
-
|
|
189
146
|
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) {
|
|
190
147
|
continue;
|
|
191
148
|
}
|
|
192
|
-
|
|
193
149
|
const basePath = url.pathname.startsWith('/') ? url.pathname : `/${url.pathname}`;
|
|
194
|
-
|
|
195
150
|
if (!match(basePath, ctx.path)) {
|
|
196
151
|
continue;
|
|
197
152
|
}
|
|
198
|
-
|
|
199
153
|
ctx.path = ctx.path.replace(basePath, '');
|
|
200
154
|
const documentRoot = getDocumentRoot(storage);
|
|
201
155
|
return (0, _koaStatic().default)(documentRoot)(ctx, /*#__PURE__*/_asyncToGenerator(function* () {
|
|
202
156
|
if (ctx.status == 404) {
|
|
203
157
|
return;
|
|
204
158
|
}
|
|
205
|
-
|
|
206
159
|
yield next();
|
|
207
160
|
}));
|
|
208
161
|
}
|
|
@@ -211,10 +164,8 @@ function _middleware() {
|
|
|
211
164
|
} finally {
|
|
212
165
|
_iterator2.f();
|
|
213
166
|
}
|
|
214
|
-
|
|
215
167
|
yield next();
|
|
216
168
|
});
|
|
217
|
-
|
|
218
169
|
return function (_x7, _x8) {
|
|
219
170
|
return _ref4.apply(this, arguments);
|
|
220
171
|
};
|
|
@@ -222,26 +173,22 @@ function _middleware() {
|
|
|
222
173
|
});
|
|
223
174
|
return _middleware.apply(this, arguments);
|
|
224
175
|
}
|
|
225
|
-
|
|
226
176
|
var _default = {
|
|
227
177
|
middleware,
|
|
228
|
-
|
|
229
178
|
make(storage) {
|
|
230
179
|
return _multer().default.diskStorage({
|
|
231
180
|
destination: function destination(req, file, cb) {
|
|
232
181
|
const destPath = _path().default.join(getDocumentRoot(storage), storage.path);
|
|
233
|
-
|
|
234
182
|
(0, _mkdirp().default)(destPath, err => cb(err, destPath));
|
|
235
183
|
},
|
|
236
184
|
filename: _utils.getFilename
|
|
237
185
|
});
|
|
238
186
|
},
|
|
239
|
-
|
|
240
187
|
defaults() {
|
|
241
188
|
const _process$env = process.env,
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
189
|
+
LOCAL_STORAGE_DEST = _process$env.LOCAL_STORAGE_DEST,
|
|
190
|
+
LOCAL_STORAGE_BASE_URL = _process$env.LOCAL_STORAGE_BASE_URL,
|
|
191
|
+
APP_PORT = _process$env.APP_PORT;
|
|
245
192
|
const documentRoot = LOCAL_STORAGE_DEST || 'uploads';
|
|
246
193
|
return {
|
|
247
194
|
title: '本地存储',
|
|
@@ -253,6 +200,5 @@ var _default = {
|
|
|
253
200
|
}
|
|
254
201
|
};
|
|
255
202
|
}
|
|
256
|
-
|
|
257
203
|
};
|
|
258
204
|
exports.default = _default;
|
|
@@ -4,40 +4,29 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _constants = require("../constants");
|
|
9
|
-
|
|
10
8
|
var _utils = require("../utils");
|
|
11
|
-
|
|
12
9
|
const _excluded = ["accessKeyId", "secretAccessKey", "bucket", "acl"];
|
|
13
|
-
|
|
14
10
|
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
11
|
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
|
|
19
|
-
|
|
12
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
13
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
14
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
20
15
|
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
16
|
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
17
|
var _default = {
|
|
25
18
|
filenameKey: 'key',
|
|
26
|
-
|
|
27
19
|
make(storage) {
|
|
28
20
|
const _require = require('@aws-sdk/client-s3'),
|
|
29
|
-
|
|
30
|
-
|
|
21
|
+
S3Client = _require.S3Client;
|
|
31
22
|
const multerS3 = require('multer-s3');
|
|
32
|
-
|
|
33
23
|
const _storage$options = storage.options,
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
24
|
+
accessKeyId = _storage$options.accessKeyId,
|
|
25
|
+
secretAccessKey = _storage$options.secretAccessKey,
|
|
26
|
+
bucket = _storage$options.bucket,
|
|
27
|
+
_storage$options$acl = _storage$options.acl,
|
|
28
|
+
acl = _storage$options$acl === void 0 ? 'public-read' : _storage$options$acl,
|
|
29
|
+
options = _objectWithoutProperties(_storage$options, _excluded);
|
|
41
30
|
const s3 = new S3Client(_objectSpread(_objectSpread({}, options), {}, {
|
|
42
31
|
credentials: {
|
|
43
32
|
accessKeyId,
|
|
@@ -48,20 +37,16 @@ var _default = {
|
|
|
48
37
|
s3,
|
|
49
38
|
bucket,
|
|
50
39
|
acl,
|
|
51
|
-
|
|
52
40
|
contentType(req, file, cb) {
|
|
53
41
|
if (file.mimetype) {
|
|
54
42
|
cb(null, file.mimetype);
|
|
55
43
|
return;
|
|
56
44
|
}
|
|
57
|
-
|
|
58
45
|
multerS3.AUTO_CONTENT_TYPE(req, file, cb);
|
|
59
46
|
},
|
|
60
|
-
|
|
61
47
|
key: (0, _utils.cloudFilenameGetter)(storage)
|
|
62
48
|
});
|
|
63
49
|
},
|
|
64
|
-
|
|
65
50
|
defaults() {
|
|
66
51
|
return {
|
|
67
52
|
title: 'AWS S3',
|
|
@@ -76,6 +61,5 @@ var _default = {
|
|
|
76
61
|
}
|
|
77
62
|
};
|
|
78
63
|
}
|
|
79
|
-
|
|
80
64
|
};
|
|
81
65
|
exports.default = _default;
|
|
@@ -4,23 +4,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _constants = require("../constants");
|
|
9
|
-
|
|
10
8
|
var _utils = require("../utils");
|
|
11
|
-
|
|
12
9
|
var _default = {
|
|
13
10
|
filenameKey: 'url',
|
|
14
|
-
|
|
15
11
|
make(storage) {
|
|
16
12
|
const createTxCosStorage = require('multer-cos');
|
|
17
|
-
|
|
18
13
|
return new createTxCosStorage({
|
|
19
14
|
cos: storage.options,
|
|
20
15
|
filename: (0, _utils.cloudFilenameGetter)(storage)
|
|
21
16
|
});
|
|
22
17
|
},
|
|
23
|
-
|
|
24
18
|
defaults() {
|
|
25
19
|
return {
|
|
26
20
|
title: '腾讯云对象存储',
|
|
@@ -35,6 +29,5 @@ var _default = {
|
|
|
35
29
|
}
|
|
36
30
|
};
|
|
37
31
|
}
|
|
38
|
-
|
|
39
32
|
};
|
|
40
33
|
exports.default = _default;
|
package/lib/server/utils.js
CHANGED
|
@@ -5,43 +5,32 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.cloudFilenameGetter = void 0;
|
|
7
7
|
exports.getFilename = getFilename;
|
|
8
|
-
|
|
9
8
|
function _crypto() {
|
|
10
9
|
const data = _interopRequireDefault(require("crypto"));
|
|
11
|
-
|
|
12
10
|
_crypto = function _crypto() {
|
|
13
11
|
return data;
|
|
14
12
|
};
|
|
15
|
-
|
|
16
13
|
return data;
|
|
17
14
|
}
|
|
18
|
-
|
|
19
15
|
function _path() {
|
|
20
16
|
const data = _interopRequireDefault(require("path"));
|
|
21
|
-
|
|
22
17
|
_path = function _path() {
|
|
23
18
|
return data;
|
|
24
19
|
};
|
|
25
|
-
|
|
26
20
|
return data;
|
|
27
21
|
}
|
|
28
|
-
|
|
29
22
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
30
|
-
|
|
31
23
|
function getFilename(req, file, cb) {
|
|
32
24
|
_crypto().default.pseudoRandomBytes(16, function (err, raw) {
|
|
33
25
|
cb(err, err ? undefined : `${raw.toString('hex')}${_path().default.extname(file.originalname)}`);
|
|
34
26
|
});
|
|
35
27
|
}
|
|
36
|
-
|
|
37
28
|
const cloudFilenameGetter = storage => (req, file, cb) => {
|
|
38
29
|
getFilename(req, file, (err, filename) => {
|
|
39
30
|
if (err) {
|
|
40
31
|
return cb(err);
|
|
41
32
|
}
|
|
42
|
-
|
|
43
33
|
cb(null, `${storage.path ? `${storage.path}/` : ''}${filename}`);
|
|
44
34
|
});
|
|
45
35
|
};
|
|
46
|
-
|
|
47
36
|
exports.cloudFilenameGetter = cloudFilenameGetter;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/plugin-file-manager",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.2-alpha.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "AGPL-3.0",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -8,8 +8,9 @@
|
|
|
8
8
|
"dependencies": {
|
|
9
9
|
"@aws-sdk/client-s3": "^3.245.0",
|
|
10
10
|
"@koa/multer": "^3.0.0",
|
|
11
|
-
"@nocobase/
|
|
12
|
-
"@nocobase/
|
|
11
|
+
"@nocobase/actions": "0.9.2-alpha.1",
|
|
12
|
+
"@nocobase/client": "0.9.2-alpha.1",
|
|
13
|
+
"@nocobase/server": "0.9.2-alpha.1",
|
|
13
14
|
"cos-nodejs-sdk-v5": "^2.11.14",
|
|
14
15
|
"koa-static": "^5.0.0",
|
|
15
16
|
"mime-match": "^1.0.2",
|
|
@@ -17,12 +18,12 @@
|
|
|
17
18
|
"multer": "^1.4.2",
|
|
18
19
|
"multer-aliyun-oss": "2.1.1",
|
|
19
20
|
"multer-cos": "^1.0.3",
|
|
20
|
-
"multer-s3": "^
|
|
21
|
+
"multer-s3": "^3.0.1"
|
|
21
22
|
},
|
|
22
23
|
"devDependencies": {
|
|
23
|
-
"@nocobase/test": "0.9.
|
|
24
|
+
"@nocobase/test": "0.9.2-alpha.1",
|
|
24
25
|
"@types/koa-multer": "^1.0.1",
|
|
25
26
|
"@types/multer": "^1.4.5"
|
|
26
27
|
},
|
|
27
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "a4f103eb0144f07205aff7b2a6be8ea6aa1330df"
|
|
28
29
|
}
|