@nocobase/plugin-file-manager 1.0.0-alpha.9 → 1.0.1-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/dist/client/FileSizeField.d.ts +10 -0
- package/dist/client/hooks/index.d.ts +1 -0
- package/dist/client/hooks/useStorageRules.d.ts +14 -0
- package/dist/client/hooks/useUploadFiles.d.ts +1 -5
- package/dist/client/index.js +1 -1
- package/dist/client/interfaces/attachment.d.ts +4 -2
- package/dist/client/schemas/storageTypes/ali-oss.d.ts +28 -1
- package/dist/client/schemas/storageTypes/common.d.ts +68 -0
- package/dist/client/schemas/storageTypes/index.d.ts +107 -1
- package/dist/client/schemas/storageTypes/local.d.ts +25 -0
- package/dist/client/schemas/storageTypes/s3.d.ts +27 -0
- package/dist/client/schemas/storageTypes/tx-cos.d.ts +27 -0
- package/dist/client/templates/file.d.ts +3 -3
- package/dist/{server/constants.d.ts → constants.d.ts} +3 -1
- package/dist/{server/constants.js → constants.js} +9 -3
- package/dist/externalVersion.js +7 -7
- package/dist/locale/zh-CN.json +10 -2
- package/dist/node_modules/@aws-sdk/client-s3/package.json +1 -1
- package/dist/node_modules/mime-match/package.json +1 -1
- package/dist/node_modules/mkdirp/package.json +1 -1
- package/dist/node_modules/multer-aliyun-oss/package.json +1 -1
- package/dist/node_modules/multer-cos/package.json +1 -1
- package/dist/node_modules/multer-s3/package.json +1 -1
- package/dist/server/FileModel.js +1 -5
- package/dist/server/actions/attachments.js +14 -9
- package/dist/server/actions/index.js +5 -0
- package/dist/server/actions/storages.d.ts +1 -0
- package/dist/server/actions/storages.js +62 -0
- package/dist/server/collections/attachments.js +1 -0
- package/dist/server/index.d.ts +1 -1
- package/dist/server/index.js +2 -2
- package/dist/server/interfaces/attachment-interface.d.ts +18 -0
- package/dist/server/interfaces/attachment-interface.js +63 -0
- package/dist/server/migrations/20240523152854-change-attachment-field-props.d.ts +14 -0
- package/dist/server/migrations/20240523152854-change-attachment-field-props.js +65 -0
- package/dist/server/rules/mimetype.js +5 -1
- package/dist/server/server.d.ts +5 -2
- package/dist/server/server.js +31 -23
- package/dist/server/storages/ali-oss.d.ts +3 -4
- package/dist/server/storages/ali-oss.js +8 -10
- package/dist/server/storages/index.d.ts +11 -8
- package/dist/server/storages/index.js +3 -27
- package/dist/server/storages/local.d.ts +6 -4
- package/dist/server/storages/local.js +9 -5
- package/dist/server/storages/s3.d.ts +3 -4
- package/dist/server/storages/s3.js +9 -11
- package/dist/server/storages/tx-cos.d.ts +3 -4
- package/dist/server/storages/tx-cos.js +15 -14
- package/dist/server/utils.d.ts +1 -0
- package/dist/server/utils.js +6 -1
- package/package.json +2 -2
package/dist/server/server.js
CHANGED
|
@@ -36,33 +36,37 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
36
36
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
37
37
|
var server_exports = {};
|
|
38
38
|
__export(server_exports, {
|
|
39
|
-
default: () => PluginFileManagerServer
|
|
40
|
-
storageTypes: () => import_storages2.default
|
|
39
|
+
default: () => PluginFileManagerServer
|
|
41
40
|
});
|
|
42
41
|
module.exports = __toCommonJS(server_exports);
|
|
43
|
-
var import_server = require("@nocobase/server");
|
|
44
42
|
var import_path = require("path");
|
|
43
|
+
var import_server = require("@nocobase/server");
|
|
44
|
+
var import_utils = require("@nocobase/utils");
|
|
45
45
|
var import_FileModel = require("./FileModel");
|
|
46
46
|
var import_actions = __toESM(require("./actions"));
|
|
47
|
-
var
|
|
48
|
-
var
|
|
47
|
+
var import_constants = require("../constants");
|
|
48
|
+
var import_local = __toESM(require("./storages/local"));
|
|
49
|
+
var import_ali_oss = __toESM(require("./storages/ali-oss"));
|
|
50
|
+
var import_s3 = __toESM(require("./storages/s3"));
|
|
51
|
+
var import_tx_cos = __toESM(require("./storages/tx-cos"));
|
|
52
|
+
var import_attachment_interface = require("./interfaces/attachment-interface");
|
|
53
|
+
const DEFAULT_STORAGE_TYPE = import_constants.STORAGE_TYPE_LOCAL;
|
|
49
54
|
class PluginFileManagerServer extends import_server.Plugin {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
55
|
+
storageTypes = new import_utils.Registry();
|
|
56
|
+
storagesCache = /* @__PURE__ */ new Map();
|
|
53
57
|
async loadStorages(options) {
|
|
54
58
|
const repository = this.db.getRepository("storages");
|
|
55
59
|
const storages = await repository.find({
|
|
56
60
|
transaction: options == null ? void 0 : options.transaction
|
|
57
61
|
});
|
|
58
|
-
|
|
62
|
+
this.storagesCache = /* @__PURE__ */ new Map();
|
|
59
63
|
for (const storage of storages) {
|
|
60
|
-
|
|
64
|
+
this.storagesCache.set(storage.get("id"), storage.toJSON());
|
|
61
65
|
}
|
|
62
|
-
this.db["_fileStorages"] =
|
|
66
|
+
this.db["_fileStorages"] = this.storagesCache;
|
|
63
67
|
}
|
|
64
68
|
async install() {
|
|
65
|
-
const defaultStorageConfig =
|
|
69
|
+
const defaultStorageConfig = this.storageTypes.get(DEFAULT_STORAGE_TYPE);
|
|
66
70
|
if (defaultStorageConfig) {
|
|
67
71
|
const Storage = this.db.getCollection("storages");
|
|
68
72
|
if (await Storage.repository.findOne({
|
|
@@ -75,7 +79,7 @@ class PluginFileManagerServer extends import_server.Plugin {
|
|
|
75
79
|
await Storage.repository.create({
|
|
76
80
|
values: {
|
|
77
81
|
...defaultStorageConfig.defaults(),
|
|
78
|
-
type:
|
|
82
|
+
type: DEFAULT_STORAGE_TYPE,
|
|
79
83
|
default: true
|
|
80
84
|
}
|
|
81
85
|
});
|
|
@@ -93,13 +97,19 @@ class PluginFileManagerServer extends import_server.Plugin {
|
|
|
93
97
|
});
|
|
94
98
|
}
|
|
95
99
|
async load() {
|
|
96
|
-
|
|
100
|
+
this.storageTypes.register(import_constants.STORAGE_TYPE_LOCAL, new import_local.default());
|
|
101
|
+
this.storageTypes.register(import_constants.STORAGE_TYPE_ALI_OSS, new import_ali_oss.default());
|
|
102
|
+
this.storageTypes.register(import_constants.STORAGE_TYPE_S3, new import_s3.default());
|
|
103
|
+
this.storageTypes.register(import_constants.STORAGE_TYPE_TX_COS, new import_tx_cos.default());
|
|
104
|
+
await this.db.import({
|
|
105
|
+
directory: (0, import_path.resolve)(__dirname, "./collections")
|
|
106
|
+
});
|
|
97
107
|
const Storage = this.db.getModel("storages");
|
|
98
|
-
Storage.afterSave(
|
|
99
|
-
|
|
108
|
+
Storage.afterSave((m) => {
|
|
109
|
+
this.storagesCache.set(m.id, m.toJSON());
|
|
100
110
|
});
|
|
101
|
-
Storage.afterDestroy(
|
|
102
|
-
|
|
111
|
+
Storage.afterDestroy((m) => {
|
|
112
|
+
this.storagesCache.delete(m.id);
|
|
103
113
|
});
|
|
104
114
|
this.app.acl.registerSnippet({
|
|
105
115
|
name: `pm.${this.name}.storages`,
|
|
@@ -115,7 +125,8 @@ class PluginFileManagerServer extends import_server.Plugin {
|
|
|
115
125
|
(0, import_actions.default)(this);
|
|
116
126
|
this.app.acl.allow("attachments", "upload", "loggedIn");
|
|
117
127
|
this.app.acl.allow("attachments", "create", "loggedIn");
|
|
118
|
-
|
|
128
|
+
this.app.acl.allow("storages", "getRules", "loggedIn");
|
|
129
|
+
const defaultStorageName = this.storageTypes.get(DEFAULT_STORAGE_TYPE).defaults().name;
|
|
119
130
|
this.app.acl.addFixedParams("storages", "destroy", () => {
|
|
120
131
|
return {
|
|
121
132
|
filter: { "name.$ne": defaultStorageName }
|
|
@@ -131,9 +142,6 @@ class PluginFileManagerServer extends import_server.Plugin {
|
|
|
131
142
|
this.app.acl.addFixedParams("attachments", "update", ownMerger);
|
|
132
143
|
this.app.acl.addFixedParams("attachments", "create", ownMerger);
|
|
133
144
|
this.app.acl.addFixedParams("attachments", "destroy", ownMerger);
|
|
145
|
+
this.app.db.interfaceManager.registerInterfaceType("attachment", import_attachment_interface.AttachmentInterface);
|
|
134
146
|
}
|
|
135
147
|
}
|
|
136
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
137
|
-
0 && (module.exports = {
|
|
138
|
-
storageTypes
|
|
139
|
-
});
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
|
-
import { AttachmentModel } from '.';
|
|
10
|
-
|
|
9
|
+
import { AttachmentModel, StorageType } from '.';
|
|
10
|
+
export default class extends StorageType {
|
|
11
11
|
make(storage: any): any;
|
|
12
12
|
defaults(): {
|
|
13
13
|
title: string;
|
|
@@ -22,5 +22,4 @@ declare const _default: {
|
|
|
22
22
|
};
|
|
23
23
|
};
|
|
24
24
|
delete(storage: any, records: AttachmentModel[]): Promise<[number, AttachmentModel[]]>;
|
|
25
|
-
}
|
|
26
|
-
export default _default;
|
|
25
|
+
}
|
|
@@ -29,16 +29,17 @@ __export(ali_oss_exports, {
|
|
|
29
29
|
default: () => ali_oss_default
|
|
30
30
|
});
|
|
31
31
|
module.exports = __toCommonJS(ali_oss_exports);
|
|
32
|
-
var
|
|
32
|
+
var import__ = require(".");
|
|
33
|
+
var import_constants = require("../../constants");
|
|
33
34
|
var import_utils = require("../utils");
|
|
34
|
-
|
|
35
|
+
class ali_oss_default extends import__.StorageType {
|
|
35
36
|
make(storage) {
|
|
36
37
|
const createAliOssStorage = require("multer-aliyun-oss");
|
|
37
38
|
return new createAliOssStorage({
|
|
38
39
|
config: storage.options,
|
|
39
40
|
filename: (0, import_utils.cloudFilenameGetter)(storage)
|
|
40
41
|
});
|
|
41
|
-
}
|
|
42
|
+
}
|
|
42
43
|
defaults() {
|
|
43
44
|
return {
|
|
44
45
|
title: "\u963F\u91CC\u4E91\u5BF9\u8C61\u5B58\u50A8",
|
|
@@ -52,13 +53,10 @@ var ali_oss_default = {
|
|
|
52
53
|
bucket: process.env.ALI_OSS_BUCKET
|
|
53
54
|
}
|
|
54
55
|
};
|
|
55
|
-
}
|
|
56
|
+
}
|
|
56
57
|
async delete(storage, records) {
|
|
57
58
|
const { client } = this.make(storage);
|
|
58
|
-
const { deleted } = await client.deleteMulti(records.map(
|
|
59
|
-
return [
|
|
60
|
-
deleted.length,
|
|
61
|
-
records.filter((record) => !deleted.find((item) => item.Key === `${record.path}/${record.filename}`))
|
|
62
|
-
];
|
|
59
|
+
const { deleted } = await client.deleteMulti(records.map(import_utils.getFileKey));
|
|
60
|
+
return [deleted.length, records.filter((record) => !deleted.find((item) => item.Key === (0, import_utils.getFileKey)(record)))];
|
|
63
61
|
}
|
|
64
|
-
}
|
|
62
|
+
}
|
|
@@ -8,16 +8,17 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { StorageEngine } from 'multer';
|
|
10
10
|
import Application from '@nocobase/server';
|
|
11
|
-
import { Registry } from '@nocobase/utils';
|
|
12
11
|
export interface StorageModel {
|
|
12
|
+
id?: number;
|
|
13
13
|
title: string;
|
|
14
14
|
type: string;
|
|
15
15
|
name: string;
|
|
16
16
|
baseUrl: string;
|
|
17
|
-
options:
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
options: Record<string, any>;
|
|
18
|
+
rules?: Record<string, any>;
|
|
19
|
+
path?: string;
|
|
20
|
+
default?: boolean;
|
|
21
|
+
paranoid?: boolean;
|
|
21
22
|
}
|
|
22
23
|
export interface AttachmentModel {
|
|
23
24
|
title: string;
|
|
@@ -36,6 +37,8 @@ export interface IStorage {
|
|
|
36
37
|
defaults(): StorageModel;
|
|
37
38
|
delete(storage: StorageModel, records: AttachmentModel[]): Promise<[number, AttachmentModel[]]>;
|
|
38
39
|
}
|
|
39
|
-
declare
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
export declare abstract class StorageType implements IStorage {
|
|
41
|
+
abstract make(storage: StorageModel): StorageEngine;
|
|
42
|
+
abstract defaults(): StorageModel;
|
|
43
|
+
abstract delete(storage: StorageModel, records: AttachmentModel[]): Promise<[number, AttachmentModel[]]>;
|
|
44
|
+
}
|
|
@@ -7,11 +7,9 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
var __create = Object.create;
|
|
11
10
|
var __defProp = Object.defineProperty;
|
|
12
11
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
12
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
15
13
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
14
|
var __export = (target, all) => {
|
|
17
15
|
for (var name in all)
|
|
@@ -25,37 +23,15 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
25
23
|
}
|
|
26
24
|
return to;
|
|
27
25
|
};
|
|
28
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
29
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
30
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
31
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
32
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
33
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
34
|
-
mod
|
|
35
|
-
));
|
|
36
26
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
37
27
|
var storages_exports = {};
|
|
38
28
|
__export(storages_exports, {
|
|
39
|
-
|
|
40
|
-
getStorageConfig: () => getStorageConfig
|
|
29
|
+
StorageType: () => StorageType
|
|
41
30
|
});
|
|
42
31
|
module.exports = __toCommonJS(storages_exports);
|
|
43
|
-
|
|
44
|
-
var import_local = __toESM(require("./local"));
|
|
45
|
-
var import_ali_oss = __toESM(require("./ali-oss"));
|
|
46
|
-
var import_s3 = __toESM(require("./s3"));
|
|
47
|
-
var import_tx_cos = __toESM(require("./tx-cos"));
|
|
48
|
-
var import_constants = require("../constants");
|
|
49
|
-
const storageTypes = new import_utils.Registry();
|
|
50
|
-
storageTypes.register(import_constants.STORAGE_TYPE_LOCAL, import_local.default);
|
|
51
|
-
storageTypes.register(import_constants.STORAGE_TYPE_ALI_OSS, import_ali_oss.default);
|
|
52
|
-
storageTypes.register(import_constants.STORAGE_TYPE_S3, import_s3.default);
|
|
53
|
-
storageTypes.register(import_constants.STORAGE_TYPE_TX_COS, import_tx_cos.default);
|
|
54
|
-
function getStorageConfig(key) {
|
|
55
|
-
return storageTypes.get(key);
|
|
32
|
+
class StorageType {
|
|
56
33
|
}
|
|
57
|
-
var storages_default = storageTypes;
|
|
58
34
|
// Annotate the CommonJS export names for ESM import in node:
|
|
59
35
|
0 && (module.exports = {
|
|
60
|
-
|
|
36
|
+
StorageType
|
|
61
37
|
});
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
import multer from 'multer';
|
|
10
|
-
import { AttachmentModel } from '.';
|
|
11
|
-
|
|
10
|
+
import { AttachmentModel, StorageType } from '.';
|
|
11
|
+
export default class extends StorageType {
|
|
12
12
|
make(storage: any): multer.StorageEngine;
|
|
13
13
|
defaults(): {
|
|
14
14
|
title: string;
|
|
@@ -18,7 +18,9 @@ declare const _default: {
|
|
|
18
18
|
options: {
|
|
19
19
|
documentRoot: string;
|
|
20
20
|
};
|
|
21
|
+
rules: {
|
|
22
|
+
size: number;
|
|
23
|
+
};
|
|
21
24
|
};
|
|
22
25
|
delete(storage: any, records: AttachmentModel[]): Promise<[number, AttachmentModel[]]>;
|
|
23
|
-
}
|
|
24
|
-
export default _default;
|
|
26
|
+
}
|
|
@@ -43,13 +43,14 @@ var import_promises = __toESM(require("fs/promises"));
|
|
|
43
43
|
var import_mkdirp = __toESM(require("mkdirp"));
|
|
44
44
|
var import_multer = __toESM(require("multer"));
|
|
45
45
|
var import_path = __toESM(require("path"));
|
|
46
|
-
var
|
|
46
|
+
var import__ = require(".");
|
|
47
|
+
var import_constants = require("../../constants");
|
|
47
48
|
var import_utils = require("../utils");
|
|
48
49
|
function getDocumentRoot(storage) {
|
|
49
50
|
const { documentRoot = process.env.LOCAL_STORAGE_DEST || "storage/uploads" } = storage.options || {};
|
|
50
51
|
return import_path.default.resolve(import_path.default.isAbsolute(documentRoot) ? documentRoot : import_path.default.join(process.cwd(), documentRoot));
|
|
51
52
|
}
|
|
52
|
-
|
|
53
|
+
class local_default extends import__.StorageType {
|
|
53
54
|
make(storage) {
|
|
54
55
|
return import_multer.default.diskStorage({
|
|
55
56
|
destination: function(req, file, cb) {
|
|
@@ -58,7 +59,7 @@ var local_default = {
|
|
|
58
59
|
},
|
|
59
60
|
filename: import_utils.getFilename
|
|
60
61
|
});
|
|
61
|
-
}
|
|
62
|
+
}
|
|
62
63
|
defaults() {
|
|
63
64
|
return {
|
|
64
65
|
title: "Local storage",
|
|
@@ -67,9 +68,12 @@ var local_default = {
|
|
|
67
68
|
baseUrl: "/storage/uploads",
|
|
68
69
|
options: {
|
|
69
70
|
documentRoot: "storage/uploads"
|
|
71
|
+
},
|
|
72
|
+
rules: {
|
|
73
|
+
size: import_constants.FILE_SIZE_LIMIT_DEFAULT
|
|
70
74
|
}
|
|
71
75
|
};
|
|
72
|
-
}
|
|
76
|
+
}
|
|
73
77
|
async delete(storage, records) {
|
|
74
78
|
const documentRoot = getDocumentRoot(storage);
|
|
75
79
|
let count = 0;
|
|
@@ -93,4 +97,4 @@ var local_default = {
|
|
|
93
97
|
);
|
|
94
98
|
return [count, undeleted];
|
|
95
99
|
}
|
|
96
|
-
}
|
|
100
|
+
}
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
|
-
import { AttachmentModel } from '.';
|
|
10
|
-
|
|
9
|
+
import { AttachmentModel, StorageType } from '.';
|
|
10
|
+
export default class extends StorageType {
|
|
11
11
|
filenameKey: string;
|
|
12
12
|
make(storage: any): any;
|
|
13
13
|
defaults(): {
|
|
@@ -23,5 +23,4 @@ declare const _default: {
|
|
|
23
23
|
};
|
|
24
24
|
};
|
|
25
25
|
delete(storage: any, records: AttachmentModel[]): Promise<[number, AttachmentModel[]]>;
|
|
26
|
-
}
|
|
27
|
-
export default _default;
|
|
26
|
+
}
|
|
@@ -29,10 +29,11 @@ __export(s3_exports, {
|
|
|
29
29
|
default: () => s3_default
|
|
30
30
|
});
|
|
31
31
|
module.exports = __toCommonJS(s3_exports);
|
|
32
|
-
var
|
|
32
|
+
var import__ = require(".");
|
|
33
|
+
var import_constants = require("../../constants");
|
|
33
34
|
var import_utils = require("../utils");
|
|
34
|
-
|
|
35
|
-
filenameKey
|
|
35
|
+
class s3_default extends import__.StorageType {
|
|
36
|
+
filenameKey = "key";
|
|
36
37
|
make(storage) {
|
|
37
38
|
const { S3Client } = require("@aws-sdk/client-s3");
|
|
38
39
|
const multerS3 = require("multer-s3");
|
|
@@ -57,7 +58,7 @@ var s3_default = {
|
|
|
57
58
|
},
|
|
58
59
|
key: (0, import_utils.cloudFilenameGetter)(storage)
|
|
59
60
|
});
|
|
60
|
-
}
|
|
61
|
+
}
|
|
61
62
|
defaults() {
|
|
62
63
|
return {
|
|
63
64
|
title: "AWS S3",
|
|
@@ -71,7 +72,7 @@ var s3_default = {
|
|
|
71
72
|
bucket: process.env.AWS_S3_BUCKET
|
|
72
73
|
}
|
|
73
74
|
};
|
|
74
|
-
}
|
|
75
|
+
}
|
|
75
76
|
async delete(storage, records) {
|
|
76
77
|
const { DeleteObjectsCommand } = require("@aws-sdk/client-s3");
|
|
77
78
|
const { s3 } = this.make(storage);
|
|
@@ -79,13 +80,10 @@ var s3_default = {
|
|
|
79
80
|
new DeleteObjectsCommand({
|
|
80
81
|
Bucket: storage.options.bucket,
|
|
81
82
|
Delete: {
|
|
82
|
-
Objects: records.map((record) => ({ Key:
|
|
83
|
+
Objects: records.map((record) => ({ Key: (0, import_utils.getFileKey)(record) }))
|
|
83
84
|
}
|
|
84
85
|
})
|
|
85
86
|
);
|
|
86
|
-
return [
|
|
87
|
-
Deleted.length,
|
|
88
|
-
records.filter((record) => !Deleted.find((item) => item.Key === `${record.path}/${record.filename}`))
|
|
89
|
-
];
|
|
87
|
+
return [Deleted.length, records.filter((record) => !Deleted.find((item) => item.Key === (0, import_utils.getFileKey)(record)))];
|
|
90
88
|
}
|
|
91
|
-
}
|
|
89
|
+
}
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
|
-
import { AttachmentModel } from '.';
|
|
10
|
-
|
|
9
|
+
import { AttachmentModel, StorageType } from '.';
|
|
10
|
+
export default class extends StorageType {
|
|
11
11
|
filenameKey: string;
|
|
12
12
|
make(storage: any): any;
|
|
13
13
|
defaults(): {
|
|
@@ -23,5 +23,4 @@ declare const _default: {
|
|
|
23
23
|
};
|
|
24
24
|
};
|
|
25
25
|
delete(storage: any, records: AttachmentModel[]): Promise<[number, AttachmentModel[]]>;
|
|
26
|
-
}
|
|
27
|
-
export default _default;
|
|
26
|
+
}
|
|
@@ -30,17 +30,21 @@ __export(tx_cos_exports, {
|
|
|
30
30
|
});
|
|
31
31
|
module.exports = __toCommonJS(tx_cos_exports);
|
|
32
32
|
var import_util = require("util");
|
|
33
|
-
var
|
|
33
|
+
var import__ = require(".");
|
|
34
|
+
var import_constants = require("../../constants");
|
|
34
35
|
var import_utils = require("../utils");
|
|
35
|
-
|
|
36
|
-
filenameKey
|
|
36
|
+
class tx_cos_default extends import__.StorageType {
|
|
37
|
+
filenameKey = "url";
|
|
37
38
|
make(storage) {
|
|
38
39
|
const createTxCosStorage = require("multer-cos");
|
|
39
40
|
return new createTxCosStorage({
|
|
40
|
-
cos:
|
|
41
|
-
|
|
41
|
+
cos: {
|
|
42
|
+
...storage.options,
|
|
43
|
+
dir: (storage.path ?? "").replace(/\/+$/, "")
|
|
44
|
+
},
|
|
45
|
+
filename: import_utils.getFilename
|
|
42
46
|
});
|
|
43
|
-
}
|
|
47
|
+
}
|
|
44
48
|
defaults() {
|
|
45
49
|
return {
|
|
46
50
|
title: "\u817E\u8BAF\u4E91\u5BF9\u8C61\u5B58\u50A8",
|
|
@@ -54,17 +58,14 @@ var tx_cos_default = {
|
|
|
54
58
|
Bucket: process.env.TX_COS_BUCKET
|
|
55
59
|
}
|
|
56
60
|
};
|
|
57
|
-
}
|
|
61
|
+
}
|
|
58
62
|
async delete(storage, records) {
|
|
59
63
|
const { cos } = this.make(storage);
|
|
60
|
-
const { Deleted } = await (0, import_util.promisify)(cos.deleteMultipleObject)({
|
|
64
|
+
const { Deleted } = await (0, import_util.promisify)(cos.deleteMultipleObject).call(cos, {
|
|
61
65
|
Region: storage.options.Region,
|
|
62
66
|
Bucket: storage.options.Bucket,
|
|
63
|
-
Objects: records.map((record) => ({ Key:
|
|
67
|
+
Objects: records.map((record) => ({ Key: (0, import_utils.getFileKey)(record) }))
|
|
64
68
|
});
|
|
65
|
-
return [
|
|
66
|
-
Deleted.length,
|
|
67
|
-
records.filter((record) => !Deleted.find((item) => item.Key === `${record.path}/${record.filename}`))
|
|
68
|
-
];
|
|
69
|
+
return [Deleted.length, records.filter((record) => !Deleted.find((item) => item.Key === (0, import_utils.getFileKey)(record)))];
|
|
69
70
|
}
|
|
70
|
-
}
|
|
71
|
+
}
|
package/dist/server/utils.d.ts
CHANGED
package/dist/server/utils.js
CHANGED
|
@@ -37,6 +37,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
37
37
|
var utils_exports = {};
|
|
38
38
|
__export(utils_exports, {
|
|
39
39
|
cloudFilenameGetter: () => cloudFilenameGetter,
|
|
40
|
+
getFileKey: () => getFileKey,
|
|
40
41
|
getFilename: () => getFilename
|
|
41
42
|
});
|
|
42
43
|
module.exports = __toCommonJS(utils_exports);
|
|
@@ -52,11 +53,15 @@ const cloudFilenameGetter = (storage) => (req, file, cb) => {
|
|
|
52
53
|
if (err) {
|
|
53
54
|
return cb(err);
|
|
54
55
|
}
|
|
55
|
-
cb(null, `${storage.path ? `${storage.path}/` : ""}${filename}`);
|
|
56
|
+
cb(null, `${storage.path ? `${storage.path.replace(/\/+$/, "")}/` : ""}${filename}`);
|
|
56
57
|
});
|
|
57
58
|
};
|
|
59
|
+
function getFileKey(record) {
|
|
60
|
+
return [record.path.replace(/^\/|\/$/g, ""), record.filename].filter(Boolean).join("/");
|
|
61
|
+
}
|
|
58
62
|
// Annotate the CommonJS export names for ESM import in node:
|
|
59
63
|
0 && (module.exports = {
|
|
60
64
|
cloudFilenameGetter,
|
|
65
|
+
getFileKey,
|
|
61
66
|
getFilename
|
|
62
67
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/plugin-file-manager",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1-alpha.1",
|
|
4
4
|
"displayName": "File manager",
|
|
5
5
|
"displayName.zh-CN": "文件管理器",
|
|
6
6
|
"description": "Provides files storage services with files collection template and attachment field.",
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"Collections",
|
|
44
44
|
"Collection fields"
|
|
45
45
|
],
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "d24aa16987a4068f857ae073fcce18f3cb490660"
|
|
47
47
|
}
|