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

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,170 +1,246 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
13
5
  });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
- return new (P || (P = Promise))(function (resolve, reject) {
24
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
- step((generator = generator.apply(thisArg, _arguments || [])).next());
28
- });
29
- };
30
- var __rest = (this && this.__rest) || function (s, e) {
31
- var t = {};
32
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
33
- t[p] = s[p];
34
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
35
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
36
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
37
- t[p[i]] = s[p[i]];
38
- }
39
- return t;
40
- };
41
- var __importDefault = (this && this.__importDefault) || function (mod) {
42
- return (mod && mod.__esModule) ? mod : { "default": mod };
43
- };
44
- Object.defineProperty(exports, "__esModule", { value: true });
45
- exports.action = exports.middleware = void 0;
46
- const path_1 = __importDefault(require("path"));
47
- const multer_1 = __importDefault(require("@koa/multer"));
48
- const storages_1 = require("../storages");
49
- const Rules = __importStar(require("../rules"));
50
- const constants_1 = require("../constants");
51
- const database_1 = require("@nocobase/database");
52
- function getRules(ctx) {
53
- const { resourceField } = ctx;
54
- if (!resourceField) {
55
- return ctx.storage.rules;
56
- }
57
- const { rules = {} } = resourceField.options.attachment || {};
58
- return Object.assign({}, ctx.storage.rules, rules);
6
+ exports.action = action;
7
+ exports.middleware = middleware;
8
+
9
+ function _multer() {
10
+ const data = _interopRequireDefault(require("@koa/multer"));
11
+
12
+ _multer = function _multer() {
13
+ return data;
14
+ };
15
+
16
+ return data;
17
+ }
18
+
19
+ function _database() {
20
+ const data = require("@nocobase/database");
21
+
22
+ _database = function _database() {
23
+ return data;
24
+ };
25
+
26
+ return data;
59
27
  }
60
- // TODO(optimize): 需要优化错误处理,计算失败后需要抛出对应错误,以便程序处理
28
+
29
+ function _path() {
30
+ const data = _interopRequireDefault(require("path"));
31
+
32
+ _path = function _path() {
33
+ return data;
34
+ };
35
+
36
+ return data;
37
+ }
38
+
39
+ var _constants = require("../constants");
40
+
41
+ var Rules = _interopRequireWildcard(require("../rules"));
42
+
43
+ var _storages = require("../storages");
44
+
45
+ const _excluded = ["size"];
46
+
47
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
48
+
49
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
50
+
51
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
52
+
53
+ 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; }
54
+
55
+ 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; }
56
+
57
+ 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; }
58
+
59
+ 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); } }
60
+
61
+ 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); }); }; }
62
+
63
+ 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; }
64
+
65
+ 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; }
66
+
67
+ function getRules(ctx) {
68
+ const resourceField = ctx.resourceField;
69
+
70
+ if (!resourceField) {
71
+ return ctx.storage.rules;
72
+ }
73
+
74
+ const _ref = resourceField.options.attachment || {},
75
+ _ref$rules = _ref.rules,
76
+ rules = _ref$rules === void 0 ? {} : _ref$rules;
77
+
78
+ return Object.assign({}, ctx.storage.rules, rules);
79
+ } // TODO(optimize): 需要优化错误处理,计算失败后需要抛出对应错误,以便程序处理
80
+
81
+
61
82
  function getFileFilter(ctx) {
62
- return (req, file, cb) => {
63
- // size 交给 limits 处理
64
- const _a = getRules(ctx), { size } = _a, rules = __rest(_a, ["size"]);
65
- const ruleKeys = Object.keys(rules);
66
- const result = !ruleKeys.length ||
67
- !ruleKeys.some((key) => typeof Rules[key] !== 'function' || !Rules[key](file, rules[key], ctx));
68
- cb(null, result);
69
- };
83
+ return (req, file, cb) => {
84
+ // size 交给 limits 处理
85
+ const _getRules = getRules(ctx),
86
+ size = _getRules.size,
87
+ rules = _objectWithoutProperties(_getRules, _excluded);
88
+
89
+ const ruleKeys = Object.keys(rules);
90
+ const result = !ruleKeys.length || !ruleKeys.some(key => typeof Rules[key] !== 'function' || !Rules[key](file, rules[key], ctx));
91
+ cb(null, result);
92
+ };
70
93
  }
