@nocobase/plugin-file-manager 2.1.0-alpha.40 → 2.1.0-alpha.46
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/867ada653cd02a3e.mjs +6 -0
- package/dist/client/876.ca16d7a6e6387862.js +11 -0
- package/dist/client/index.js +1 -1
- package/dist/client/locale/index.d.ts +1 -1
- package/dist/client/previewer/filePreviewTypes.d.ts +1 -1
- package/dist/client/templates/file.d.ts +1 -1
- package/dist/client-v2/125.0b8eef1f19b87042.js +10 -0
- package/dist/client-v2/867ada653cd02a3e.mjs +6 -0
- package/dist/client-v2/876.22cd8e41ac8631ed.js +11 -0
- package/dist/client-v2/{942.9dc2d49980a4dd9e.js → 942.f36d807d763a1b53.js} +1 -1
- package/dist/client-v2/index.d.ts +2 -0
- package/dist/client-v2/index.js +1 -1
- package/dist/{shared → client-v2}/previewer/filePreviewTypes.d.ts +4 -0
- package/dist/externalVersion.js +9 -9
- package/dist/locale/de-DE.json +3 -0
- package/dist/locale/en-US.json +3 -0
- package/dist/locale/es-ES.json +3 -0
- package/dist/locale/fr-FR.json +3 -0
- package/dist/locale/hu-HU.json +4 -1
- package/dist/locale/id-ID.json +4 -1
- package/dist/locale/it-IT.json +3 -0
- package/dist/locale/ja-JP.json +3 -0
- package/dist/locale/ko-KR.json +3 -0
- package/dist/locale/nl-NL.json +3 -0
- package/dist/locale/pt-BR.json +3 -0
- package/dist/locale/ru-RU.json +3 -0
- package/dist/locale/tr-TR.json +3 -0
- package/dist/locale/uk-UA.json +3 -0
- package/dist/locale/vi-VN.json +4 -1
- package/dist/locale/zh-CN.json +3 -0
- package/dist/locale/zh-TW.json +3 -0
- package/dist/node_modules/@aws-sdk/client-s3/package.json +1 -1
- package/dist/node_modules/@aws-sdk/lib-storage/package.json +1 -1
- package/dist/node_modules/ali-oss/package.json +1 -1
- package/dist/node_modules/cos-nodejs-sdk-v5/package.json +1 -1
- package/dist/node_modules/mime-match/package.json +1 -1
- package/dist/node_modules/mime-types/package.json +1 -1
- package/dist/node_modules/mkdirp/package.json +1 -1
- package/dist/node_modules/url-join/package.json +1 -1
- package/dist/server/actions/attachments.js +2 -2
- package/dist/server/actions/index.js +8 -1
- package/dist/{shared/locale.d.ts → server/actions/storage-validation.d.ts} +2 -1
- package/dist/server/actions/storage-validation.js +73 -0
- package/dist/server/commands/repair-filenames.d.ts +55 -0
- package/dist/server/commands/repair-filenames.js +283 -0
- package/dist/server/server.d.ts +1 -0
- package/dist/server/server.js +7 -0
- package/dist/server/storages/ali-oss.d.ts +3 -1
- package/dist/server/storages/ali-oss.js +23 -2
- package/dist/server/storages/index.d.ts +3 -0
- package/dist/server/storages/index.js +6 -0
- package/dist/server/storages/local.d.ts +6 -0
- package/dist/server/storages/local.js +74 -13
- package/dist/server/storages/s3.d.ts +2 -0
- package/dist/server/storages/s3.js +26 -0
- package/dist/server/storages/tx-cos.d.ts +2 -0
- package/dist/server/storages/tx-cos.js +27 -0
- package/dist/server/utils.js +12 -2
- package/package.json +4 -2
- package/dist/client-v2/125.01d5562df948d974.js +0 -10
- package/dist/shared/locale.js +0 -36
- package/dist/shared/previewer/filePreviewTypes.js +0 -459
package/dist/server/server.d.ts
CHANGED
|
@@ -27,6 +27,7 @@ export type UploadFileOptions = {
|
|
|
27
27
|
export declare class PluginFileManagerServer extends Plugin {
|
|
28
28
|
storageTypes: Registry<StorageClassType>;
|
|
29
29
|
storagesCache: Map<string | number, StorageModel>;
|
|
30
|
+
static staticImport(): Promise<void>;
|
|
30
31
|
afterDestroy: (record: Model, options: any) => Promise<void>;
|
|
31
32
|
registerStorageType(type: string, Type: StorageClassType): void;
|
|
32
33
|
createFileRecord(options: FileRecordOptions): Promise<any>;
|
package/dist/server/server.js
CHANGED
|
@@ -54,6 +54,7 @@ var import_local = __toESM(require("./storages/local"));
|
|
|
54
54
|
var import_s3 = __toESM(require("./storages/s3"));
|
|
55
55
|
var import_tx_cos = __toESM(require("./storages/tx-cos"));
|
|
56
56
|
var import_utils2 = require("./utils");
|
|
57
|
+
var import_repair_filenames = require("./commands/repair-filenames");
|
|
57
58
|
const DEFAULT_STORAGE_TYPE = import_constants.STORAGE_TYPE_LOCAL;
|
|
58
59
|
class FileDeleteError extends Error {
|
|
59
60
|
data;
|
|
@@ -66,6 +67,9 @@ class FileDeleteError extends Error {
|
|
|
66
67
|
class PluginFileManagerServer extends import_server.Plugin {
|
|
67
68
|
storageTypes = new import_utils.Registry();
|
|
68
69
|
storagesCache = /* @__PURE__ */ new Map();
|
|
70
|
+
static async staticImport() {
|
|
71
|
+
import_server.Application.addCommand(import_repair_filenames.registerRepairFilenamesCommand);
|
|
72
|
+
}
|
|
69
73
|
afterDestroy = async (record, options) => {
|
|
70
74
|
var _a;
|
|
71
75
|
const { collection } = record.constructor;
|
|
@@ -212,6 +216,9 @@ class PluginFileManagerServer extends import_server.Plugin {
|
|
|
212
216
|
this.storageTypes.register(import_constants.STORAGE_TYPE_S3, import_s3.default);
|
|
213
217
|
this.storageTypes.register(import_constants.STORAGE_TYPE_TX_COS, import_tx_cos.default);
|
|
214
218
|
const Storage = this.db.getModel("storages");
|
|
219
|
+
Storage.beforeSave((m) => {
|
|
220
|
+
(0, import_local.validateLocalStorageConfig)(m.toJSON());
|
|
221
|
+
});
|
|
215
222
|
Storage.afterSave(async (m, { transaction }) => {
|
|
216
223
|
await this.loadStorages({ transaction });
|
|
217
224
|
this.sendSyncMessage({ type: "reloadStorages" }, { transaction });
|
|
@@ -18,7 +18,7 @@ declare class AliYunOssStorage {
|
|
|
18
18
|
filename?: typeof getRandomFilename;
|
|
19
19
|
});
|
|
20
20
|
_handleFile(req: any, file: any, cb: any): any;
|
|
21
|
-
_removeFile(req: any, file: any, cb: any): any
|
|
21
|
+
_removeFile(req: any, file: any, cb: any): Promise<any>;
|
|
22
22
|
}
|
|
23
23
|
export default class extends StorageType {
|
|
24
24
|
static defaults(): {
|
|
@@ -34,6 +34,8 @@ export default class extends StorageType {
|
|
|
34
34
|
};
|
|
35
35
|
};
|
|
36
36
|
make(): AliYunOssStorage;
|
|
37
|
+
exists(record: AttachmentModel): Promise<boolean>;
|
|
38
|
+
copy(source: AttachmentModel, target: AttachmentModel): Promise<void>;
|
|
37
39
|
delete(records: AttachmentModel[]): Promise<[number, AttachmentModel[]]>;
|
|
38
40
|
}
|
|
39
41
|
export {};
|
|
@@ -90,11 +90,16 @@ class AliYunOssStorage {
|
|
|
90
90
|
});
|
|
91
91
|
}).catch(cb);
|
|
92
92
|
}
|
|
93
|
-
_removeFile(req, file, cb) {
|
|
93
|
+
async _removeFile(req, file, cb) {
|
|
94
94
|
if (!this.client) {
|
|
95
95
|
return cb(ERROR_NO_CLIENT);
|
|
96
96
|
}
|
|
97
|
-
|
|
97
|
+
try {
|
|
98
|
+
const result = await this.client.delete(file.filename);
|
|
99
|
+
cb(null, result);
|
|
100
|
+
} catch (error) {
|
|
101
|
+
cb(error);
|
|
102
|
+
}
|
|
98
103
|
}
|
|
99
104
|
}
|
|
100
105
|
class ali_oss_default extends import__.StorageType {
|
|
@@ -118,6 +123,22 @@ class ali_oss_default extends import__.StorageType {
|
|
|
118
123
|
filename: (0, import_utils.cloudFilenameGetter)(this.storage)
|
|
119
124
|
});
|
|
120
125
|
}
|
|
126
|
+
async exists(record) {
|
|
127
|
+
const { client } = this.make();
|
|
128
|
+
try {
|
|
129
|
+
await client.head((0, import_utils.getFileKey)(record));
|
|
130
|
+
return true;
|
|
131
|
+
} catch (error) {
|
|
132
|
+
if (["NoSuchKey", "NotFoundError"].includes(error.name)) {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
throw error;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
async copy(source, target) {
|
|
139
|
+
const { client } = this.make();
|
|
140
|
+
await client.copy((0, import_utils.getFileKey)(target), (0, import_utils.getFileKey)(source));
|
|
141
|
+
}
|
|
121
142
|
async delete(records) {
|
|
122
143
|
const { client } = this.make();
|
|
123
144
|
const { deleted } = await client.deleteMulti(records.map(import_utils.getFileKey));
|
|
@@ -24,6 +24,7 @@ export interface StorageModel {
|
|
|
24
24
|
settings?: Record<string, any>;
|
|
25
25
|
}
|
|
26
26
|
export interface AttachmentModel {
|
|
27
|
+
id?: number;
|
|
27
28
|
title: string;
|
|
28
29
|
filename: string;
|
|
29
30
|
mimetype?: string;
|
|
@@ -38,6 +39,8 @@ export declare abstract class StorageType {
|
|
|
38
39
|
constructor(storage: StorageModel);
|
|
39
40
|
abstract make(): StorageEngine;
|
|
40
41
|
abstract delete(records: AttachmentModel[]): [number, AttachmentModel[]] | Promise<[number, AttachmentModel[]]>;
|
|
42
|
+
exists(record: AttachmentModel): Promise<boolean>;
|
|
43
|
+
copy(source: AttachmentModel, target: AttachmentModel): Promise<void>;
|
|
41
44
|
getFileKey(record: AttachmentModel): any;
|
|
42
45
|
getFileData(file: any, meta?: {}): {
|
|
43
46
|
title: string;
|
|
@@ -52,6 +52,12 @@ class StorageType {
|
|
|
52
52
|
return {};
|
|
53
53
|
}
|
|
54
54
|
static filenameKey;
|
|
55
|
+
async exists(record) {
|
|
56
|
+
throw new Error(`Storage type "${this.storage.type}" does not support object existence checks`);
|
|
57
|
+
}
|
|
58
|
+
async copy(source, target) {
|
|
59
|
+
throw new Error(`Storage type "${this.storage.type}" does not support object copy`);
|
|
60
|
+
}
|
|
55
61
|
getFileKey(record) {
|
|
56
62
|
return (0, import_utils2.getFileKey)(record);
|
|
57
63
|
}
|
|
@@ -10,8 +10,12 @@
|
|
|
10
10
|
import multer from 'multer';
|
|
11
11
|
import type { Readable } from 'stream';
|
|
12
12
|
import { AttachmentModel, StorageType } from '.';
|
|
13
|
+
export declare function normalizeLocalStoragePath(storagePath?: unknown): string;
|
|
13
14
|
export declare function getDocumentRoot(storage: any): string;
|
|
14
15
|
export declare function resolveSafePath(documentRoot: string, filePath?: string, filename?: string): string;
|
|
16
|
+
export declare function validateLocalStorageConfig(storage: Pick<StorageType['storage'], 'type' | 'options' | 'path'>, { validateDocumentRoot }?: {
|
|
17
|
+
validateDocumentRoot?: boolean;
|
|
18
|
+
}): void;
|
|
15
19
|
export default class extends StorageType {
|
|
16
20
|
static defaults(): {
|
|
17
21
|
title: string;
|
|
@@ -27,6 +31,8 @@ export default class extends StorageType {
|
|
|
27
31
|
};
|
|
28
32
|
};
|
|
29
33
|
make(): multer.StorageEngine;
|
|
34
|
+
exists(record: AttachmentModel): Promise<boolean>;
|
|
35
|
+
copy(source: AttachmentModel, target: AttachmentModel): Promise<void>;
|
|
30
36
|
delete(records: AttachmentModel[]): Promise<[number, AttachmentModel[]]>;
|
|
31
37
|
getFileURL(file: AttachmentModel, preview?: boolean): Promise<any>;
|
|
32
38
|
getFileStream(file: AttachmentModel): Promise<{
|
|
@@ -38,7 +38,9 @@ var local_exports = {};
|
|
|
38
38
|
__export(local_exports, {
|
|
39
39
|
default: () => local_default,
|
|
40
40
|
getDocumentRoot: () => getDocumentRoot,
|
|
41
|
-
|
|
41
|
+
normalizeLocalStoragePath: () => normalizeLocalStoragePath,
|
|
42
|
+
resolveSafePath: () => resolveSafePath,
|
|
43
|
+
validateLocalStorageConfig: () => validateLocalStorageConfig
|
|
42
44
|
});
|
|
43
45
|
module.exports = __toCommonJS(local_exports);
|
|
44
46
|
var import_utils = require("@nocobase/utils");
|
|
@@ -51,25 +53,64 @@ var import__ = require(".");
|
|
|
51
53
|
var import_constants = require("../../constants");
|
|
52
54
|
var import_utils2 = require("../utils");
|
|
53
55
|
const DEFAULT_BASE_URL = "/storage/uploads";
|
|
56
|
+
function pathError(message) {
|
|
57
|
+
const error = new Error(message);
|
|
58
|
+
error.code = "PATH_TRAVERSAL";
|
|
59
|
+
return error;
|
|
60
|
+
}
|
|
61
|
+
function isInside(base, target) {
|
|
62
|
+
const relative = import_path.default.relative(base, target);
|
|
63
|
+
return !relative.startsWith("..") && !import_path.default.isAbsolute(relative);
|
|
64
|
+
}
|
|
65
|
+
function resolveDocumentRoot(documentRoot) {
|
|
66
|
+
if (typeof documentRoot !== "string" || !documentRoot || documentRoot.includes("\0")) {
|
|
67
|
+
throw pathError("Invalid local storage document root");
|
|
68
|
+
}
|
|
69
|
+
return (0, import_utils2.normalizeDocumentRoot)(documentRoot);
|
|
70
|
+
}
|
|
71
|
+
function allowedRoots() {
|
|
72
|
+
var _a;
|
|
73
|
+
const roots = [(0, import_utils.storagePathJoin)()];
|
|
74
|
+
const extra = [process.env.LOCAL_STORAGE_DEST, ...((_a = process.env.LOCAL_STORAGE_ALLOWED_ROOTS) == null ? void 0 : _a.split(",")) ?? []];
|
|
75
|
+
for (const item of extra) {
|
|
76
|
+
if (item == null ? void 0 : item.trim()) {
|
|
77
|
+
roots.push(resolveDocumentRoot(item.trim()));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return roots;
|
|
81
|
+
}
|
|
82
|
+
function normalizeLocalStoragePath(storagePath) {
|
|
83
|
+
if (storagePath == null || storagePath === "") {
|
|
84
|
+
return "";
|
|
85
|
+
}
|
|
86
|
+
if (typeof storagePath !== "string" || storagePath.includes("\0")) {
|
|
87
|
+
throw pathError("Invalid local storage path");
|
|
88
|
+
}
|
|
89
|
+
return storagePath.replace(/\\/g, "/").replace(/^\/+/, "");
|
|
90
|
+
}
|
|
54
91
|
function getDocumentRoot(storage) {
|
|
55
92
|
var _a;
|
|
56
93
|
const raw = ((_a = storage == null ? void 0 : storage.options) == null ? void 0 : _a.documentRoot) ?? process.env.LOCAL_STORAGE_DEST ?? (0, import_utils.storagePathJoin)("uploads");
|
|
57
|
-
|
|
58
|
-
return raw;
|
|
59
|
-
}
|
|
60
|
-
return (0, import_utils2.normalizeDocumentRoot)(raw);
|
|
94
|
+
return resolveDocumentRoot(raw);
|
|
61
95
|
}
|
|
62
96
|
function resolveSafePath(documentRoot, filePath, filename) {
|
|
63
|
-
const root = (
|
|
97
|
+
const root = resolveDocumentRoot(documentRoot);
|
|
64
98
|
const target = import_path.default.resolve(root, filePath || "", filename || "");
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const error = new Error("Access denied");
|
|
68
|
-
error.code = "PATH_TRAVERSAL";
|
|
69
|
-
throw error;
|
|
99
|
+
if (!isInside(root, target)) {
|
|
100
|
+
throw pathError("Access denied");
|
|
70
101
|
}
|
|
71
102
|
return target;
|
|
72
103
|
}
|
|
104
|
+
function validateLocalStorageConfig(storage, { validateDocumentRoot = false } = {}) {
|
|
105
|
+
if (storage.type !== import_constants.STORAGE_TYPE_LOCAL) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const root = getDocumentRoot(storage);
|
|
109
|
+
if (validateDocumentRoot && !allowedRoots().some((allowed) => isInside(allowed, root))) {
|
|
110
|
+
throw pathError("Invalid local storage document root");
|
|
111
|
+
}
|
|
112
|
+
resolveSafePath(root, normalizeLocalStoragePath(storage.path));
|
|
113
|
+
}
|
|
73
114
|
class local_default extends import__.StorageType {
|
|
74
115
|
static defaults() {
|
|
75
116
|
return {
|
|
@@ -89,13 +130,31 @@ class local_default extends import__.StorageType {
|
|
|
89
130
|
make() {
|
|
90
131
|
return import_multer.default.diskStorage({
|
|
91
132
|
destination: (req, file, cb) => {
|
|
92
|
-
const destPath =
|
|
133
|
+
const destPath = resolveSafePath(getDocumentRoot(this.storage), normalizeLocalStoragePath(this.storage.path));
|
|
93
134
|
const mkdirp = require("mkdirp");
|
|
94
135
|
mkdirp(destPath, (err) => cb(err, destPath));
|
|
95
136
|
},
|
|
96
137
|
filename: (0, import_utils2.diskFilenameGetter)(this.storage)
|
|
97
138
|
});
|
|
98
139
|
}
|
|
140
|
+
async exists(record) {
|
|
141
|
+
try {
|
|
142
|
+
await import_promises.default.stat(resolveSafePath(getDocumentRoot(this.storage), record.path, record.filename));
|
|
143
|
+
return true;
|
|
144
|
+
} catch (error) {
|
|
145
|
+
if (error.code === "ENOENT") {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
throw error;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
async copy(source, target) {
|
|
152
|
+
const documentRoot = getDocumentRoot(this.storage);
|
|
153
|
+
const sourcePath = resolveSafePath(documentRoot, source.path, source.filename);
|
|
154
|
+
const targetPath = resolveSafePath(documentRoot, target.path, target.filename);
|
|
155
|
+
await import_promises.default.mkdir(import_path.default.dirname(targetPath), { recursive: true });
|
|
156
|
+
await import_promises.default.copyFile(sourcePath, targetPath);
|
|
157
|
+
}
|
|
99
158
|
async delete(records) {
|
|
100
159
|
const documentRoot = getDocumentRoot(this.storage);
|
|
101
160
|
let count = 0;
|
|
@@ -144,5 +203,7 @@ class local_default extends import__.StorageType {
|
|
|
144
203
|
// Annotate the CommonJS export names for ESM import in node:
|
|
145
204
|
0 && (module.exports = {
|
|
146
205
|
getDocumentRoot,
|
|
147
|
-
|
|
206
|
+
normalizeLocalStoragePath,
|
|
207
|
+
resolveSafePath,
|
|
208
|
+
validateLocalStorageConfig
|
|
148
209
|
});
|
|
@@ -32,5 +32,7 @@ export default class extends StorageType {
|
|
|
32
32
|
deleteS3Objects(bucketName: string, objects: string[]): Promise<{
|
|
33
33
|
Deleted: any[];
|
|
34
34
|
}>;
|
|
35
|
+
exists(record: AttachmentModel): Promise<boolean>;
|
|
36
|
+
copy(source: AttachmentModel, target: AttachmentModel): Promise<void>;
|
|
35
37
|
delete(records: AttachmentModel[]): Promise<[number, AttachmentModel[]]>;
|
|
36
38
|
}
|
|
@@ -173,6 +173,32 @@ class s3_default extends import__.StorageType {
|
|
|
173
173
|
Deleted
|
|
174
174
|
};
|
|
175
175
|
}
|
|
176
|
+
async exists(record) {
|
|
177
|
+
try {
|
|
178
|
+
await this.client.send(
|
|
179
|
+
new import_client_s3.HeadObjectCommand({
|
|
180
|
+
Bucket: this.storage.options.bucket,
|
|
181
|
+
Key: this.getFileKey(record)
|
|
182
|
+
})
|
|
183
|
+
);
|
|
184
|
+
return true;
|
|
185
|
+
} catch (error) {
|
|
186
|
+
if (["NotFound", "NoSuchKey", "NoSuchBucket"].includes(error.name)) {
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
throw error;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
async copy(source, target) {
|
|
193
|
+
const sourceKey = this.getFileKey(source);
|
|
194
|
+
await this.client.send(
|
|
195
|
+
new import_client_s3.CopyObjectCommand({
|
|
196
|
+
Bucket: this.storage.options.bucket,
|
|
197
|
+
Key: this.getFileKey(target),
|
|
198
|
+
CopySource: `${this.storage.options.bucket}/${sourceKey.split("/").map((segment) => encodeURIComponent(segment)).join("/")}`
|
|
199
|
+
})
|
|
200
|
+
);
|
|
201
|
+
}
|
|
176
202
|
async delete(records) {
|
|
177
203
|
const { Deleted } = await this.deleteS3Objects(
|
|
178
204
|
this.storage.options.bucket,
|
|
@@ -36,6 +36,8 @@ export default class extends StorageType {
|
|
|
36
36
|
};
|
|
37
37
|
static filenameKey: string;
|
|
38
38
|
make(): TxCosStorage;
|
|
39
|
+
exists(record: AttachmentModel): Promise<boolean>;
|
|
40
|
+
copy(source: AttachmentModel, target: AttachmentModel): Promise<void>;
|
|
39
41
|
delete(records: AttachmentModel[]): Promise<[number, AttachmentModel[]]>;
|
|
40
42
|
}
|
|
41
43
|
export {};
|
|
@@ -160,6 +160,33 @@ class tx_cos_default extends import__.StorageType {
|
|
|
160
160
|
filename: (0, import_utils.cloudFilenameGetter)(this.storage)
|
|
161
161
|
});
|
|
162
162
|
}
|
|
163
|
+
async exists(record) {
|
|
164
|
+
const { cos } = this.make();
|
|
165
|
+
try {
|
|
166
|
+
await (0, import_util.promisify)(cos.headObject).call(cos, {
|
|
167
|
+
Region: this.storage.options.Region,
|
|
168
|
+
Bucket: this.storage.options.Bucket,
|
|
169
|
+
Key: (0, import_utils.getFileKey)(record)
|
|
170
|
+
});
|
|
171
|
+
return true;
|
|
172
|
+
} catch (error) {
|
|
173
|
+
if (["NoSuchKey", "NotFound"].includes(error.name)) {
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
throw error;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
async copy(source, target) {
|
|
180
|
+
const { cos } = this.make();
|
|
181
|
+
const sourceKey = (0, import_utils.getFileKey)(source);
|
|
182
|
+
const copySource = `${this.storage.options.Bucket}.cos.${this.storage.options.Region}.myqcloud.com/${sourceKey.split("/").map((segment) => encodeURIComponent(segment)).join("/")}`;
|
|
183
|
+
await (0, import_util.promisify)(cos.putObjectCopy).call(cos, {
|
|
184
|
+
Region: this.storage.options.Region,
|
|
185
|
+
Bucket: this.storage.options.Bucket,
|
|
186
|
+
Key: (0, import_utils.getFileKey)(target),
|
|
187
|
+
CopySource: copySource
|
|
188
|
+
});
|
|
189
|
+
}
|
|
163
190
|
async delete(records) {
|
|
164
191
|
const { cos } = this.make();
|
|
165
192
|
const { Deleted } = await (0, import_util.promisify)(cos.deleteMultipleObject).call(cos, {
|
package/dist/server/utils.js
CHANGED
|
@@ -49,6 +49,13 @@ var import_utils = require("@nocobase/utils");
|
|
|
49
49
|
var import_crypto = __toESM(require("crypto"));
|
|
50
50
|
var import_path = __toESM(require("path"));
|
|
51
51
|
var import_url_join = __toESM(require("url-join"));
|
|
52
|
+
const INVALID_FILENAME_CHARS = /* @__PURE__ */ new Set(["<", ">", "?", "*", "|", ":", '"', "\\", "/"]);
|
|
53
|
+
function sanitizeFilename(value) {
|
|
54
|
+
return Array.from(value).map((char) => {
|
|
55
|
+
const code = char.charCodeAt(0);
|
|
56
|
+
return code < 32 || code === 127 || INVALID_FILENAME_CHARS.has(char) ? "-" : char;
|
|
57
|
+
}).join("");
|
|
58
|
+
}
|
|
52
59
|
function normalizeOriginalname(file) {
|
|
53
60
|
const originalname = file == null ? void 0 : file.originalname;
|
|
54
61
|
if (!originalname) {
|
|
@@ -57,6 +64,9 @@ function normalizeOriginalname(file) {
|
|
|
57
64
|
if (Buffer.isBuffer(originalname)) {
|
|
58
65
|
return originalname.toString("utf8");
|
|
59
66
|
}
|
|
67
|
+
if (Array.from(originalname).some((char) => char.charCodeAt(0) > 255)) {
|
|
68
|
+
return originalname;
|
|
69
|
+
}
|
|
60
70
|
const decoded = Buffer.from(originalname, "binary").toString("utf8");
|
|
61
71
|
if (decoded.includes("\uFFFD")) {
|
|
62
72
|
return originalname;
|
|
@@ -65,13 +75,13 @@ function normalizeOriginalname(file) {
|
|
|
65
75
|
}
|
|
66
76
|
function getFilename(req, file, cb) {
|
|
67
77
|
const originalname = normalizeOriginalname(file);
|
|
68
|
-
const baseName = import_path.default.basename(originalname
|
|
78
|
+
const baseName = import_path.default.basename(sanitizeFilename(originalname), import_path.default.extname(originalname));
|
|
69
79
|
cb(null, `${baseName}-${(0, import_utils.uid)(6)}${import_path.default.extname(originalname)}`);
|
|
70
80
|
}
|
|
71
81
|
function getOriginalFilename(file) {
|
|
72
82
|
const originalname = normalizeOriginalname(file);
|
|
73
83
|
const extname = import_path.default.extname(originalname);
|
|
74
|
-
const baseName = import_path.default.basename(originalname
|
|
84
|
+
const baseName = import_path.default.basename(sanitizeFilename(originalname), extname);
|
|
75
85
|
return `${baseName}${extname}`;
|
|
76
86
|
}
|
|
77
87
|
const cloudFilenameGetter = (storage) => (req, file, cb) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/plugin-file-manager",
|
|
3
|
-
"version": "2.1.0-alpha.
|
|
3
|
+
"version": "2.1.0-alpha.46",
|
|
4
4
|
"displayName": "File manager",
|
|
5
5
|
"displayName.ru-RU": "Менеджер файлов",
|
|
6
6
|
"displayName.zh-CN": "文件管理器",
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
"multer": "^1.4.5-lts.2",
|
|
35
35
|
"multer-s3": "^3.0.1",
|
|
36
36
|
"multistream": "^4.1.0",
|
|
37
|
+
"pdfjs-dist": "^5.3.31",
|
|
37
38
|
"react": "^18.2.0",
|
|
38
39
|
"react-i18next": "^11.15.1",
|
|
39
40
|
"supertest": "^6.1.6",
|
|
@@ -49,6 +50,7 @@
|
|
|
49
50
|
"@nocobase/database": "2.x",
|
|
50
51
|
"@nocobase/flow-engine": "2.x",
|
|
51
52
|
"@nocobase/plugin-data-source-main": "2.x",
|
|
53
|
+
"@nocobase/plugin-data-source-manager": "2.x",
|
|
52
54
|
"@nocobase/plugin-environment-variables": "2.x",
|
|
53
55
|
"@nocobase/server": "2.x",
|
|
54
56
|
"@nocobase/test": "2.x",
|
|
@@ -58,5 +60,5 @@
|
|
|
58
60
|
"Collections",
|
|
59
61
|
"Collection fields"
|
|
60
62
|
],
|
|
61
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "42b269944cdd1908d7a848c0af4936fe94c03bb7"
|
|
62
64
|
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is part of the NocoBase (R) project.
|
|
3
|
-
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
-
* Authors: NocoBase Team.
|
|
5
|
-
*
|
|
6
|
-
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
-
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
"use strict";(self.webpackChunk_nocobase_plugin_file_manager_client_v2=self.webpackChunk_nocobase_plugin_file_manager_client_v2||[]).push([["125"],{212:function(e,t,r){r.r(t),r.d(t,{DisplayPreviewFieldModel:function(){return P}});var n=r(477),o=r(485),l=r(694),a=r(59),i=r(773),c=r(155),u=r.n(c),s=r(953),f=r(348);function p(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function b(e,t,r,n,o,l,a){try{var i=e[l](a),c=i.value}catch(e){r(e);return}i.done?t(c):Promise.resolve(c).then(n,o)}function y(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function d(e){return(d=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function h(e,t){return null!=t&&"u">typeof Symbol&&t[Symbol.hasInstance]?!!t[Symbol.hasInstance](e):e instanceof t}function m(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))),n.forEach(function(t){y(e,t,r[t])})}return e}function v(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):(function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t.push.apply(t,r)}return t})(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}),e}function w(e,t){return(w=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function g(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r,n,o=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var l=[],a=!0,i=!1;try{for(o=o.call(e);!(a=(r=o.next()).done)&&(l.push(r.value),!t||l.length!==t);a=!0);}catch(e){i=!0,n=e}finally{try{a||null==o.return||o.return()}finally{if(i)throw n}}return l}}(e,t)||function(e,t){if(e){if("string"==typeof e)return p(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if("Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r)return Array.from(r);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return p(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function O(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(O=function(){return!!e})()}function j(){var e,t,r=(e=["\n .ant-image-img {\n border: 1px solid #d9d9d9;\n padding: 2px;\n }\n "],t||(t=e.slice(0)),Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(t)}})));return j=function(){return r},r}var k=function(e){var t=e.file,r=e.size,o=e.showFileName,l=e.onClick,i=(0,f._H)(t),c=(0,f.q)(i);if(!c)return null;var s=(0,f.WP)(i,c),p=(0,f._Y)(i,c),b=(0,f.qk)(i)||p,y=u().createElement("div",{className:(0,n.css)(j())},u().createElement(a.Image,{src:b,fallback:p,width:r,height:r,preview:!1,style:{borderRadius:4,objectFit:"cover",boxShadow:"0 0 0 2px #fff"}}));return u().createElement("div",{onClick:l,style:{textAlign:"center",width:r,wordBreak:"break-all",cursor:l?"pointer":"default"}},y,o&&u().createElement(a.Tooltip,{title:s},u().createElement("div",{style:{fontSize:12,marginTop:4,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",width:"100%"}},s)))},S=function(e){var t=e.value,r=void 0===t?[]:t,n=e.size,o=void 0===n?28:n,l=e.showFileName,c=(0,s.useTranslation)().t,p=g(u().useState(0),2),y=p[0],d=p[1],h=g(u().useState(!1),2),m=h[0],v=h[1],w=u().useMemo(function(){return(0,i.castArray)(r).filter(Boolean).map(f._H).filter(function(e){return(0,f.q)(e)})},[r]);u().useEffect(function(){y>=w.length&&w.length&&d(0)},[y,w.length]),u().useEffect(function(){!w.length&&m&&v(!1)},[w.length,m]);var O=u().useCallback(function(e){var t;return(t=function(){var t,r,n,o,l,i,u;return function(e,t){var r,n,o,l={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(a,"next",{value:c(0)}),i(a,"throw",{value:c(1)}),i(a,"return",{value:c(2)}),"function"==typeof Symbol&&i(a,Symbol.iterator,{value:function(){return this}}),a;function c(i){return function(c){var u=[i,c];if(r)throw TypeError("Generator is already executing.");for(;a&&(a=0,u[0]&&(l=0)),l;)try{if(r=1,n&&(o=2&u[0]?n.return:u[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,u[1])).done)return o;switch(n=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return l.label++,{value:u[1],done:!1};case 5:l.label++,n=u[1],u=[0];continue;case 7:u=l.ops.pop(),l.trys.pop();continue;default:if(!(o=(o=l.trys).length>0&&o[o.length-1])&&(6===u[0]||2===u[0])){l=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){l.label=u[1];break}if(6===u[0]&&l.label<o[1]){l.label=o[1],o=u;break}if(o&&l.label<o[2]){l.label=o[2],l.ops.push(u);break}o[2]&&l.ops.pop(),l.trys.pop();continue}u=t.call(e,l)}catch(e){u=[6,e],n=0}finally{r=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}}(this,function(s){switch(s.label){case 0:if(!(t=e||w[y])||!(r=t.url||t.preview))return[2];n=(0,f.ub)(t,r),s.label=1;case 1:return s.trys.push([1,4,5,6]),[4,fetch(r)];case 2:if(!(i=s.sent()).ok)throw Error("Download failed with status ".concat(i.status));return[4,i.blob()];case 3:return u=s.sent(),o=URL.createObjectURL(u),(l=document.createElement("a")).href=o,l.download=n,document.body.appendChild(l),l.click(),[3,6];case 4:return console.error("File download failed:",s.sent()),a.message.error(c("file-manager:File download failed")),[3,6];case 5:return l&&l.remove(),o&&setTimeout(function(){URL.revokeObjectURL(o)},1e3),[7];case 6:return[2]}})},function(){var e=this,r=arguments;return new Promise(function(n,o){var l=t.apply(e,r);function a(e){b(l,n,o,a,i,"next",e)}function i(e){b(l,n,o,a,i,"throw",e)}a(void 0)})})()},[y,w,c]),j=u().useCallback(function(e){d(e),v(!0)},[]),S=u().useCallback(function(e){e<0||e>=w.length||d(e)},[w.length]);return u().createElement(u().Fragment,null,u().createElement(a.Space,{wrap:!0},w.map(function(e,t){return u().createElement(k,{file:e,size:o,key:t,showFileName:l,onClick:function(){return j(t)}})})),w[y]?u().createElement(f.Mo,{open:m,file:w[y],index:y,list:w,onOpenChange:v,onClose:function(){return v(!1)},onSwitchIndex:S,onDownload:O}):null)},P=function(e){var t;if("function"!=typeof e&&null!==e)throw TypeError("Super expression must either be null or a function");function r(){var e,t,n;if(!(this instanceof r))throw TypeError("Cannot call a class as a function");return t=r,n=arguments,t=d(t),y(e=function(e,t){var r;if(t&&("object"==((r=t)&&"u">typeof Symbol&&r.constructor===Symbol?"symbol":typeof r)||"function"==typeof t))return t;if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(this,O()?Reflect.construct(t,n||[],d(this).constructor):t.apply(this,n)),"disableTitleField",!0),e}return r.prototype=Object.create(e&&e.prototype,{constructor:{value:r,writable:!0,configurable:!0}}),e&&w(r,e),t=[{key:"render",value:function(){var e=this,t=this.props,r=t.value,n=t.titleField,o=t.template,l=t.target;return n&&"file"!==o&&"attachments"!==l?(0,i.castArray)(r).flatMap(function(t,r){var o=null==t?void 0:t[n],l=o?u().createElement(S,v(m({key:r},e.props),{value:(0,i.castArray)(o).filter(Boolean)})):u().createElement("span",{key:r},"N/A");return 0===r?[l]:[u().createElement("span",{key:"sep-".concat(r)},", "),l]}):u().createElement(S,v(m({},this.props),{value:(0,i.castArray)(r).filter(Boolean)}))}}],function(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}(r.prototype,t),r}(o.FieldModel);P.registerFlow({key:"previewReadPrettySetting",sort:500,title:(0,l.tExpr)("Preview Settings"),steps:{size:{title:(0,l.tExpr)("Size"),uiMode:function(e){var t=e.t;return{type:"select",key:"size",props:{options:[{value:300,label:t("Large")},{value:100,label:t("Middle")},{value:28,label:t("Small")}]}}},hideInSettings:function(e){return h(e.model.parent,o.TableColumnModel)},defaultParams:function(e){return{size:h(e.model.parent,o.DetailsItemModel)?100:28}},handler:function(e,t){e.model.setProps("size",t.size)}},showFileName:{title:(0,l.tExpr)("Show file name"),uiMode:{type:"switch",key:"showFileName"},hideInSettings:function(e){return h(e.model.parent,o.TableColumnModel)},defaultParams:{showFileName:!1},handler:function(e,t){e.model.setProps("showFileName",t.showFileName)}}}}),P.define({label:(0,l.tExpr)("Preview")}),l.DisplayItemModel.bindModelToInterface("DisplayPreviewFieldModel",["url","attachment","attachmentURL","m2m","m2o","o2o","o2m","oho","obo","mbm"],{isDefault:!0,when:function(e,t){return!t.targetCollection||"file"===t.targetCollection.template}})}}]);
|
package/dist/shared/locale.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is part of the NocoBase (R) project.
|
|
3
|
-
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
-
* Authors: NocoBase Team.
|
|
5
|
-
*
|
|
6
|
-
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
-
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
var __defProp = Object.defineProperty;
|
|
11
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
-
var __export = (target, all) => {
|
|
15
|
-
for (var name in all)
|
|
16
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
-
};
|
|
18
|
-
var __copyProps = (to, from, except, desc) => {
|
|
19
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
-
for (let key of __getOwnPropNames(from))
|
|
21
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
-
}
|
|
24
|
-
return to;
|
|
25
|
-
};
|
|
26
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
-
var locale_exports = {};
|
|
28
|
-
__export(locale_exports, {
|
|
29
|
-
NAMESPACE: () => NAMESPACE
|
|
30
|
-
});
|
|
31
|
-
module.exports = __toCommonJS(locale_exports);
|
|
32
|
-
const NAMESPACE = "file-manager";
|
|
33
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
34
|
-
0 && (module.exports = {
|
|
35
|
-
NAMESPACE
|
|
36
|
-
});
|