@nocobase/plugin-file-manager 2.1.0-beta.30 → 2.1.0-beta.33
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 -1
- package/dist/client-v2/125.01d5562df948d974.js +10 -0
- package/dist/client-v2/229.bd72c2d7aa088310.js +10 -0
- package/dist/client-v2/336.1dd1b32466d0c778.js +10 -0
- package/dist/client-v2/43.eb45d53ba3e9828b.js +10 -0
- package/dist/client-v2/450.f590b4c220108742.js +10 -0
- package/dist/client-v2/929.d7e783304cc1f236.js +10 -0
- package/dist/client-v2/942.c10c97317af6dd02.js +10 -0
- package/dist/{client/StorageOptions.d.ts → client-v2/components/BaseUrlField.d.ts} +1 -1
- package/dist/client-v2/components/DefaultField.d.ts +18 -0
- package/dist/client-v2/{storageTypes/index.d.ts → components/FileSizeField.d.ts} +2 -2
- package/dist/client-v2/components/MimetypeField.d.ts +10 -0
- package/dist/client-v2/components/NameField.d.ts +10 -0
- package/dist/client-v2/components/ParanoidField.d.ts +10 -0
- package/dist/client-v2/components/PathField.d.ts +18 -0
- package/dist/client-v2/components/RenameModeField.d.ts +10 -0
- package/dist/client-v2/components/TitleField.d.ts +10 -0
- package/dist/client-v2/components/index.d.ts +17 -0
- package/dist/client-v2/index.d.ts +5 -0
- package/dist/client-v2/index.js +1 -1
- package/dist/client-v2/plugin.d.ts +47 -6
- package/dist/client-v2/storage-forms/AliOssStorageForm.d.ts +10 -0
- package/dist/client-v2/storage-forms/LocalStorageForm.d.ts +10 -0
- package/dist/client-v2/storage-forms/S3StorageForm.d.ts +10 -0
- package/dist/client-v2/storage-forms/TxCosStorageForm.d.ts +10 -0
- package/dist/externalVersion.js +10 -13
- 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/.github/workflows/auto-changelog.yml +55 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/.prettierrc +10 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/.travis.yml +16 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/LICENSE +21 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/demo/crc64.js +9 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/demo/demo-sts-scope.js +75 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/demo/demo-sts.js +65 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/demo/demo.js +4542 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/demo/util.js +135 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/index.d.ts +2610 -0
- package/dist/node_modules/{multer-cos → cos-nodejs-sdk-v5}/index.js +2 -2
- package/dist/node_modules/cos-nodejs-sdk-v5/package.json +1 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/sdk/advance.js +1659 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/sdk/async.js +59 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/sdk/base.js +4404 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/sdk/cos.js +137 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/sdk/event.js +34 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/sdk/select-stream.js +181 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/sdk/session.js +126 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/sdk/task.js +255 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/sdk/util.js +776 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/test/csp.js +1302 -0
- package/dist/node_modules/cos-nodejs-sdk-v5/test/test.js +6119 -0
- 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/storages/tx-cos.d.ts +16 -1
- package/dist/server/storages/tx-cos.js +111 -10
- package/dist/shared/previewer/filePreviewTypes.d.ts +1 -0
- package/dist/shared/previewer/filePreviewTypes.js +21 -0
- package/package.json +2 -3
- package/dist/client-v2/855.e7d2e24a0b457a89.js +0 -10
- package/dist/client-v2/storageTypes/types.d.ts +0 -26
- package/dist/node_modules/multer-cos/LICENSE +0 -24
- package/dist/node_modules/multer-cos/demo/index.js +0 -39
- package/dist/node_modules/multer-cos/demo/myMulter.js +0 -88
- package/dist/node_modules/multer-cos/package.json +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"mime-match","version":"1.0.2","description":"A simple function to check whether a mimetype matches the specified mimetype (with wildcard support)","main":"index.js","scripts":{"test":"node test.js","gendocs":"gendocs > README.md"},"repository":{"type":"git","url":"https://github.com/DamonOehlman/mime-match.git"},"keywords":["mime","wildcard"],"author":"Damon Oehlman <damon.oehlman@gmail.com>","license":"ISC","bugs":{"url":"https://github.com/DamonOehlman/mime-match/issues"},"homepage":"https://github.com/DamonOehlman/mime-match","dependencies":{"wildcard":"^1.1.0"},"devDependencies":{"tape":"^4.5.1"},"_lastModified":"2026-05-
|
|
1
|
+
{"name":"mime-match","version":"1.0.2","description":"A simple function to check whether a mimetype matches the specified mimetype (with wildcard support)","main":"index.js","scripts":{"test":"node test.js","gendocs":"gendocs > README.md"},"repository":{"type":"git","url":"https://github.com/DamonOehlman/mime-match.git"},"keywords":["mime","wildcard"],"author":"Damon Oehlman <damon.oehlman@gmail.com>","license":"ISC","bugs":{"url":"https://github.com/DamonOehlman/mime-match/issues"},"homepage":"https://github.com/DamonOehlman/mime-match","dependencies":{"wildcard":"^1.1.0"},"devDependencies":{"tape":"^4.5.1"},"_lastModified":"2026-05-15T15:54:17.432Z"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"mime-types","description":"The ultimate javascript content-type utility.","version":"3.0.1","contributors":["Douglas Christopher Wilson <doug@somethingdoug.com>","Jeremiah Senkpiel <fishrock123@rocketmail.com> (https://searchbeam.jit.su)","Jonathan Ong <me@jongleberry.com> (http://jongleberry.com)"],"license":"MIT","keywords":["mime","types"],"repository":"jshttp/mime-types","dependencies":{"mime-db":"^1.54.0"},"devDependencies":{"eslint":"8.33.0","eslint-config-standard":"14.1.1","eslint-plugin-import":"2.27.5","eslint-plugin-markdown":"3.0.0","eslint-plugin-node":"11.1.0","eslint-plugin-promise":"6.1.1","eslint-plugin-standard":"4.1.0","mocha":"10.2.0","nyc":"15.1.0"},"files":["HISTORY.md","LICENSE","index.js","mimeScore.js"],"engines":{"node":">= 0.6"},"scripts":{"lint":"eslint .","test":"mocha --reporter spec test/test.js","test-ci":"nyc --reporter=lcov --reporter=text npm test","test-cov":"nyc --reporter=html --reporter=text npm test"},"_lastModified":"2026-05-
|
|
1
|
+
{"name":"mime-types","description":"The ultimate javascript content-type utility.","version":"3.0.1","contributors":["Douglas Christopher Wilson <doug@somethingdoug.com>","Jeremiah Senkpiel <fishrock123@rocketmail.com> (https://searchbeam.jit.su)","Jonathan Ong <me@jongleberry.com> (http://jongleberry.com)"],"license":"MIT","keywords":["mime","types"],"repository":"jshttp/mime-types","dependencies":{"mime-db":"^1.54.0"},"devDependencies":{"eslint":"8.33.0","eslint-config-standard":"14.1.1","eslint-plugin-import":"2.27.5","eslint-plugin-markdown":"3.0.0","eslint-plugin-node":"11.1.0","eslint-plugin-promise":"6.1.1","eslint-plugin-standard":"4.1.0","mocha":"10.2.0","nyc":"15.1.0"},"files":["HISTORY.md","LICENSE","index.js","mimeScore.js"],"engines":{"node":">= 0.6"},"scripts":{"lint":"eslint .","test":"mocha --reporter spec test/test.js","test-ci":"nyc --reporter=lcov --reporter=text npm test","test-cov":"nyc --reporter=html --reporter=text npm test"},"_lastModified":"2026-05-15T15:54:17.723Z"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"mkdirp","description":"Recursively mkdir, like `mkdir -p`","version":"0.5.6","publishConfig":{"tag":"legacy"},"author":"James Halliday <mail@substack.net> (http://substack.net)","main":"index.js","keywords":["mkdir","directory"],"repository":{"type":"git","url":"https://github.com/substack/node-mkdirp.git"},"scripts":{"test":"tap test/*.js"},"dependencies":{"minimist":"^1.2.6"},"devDependencies":{"tap":"^16.0.1"},"bin":"bin/cmd.js","license":"MIT","files":["bin","index.js"],"_lastModified":"2026-05-
|
|
1
|
+
{"name":"mkdirp","description":"Recursively mkdir, like `mkdir -p`","version":"0.5.6","publishConfig":{"tag":"legacy"},"author":"James Halliday <mail@substack.net> (http://substack.net)","main":"index.js","keywords":["mkdir","directory"],"repository":{"type":"git","url":"https://github.com/substack/node-mkdirp.git"},"scripts":{"test":"tap test/*.js"},"dependencies":{"minimist":"^1.2.6"},"devDependencies":{"tap":"^16.0.1"},"bin":"bin/cmd.js","license":"MIT","files":["bin","index.js"],"_lastModified":"2026-05-15T15:54:21.862Z"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"url-join","version":"4.0.1","description":"Join urls and normalize as in path.join.","main":"lib/url-join.js","scripts":{"test":"mocha --require should"},"repository":{"type":"git","url":"git://github.com/jfromaniello/url-join.git"},"keywords":["url","join"],"author":"José F. Romaniello <jfromaniello@gmail.com> (http://joseoncode.com)","license":"MIT","devDependencies":{"conventional-changelog":"^1.1.10","mocha":"^3.2.0","should":"~1.2.1"},"_lastModified":"2026-05-
|
|
1
|
+
{"name":"url-join","version":"4.0.1","description":"Join urls and normalize as in path.join.","main":"lib/url-join.js","scripts":{"test":"mocha --require should"},"repository":{"type":"git","url":"git://github.com/jfromaniello/url-join.git"},"keywords":["url","join"],"author":"José F. Romaniello <jfromaniello@gmail.com> (http://joseoncode.com)","license":"MIT","devDependencies":{"conventional-changelog":"^1.1.10","mocha":"^3.2.0","should":"~1.2.1"},"_lastModified":"2026-05-15T15:54:17.533Z"}
|
|
@@ -7,6 +7,20 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
import { AttachmentModel, StorageType } from '.';
|
|
10
|
+
declare class TxCosStorage {
|
|
11
|
+
cos: any;
|
|
12
|
+
getFilename: Function;
|
|
13
|
+
baseUrl: string;
|
|
14
|
+
options: Record<string, any>;
|
|
15
|
+
constructor({ config, baseUrl, filename }: {
|
|
16
|
+
config: any;
|
|
17
|
+
baseUrl: any;
|
|
18
|
+
filename: any;
|
|
19
|
+
});
|
|
20
|
+
getUploadedFileURL(key: string, location?: string): any;
|
|
21
|
+
_handleFile(req: any, file: any, cb: any): any;
|
|
22
|
+
_removeFile(req: any, file: any, cb: any): any;
|
|
23
|
+
}
|
|
10
24
|
export default class extends StorageType {
|
|
11
25
|
static defaults(): {
|
|
12
26
|
title: string;
|
|
@@ -21,6 +35,7 @@ export default class extends StorageType {
|
|
|
21
35
|
};
|
|
22
36
|
};
|
|
23
37
|
static filenameKey: string;
|
|
24
|
-
make():
|
|
38
|
+
make(): TxCosStorage;
|
|
25
39
|
delete(records: AttachmentModel[]): Promise<[number, AttachmentModel[]]>;
|
|
26
40
|
}
|
|
41
|
+
export {};
|
|
@@ -7,9 +7,11 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
var __create = Object.create;
|
|
10
11
|
var __defProp = Object.defineProperty;
|
|
11
12
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
13
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
13
15
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
16
|
var __export = (target, all) => {
|
|
15
17
|
for (var name in all)
|
|
@@ -23,6 +25,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
23
25
|
}
|
|
24
26
|
return to;
|
|
25
27
|
};
|
|
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
|
+
));
|
|
26
36
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
37
|
var tx_cos_exports = {};
|
|
28
38
|
__export(tx_cos_exports, {
|
|
@@ -30,9 +40,103 @@ __export(tx_cos_exports, {
|
|
|
30
40
|
});
|
|
31
41
|
module.exports = __toCommonJS(tx_cos_exports);
|
|
32
42
|
var import_util = require("util");
|
|
43
|
+
var import_stream = require("stream");
|
|
44
|
+
var import_url_join = __toESM(require("url-join"));
|
|
33
45
|
var import__ = require(".");
|
|
34
46
|
var import_constants = require("../../constants");
|
|
35
|
-
var
|
|
47
|
+
var import_utils = require("../utils");
|
|
48
|
+
const ERROR_NO_CLIENT = new Error("cos client undefined");
|
|
49
|
+
class CountingStream extends import_stream.Transform {
|
|
50
|
+
size = 0;
|
|
51
|
+
_transform(chunk, encoding, callback) {
|
|
52
|
+
this.size += chunk.length;
|
|
53
|
+
callback(null, chunk);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
class TxCosStorage {
|
|
57
|
+
cos;
|
|
58
|
+
getFilename;
|
|
59
|
+
baseUrl;
|
|
60
|
+
options;
|
|
61
|
+
constructor({ config, baseUrl, filename }) {
|
|
62
|
+
const COS = require("cos-nodejs-sdk-v5");
|
|
63
|
+
this.cos = new COS({
|
|
64
|
+
SecretId: config.SecretId,
|
|
65
|
+
SecretKey: config.SecretKey,
|
|
66
|
+
SecurityToken: config.SecurityToken,
|
|
67
|
+
XCosSecurityToken: config.XCosSecurityToken,
|
|
68
|
+
FileParallelLimit: config.FileParallelLimit,
|
|
69
|
+
ChunkParallelLimit: config.ChunkParallelLimit,
|
|
70
|
+
ChunkSize: config.ChunkSize,
|
|
71
|
+
Domain: config.Domain,
|
|
72
|
+
Protocol: config.Protocol,
|
|
73
|
+
Timeout: config.Timeout,
|
|
74
|
+
KeepAlive: config.KeepAlive,
|
|
75
|
+
ForcePathStyle: config.ForcePathStyle,
|
|
76
|
+
CompatibilityMode: config.CompatibilityMode,
|
|
77
|
+
UseAccelerate: config.UseAccelerate
|
|
78
|
+
});
|
|
79
|
+
this.getFilename = filename;
|
|
80
|
+
this.baseUrl = baseUrl;
|
|
81
|
+
this.options = config;
|
|
82
|
+
}
|
|
83
|
+
getUploadedFileURL(key, location) {
|
|
84
|
+
if (this.baseUrl) {
|
|
85
|
+
return (0, import_url_join.default)(this.baseUrl, key);
|
|
86
|
+
}
|
|
87
|
+
if (!location) {
|
|
88
|
+
return key;
|
|
89
|
+
}
|
|
90
|
+
if (/^https?:\/\//.test(location)) {
|
|
91
|
+
return location;
|
|
92
|
+
}
|
|
93
|
+
return `https://${location}`;
|
|
94
|
+
}
|
|
95
|
+
_handleFile(req, file, cb) {
|
|
96
|
+
if (!this.cos) {
|
|
97
|
+
return cb(ERROR_NO_CLIENT);
|
|
98
|
+
}
|
|
99
|
+
const getFilename = (0, import_util.promisify)(this.getFilename);
|
|
100
|
+
Promise.resolve().then(async () => {
|
|
101
|
+
const key = await getFilename(req, file);
|
|
102
|
+
const counter = new CountingStream();
|
|
103
|
+
const body = file.stream.pipe(counter);
|
|
104
|
+
const params = {
|
|
105
|
+
Bucket: this.options.Bucket,
|
|
106
|
+
Region: this.options.Region,
|
|
107
|
+
Key: key,
|
|
108
|
+
Body: body
|
|
109
|
+
};
|
|
110
|
+
if (file.mimetype === "text/plain") {
|
|
111
|
+
params.ContentType = "text/plain; charset=utf-8";
|
|
112
|
+
} else if (file.mimetype) {
|
|
113
|
+
params.ContentType = file.mimetype;
|
|
114
|
+
}
|
|
115
|
+
const result = await (0, import_util.promisify)(this.cos.putObject).call(this.cos, params);
|
|
116
|
+
cb(null, {
|
|
117
|
+
key,
|
|
118
|
+
size: counter.size,
|
|
119
|
+
url: this.getUploadedFileURL(key, result == null ? void 0 : result.Location)
|
|
120
|
+
});
|
|
121
|
+
}).catch(cb);
|
|
122
|
+
}
|
|
123
|
+
_removeFile(req, file, cb) {
|
|
124
|
+
if (!this.cos) {
|
|
125
|
+
return cb(ERROR_NO_CLIENT);
|
|
126
|
+
}
|
|
127
|
+
if (!file.key) {
|
|
128
|
+
return cb(null);
|
|
129
|
+
}
|
|
130
|
+
this.cos.deleteObject(
|
|
131
|
+
{
|
|
132
|
+
Bucket: this.options.Bucket,
|
|
133
|
+
Region: this.options.Region,
|
|
134
|
+
Key: file.key
|
|
135
|
+
},
|
|
136
|
+
cb
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
36
140
|
class tx_cos_default extends import__.StorageType {
|
|
37
141
|
static defaults() {
|
|
38
142
|
return {
|
|
@@ -50,13 +154,10 @@ class tx_cos_default extends import__.StorageType {
|
|
|
50
154
|
}
|
|
51
155
|
static filenameKey = "url";
|
|
52
156
|
make() {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
dir: (this.storage.path ?? "").replace(/\/+$/, "")
|
|
58
|
-
},
|
|
59
|
-
filename: (0, import_utils2.diskFilenameGetter)(this.storage)
|
|
157
|
+
return new TxCosStorage({
|
|
158
|
+
config: this.storage.options,
|
|
159
|
+
baseUrl: this.storage.baseUrl,
|
|
160
|
+
filename: (0, import_utils.cloudFilenameGetter)(this.storage)
|
|
60
161
|
});
|
|
61
162
|
}
|
|
62
163
|
async delete(records) {
|
|
@@ -64,8 +165,8 @@ class tx_cos_default extends import__.StorageType {
|
|
|
64
165
|
const { Deleted } = await (0, import_util.promisify)(cos.deleteMultipleObject).call(cos, {
|
|
65
166
|
Region: this.storage.options.Region,
|
|
66
167
|
Bucket: this.storage.options.Bucket,
|
|
67
|
-
Objects: records.map((record) => ({ Key: (0,
|
|
168
|
+
Objects: records.map((record) => ({ Key: (0, import_utils.getFileKey)(record) }))
|
|
68
169
|
});
|
|
69
|
-
return [Deleted.length, records.filter((record) => !Deleted.find((item) => item.Key === (0,
|
|
170
|
+
return [Deleted.length, records.filter((record) => !Deleted.find((item) => item.Key === (0, import_utils.getFileKey)(record)))];
|
|
70
171
|
}
|
|
71
172
|
}
|
|
@@ -33,6 +33,7 @@ export declare function getPreviewFileUrl(file: any): any;
|
|
|
33
33
|
export declare function getFileUrl(file: any): any;
|
|
34
34
|
export declare function matchMimetype(file: any, type: string): any;
|
|
35
35
|
export declare const getFileExt: (file: any, url?: string) => string;
|
|
36
|
+
export declare const isActiveContentFile: (file: any, url?: string) => boolean;
|
|
36
37
|
export declare const getFileName: (file: any, url?: string) => any;
|
|
37
38
|
export declare const getDownloadFileName: (file: any, url?: string) => string;
|
|
38
39
|
export declare const getFallbackIcon: (file: any, url?: string) => string;
|
|
@@ -46,6 +46,7 @@ __export(filePreviewTypes_exports, {
|
|
|
46
46
|
getFileUrl: () => getFileUrl,
|
|
47
47
|
getPreviewFileUrl: () => getPreviewFileUrl,
|
|
48
48
|
getPreviewThumbnailUrl: () => getPreviewThumbnailUrl,
|
|
49
|
+
isActiveContentFile: () => isActiveContentFile,
|
|
49
50
|
matchMimetype: () => matchMimetype,
|
|
50
51
|
normalizePreviewFile: () => normalizePreviewFile,
|
|
51
52
|
wrapWithModalPreviewer: () => wrapWithModalPreviewer
|
|
@@ -124,6 +125,8 @@ const FALLBACK_ICON_MAP = {
|
|
|
124
125
|
svg: "/file-placeholder/svg-200-200.png",
|
|
125
126
|
default: "/file-placeholder/unknown-200-200.png"
|
|
126
127
|
};
|
|
128
|
+
const ACTIVE_CONTENT_MIMETYPES = /* @__PURE__ */ new Set(["application/xhtml+xml", "image/svg+xml", "text/html"]);
|
|
129
|
+
const ACTIVE_CONTENT_EXTENSIONS = /* @__PURE__ */ new Set(["htm", "html", "svg", "svgz", "xhtml"]);
|
|
127
130
|
const stripQueryAndHash = (url) => url.split("?")[0].split("#")[0];
|
|
128
131
|
const getExtFromName = (value) => {
|
|
129
132
|
if (!value) {
|
|
@@ -198,6 +201,14 @@ const getFileExt = (file, url) => {
|
|
|
198
201
|
}
|
|
199
202
|
return getExtFromName(url);
|
|
200
203
|
};
|
|
204
|
+
const isActiveContentFile = (file, url) => {
|
|
205
|
+
const mimetype = (file == null ? void 0 : file.mimetype) || (file == null ? void 0 : file.type);
|
|
206
|
+
if (typeof mimetype === "string" && ACTIVE_CONTENT_MIMETYPES.has(mimetype.toLowerCase())) {
|
|
207
|
+
return true;
|
|
208
|
+
}
|
|
209
|
+
const ext = getFileExt(file, url);
|
|
210
|
+
return ACTIVE_CONTENT_EXTENSIONS.has(ext);
|
|
211
|
+
};
|
|
201
212
|
const getFileName = (file, url) => {
|
|
202
213
|
const nameFromUrl = getNameFromUrl(url);
|
|
203
214
|
if (!file || typeof file === "string") {
|
|
@@ -221,6 +232,9 @@ const getFallbackIcon = (file, url) => {
|
|
|
221
232
|
const getPreviewThumbnailUrl = (file) => {
|
|
222
233
|
const previewFile = normalizePreviewFile(file);
|
|
223
234
|
const src = getPreviewFileUrl(previewFile);
|
|
235
|
+
if (isActiveContentFile(previewFile, src)) {
|
|
236
|
+
return getFallbackIcon(previewFile, src);
|
|
237
|
+
}
|
|
224
238
|
const { getThumbnailURL } = filePreviewTypes.getTypeByFile(previewFile) ?? {};
|
|
225
239
|
const thumbnail = getThumbnailURL == null ? void 0 : getThumbnailURL(previewFile);
|
|
226
240
|
if (thumbnail) {
|
|
@@ -409,6 +423,12 @@ filePreviewTypes.add({
|
|
|
409
423
|
},
|
|
410
424
|
Previewer: wrapWithModalPreviewer(VideoPreviewer)
|
|
411
425
|
});
|
|
426
|
+
filePreviewTypes.add({
|
|
427
|
+
match(file) {
|
|
428
|
+
return isActiveContentFile(file, getFileUrl(file));
|
|
429
|
+
},
|
|
430
|
+
Previewer: wrapWithModalPreviewer(UnsupportedPreviewer)
|
|
431
|
+
});
|
|
412
432
|
const FilePreviewRenderer = (props) => {
|
|
413
433
|
const normalized = normalizePreviewFile(props.file);
|
|
414
434
|
if (!normalized) {
|
|
@@ -432,6 +452,7 @@ const FilePreviewRenderer = (props) => {
|
|
|
432
452
|
getFileUrl,
|
|
433
453
|
getPreviewFileUrl,
|
|
434
454
|
getPreviewThumbnailUrl,
|
|
455
|
+
isActiveContentFile,
|
|
435
456
|
matchMimetype,
|
|
436
457
|
normalizePreviewFile,
|
|
437
458
|
wrapWithModalPreviewer
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/plugin-file-manager",
|
|
3
|
-
"version": "2.1.0-beta.
|
|
3
|
+
"version": "2.1.0-beta.33",
|
|
4
4
|
"displayName": "File manager",
|
|
5
5
|
"displayName.ru-RU": "Менеджер файлов",
|
|
6
6
|
"displayName.zh-CN": "文件管理器",
|
|
@@ -32,7 +32,6 @@
|
|
|
32
32
|
"mime-types": "^3.0.1",
|
|
33
33
|
"mkdirp": "~0.5.4",
|
|
34
34
|
"multer": "^1.4.5-lts.2",
|
|
35
|
-
"multer-cos": "^1.0.3",
|
|
36
35
|
"multer-s3": "^3.0.1",
|
|
37
36
|
"multistream": "^4.1.0",
|
|
38
37
|
"react": "^18.2.0",
|
|
@@ -59,5 +58,5 @@
|
|
|
59
58
|
"Collections",
|
|
60
59
|
"Collection fields"
|
|
61
60
|
],
|
|
62
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "4815c394e80a264fa8ed619246280923c47aeb72"
|
|
63
62
|
}
|
|
@@ -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=self.webpackChunk_nocobase_plugin_file_manager||[]).push([["855"],{138:function(e,t,n){n.r(t),n.d(t,{default:function(){return V}});var r=n(375),a=n(477),l=n(485),o=n(694),u=n(59),i=n(625),c=n(773),s=n(155),d=n.n(s),f=n(624),m=n(301);function p(){var e=(0,o.useFlowEngine)();return function(t,n){return e.context.t(t,function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){var r;r=n[t],t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r})}return e}({ns:[m.C,"client"]},n))}}var v=n(907),b=n(191);function y(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function h(e,t,n,r,a,l,o){try{var u=e[l](o),i=u.value}catch(e){n(e);return}u.done?t(i):Promise.resolve(i).then(r,a)}function g(e){return function(){var t=this,n=arguments;return new Promise(function(r,a){var l=e.apply(t,n);function o(e){h(l,r,a,o,u,"next",e)}function u(e){h(l,r,a,o,u,"throw",e)}o(void 0)})}}function w(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){var r;r=n[t],t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r})}return e}function E(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,a=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=a){var l=[],o=!0,u=!1;try{for(a=a.call(e);!(o=(n=a.next()).done)&&(l.push(n.value),!t||l.length!==t);o=!0);}catch(e){u=!0,r=e}finally{try{o||null==a.return||a.return()}finally{if(u)throw r}}return l}}(e,t)||function(e,t){if(e){if("string"==typeof e)return y(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return y(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(e,t){return t||(t=e.slice(0)),Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(t)}}))}function k(e,t){var n,r,a,l={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),u=Object.defineProperty;return u(o,"next",{value:i(0)}),u(o,"throw",{value:i(1)}),u(o,"return",{value:i(2)}),"function"==typeof Symbol&&u(o,Symbol.iterator,{value:function(){return this}}),o;function i(u){return function(i){var c=[u,i];if(n)throw TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(l=0)),l;)try{if(n=1,r&&(a=2&c[0]?r.return:c[0]?r.throw||((a=r.return)&&a.call(r),0):r.next)&&!(a=a.call(r,c[1])).done)return a;switch(r=0,a&&(c=[2&c[0],a.value]),c[0]){case 0:case 1:a=c;break;case 4:return l.label++,{value:c[1],done:!1};case 5:l.label++,r=c[1],c=[0];continue;case 7:c=l.ops.pop(),l.trys.pop();continue;default:if(!(a=(a=l.trys).length>0&&a[a.length-1])&&(6===c[0]||2===c[0])){l=0;continue}if(3===c[0]&&(!a||c[1]>a[0]&&c[1]<a[3])){l.label=c[1];break}if(6===c[0]&&l.label<a[1]){l.label=a[1],a=c;break}if(a&&l.label<a[2]){l.label=a[2],l.ops.push(c);break}a[2]&&l.ops.pop(),l.trys.pop();continue}c=t.call(e,l)}catch(e){c=[6,e],r=0}finally{n=a=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}function S(){var e=O(["\n .ant-radio-group {\n display: flex;\n flex-wrap: wrap;\n gap: ","px;\n }\n\n .ant-radio-wrapper {\n margin-inline-end: 0;\n max-width: 100%;\n }\n "]);return S=function(){return e},e}function j(){var e=O(["\n &.ant-input-number,\n &.ant-select {\n width: auto;\n min-width: 6em;\n }\n"]);return j=function(){return e},e}function C(){var e=O(["\n display: inline-flex;\n align-items: center;\n gap: 8px;\n margin-left: -8px;\n"]);return C=function(){return e},e}var x=(0,a.css)(j()),I=(0,a.css)(C()),A=[{label:"Append random ID",value:"appendRandomID"},{label:"Random string",value:"random"},{label:"Keep original filename (will be overwrite if filename is existed)",value:"none"}],P=[{value:1,label:"Byte"},{value:1024,label:"KB"},{value:1048576,label:"MB"},{value:0x40000000,label:"GB"}];function D(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1048576,n=e||t,r=P.length-1;r>=0;r-=1){var a=P[r];if(n%a.value==0)return a}return P[0]}function B(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:f.UW,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:f.Qj;return Math.min(Math.max(t,e),n)}function T(e){var t,n=f.ZH,r=D(null!=(t=e.value)?t:n),a=null==e.value?e.value:e.value/r.value,l=(0,s.useCallback)(function(){if(null==e.value||e.value<f.UW){var t;null==(t=e.onChange)||t.call(e,f.UW)}},[e]);return d().createElement(u.Space.Compact,null,d().createElement(u.InputNumber,{value:a,disabled:e.disabled,defaultValue:n/D(n).value,step:1,className:x,onBlur:l,onChange:function(t){var n;null==(n=e.onChange)||n.call(e,null==t?void 0:B(Number(t)*r.value))}}),d().createElement(u.Select,{disabled:e.disabled,options:P,value:r.value,className:x,onChange:function(t){var n;null==(n=e.onChange)||n.call(e,null==a?void 0:B(Number(a)*t))}}))}function F(){return(0,o.useFlowContext)().api.resource("storages")}function N(e){var t=e.field,n=e.disabledDefault,r=p();if(t.hidden)return d().createElement(u.Form.Item,{name:t.name,hidden:!0},d().createElement(u.Input,null));if("checkbox"===t.component)return d().createElement(u.Form.Item,{name:t.name,valuePropName:"checked",extra:t.description?r(t.description):void 0},d().createElement(u.Checkbox,{disabled:n&&"default"===t.name},r(t.label)));var a=t.required?[{required:!0,message:r("The field value is required")}]:void 0,o=t.description?r(t.description):void 0;return d().createElement(u.Form.Item,{name:t.name,label:"".concat(r(t.label)," :"),rules:a,extra:o},"variableInput"===t.component?d().createElement(b.EnvVariableInput,{placeholder:t.placeholder?r(t.placeholder):void 0,addonBefore:t.addonBefore}):"passwordVariableInput"===t.component?d().createElement(b.EnvVariableInput,{password:!0}):"number"===t.component?Array.isArray(t.name)&&"rules.size"===t.name.join(".")?d().createElement(T,null):d().createElement(u.InputNumber,{style:{width:"100%"}}):"radio"===t.component?d().createElement(u.Radio.Group,{options:A.map(function(e){var t,n;return t=w({},e),n=n={label:r(e.label)},Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):(function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t.push.apply(t,n)}return t})(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}),t})}):"json"===t.component?d().createElement(l.JsonTextArea,{autoSize:{minRows:5}}):d().createElement(u.Input,{placeholder:t.placeholder?r(t.placeholder):void 0,addonBefore:t.addonBefore}))}function M(e){var t,n=p(),l=(0,o.useFlowView)(),i=F(),f=E(u.Form.useForm(),1)[0],m=E((0,s.useState)(!1),2),v=m[0],b=m[1],y=(t=u.theme.useToken().token,(0,s.useMemo)(function(){return(0,a.css)(S(),t.marginSM)},[t.marginSM])),h=(0,s.useMemo)(function(){var t,n;return n="create"===(t={mode:e.mode,storageType:e.storageType,record:e.record}).mode?{type:t.storageType.name,name:"s_".concat(Math.random().toString(36).slice(2,12))}:w({},t.record),function(e,t){var n=(0,c.cloneDeep)(t||{}),r=!0,a=!1,l=void 0;try{for(var o,u=e.fields[Symbol.iterator]();!(r=(o=u.next()).done);r=!0){var i=o.value;void 0!==i.defaultValue&&void 0===(0,c.get)(n,i.name)&&(0,c.set)(n,i.name,i.defaultValue)}}catch(e){a=!0,l=e}finally{try{r||null==u.return||u.return()}finally{if(a)throw l}}return n}(t.storageType,n)},[e.mode,e.record,e.storageType]);(0,s.useEffect)(function(){f.setFieldsValue(h)},[f,h]);var O=(0,s.useCallback)(function(){return g(function(){var t,n;return k(this,function(r){switch(r.label){case 0:return[4,f.validateFields()];case 1:t=r.sent(),b(!0),r.label=2;case 2:if(r.trys.push([2,,8,9]),"create"!==e.mode)return[3,4];return[4,i.create({values:t})];case 3:return r.sent(),[3,6];case 4:return[4,i.update({filterByTk:null==(n=e.record)?void 0:n.id,values:t})];case 5:r.sent(),r.label=6;case 6:return e.onSubmitted(),[4,l.close()];case 7:return r.sent(),[3,9];case 8:return b(!1),[7];case 9:return[2]}})})()},[f,e,i,l]),j="".concat(n("create"===e.mode?"Add new":"Edit")," - ").concat(n(e.storageType.title));return d().createElement("div",null,l.Header?d().createElement(l.Header,{title:d().createElement("span",{className:I},d().createElement(u.Button,{type:"text",size:"small",icon:d().createElement(r.CloseOutlined,null),onClick:function(){return g(function(){return k(this,function(e){switch(e.label){case 0:return[4,l.close()];case 1:return e.sent(),[2]}})})()}}),d().createElement("span",null,j))}):null,d().createElement(u.Form,{form:f,layout:"vertical",initialValues:h,className:y},d().createElement(u.Form.Item,{name:"type",hidden:!0},d().createElement(u.Input,null)),e.storageType.fields.map(function(t){var n;return d().createElement(N,{field:t,key:Array.isArray(t.name)?t.name.join("."):t.name,disabledDefault:"edit"===e.mode&&!!(null==(n=e.record)?void 0:n.default)})})),l.Footer?d().createElement(l.Footer,null,d().createElement(u.Space,null,d().createElement(u.Button,{onClick:function(){return g(function(){return k(this,function(e){switch(e.label){case 0:return[4,l.close()];case 1:return e.sent(),[2]}})})()}},n("Cancel")),d().createElement(u.Button,{type:"primary",loading:v,onClick:O},n("Submit")))):null)}function V(){var e=p(),t=(0,o.useFlowContext)(),n=u.App.useApp(),a=n.modal,l=n.message,c=F(),f=E((0,s.useState)(1),2),m=f[0],b=f[1],y=E((0,s.useState)([]),2),h=y[0],w=y[1],O=(0,i.useRequest)(function(){return g(function(){return k(this,function(e){switch(e.label){case 0:return[4,c.list({page:m,pageSize:50,sort:["id"],appends:[]})];case 1:var t,n,r,a,l;return[2,{records:a=Array.isArray(r=null==(n=null==(t=e.sent())?void 0:t.data)?void 0:n.data)?r:Array.isArray(null==r?void 0:r.data)?r.data:[],total:(l=(null==n?void 0:n.meta)||(null==r?void 0:r.meta)||{}).count||l.total||a.length}]}})})()},{refreshDeps:[m]}),S=O.data,j=O.loading,C=O.refresh,x=(0,s.useCallback)(function(e,n,r){t.viewer.drawer({width:"50%",content:function(){return d().createElement(M,{mode:e,storageType:n,record:r,onSubmitted:function(){return C()}})}})},[t.viewer,C]),I=(0,s.useCallback)(function(t){a.confirm({title:e("Delete"),content:e("Are you sure you want to delete it?"),onOk:function(){return g(function(){return k(this,function(e){switch(e.label){case 0:return[4,c.destroy({filterByTk:t})];case 1:return e.sent(),w([]),C(),[2]}})})()}})},[a,C,c,e]),A=(0,s.useMemo)(function(){return[{title:e("Title"),dataIndex:"title"},{title:e("Storage name"),dataIndex:"name"},{title:e("Default storage"),dataIndex:"default",render:function(e){return d().createElement(u.Checkbox,{checked:!!e,disabled:!0})}},{title:e("Actions"),render:function(t,n){return d().createElement(u.Space,null,d().createElement("a",{onClick:function(){var t=v.N[n.type||""];t?x("edit",t,n):l.error(e("Storage type {{type}} is not registered, please check if related plugin is enabled.").replace("{{type}}",n.type||""))}},e("Edit")),d().createElement("a",{onClick:function(){return I(n.id)}},e("Delete")))}}]},[I,l,x,e]);return d().createElement(u.Card,{variant:"borderless"},d().createElement("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginBottom:16}},d().createElement(u.Button,{icon:d().createElement(r.DeleteOutlined,null),disabled:!h.length,onClick:function(){return I(h)}},e("Delete")),d().createElement(u.Dropdown,{menu:{items:Object.values(v.N).map(function(t){return{key:t.name,label:e(t.title)}}),onClick:function(e){var t=v.N[e.key];t&&x("create",t)}}},d().createElement(u.Button,{type:"primary",icon:d().createElement(r.PlusOutlined,null)},e("Add new")," ",d().createElement(r.DownOutlined,null)))),d().createElement(u.Table,{rowKey:"id",loading:j,columns:A,dataSource:(null==S?void 0:S.records)||[],rowSelection:{selectedRowKeys:h,onChange:w},pagination:{current:m,pageSize:50,total:(null==S?void 0:S.total)||0,showSizeChanger:!1,onChange:b}}))}}}]);
|
|
@@ -1,26 +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
|
-
export type StorageFieldComponent = 'checkbox' | 'input' | 'json' | 'number' | 'passwordVariableInput' | 'radio' | 'variableInput';
|
|
10
|
-
export interface StorageFieldMeta {
|
|
11
|
-
name: string | string[];
|
|
12
|
-
label: string;
|
|
13
|
-
component: StorageFieldComponent;
|
|
14
|
-
required?: boolean;
|
|
15
|
-
hidden?: boolean;
|
|
16
|
-
defaultValue?: any;
|
|
17
|
-
description?: string;
|
|
18
|
-
placeholder?: string;
|
|
19
|
-
addonBefore?: string;
|
|
20
|
-
}
|
|
21
|
-
export interface StorageTypeMeta {
|
|
22
|
-
name: string;
|
|
23
|
-
title: string;
|
|
24
|
-
thumbnailRuleLink?: string;
|
|
25
|
-
fields: StorageFieldMeta[];
|
|
26
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
(The MIT License)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2009-2014 TJ Holowaychuk <tj@vision-media.ca>
|
|
4
|
-
Copyright (c) 2013-2014 Roman Shtylman <shtylman+expressjs@gmail.com>
|
|
5
|
-
Copyright (c) 2014-2015 Douglas Christopher Wilson <doug@somethingdoug.com>
|
|
6
|
-
|
|
7
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
|
8
|
-
a copy of this software and associated documentation files (the
|
|
9
|
-
'Software'), to deal in the Software without restriction, including
|
|
10
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
|
11
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
|
12
|
-
permit persons to whom the Software is furnished to do so, subject to
|
|
13
|
-
the following conditions:
|
|
14
|
-
|
|
15
|
-
The above copyright notice and this permission notice shall be
|
|
16
|
-
included in all copies or substantial portions of the Software.
|
|
17
|
-
|
|
18
|
-
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
19
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
20
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
21
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
22
|
-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
23
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
24
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
let express= require('express');
|
|
2
|
-
let myMulter = require('./myMulter');
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
let app = express();
|
|
6
|
-
let server = require('http').Server(app);
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
//文件上传服务
|
|
10
|
-
app.post('/upload', function (req, res, next) {
|
|
11
|
-
|
|
12
|
-
let responseData; //响应的数据
|
|
13
|
-
|
|
14
|
-
var upload=myMulter('file',1);
|
|
15
|
-
|
|
16
|
-
upload(req, res, function (err) {
|
|
17
|
-
|
|
18
|
-
try {
|
|
19
|
-
if (err) throw err;
|
|
20
|
-
if(req.files.length==0) throw new Error("不能上传空文件");
|
|
21
|
-
|
|
22
|
-
responseData={msg:"上传成功",code:2000};
|
|
23
|
-
responseData.url=req.files[0].url;
|
|
24
|
-
res.json(responseData);
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
catch (err) {
|
|
29
|
-
responseData={msg:"上传失败",code:4000};;
|
|
30
|
-
responseData.error=err.message;
|
|
31
|
-
res.status(500).json(responseData);
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
server.listen(3000);
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
let path=require('path');
|
|
2
|
-
let multer = require('multer');
|
|
3
|
-
let multerCOS = require('multer-COS');
|
|
4
|
-
require( 'dotenv' ).config();
|
|
5
|
-
/**
|
|
6
|
-
* multer
|
|
7
|
-
* https://github.com/expressjs/multer/blob/master/doc/README-zh-cn.md
|
|
8
|
-
* cos
|
|
9
|
-
* https://cloud.tencent.com/document/product/436/12264#options-object
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
//定义临时文件
|
|
14
|
-
let dir=path.resolve(__dirname,'./tmp');
|
|
15
|
-
|
|
16
|
-
//定义mimes-type
|
|
17
|
-
const mimes = {
|
|
18
|
-
'.png': 'image/png',
|
|
19
|
-
'.gif': 'image/gif',
|
|
20
|
-
'.jpg': 'image/jpeg',
|
|
21
|
-
'.jpeg': 'image/jpeg',
|
|
22
|
-
'.zip':'application/zip',
|
|
23
|
-
'.txt':'text/plain'
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const cosConfig={
|
|
28
|
-
//id和key是必须
|
|
29
|
-
|
|
30
|
-
//SecretId: AKIXXXXXXXXXXX,
|
|
31
|
-
//SecretKey:XXXXXXXXXXXXXX,
|
|
32
|
-
//Bucket:test-bucket-125XXXXXXXXX
|
|
33
|
-
//Region=ap-shanghai
|
|
34
|
-
// 可选参数
|
|
35
|
-
FileParallelLimit: 3, // 控制文件上传并发数
|
|
36
|
-
ChunkParallelLimit: 3, // 控制单个文件下分片上传并发数
|
|
37
|
-
ChunkSize: 1024 * 1024, // 控制分片大小,单位 B
|
|
38
|
-
domain:'static.dorodoro-lab.com', //cos域名
|
|
39
|
-
dir:'upload', //cos文件路径
|
|
40
|
-
onProgress:function(progressData){//进度回调函数,回调是一个对象,包含进度信息
|
|
41
|
-
//console.log(progressData);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
//定义仓库
|
|
48
|
-
const storage = multerCOS({
|
|
49
|
-
cos:cosConfig,
|
|
50
|
-
//Note:如果你传递的是一个函数,你负责创建文件夹,如果你传递的是一个字符串,multer会自动创建 如果什么都不传 系统自己会生成tmp目录
|
|
51
|
-
destination: function (req, file, cb) {
|
|
52
|
-
cb(null, dir);
|
|
53
|
-
},
|
|
54
|
-
//自己会生成个随机16字母的文件名和后缀
|
|
55
|
-
filename:'auto'
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
//测试cos
|
|
59
|
-
//storage.test();
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
//定义过滤器
|
|
63
|
-
const fileFilter =function (req, file, cb) {
|
|
64
|
-
|
|
65
|
-
// 指示是否应接受该文件
|
|
66
|
-
let test = Object.values(mimes).filter(type=>type===file.mimetype);
|
|
67
|
-
|
|
68
|
-
// 接受这个文件,使用`true`,像这样:
|
|
69
|
-
if(test.length>0){
|
|
70
|
-
cb(null, true);
|
|
71
|
-
}else{ // 拒绝这个文件,使用`false`,像这样:
|
|
72
|
-
cb(new Error('file mimes not allow!'), false);
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
//定义限制
|
|
77
|
-
const limits={
|
|
78
|
-
fileSize:1024 * 1024 * 30
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
module.exports=function(opt) {
|
|
83
|
-
return multer({
|
|
84
|
-
storage: storage,
|
|
85
|
-
fileFilter:fileFilter,
|
|
86
|
-
limits: limits,
|
|
87
|
-
}).array(opt);
|
|
88
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"_from":"multer-cos","_id":"multer-cos@1.0.2","_inBundle":false,"_integrity":"sha512-4F8P1VTCSNhiem+BFJFLe3Ixco6cIuAQ6j7U+PBRvdbBJRZgq5Q+vaDMMBWJ1HmPGOOP3AyKS5yk2f0nbFoqqA==","_location":"/multer-cos","_phantomChildren":{},"_requested":{"type":"tag","registry":true,"raw":"multer-cos","name":"multer-cos","escapedName":"multer-cos","rawSpec":"","saveSpec":null,"fetchSpec":"latest"},"_requiredBy":["#USER","/"],"_resolved":"https://registry.npmjs.org/multer-cos/-/multer-cos-1.0.2.tgz","_shasum":"95c7c06cdee1b9311675a895481f9d946de6dcf3","_spec":"multer-cos","_where":"/Users/lanbo/workplace/websocket","author":{"name":"lanbosm"},"bugs":{"url":"https://github.com/lanbosm/multer-COS/issues"},"bundleDependencies":false,"deprecated":false,"description":"Streaming multer storage engine for QCloud COS","devDependencies":{"cos-nodejs-sdk-v5":"^2.2.6","dotenv":"^5.0.1","multer":"^1.3.0"},"engines":{"node":">= 6.10.0"},"homepage":"https://github.com/lanbosm/multer-COS#readme","keywords":["express","multer","COS"],"license":"MIT","main":"index.js","name":"multer-cos","repository":{"type":"git","url":"git+ssh://git@github.com/lanbosm/multer-COS.git"},"scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"version":"1.0.3","_lastModified":"2026-05-11T23:07:42.358Z"}
|