71
- function middleware(ctx, next) {
72
- return __awaiter(this, void 0, void 0, function* () {
73
- const { resourceName, actionName, associatedName } = ctx.action.params;
74
- if (actionName !== 'upload') {
75
- return next();
76
- }
77
- // NOTE:
78
- // 1. 存储引擎选择依赖于字段定义
79
- // 2. 字段定义中需包含引擎的外键值
80
- // 3. 无字段时按 storages 表的默认项
81
- // 4. 插件初始化后应提示用户添加至少一个存储引擎并设为默认
82
- const Storage = ctx.db.getCollection('storages');
83
- let storage;
84
- if (resourceName === 'attachments') {
85
- // 如果没有包含关联,则直接按默认文件上传至默认存储引擎
86
- storage = yield Storage.repository.findOne({ filter: { default: true } });
87
- }
88
- else if (associatedName) {
89
- const AssociatedCollection = ctx.db.getCollection(associatedName);
90
- const resourceField = AssociatedCollection.getField(resourceName);
91
- ctx.resourceField = resourceField;
92
- const { attachment = {} } = resourceField.options;
93
- storage = yield Storage.repository.findOne({
94
- filter: attachment.storage ? { name: attachment.storage } : { default: true },
95
- });
96
- }
97
- if (!storage) {
98
- console.error('[file-manager] no default or linked storage provided');
99
- return ctx.throw(500);
94
+
95
+ function middleware(_x, _x2) {
96
+ return _middleware.apply(this, arguments);
97
+ }
98
+
99
+ function _middleware() {
100
+ _middleware = _asyncToGenerator(function* (ctx, next) {
101
+ const _ctx$action$params = ctx.action.params,
102
+ resourceName = _ctx$action$params.resourceName,
103
+ actionName = _ctx$action$params.actionName,
104
+ associatedName = _ctx$action$params.associatedName;
105
+
106
+ if (actionName !== 'upload') {
107
+ return next();
108
+ } // NOTE:
109
+ // 1. 存储引擎选择依赖于字段定义
110
+ // 2. 字段定义中需包含引擎的外键值
111
+ // 3. 无字段时按 storages 表的默认项
112
+ // 4. 插件初始化后应提示用户添加至少一个存储引擎并设为默认
113
+
114
+
115
+ const Storage = ctx.db.getCollection('storages');
116
+ let storage;
117
+
118
+ if (resourceName === 'attachments') {
119
+ // 如果没有包含关联,则直接按默认文件上传至默认存储引擎
120
+ storage = yield Storage.repository.findOne({
121
+ filter: {
122
+ default: true
100
123
  }
101
- // 传递已取得的存储引擎,避免重查
102
- ctx.storage = storage;
103
- const storageConfig = (0, storages_1.getStorageConfig)(storage.type);
104
- if (!storageConfig) {
105
- console.error(`[file-manager] storage type "${storage.type}" is not defined`);
106
- return ctx.throw(500);
124
+ });
125
+ } else if (associatedName) {
126
+ const AssociatedCollection = ctx.db.getCollection(associatedName);
127
+ const resourceField = AssociatedCollection.getField(resourceName);
128
+ ctx.resourceField = resourceField;
129
+ const _resourceField$option = resourceField.options.attachment,
130
+ attachment = _resourceField$option === void 0 ? {} : _resourceField$option;
131
+ storage = yield Storage.repository.findOne({
132
+ filter: attachment.storage ? {
133
+ name: attachment.storage
134
+ } : {
135
+ default: true
107
136
  }
108
- const multerOptions = {
109
- fileFilter: getFileFilter(ctx),
110
- limits: {
111
- fileSize: Math.min(getRules(ctx).size || constants_1.LIMIT_MAX_FILE_SIZE, constants_1.LIMIT_MAX_FILE_SIZE),
112
- // 每次只允许提交一个文件
113
- files: constants_1.LIMIT_FILES,
114
- },
115
- storage: storageConfig.make(storage),
116
- };
117
- const upload = (0, multer_1.default)(multerOptions).single(constants_1.FILE_FIELD_NAME);
118
- return upload(ctx, next);
119
- });
137
+ });
138
+ }
139
+
140
+ if (!storage) {
141
+ console.error('[file-manager] no default or linked storage provided');
142
+ return ctx.throw(500);
143
+ } // 传递已取得的存储引擎,避免重查
144
+
145
+
146
+ ctx.storage = storage;
147
+ const storageConfig = (0, _storages.getStorageConfig)(storage.type);
148
+
149
+ if (!storageConfig) {
150
+ console.error(`[file-manager] storage type "${storage.type}" is not defined`);
151
+ return ctx.throw(500);
152
+ }
153
+
154
+ const multerOptions = {
155
+ fileFilter: getFileFilter(ctx),
156
+ limits: {
157
+ fileSize: Math.min(getRules(ctx).size || _constants.LIMIT_MAX_FILE_SIZE, _constants.LIMIT_MAX_FILE_SIZE),
158
+ // 每次只允许提交一个文件
159
+ files: _constants.LIMIT_FILES
160
+ },
161
+ storage: storageConfig.make(storage)
162
+ };
163
+ const upload = (0, _multer().default)(multerOptions).single(_constants.FILE_FIELD_NAME);
164
+ return upload(ctx, next);
165
+ });
166
+ return _middleware.apply(this, arguments);
120
167
  }
121
- exports.middleware = middleware;
122
- function action(ctx, next) {
123
- return __awaiter(this, void 0, void 0, function* () {
124
- const { [constants_1.FILE_FIELD_NAME]: file, storage } = ctx;
125
- if (!file) {
126
- return ctx.throw(400, 'file validation failed');
127
- }
128
- const storageConfig = (0, storages_1.getStorageConfig)(storage.type);
129
- const { [storageConfig.filenameKey || 'filename']: name } = file;
130
- // make compatible filename across cloud service (with path)
131
- const filename = path_1.default.basename(name);
132
- const extname = path_1.default.extname(filename);
133
- const urlPath = storage.path ? storage.path.replace(/^([^\/])/, '/$1') : '';
134
- const data = Object.assign({ title: file.originalname.replace(extname, ''), filename,
135
- extname,
136
- // TODO(feature): 暂时两者相同,后面 storage.path 模版化以后,这里只是 file 实际的 path
137
- path: storage.path, size: file.size,
138
- // 直接缓存起来
139
- url: `${storage.baseUrl}${urlPath}/${filename}`, mimetype: file.mimetype,
140
- // @ts-ignore
141
- meta: ctx.request.body }, (storageConfig.getFileData ? storageConfig.getFileData(file) : {}));
142
- const attachment = yield ctx.db.sequelize.transaction((transaction) => __awaiter(this, void 0, void 0, function* () {
143
- // TODO(optimize): 应使用关联 accessors 获取
144
- const result = yield storage.createAttachment(data, { transaction });
145
- const { associatedName, associatedIndex, resourceName } = ctx.action.params;
146
- const AssociatedCollection = ctx.db.getCollection(associatedName);
147
- if (AssociatedCollection && associatedIndex && resourceName) {
148
- const Repo = AssociatedCollection.repository.relation(resourceName).of(associatedIndex);
149
- const Attachment = ctx.db.getCollection('attachments').model;
150
- const opts = {
151
- tk: result[Attachment.primaryKeyAttribute],
152
- transaction,
153
- };
154
- if (Repo instanceof database_1.BelongsToManyRepository) {
155
- yield Repo.add(opts);
156
- }
157
- else if (Repo instanceof database_1.BelongsToRepository) {
158
- yield Repo.set(opts);
159
- }
160
- }
161
- return result;
162
- }));
163
- // 将存储引擎的信息附在已创建的记录里,节省一次查询
164
- // attachment.setDataValue('storage', storage);
165
- ctx.body = attachment;
166
- yield next();
167
- });
168
+
169
+ function action(_x3, _x4) {
170
+ return _action.apply(this, arguments);
168
171
  }
169
- exports.action = action;
170
- //# sourceMappingURL=upload.js.map
172
+
173
+ function _action() {
174
+ _action = _asyncToGenerator(function* (ctx, next) {
175
+ const file = ctx[_constants.FILE_FIELD_NAME],
176
+ storage = ctx.storage;
177
+
178
+ if (!file) {
179
+ return ctx.throw(400, 'file validation failed');
180
+ }
181
+
182
+ const storageConfig = (0, _storages.getStorageConfig)(storage.type);
183
+ const name = file[storageConfig.filenameKey || 'filename']; // make compatible filename across cloud service (with path)
184
+
185
+ const filename = _path().default.basename(name);
186
+
187
+ const extname = _path().default.extname(filename);
188
+
189
+ const urlPath = storage.path ? storage.path.replace(/^([^\/])/, '/$1') : '';
190
+
191
+ const data = _objectSpread({
192
+ title: file.originalname.replace(extname, ''),
193
+ filename,
194
+ extname,
195
+ // TODO(feature): 暂时两者相同,后面 storage.path 模版化以后,这里只是 file 实际的 path
196
+ path: storage.path,
197
+ size: file.size,
198
+ // 直接缓存起来
199
+ url: `${storage.baseUrl}${urlPath}/${filename}`,
200
+ mimetype: file.mimetype,
201
+ // @ts-ignore
202
+ meta: ctx.request.body
203
+ }, storageConfig.getFileData ? storageConfig.getFileData(file) : {});
204
+
205
+ const attachment = yield ctx.db.sequelize.transaction( /*#__PURE__*/function () {
206
+ var _ref2 = _asyncToGenerator(function* (transaction) {
207
+ // TODO(optimize): 应使用关联 accessors 获取
208
+ const result = yield storage.createAttachment(data, {
209
+ context: ctx,
210
+ transaction
211
+ });
212
+ const _ctx$action$params2 = ctx.action.params,
213
+ associatedName = _ctx$action$params2.associatedName,
214
+ associatedIndex = _ctx$action$params2.associatedIndex,
215
+ resourceName = _ctx$action$params2.resourceName;
216
+ const AssociatedCollection = ctx.db.getCollection(associatedName);
217
+
218
+ if (AssociatedCollection && associatedIndex && resourceName) {
219
+ const Repo = AssociatedCollection.repository.relation(resourceName).of(associatedIndex);
220
+ const Attachment = ctx.db.getCollection('attachments').model;
221
+ const opts = {
222
+ tk: result[Attachment.primaryKeyAttribute],
223
+ transaction
224
+ };
225
+
226
+ if (Repo instanceof _database().BelongsToManyRepository) {
227
+ yield Repo.add(opts);
228
+ } else if (Repo instanceof _database().BelongsToRepository) {
229
+ yield Repo.set(opts);
230
+ }
231
+ }
232
+
233
+ return result;
234
+ });
235
+
236
+ return function (_x5) {
237
+ return _ref2.apply(this, arguments);
238
+ };
239
+ }()); // 将存储引擎的信息附在已创建的记录里,节省一次查询
240
+ // attachment.setDataValue('storage', storage);
241
+
242
+ ctx.body = attachment;
243
+ yield next();
244
+ });
245
+ return _action.apply(this, arguments);
246
+ }
@@ -1,61 +1,57 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = {
4
- name: 'attachments',
5
- title: '文件管理器',
6
- fields: [
7
- {
8
- comment: '用户文件名(不含扩展名)',
9
- type: 'string',
10
- name: 'title',
11
- },
12
- {
13
- comment: '系统文件名(含扩展名)',
14
- type: 'string',
15
- name: 'filename',
16
- },
17
- {
18
- comment: '扩展名(含“.”)',
19
- type: 'string',
20
- name: 'extname',
21
- },
22
- {
23
- comment: '文件体积(字节)',
24
- type: 'integer',
25
- name: 'size',
26
- },
27
- // TODO: 使用暂不明确,以后再考虑
28
- // {
29
- // comment: '文件类型(mimetype 前半段,通常用于预览)',
30
- // type: 'string',
31
- // name: 'type',
32
- // },
33
- {
34
- type: 'string',
35
- name: 'mimetype',
36
- },
37
- {
38
- comment: '存储引擎',
39
- type: 'belongsTo',
40
- name: 'storage',
41
- },
42
- {
43
- comment: '相对路径(含“/”前缀)',
44
- type: 'string',
45
- name: 'path',
46
- },
47
- {
48
- comment: '其他文件信息(如图片的宽高)',
49
- type: 'jsonb',
50
- name: 'meta',
51
- defaultValue: {},
52
- },
53
- {
54
- comment: '网络访问地址',
55
- type: 'string',
56
- name: 'url',
57
- // formula: '{{ storage.baseUrl }}{{ path }}/{{ filename }}'
58
- },
59
- ],
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _default = {
8
+ name: 'attachments',
9
+ title: '文件管理器',
10
+ createdBy: true,
11
+ updatedBy: true,
12
+ fields: [{
13
+ comment: '用户文件名(不含扩展名)',
14
+ type: 'string',
15
+ name: 'title'
16
+ }, {
17
+ comment: '系统文件名(含扩展名)',
18
+ type: 'string',
19
+ name: 'filename'
20
+ }, {
21
+ comment: '扩展名(含“.”)',
22
+ type: 'string',
23
+ name: 'extname'
24
+ }, {
25
+ comment: '文件体积(字节)',
26
+ type: 'integer',
27
+ name: 'size'
28
+ }, // TODO: 使用暂不明确,以后再考虑
29
+ // {
30
+ // comment: '文件类型(mimetype 前半段,通常用于预览)',
31
+ // type: 'string',
32
+ // name: 'type',
33
+ // },
34
+ {
35
+ type: 'string',
36
+ name: 'mimetype'
37
+ }, {
38
+ comment: '存储引擎',
39
+ type: 'belongsTo',
40
+ name: 'storage'
41
+ }, {
42
+ comment: '相对路径(含“/”前缀)',
43
+ type: 'string',
44
+ name: 'path'
45
+ }, {
46
+ comment: '其他文件信息(如图片的宽高)',
47
+ type: 'jsonb',
48
+ name: 'meta',
49
+ defaultValue: {}
50
+ }, {
51
+ comment: '网络访问地址',
52
+ type: 'string',
53
+ name: 'url' // formula: '{{ storage.baseUrl }}{{ path }}/{{ filename }}'
54
+
55
+ }]
60
56
  };
61
- //# sourceMappingURL=attachments.js.map
57
+ exports.default = _default;
@@ -1,62 +1,56 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = {
4
- name: 'storages',
5
- title: '存储引擎',
6
- fields: [
7
- {
8
- title: '存储引擎名称',
9
- comment: '存储引擎名称',
10
- type: 'string',
11
- name: 'title',
12
- },
13
- {
14
- title: '英文标识',
15
- // comment: '英文标识,用于代码层面配置',
16
- type: 'string',
17
- name: 'name',
18
- unique: true,
19
- },
20
- {
21
- comment: '类型标识,如 local/ali-oss 等',
22
- type: 'string',
23
- name: 'type',
24
- },
25
- {
26
- comment: '配置项',
27
- type: 'jsonb',
28
- name: 'options',
29
- defaultValue: {},
30
- },
31
- {
32
- comment: '文件规则',
33
- type: 'jsonb',
34
- name: 'rules',
35
- defaultValue: {},
36
- },
37
- {
38
- comment: '存储相对路径模板',
39
- type: 'string',
40
- name: 'path',
41
- defaultValue: '',
42
- },
43
- {
44
- comment: '访问地址前缀',
45
- type: 'string',
46
- name: 'baseUrl',
47
- defaultValue: '',
48
- },
49
- // TODO(feature): 需要使用一个实现了可设置默认值的字段
50
- {
51
- comment: '默认引擎',
52
- type: 'radio',
53
- name: 'default',
54
- defaultValue: false,
55
- },
56
- {
57
- type: 'hasMany',
58
- name: 'attachments',
59
- },
60
- ],
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _default = {
8
+ name: 'storages',
9
+ title: '存储引擎',
10
+ fields: [{
11
+ title: '存储引擎名称',
12
+ comment: '存储引擎名称',
13
+ type: 'string',
14
+ name: 'title'
15
+ }, {
16
+ title: '英文标识',
17
+ // comment: '英文标识,用于代码层面配置',
18
+ type: 'string',
19
+ name: 'name',
20
+ unique: true
21
+ }, {
22
+ comment: '类型标识,如 local/ali-oss 等',
23
+ type: 'string',
24
+ name: 'type'
25
+ }, {
26
+ comment: '配置项',
27
+ type: 'jsonb',
28
+ name: 'options',
29
+ defaultValue: {}
30
+ }, {
31
+ comment: '文件规则',
32
+ type: 'jsonb',
33
+ name: 'rules',
34
+ defaultValue: {}
35
+ }, {
36
+ comment: '存储相对路径模板',
37
+ type: 'string',
38
+ name: 'path',
39
+ defaultValue: ''
40
+ }, {
41
+ comment: '访问地址前缀',
42
+ type: 'string',
43
+ name: 'baseUrl',
44
+ defaultValue: ''
45
+ }, // TODO(feature): 需要使用一个实现了可设置默认值的字段
46
+ {
47
+ comment: '默认引擎',
48
+ type: 'radio',
49
+ name: 'default',
50
+ defaultValue: false
51
+ }, {
52
+ type: 'hasMany',
53
+ name: 'attachments'
54
+ }]
61
55
  };
62
- //# sourceMappingURL=storages.js.map
56
+ exports.default = _default;