@nocobase/plugin-file-manager 0.13.0-alpha.4 → 0.13.0-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.
- package/dist/client/index.js +1 -975
- package/dist/index.js +37 -16
- package/dist/locale/en-US.js +22 -4
- package/dist/locale/fr-FR.js +22 -4
- package/dist/locale/ja-JP.js +22 -4
- package/dist/locale/ru-RU.js +22 -4
- package/dist/locale/tr-TR.js +22 -4
- package/dist/locale/zh-CN.js +22 -4
- package/dist/node_modules/@aws-sdk/client-s3/dist-cjs/index.js +3 -3
- package/dist/node_modules/@aws-sdk/client-s3/package.json +1 -1
- package/dist/node_modules/mime-match/index.js +1 -1
- package/dist/node_modules/mime-match/package.json +1 -1
- package/dist/node_modules/mkdirp/index.js +1 -1
- package/dist/node_modules/mkdirp/package.json +1 -1
- package/dist/node_modules/multer-aliyun-oss/index.js +22 -22
- package/dist/node_modules/multer-aliyun-oss/package.json +1 -1
- package/dist/node_modules/multer-cos/index.js +15 -15
- package/dist/node_modules/multer-cos/package.json +1 -1
- package/dist/node_modules/multer-s3/index.js +5 -5
- package/dist/node_modules/multer-s3/package.json +1 -1
- package/dist/server/actions/attachments.js +54 -45
- package/dist/server/actions/index.js +37 -14
- package/dist/server/collections/attachments.js +22 -4
- package/dist/server/collections/storages.js +22 -4
- package/dist/server/constants.js +38 -10
- package/dist/server/index.js +37 -21
- package/dist/server/migrations/20230831160742-fix-attachment-field.d.ts +4 -0
- package/dist/server/migrations/20230831160742-fix-attachment-field.js +60 -0
- package/dist/server/rules/index.js +36 -13
- package/dist/server/rules/mimetype.js +34 -11
- package/dist/server/server.js +53 -24
- package/dist/server/storages/ali-oss.js +26 -9
- package/dist/server/storages/index.js +48 -26
- package/dist/server/storages/local.js +45 -25
- package/dist/server/storages/s3.js +26 -9
- package/dist/server/storages/tx-cos.js +28 -11
- package/dist/server/utils.js +42 -15
- package/dist/swagger/index.json +81 -0
- package/package.json +2 -2
- package/dist/swagger/index.js +0 -95
package/dist/server/server.js
CHANGED
|
@@ -1,23 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var server_exports = {};
|
|
29
|
+
__export(server_exports, {
|
|
30
|
+
default: () => PluginFileManager,
|
|
31
|
+
storageTypes: () => import_storages2.default
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(server_exports);
|
|
34
|
+
var import_server = require("@nocobase/server");
|
|
35
|
+
var import_path = require("path");
|
|
36
|
+
var import_actions = __toESM(require("./actions"));
|
|
37
|
+
var import_storages = require("./storages");
|
|
38
|
+
var import_storages2 = __toESM(require("./storages"));
|
|
39
|
+
class PluginFileManager extends import_server.Plugin {
|
|
16
40
|
storageType() {
|
|
17
41
|
return process.env.DEFAULT_STORAGE_TYPE ?? "local";
|
|
18
42
|
}
|
|
19
43
|
async install() {
|
|
20
|
-
const defaultStorageConfig =
|
|
44
|
+
const defaultStorageConfig = (0, import_storages.getStorageConfig)(this.storageType());
|
|
21
45
|
if (defaultStorageConfig) {
|
|
22
46
|
const Storage = this.db.getCollection("storages");
|
|
23
47
|
if (await Storage.repository.findOne({
|
|
@@ -37,15 +61,22 @@ class PluginFileManager extends server.Plugin {
|
|
|
37
61
|
}
|
|
38
62
|
}
|
|
39
63
|
async load() {
|
|
40
|
-
await this.importCollections(
|
|
64
|
+
await this.importCollections((0, import_path.resolve)(__dirname, "./collections"));
|
|
41
65
|
this.app.acl.registerSnippet({
|
|
42
66
|
name: `pm.${this.name}.storages`,
|
|
43
67
|
actions: ["storages:*"]
|
|
44
68
|
});
|
|
45
|
-
|
|
69
|
+
this.db.addMigrations({
|
|
70
|
+
namespace: "file-manager",
|
|
71
|
+
directory: (0, import_path.resolve)(__dirname, "migrations"),
|
|
72
|
+
context: {
|
|
73
|
+
plugin: this
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
(0, import_actions.default)(this);
|
|
46
77
|
this.app.acl.allow("attachments", "upload", "loggedIn");
|
|
47
78
|
this.app.acl.allow("attachments", "create", "loggedIn");
|
|
48
|
-
const defaultStorageName =
|
|
79
|
+
const defaultStorageName = (0, import_storages.getStorageConfig)(this.storageType()).defaults().name;
|
|
49
80
|
this.app.acl.addFixedParams("storages", "destroy", () => {
|
|
50
81
|
return {
|
|
51
82
|
filter: { "name.$ne": defaultStorageName }
|
|
@@ -63,9 +94,7 @@ class PluginFileManager extends server.Plugin {
|
|
|
63
94
|
this.app.acl.addFixedParams("attachments", "destroy", ownMerger);
|
|
64
95
|
}
|
|
65
96
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
get: function () { return storages__default.default; }
|
|
97
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
98
|
+
0 && (module.exports = {
|
|
99
|
+
storageTypes
|
|
70
100
|
});
|
|
71
|
-
exports.default = PluginFileManager;
|
|
@@ -1,20 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var ali_oss_exports = {};
|
|
19
|
+
__export(ali_oss_exports, {
|
|
20
|
+
default: () => ali_oss_default
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(ali_oss_exports);
|
|
23
|
+
var import_constants = require("../constants");
|
|
24
|
+
var import_utils = require("../utils");
|
|
6
25
|
var ali_oss_default = {
|
|
7
26
|
make(storage) {
|
|
8
27
|
const createAliOssStorage = require("multer-aliyun-oss");
|
|
9
28
|
return new createAliOssStorage({
|
|
10
29
|
config: storage.options,
|
|
11
|
-
filename:
|
|
30
|
+
filename: (0, import_utils.cloudFilenameGetter)(storage)
|
|
12
31
|
});
|
|
13
32
|
},
|
|
14
33
|
defaults() {
|
|
15
34
|
return {
|
|
16
35
|
title: "\u963F\u91CC\u4E91\u5BF9\u8C61\u5B58\u50A8",
|
|
17
|
-
type:
|
|
36
|
+
type: import_constants.STORAGE_TYPE_ALI_OSS,
|
|
18
37
|
name: "ali-oss-1",
|
|
19
38
|
baseUrl: process.env.ALI_OSS_STORAGE_BASE_URL,
|
|
20
39
|
options: {
|
|
@@ -34,5 +53,3 @@ var ali_oss_default = {
|
|
|
34
53
|
];
|
|
35
54
|
}
|
|
36
55
|
};
|
|
37
|
-
|
|
38
|
-
module.exports = ali_oss_default;
|
|
@@ -1,30 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var storages_exports = {};
|
|
29
|
+
__export(storages_exports, {
|
|
30
|
+
default: () => storages_default,
|
|
31
|
+
getStorageConfig: () => getStorageConfig
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(storages_exports);
|
|
34
|
+
var import_utils = require("@nocobase/utils");
|
|
35
|
+
var import_local = __toESM(require("./local"));
|
|
36
|
+
var import_ali_oss = __toESM(require("./ali-oss"));
|
|
37
|
+
var import_s3 = __toESM(require("./s3"));
|
|
38
|
+
var import_tx_cos = __toESM(require("./tx-cos"));
|
|
39
|
+
var import_constants = require("../constants");
|
|
40
|
+
const storageTypes = new import_utils.Registry();
|
|
41
|
+
storageTypes.register(import_constants.STORAGE_TYPE_LOCAL, import_local.default);
|
|
42
|
+
storageTypes.register(import_constants.STORAGE_TYPE_ALI_OSS, import_ali_oss.default);
|
|
43
|
+
storageTypes.register(import_constants.STORAGE_TYPE_S3, import_s3.default);
|
|
44
|
+
storageTypes.register(import_constants.STORAGE_TYPE_TX_COS, import_tx_cos.default);
|
|
24
45
|
function getStorageConfig(key) {
|
|
25
46
|
return storageTypes.get(key);
|
|
26
47
|
}
|
|
27
48
|
var storages_default = storageTypes;
|
|
28
|
-
|
|
29
|
-
exports
|
|
30
|
-
|
|
49
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
50
|
+
0 && (module.exports = {
|
|
51
|
+
getStorageConfig
|
|
52
|
+
});
|
|
@@ -1,31 +1,53 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var local_exports = {};
|
|
29
|
+
__export(local_exports, {
|
|
30
|
+
default: () => local_default
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(local_exports);
|
|
33
|
+
var import_promises = __toESM(require("fs/promises"));
|
|
34
|
+
var import_mkdirp = __toESM(require("mkdirp"));
|
|
35
|
+
var import_multer = __toESM(require("multer"));
|
|
36
|
+
var import_path = __toESM(require("path"));
|
|
37
|
+
var import_constants = require("../constants");
|
|
38
|
+
var import_utils = require("../utils");
|
|
17
39
|
function getDocumentRoot(storage) {
|
|
18
40
|
const { documentRoot = process.env.LOCAL_STORAGE_DEST || "storage/uploads" } = storage.options || {};
|
|
19
|
-
return
|
|
41
|
+
return import_path.default.resolve(import_path.default.isAbsolute(documentRoot) ? documentRoot : import_path.default.join(process.cwd(), documentRoot));
|
|
20
42
|
}
|
|
21
43
|
var local_default = {
|
|
22
44
|
make(storage) {
|
|
23
|
-
return
|
|
45
|
+
return import_multer.default.diskStorage({
|
|
24
46
|
destination: function(req, file, cb) {
|
|
25
|
-
const destPath =
|
|
26
|
-
|
|
47
|
+
const destPath = import_path.default.join(getDocumentRoot(storage), storage.path);
|
|
48
|
+
(0, import_mkdirp.default)(destPath, (err) => cb(err, destPath));
|
|
27
49
|
},
|
|
28
|
-
filename:
|
|
50
|
+
filename: import_utils.getFilename
|
|
29
51
|
});
|
|
30
52
|
},
|
|
31
53
|
defaults() {
|
|
@@ -33,7 +55,7 @@ var local_default = {
|
|
|
33
55
|
const documentRoot = LOCAL_STORAGE_DEST || "storage/uploads";
|
|
34
56
|
return {
|
|
35
57
|
title: "Local storage",
|
|
36
|
-
type:
|
|
58
|
+
type: import_constants.STORAGE_TYPE_LOCAL,
|
|
37
59
|
name: `local`,
|
|
38
60
|
baseUrl: LOCAL_STORAGE_BASE_URL || `http://localhost:${APP_PORT || "13000"}/${documentRoot}`,
|
|
39
61
|
options: {
|
|
@@ -48,7 +70,7 @@ var local_default = {
|
|
|
48
70
|
await records.reduce(
|
|
49
71
|
(promise, record) => promise.then(async () => {
|
|
50
72
|
try {
|
|
51
|
-
await
|
|
73
|
+
await import_promises.default.unlink(import_path.default.join(documentRoot, record.path, record.filename));
|
|
52
74
|
count += 1;
|
|
53
75
|
} catch (ex) {
|
|
54
76
|
if (ex.code === "ENOENT") {
|
|
@@ -65,5 +87,3 @@ var local_default = {
|
|
|
65
87
|
return [count, undeleted];
|
|
66
88
|
}
|
|
67
89
|
};
|
|
68
|
-
|
|
69
|
-
module.exports = local_default;
|
|
@@ -1,8 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var s3_exports = {};
|
|
19
|
+
__export(s3_exports, {
|
|
20
|
+
default: () => s3_default
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(s3_exports);
|
|
23
|
+
var import_constants = require("../constants");
|
|
24
|
+
var import_utils = require("../utils");
|
|
6
25
|
var s3_default = {
|
|
7
26
|
filenameKey: "key",
|
|
8
27
|
make(storage) {
|
|
@@ -27,14 +46,14 @@ var s3_default = {
|
|
|
27
46
|
}
|
|
28
47
|
multerS3.AUTO_CONTENT_TYPE(req, file, cb);
|
|
29
48
|
},
|
|
30
|
-
key:
|
|
49
|
+
key: (0, import_utils.cloudFilenameGetter)(storage)
|
|
31
50
|
});
|
|
32
51
|
},
|
|
33
52
|
defaults() {
|
|
34
53
|
return {
|
|
35
54
|
title: "AWS S3",
|
|
36
55
|
name: "aws-s3",
|
|
37
|
-
type:
|
|
56
|
+
type: import_constants.STORAGE_TYPE_S3,
|
|
38
57
|
baseUrl: process.env.AWS_S3_STORAGE_BASE_URL,
|
|
39
58
|
options: {
|
|
40
59
|
region: process.env.AWS_S3_REGION,
|
|
@@ -61,5 +80,3 @@ var s3_default = {
|
|
|
61
80
|
];
|
|
62
81
|
}
|
|
63
82
|
};
|
|
64
|
-
|
|
65
|
-
module.exports = s3_default;
|
|
@@ -1,22 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var tx_cos_exports = {};
|
|
19
|
+
__export(tx_cos_exports, {
|
|
20
|
+
default: () => tx_cos_default
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(tx_cos_exports);
|
|
23
|
+
var import_util = require("util");
|
|
24
|
+
var import_constants = require("../constants");
|
|
25
|
+
var import_utils = require("../utils");
|
|
7
26
|
var tx_cos_default = {
|
|
8
27
|
filenameKey: "url",
|
|
9
28
|
make(storage) {
|
|
10
29
|
const createTxCosStorage = require("multer-cos");
|
|
11
30
|
return new createTxCosStorage({
|
|
12
31
|
cos: storage.options,
|
|
13
|
-
filename:
|
|
32
|
+
filename: (0, import_utils.cloudFilenameGetter)(storage)
|
|
14
33
|
});
|
|
15
34
|
},
|
|
16
35
|
defaults() {
|
|
17
36
|
return {
|
|
18
37
|
title: "\u817E\u8BAF\u4E91\u5BF9\u8C61\u5B58\u50A8",
|
|
19
|
-
type:
|
|
38
|
+
type: import_constants.STORAGE_TYPE_TX_COS,
|
|
20
39
|
name: "tx-cos-1",
|
|
21
40
|
baseUrl: process.env.TX_COS_STORAGE_BASE_URL,
|
|
22
41
|
options: {
|
|
@@ -29,7 +48,7 @@ var tx_cos_default = {
|
|
|
29
48
|
},
|
|
30
49
|
async delete(storage, records) {
|
|
31
50
|
const { cos } = this.make(storage);
|
|
32
|
-
const { Deleted } = await
|
|
51
|
+
const { Deleted } = await (0, import_util.promisify)(cos.deleteMultipleObject)({
|
|
33
52
|
Region: storage.options.Region,
|
|
34
53
|
Bucket: storage.options.Bucket,
|
|
35
54
|
Objects: records.map((record) => ({ Key: `${record.path}/${record.filename}` }))
|
|
@@ -40,5 +59,3 @@ var tx_cos_default = {
|
|
|
40
59
|
];
|
|
41
60
|
}
|
|
42
61
|
};
|
|
43
|
-
|
|
44
|
-
module.exports = tx_cos_default;
|
package/dist/server/utils.js
CHANGED
|
@@ -1,16 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var utils_exports = {};
|
|
29
|
+
__export(utils_exports, {
|
|
30
|
+
cloudFilenameGetter: () => cloudFilenameGetter,
|
|
31
|
+
getFilename: () => getFilename
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(utils_exports);
|
|
34
|
+
var import_crypto = __toESM(require("crypto"));
|
|
35
|
+
var import_path = __toESM(require("path"));
|
|
11
36
|
function getFilename(req, file, cb) {
|
|
12
|
-
|
|
13
|
-
cb(err, err ? void 0 : `${raw.toString("hex")}${
|
|
37
|
+
import_crypto.default.pseudoRandomBytes(16, function(err, raw) {
|
|
38
|
+
cb(err, err ? void 0 : `${raw.toString("hex")}${import_path.default.extname(file.originalname)}`);
|
|
14
39
|
});
|
|
15
40
|
}
|
|
16
41
|
const cloudFilenameGetter = (storage) => (req, file, cb) => {
|
|
@@ -21,6 +46,8 @@ const cloudFilenameGetter = (storage) => (req, file, cb) => {
|
|
|
21
46
|
cb(null, `${storage.path ? `${storage.path}/` : ""}${filename}`);
|
|
22
47
|
});
|
|
23
48
|
};
|
|
24
|
-
|
|
25
|
-
exports
|
|
26
|
-
|
|
49
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
50
|
+
0 && (module.exports = {
|
|
51
|
+
cloudFilenameGetter,
|
|
52
|
+
getFilename
|
|
53
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
{
|
|
2
|
+
"openapi": "3.0.2",
|
|
3
|
+
"info": {
|
|
4
|
+
"title": "NocoBase API - File manager plugin"
|
|
5
|
+
},
|
|
6
|
+
"tags": [],
|
|
7
|
+
"paths": {
|
|
8
|
+
"/{fileCollectionName}:create": {
|
|
9
|
+
"post": {
|
|
10
|
+
"tags": ["$collection"],
|
|
11
|
+
"description": "",
|
|
12
|
+
"parameters": [],
|
|
13
|
+
"responses": {
|
|
14
|
+
"200": {
|
|
15
|
+
"description": "OK"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"/storages:list": {
|
|
21
|
+
"get": {
|
|
22
|
+
"tags": ["storages"],
|
|
23
|
+
"description": "",
|
|
24
|
+
"parameters": [],
|
|
25
|
+
"responses": {
|
|
26
|
+
"200": {
|
|
27
|
+
"description": "OK"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"/storages:get": {
|
|
33
|
+
"get": {
|
|
34
|
+
"tags": ["storages"],
|
|
35
|
+
"description": "",
|
|
36
|
+
"parameters": [],
|
|
37
|
+
"responses": {
|
|
38
|
+
"200": {
|
|
39
|
+
"description": "OK"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"/storages:create": {
|
|
45
|
+
"post": {
|
|
46
|
+
"tags": ["storages"],
|
|
47
|
+
"description": "",
|
|
48
|
+
"parameters": [],
|
|
49
|
+
"responses": {
|
|
50
|
+
"200": {
|
|
51
|
+
"description": "OK"
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"/storages:update": {
|
|
57
|
+
"post": {
|
|
58
|
+
"tags": ["storages"],
|
|
59
|
+
"description": "",
|
|
60
|
+
"parameters": [],
|
|
61
|
+
"responses": {
|
|
62
|
+
"200": {
|
|
63
|
+
"description": "OK"
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
"/storages:destroy": {
|
|
69
|
+
"post": {
|
|
70
|
+
"tags": ["storages"],
|
|
71
|
+
"description": "",
|
|
72
|
+
"parameters": [],
|
|
73
|
+
"responses": {
|
|
74
|
+
"200": {
|
|
75
|
+
"description": "OK"
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/plugin-file-manager",
|
|
3
|
-
"version": "0.13.0-alpha.
|
|
3
|
+
"version": "0.13.0-alpha.6",
|
|
4
4
|
"displayName": "File manager",
|
|
5
5
|
"displayName.zh-CN": "文件管理器",
|
|
6
6
|
"description": "file management plugin.",
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"@nocobase/test": "0.x",
|
|
38
38
|
"@nocobase/utils": "0.x"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "49ef71c8bdaab986f47c8a84bcf15e2123ba9b59"
|
|
41
41
|
}
|