@nocobase/plugin-file-manager 0.8.0-alpha.8 → 0.8.1-alpha.3

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.
@@ -5,16 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.FileStoragePane = void 0;
7
7
 
8
- function _shared() {
9
- const data = require("@formily/shared");
10
-
11
- _shared = function _shared() {
12
- return data;
13
- };
14
-
15
- return data;
16
- }
17
-
18
8
  function _client() {
19
9
  const data = require("@nocobase/client");
20
10
 
@@ -75,13 +65,6 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
75
65
 
76
66
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
77
67
 
78
- const schema = {
79
- type: 'object',
80
- properties: {
81
- [(0, _shared().uid)()]: _storage.storageSchema
82
- }
83
- };
84
-
85
68
  const FileStoragePane = () => {
86
69
  const _useState = (0, _react().useState)(false),
87
70
  _useState2 = _slicedToArray(_useState, 2),
@@ -97,7 +80,7 @@ const FileStoragePane = () => {
97
80
  components: {
98
81
  StorageOptions: _StorageOptions.StorageOptions
99
82
  },
100
- schema: schema
83
+ schema: _storage.storageSchema
101
84
  }));
102
85
  };
103
86
 
@@ -59,7 +59,7 @@ const schema = {
59
59
  type: 'string',
60
60
  'x-decorator': 'FormItem',
61
61
  'x-component': 'Input',
62
- default: 'uploads'
62
+ required: true
63
63
  },
64
64
  path: {
65
65
  title: '{{t("Path")}}',
@@ -195,16 +195,16 @@ const StorageOptions = (0, _react().observer)(props => {
195
195
  setSchema = _useState2[1];
196
196
 
197
197
  (0, _react2().useEffect)(() => {
198
- form.clearFormGraph('options.*');
198
+ // form.clearFormGraph('options.*');
199
199
  setSchema(new (_react().Schema)(schema[form.values.type] || {}));
200
200
  }, [form.values.type]);
201
- return _react2().default.createElement("div", null, _react2().default.createElement(_antd().FormLayout, {
201
+ return _react2().default.createElement(_antd().FormLayout, {
202
202
  layout: 'vertical'
203
203
  }, _react2().default.createElement(_react().RecursionField, {
204
204
  key: form.values.type || 'local',
205
205
  basePath: field.address,
206
206
  onlyRenderProperties: true,
207
207
  schema: s
208
- })));
208
+ }));
209
209
  });
210
210
  exports.StorageOptions = StorageOptions;
@@ -82,7 +82,8 @@ const collection = {
82
82
  uiSchema: {
83
83
  title: '{{t("Storage base URL")}}',
84
84
  type: 'string',
85
- 'x-component': 'Input'
85
+ 'x-component': 'Input',
86
+ required: true
86
87
  }
87
88
  }, {
88
89
  type: 'boolean',
@@ -1,6 +1,6 @@
1
1
  import Application from '@nocobase/server';
2
2
  import multer from 'multer';
3
- declare function middleware(app: Application, options?: any): Promise<void>;
3
+ declare function middleware(app: Application): Promise<void>;
4
4
  declare const _default: {
5
5
  middleware: typeof middleware;
6
6
  make(storage: any): multer.StorageEngine;
@@ -86,17 +86,18 @@ function match(basePath, pathname) {
86
86
  return newPath[0] === '/';
87
87
  }
88
88
 
89
- function update(_x, _x2) {
90
- return _update.apply(this, arguments);
89
+ function refresh(_x, _x2, _x3) {
90
+ return _refresh.apply(this, arguments);
91
91
  }
92
92
 
93
- function _update() {
94
- _update = _asyncToGenerator(function* (app, storages) {
93
+ function _refresh() {
94
+ _refresh = _asyncToGenerator(function* (app, storages, options) {
95
95
  const Storage = app.db.getCollection('storages');
96
96
  const items = yield Storage.repository.find({
97
97
  filter: {
98
98
  type: _constants.STORAGE_TYPE_LOCAL
99
- }
99
+ },
100
+ transaction: options === null || options === void 0 ? void 0 : options.transaction
100
101
  });
101
102
  const primaryKey = Storage.model.primaryKeyAttribute;
102
103
  storages.clear();
@@ -115,18 +116,18 @@ function _update() {
115
116
  _iterator.f();
116
117
  }
117
118
  });
118
- return _update.apply(this, arguments);
119
+ return _refresh.apply(this, arguments);
119
120
  }
120
121
 
121
122
  function createLocalServerUpdateHook(app, storages) {
122
123
  return /*#__PURE__*/function () {
123
- var _ref = _asyncToGenerator(function* (row) {
124
+ var _ref = _asyncToGenerator(function* (row, options) {
124
125
  if (row.get('type') === _constants.STORAGE_TYPE_LOCAL) {
125
- yield update(app, storages);
126
+ yield refresh(app, storages, options);
126
127
  }
127
128
  });
128
129
 
129
- return function (_x3) {
130
+ return function (_x4, _x5) {
130
131
  return _ref.apply(this, arguments);
131
132
  };
132
133
  }();
@@ -141,21 +142,19 @@ function getDocumentRoot(storage) {
141
142
  return _path().default.resolve(_path().default.isAbsolute(documentRoot) ? documentRoot : _path().default.join(process.cwd(), documentRoot));
142
143
  }
143
144
 
144
- function middleware(_x4, _x5) {
145
+ function middleware(_x6) {
145
146
  return _middleware.apply(this, arguments);
146
147
  }
147
148
 
148
149
  function _middleware() {
149
- _middleware = _asyncToGenerator(function* (app, options) {
150
- const LOCALHOST = `http://localhost:${process.env.APP_PORT || '13000'}`;
150
+ _middleware = _asyncToGenerator(function* (app) {
151
151
  const Storage = app.db.getCollection('storages');
152
152
  const storages = new Map();
153
153
  const localServerUpdateHook = createLocalServerUpdateHook(app, storages);
154
- Storage.model.addHook('afterCreate', localServerUpdateHook);
155
- Storage.model.addHook('afterUpdate', localServerUpdateHook);
154
+ Storage.model.addHook('afterSave', localServerUpdateHook);
156
155
  Storage.model.addHook('afterDestroy', localServerUpdateHook);
157
156
  app.on('beforeStart', /*#__PURE__*/_asyncToGenerator(function* () {
158
- yield update(app, storages);
157
+ yield refresh(app, storages);
159
158
  }));
160
159
  app.use( /*#__PURE__*/function () {
161
160
  var _ref4 = _asyncToGenerator(function* (ctx, next) {
@@ -167,7 +166,14 @@ function _middleware() {
167
166
  var _storage$options;
168
167
 
169
168
  const storage = _step2.value;
170
- const baseUrl = storage.get('baseUrl');
169
+ const baseUrl = storage.get('baseUrl').trim();
170
+
171
+ if (!baseUrl) {
172
+ console.error('"baseUrl" is not configured'); // return ctx.throw(500);
173
+
174
+ continue;
175
+ }
176
+
171
177
  let url;
172
178
 
173
179
  try {
@@ -190,12 +196,11 @@ function _middleware() {
190
196
  continue;
191
197
  }
192
198
 
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
+ ctx.path = ctx.path.replace(basePath, '');
200
+ const documentRoot = getDocumentRoot(storage);
201
+ return (0, _koaStatic().default)(documentRoot)(ctx, /*#__PURE__*/_asyncToGenerator(function* () {
202
+ if (ctx.status == 404) {
203
+ return;
199
204
  }
200
205
 
201
206
  yield next();
@@ -210,7 +215,7 @@ function _middleware() {
210
215
  yield next();
211
216
  });
212
217
 
213
- return function (_x6, _x7) {
218
+ return function (_x7, _x8) {
214
219
  return _ref4.apply(this, arguments);
215
220
  };
216
221
  }());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/plugin-file-manager",
3
- "version": "0.8.0-alpha.8",
3
+ "version": "0.8.1-alpha.3",
4
4
  "main": "lib/index.js",
5
5
  "license": "Apache-2.0",
6
6
  "licenses": [
@@ -11,8 +11,8 @@
11
11
  ],
12
12
  "dependencies": {
13
13
  "@koa/multer": "^3.0.0",
14
- "@nocobase/client": "0.8.0-alpha.8",
15
- "@nocobase/server": "0.8.0-alpha.8",
14
+ "@nocobase/client": "0.8.1-alpha.3",
15
+ "@nocobase/server": "0.8.1-alpha.3",
16
16
  "aws-sdk": "^2.2.32",
17
17
  "cos-nodejs-sdk-v5": "^2.11.14",
18
18
  "koa-static": "^5.0.0",
@@ -24,9 +24,9 @@
24
24
  "multer-s3": "^2.10.0"
25
25
  },
26
26
  "devDependencies": {
27
- "@nocobase/test": "0.8.0-alpha.8",
27
+ "@nocobase/test": "0.8.1-alpha.3",
28
28
  "@types/koa-multer": "^1.0.1",
29
29
  "@types/multer": "^1.4.5"
30
30
  },
31
- "gitHead": "d53b20e08591651692c37b8bfdf1bfe59332bbdb"
31
+ "gitHead": "e03df3df5962b99d9fbf5b6e33fbe2b23f14f3d3"
32
32
  }