@nocobase/plugin-file-manager 2.1.0-alpha.4 → 2.1.0-alpha.40
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/LICENSE +201 -661
- package/README.md +79 -10
- package/client-v2.d.ts +2 -0
- package/client-v2.js +1 -0
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client/locale/index.d.ts +2 -1
- package/dist/client/previewer/filePreviewTypes.d.ts +1 -31
- 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.9dc2d49980a4dd9e.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/components/FileSizeField.d.ts +10 -0
- 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 +15 -0
- package/dist/client-v2/index.js +10 -0
- package/dist/client-v2/locale.d.ts +10 -0
- package/dist/{client → client-v2}/models/DisplayPreviewFieldModel.d.ts +1 -1
- package/dist/{client → client-v2}/models/UploadActionModel.d.ts +2 -2
- package/dist/{client → client-v2}/models/UploadFieldModel.d.ts +1 -1
- package/dist/client-v2/models/index.d.ts +11 -0
- package/dist/client-v2/models/uploadFieldUtils.d.ts +64 -0
- package/dist/client-v2/pages/FileStoragePage.d.ts +10 -0
- package/dist/client-v2/plugin.d.ts +87 -0
- 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 +12 -12
- package/dist/locale/en-US.json +1 -0
- package/dist/locale/zh-CN.json +1 -0
- package/dist/node_modules/@aws-sdk/client-s3/dist-cjs/index.js +190 -190
- package/dist/node_modules/@aws-sdk/client-s3/package.json +1 -1
- package/dist/node_modules/@aws-sdk/lib-storage/dist-cjs/index.js +195 -195
- package/dist/node_modules/@aws-sdk/lib-storage/node_modules/buffer/index.d.ts +186 -0
- package/dist/node_modules/@aws-sdk/lib-storage/node_modules/buffer/index.js +1794 -0
- package/dist/node_modules/@aws-sdk/lib-storage/node_modules/buffer/package.json +82 -0
- package/dist/node_modules/@aws-sdk/lib-storage/package.json +1 -1
- package/dist/node_modules/ali-oss/lib/client.js +14 -14
- 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/cos-nodejs-sdk-v5/index.js +220 -0
- 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/index.js +1 -1
- package/dist/node_modules/mime-match/package.json +1 -1
- package/dist/node_modules/mime-types/index.js +3 -3
- package/dist/node_modules/mime-types/package.json +1 -1
- package/dist/node_modules/mkdirp/index.js +1 -1
- package/dist/node_modules/mkdirp/package.json +1 -1
- package/dist/node_modules/url-join/lib/url-join.js +1 -1
- package/dist/node_modules/url-join/package.json +1 -1
- package/dist/server/index.d.ts +1 -1
- package/dist/server/index.js +2 -0
- package/dist/server/server.d.ts +2 -2
- package/dist/server/server.js +2 -2
- package/dist/server/storages/index.d.ts +4 -1
- package/dist/server/storages/index.js +2 -1
- package/dist/server/storages/local.js +7 -3
- package/dist/server/storages/tx-cos.d.ts +16 -1
- package/dist/server/storages/tx-cos.js +111 -10
- package/dist/server/utils.d.ts +1 -0
- package/dist/server/utils.js +21 -2
- package/dist/shared/locale.d.ts +9 -0
- package/dist/shared/locale.js +36 -0
- package/dist/shared/previewer/filePreviewTypes.d.ts +42 -0
- package/dist/shared/previewer/filePreviewTypes.js +459 -0
- package/package.json +7 -4
- 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/index.js +0 -220
- package/dist/node_modules/multer-cos/package.json +0 -1
|
@@ -0,0 +1,459 @@
|
|
|
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 __create = Object.create;
|
|
11
|
+
var __defProp = Object.defineProperty;
|
|
12
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
15
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
+
var __export = (target, all) => {
|
|
17
|
+
for (var name in all)
|
|
18
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
19
|
+
};
|
|
20
|
+
var __copyProps = (to, from, except, desc) => {
|
|
21
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
22
|
+
for (let key of __getOwnPropNames(from))
|
|
23
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
24
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
25
|
+
}
|
|
26
|
+
return to;
|
|
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
|
+
));
|
|
36
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
37
|
+
var filePreviewTypes_exports = {};
|
|
38
|
+
__export(filePreviewTypes_exports, {
|
|
39
|
+
FilePreviewRenderer: () => FilePreviewRenderer,
|
|
40
|
+
FilePreviewTypes: () => FilePreviewTypes,
|
|
41
|
+
filePreviewTypes: () => filePreviewTypes,
|
|
42
|
+
getDownloadFileName: () => getDownloadFileName,
|
|
43
|
+
getFallbackIcon: () => getFallbackIcon,
|
|
44
|
+
getFileExt: () => getFileExt,
|
|
45
|
+
getFileName: () => getFileName,
|
|
46
|
+
getFileUrl: () => getFileUrl,
|
|
47
|
+
getPreviewFileUrl: () => getPreviewFileUrl,
|
|
48
|
+
getPreviewThumbnailUrl: () => getPreviewThumbnailUrl,
|
|
49
|
+
isActiveContentFile: () => isActiveContentFile,
|
|
50
|
+
matchMimetype: () => matchMimetype,
|
|
51
|
+
normalizePreviewFile: () => normalizePreviewFile,
|
|
52
|
+
wrapWithModalPreviewer: () => wrapWithModalPreviewer
|
|
53
|
+
});
|
|
54
|
+
module.exports = __toCommonJS(filePreviewTypes_exports);
|
|
55
|
+
var import_react = __toESM(require("react"));
|
|
56
|
+
var import_icons = require("@ant-design/icons");
|
|
57
|
+
var import_antd = require("antd");
|
|
58
|
+
var import_mime_match = __toESM(require("mime-match"));
|
|
59
|
+
var import_react_i18next = require("react-i18next");
|
|
60
|
+
var import_locale = require("../locale");
|
|
61
|
+
class FilePreviewTypes {
|
|
62
|
+
types = [];
|
|
63
|
+
add(type) {
|
|
64
|
+
this.types.unshift(type);
|
|
65
|
+
}
|
|
66
|
+
getTypeByFile(file) {
|
|
67
|
+
const normalized = normalizePreviewFile(file);
|
|
68
|
+
return this.types.find((type) => type.match(normalized));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const filePreviewTypes = new FilePreviewTypes();
|
|
72
|
+
function normalizePreviewFile(file) {
|
|
73
|
+
if (!file) {
|
|
74
|
+
return file;
|
|
75
|
+
}
|
|
76
|
+
if (typeof file === "string") {
|
|
77
|
+
return { url: file };
|
|
78
|
+
}
|
|
79
|
+
return file;
|
|
80
|
+
}
|
|
81
|
+
function getPreviewFileUrl(file) {
|
|
82
|
+
if (!file) {
|
|
83
|
+
return "";
|
|
84
|
+
}
|
|
85
|
+
if (typeof file === "string") {
|
|
86
|
+
return file;
|
|
87
|
+
}
|
|
88
|
+
return file.preview || file.url || "";
|
|
89
|
+
}
|
|
90
|
+
function getFileUrl(file) {
|
|
91
|
+
if (!file) {
|
|
92
|
+
return "";
|
|
93
|
+
}
|
|
94
|
+
if (typeof file === "string") {
|
|
95
|
+
return file;
|
|
96
|
+
}
|
|
97
|
+
return file.url || file.preview || "";
|
|
98
|
+
}
|
|
99
|
+
const FALLBACK_ICON_MAP = {
|
|
100
|
+
pdf: "/file-placeholder/pdf-200-200.png",
|
|
101
|
+
mp4: "/file-placeholder/video-200-200.png",
|
|
102
|
+
mov: "/file-placeholder/video-200-200.png",
|
|
103
|
+
avi: "/file-placeholder/video-200-200.png",
|
|
104
|
+
wmv: "/file-placeholder/video-200-200.png",
|
|
105
|
+
flv: "/file-placeholder/video-200-200.png",
|
|
106
|
+
mkv: "/file-placeholder/video-200-200.png",
|
|
107
|
+
mp3: "/file-placeholder/audio-200-200.png",
|
|
108
|
+
wav: "/file-placeholder/audio-200-200.png",
|
|
109
|
+
aac: "/file-placeholder/audio-200-200.png",
|
|
110
|
+
ogg: "/file-placeholder/audio-200-200.png",
|
|
111
|
+
doc: "/file-placeholder/docx-200-200.png",
|
|
112
|
+
docx: "/file-placeholder/docx-200-200.png",
|
|
113
|
+
odt: "/file-placeholder/docx-200-200.png",
|
|
114
|
+
xls: "/file-placeholder/xlsx-200-200.png",
|
|
115
|
+
xlsx: "/file-placeholder/xlsx-200-200.png",
|
|
116
|
+
csv: "/file-placeholder/xlsx-200-200.png",
|
|
117
|
+
ppt: "/file-placeholder/pptx-200-200.png",
|
|
118
|
+
pptx: "/file-placeholder/pptx-200-200.png",
|
|
119
|
+
jpg: "/file-placeholder/jpeg-200-200.png",
|
|
120
|
+
jpeg: "/file-placeholder/jpeg-200-200.png",
|
|
121
|
+
png: "/file-placeholder/png-200-200.png",
|
|
122
|
+
gif: "/file-placeholder/gif-200-200.png",
|
|
123
|
+
webp: "/file-placeholder/png-200-200.png",
|
|
124
|
+
bmp: "/file-placeholder/png-200-200.png",
|
|
125
|
+
svg: "/file-placeholder/svg-200-200.png",
|
|
126
|
+
default: "/file-placeholder/unknown-200-200.png"
|
|
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"]);
|
|
130
|
+
const stripQueryAndHash = (url) => url.split("?")[0].split("#")[0];
|
|
131
|
+
const getExtFromName = (value) => {
|
|
132
|
+
if (!value) {
|
|
133
|
+
return "";
|
|
134
|
+
}
|
|
135
|
+
const clean = stripQueryAndHash(value);
|
|
136
|
+
const index = clean.lastIndexOf(".");
|
|
137
|
+
return index !== -1 ? clean.slice(index + 1).toLowerCase() : "";
|
|
138
|
+
};
|
|
139
|
+
const EXT_MIMETYPE_MAP = {
|
|
140
|
+
aac: "audio/aac",
|
|
141
|
+
avi: "video/x-msvideo",
|
|
142
|
+
bmp: "image/bmp",
|
|
143
|
+
csv: "text/csv",
|
|
144
|
+
doc: "application/msword",
|
|
145
|
+
docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
146
|
+
flv: "video/x-flv",
|
|
147
|
+
gif: "image/gif",
|
|
148
|
+
jpeg: "image/jpeg",
|
|
149
|
+
jpg: "image/jpeg",
|
|
150
|
+
json: "application/json",
|
|
151
|
+
mkv: "video/x-matroska",
|
|
152
|
+
mov: "video/quicktime",
|
|
153
|
+
mp3: "audio/mpeg",
|
|
154
|
+
mp4: "video/mp4",
|
|
155
|
+
odt: "application/vnd.oasis.opendocument.text",
|
|
156
|
+
ogg: "audio/ogg",
|
|
157
|
+
pdf: "application/pdf",
|
|
158
|
+
png: "image/png",
|
|
159
|
+
ppt: "application/vnd.ms-powerpoint",
|
|
160
|
+
pptx: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
161
|
+
svg: "image/svg+xml",
|
|
162
|
+
txt: "text/plain",
|
|
163
|
+
wav: "audio/wav",
|
|
164
|
+
webp: "image/webp",
|
|
165
|
+
wmv: "video/x-ms-wmv",
|
|
166
|
+
xls: "application/vnd.ms-excel",
|
|
167
|
+
xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
|
168
|
+
};
|
|
169
|
+
function matchMimetype(file, type) {
|
|
170
|
+
if (!file) {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
if (file.originFileObj) {
|
|
174
|
+
return (0, import_mime_match.default)(file.type, type);
|
|
175
|
+
}
|
|
176
|
+
if (file.mimetype) {
|
|
177
|
+
return (0, import_mime_match.default)(file.mimetype, type);
|
|
178
|
+
}
|
|
179
|
+
if (file.url) {
|
|
180
|
+
return (0, import_mime_match.default)(EXT_MIMETYPE_MAP[getExtFromName(file.url)] || "", type);
|
|
181
|
+
}
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
const getNameFromUrl = (url) => {
|
|
185
|
+
if (!url) {
|
|
186
|
+
return "";
|
|
187
|
+
}
|
|
188
|
+
const clean = stripQueryAndHash(url);
|
|
189
|
+
const index = clean.lastIndexOf("/");
|
|
190
|
+
return index !== -1 ? clean.slice(index + 1) : clean;
|
|
191
|
+
};
|
|
192
|
+
const getFileExt = (file, url) => {
|
|
193
|
+
if (file && typeof file === "object") {
|
|
194
|
+
if (file.extname) {
|
|
195
|
+
return String(file.extname).replace(/^\./, "").toLowerCase();
|
|
196
|
+
}
|
|
197
|
+
const nameExt = getExtFromName(file.name || file.filename || file.title);
|
|
198
|
+
if (nameExt) {
|
|
199
|
+
return nameExt;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return getExtFromName(url);
|
|
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
|
+
};
|
|
212
|
+
const getFileName = (file, url) => {
|
|
213
|
+
const nameFromUrl = getNameFromUrl(url);
|
|
214
|
+
if (!file || typeof file === "string") {
|
|
215
|
+
return nameFromUrl;
|
|
216
|
+
}
|
|
217
|
+
return file.name || file.filename || file.title || nameFromUrl;
|
|
218
|
+
};
|
|
219
|
+
const getDownloadFileName = (file, url) => {
|
|
220
|
+
const resolvedUrl = url || getFileUrl(file);
|
|
221
|
+
let filename = getFileName(file, resolvedUrl);
|
|
222
|
+
const ext = getFileExt(file, resolvedUrl);
|
|
223
|
+
if (filename && ext && !filename.toLowerCase().endsWith(`.${ext}`)) {
|
|
224
|
+
filename = `${filename}.${ext}`;
|
|
225
|
+
}
|
|
226
|
+
return `${Date.now()}_${filename || "file"}`;
|
|
227
|
+
};
|
|
228
|
+
const getFallbackIcon = (file, url) => {
|
|
229
|
+
const ext = getFileExt(file, url);
|
|
230
|
+
return FALLBACK_ICON_MAP[ext] || FALLBACK_ICON_MAP.default;
|
|
231
|
+
};
|
|
232
|
+
const getPreviewThumbnailUrl = (file) => {
|
|
233
|
+
const previewFile = normalizePreviewFile(file);
|
|
234
|
+
const src = getPreviewFileUrl(previewFile);
|
|
235
|
+
if (isActiveContentFile(previewFile, src)) {
|
|
236
|
+
return getFallbackIcon(previewFile, src);
|
|
237
|
+
}
|
|
238
|
+
const { getThumbnailURL } = filePreviewTypes.getTypeByFile(previewFile) ?? {};
|
|
239
|
+
const thumbnail = getThumbnailURL == null ? void 0 : getThumbnailURL(previewFile);
|
|
240
|
+
if (thumbnail) {
|
|
241
|
+
return thumbnail;
|
|
242
|
+
}
|
|
243
|
+
if (matchMimetype(previewFile, "image/*")) {
|
|
244
|
+
return "";
|
|
245
|
+
}
|
|
246
|
+
return getFallbackIcon(previewFile, src);
|
|
247
|
+
};
|
|
248
|
+
const renderModalFooter = (props) => {
|
|
249
|
+
const { index, list, onSwitchIndex, onDownload, file } = props;
|
|
250
|
+
const canPrev = typeof index === "number" && !!onSwitchIndex && index > 0;
|
|
251
|
+
const canNext = typeof index === "number" && !!onSwitchIndex && index < list.length - 1;
|
|
252
|
+
return /* @__PURE__ */ import_react.default.createElement(import_antd.Space, { size: 14, style: { fontSize: "20px" } }, /* @__PURE__ */ import_react.default.createElement(
|
|
253
|
+
import_icons.LeftOutlined,
|
|
254
|
+
{
|
|
255
|
+
style: { cursor: canPrev ? "pointer" : "not-allowed" },
|
|
256
|
+
disabled: !canPrev,
|
|
257
|
+
onClick: () => canPrev && (onSwitchIndex == null ? void 0 : onSwitchIndex(index - 1))
|
|
258
|
+
}
|
|
259
|
+
), /* @__PURE__ */ import_react.default.createElement(
|
|
260
|
+
import_icons.RightOutlined,
|
|
261
|
+
{
|
|
262
|
+
style: { cursor: canNext ? "pointer" : "not-allowed" },
|
|
263
|
+
disabled: !canNext,
|
|
264
|
+
onClick: () => canNext && (onSwitchIndex == null ? void 0 : onSwitchIndex(index + 1))
|
|
265
|
+
}
|
|
266
|
+
), /* @__PURE__ */ import_react.default.createElement(import_icons.DownloadOutlined, { onClick: () => onDownload(file) }));
|
|
267
|
+
};
|
|
268
|
+
const wrapWithModalPreviewer = (Previewer) => {
|
|
269
|
+
return function WrappedPreviewer(props) {
|
|
270
|
+
const { open, onOpenChange, onClose, file } = props;
|
|
271
|
+
if (typeof open !== "boolean") {
|
|
272
|
+
return /* @__PURE__ */ import_react.default.createElement(Previewer, { ...props });
|
|
273
|
+
}
|
|
274
|
+
const title = getFileName(file, getFileUrl(file));
|
|
275
|
+
return /* @__PURE__ */ import_react.default.createElement(
|
|
276
|
+
import_antd.Modal,
|
|
277
|
+
{
|
|
278
|
+
open,
|
|
279
|
+
title,
|
|
280
|
+
onCancel: () => {
|
|
281
|
+
onOpenChange == null ? void 0 : onOpenChange(false);
|
|
282
|
+
onClose == null ? void 0 : onClose();
|
|
283
|
+
},
|
|
284
|
+
footer: renderModalFooter(props),
|
|
285
|
+
width: "90vw",
|
|
286
|
+
centered: true
|
|
287
|
+
},
|
|
288
|
+
/* @__PURE__ */ import_react.default.createElement(
|
|
289
|
+
"div",
|
|
290
|
+
{
|
|
291
|
+
style: {
|
|
292
|
+
maxWidth: "100%",
|
|
293
|
+
maxHeight: "calc(100vh - 256px)",
|
|
294
|
+
height: "80vh",
|
|
295
|
+
width: "100%",
|
|
296
|
+
background: "white",
|
|
297
|
+
display: "flex",
|
|
298
|
+
flexDirection: "column",
|
|
299
|
+
justifyContent: "center",
|
|
300
|
+
alignItems: "center",
|
|
301
|
+
overflowY: "auto"
|
|
302
|
+
}
|
|
303
|
+
},
|
|
304
|
+
/* @__PURE__ */ import_react.default.createElement(Previewer, { ...props })
|
|
305
|
+
)
|
|
306
|
+
);
|
|
307
|
+
};
|
|
308
|
+
};
|
|
309
|
+
const ImagePreviewer = (props) => {
|
|
310
|
+
const { file, list, index, open, onOpenChange, onSwitchIndex, onClose, onDownload } = props;
|
|
311
|
+
if (typeof open !== "boolean") {
|
|
312
|
+
return null;
|
|
313
|
+
}
|
|
314
|
+
const src = getFileUrl(file);
|
|
315
|
+
if (!src) {
|
|
316
|
+
return null;
|
|
317
|
+
}
|
|
318
|
+
const canPrev = typeof index === "number" && index > 0;
|
|
319
|
+
const canNext = typeof index === "number" && index < list.length - 1;
|
|
320
|
+
return /* @__PURE__ */ import_react.default.createElement(
|
|
321
|
+
import_antd.Image,
|
|
322
|
+
{
|
|
323
|
+
wrapperStyle: { display: "none" },
|
|
324
|
+
preview: {
|
|
325
|
+
visible: open,
|
|
326
|
+
onVisibleChange: (visible) => onOpenChange == null ? void 0 : onOpenChange(visible),
|
|
327
|
+
afterOpenChange: (visible) => {
|
|
328
|
+
if (!visible) {
|
|
329
|
+
onClose == null ? void 0 : onClose();
|
|
330
|
+
}
|
|
331
|
+
},
|
|
332
|
+
toolbarRender: (_, {
|
|
333
|
+
transform: { scale },
|
|
334
|
+
actions: { onFlipY, onFlipX, onRotateLeft, onRotateRight, onZoomOut, onZoomIn, onReset }
|
|
335
|
+
}) => /* @__PURE__ */ import_react.default.createElement(import_antd.Space, { size: 14, className: "toolbar-wrapper", style: { fontSize: "20px" } }, /* @__PURE__ */ import_react.default.createElement(
|
|
336
|
+
import_icons.LeftOutlined,
|
|
337
|
+
{
|
|
338
|
+
style: { cursor: canPrev ? "pointer" : "not-allowed" },
|
|
339
|
+
disabled: !canPrev,
|
|
340
|
+
onClick: () => canPrev && (onSwitchIndex == null ? void 0 : onSwitchIndex(index - 1))
|
|
341
|
+
}
|
|
342
|
+
), /* @__PURE__ */ import_react.default.createElement(
|
|
343
|
+
import_icons.RightOutlined,
|
|
344
|
+
{
|
|
345
|
+
style: { cursor: canNext ? "pointer" : "not-allowed" },
|
|
346
|
+
disabled: !canNext,
|
|
347
|
+
onClick: () => canNext && (onSwitchIndex == null ? void 0 : onSwitchIndex(index + 1))
|
|
348
|
+
}
|
|
349
|
+
), onDownload ? /* @__PURE__ */ import_react.default.createElement(import_icons.DownloadOutlined, { onClick: () => onDownload(file) }) : null, /* @__PURE__ */ import_react.default.createElement(import_icons.SwapOutlined, { rotate: 90, onClick: onFlipY }), /* @__PURE__ */ import_react.default.createElement(import_icons.SwapOutlined, { onClick: onFlipX }), /* @__PURE__ */ import_react.default.createElement(import_icons.RotateLeftOutlined, { onClick: onRotateLeft }), /* @__PURE__ */ import_react.default.createElement(import_icons.RotateRightOutlined, { onClick: onRotateRight }), /* @__PURE__ */ import_react.default.createElement(import_icons.ZoomOutOutlined, { disabled: scale === 1, onClick: onZoomOut }), /* @__PURE__ */ import_react.default.createElement(import_icons.ZoomInOutlined, { disabled: scale === 50, onClick: onZoomIn }), /* @__PURE__ */ import_react.default.createElement(import_icons.UndoOutlined, { onClick: onReset }))
|
|
350
|
+
},
|
|
351
|
+
src
|
|
352
|
+
}
|
|
353
|
+
);
|
|
354
|
+
};
|
|
355
|
+
const IframePreviewer = ({ file }) => {
|
|
356
|
+
const src = getFileUrl(file);
|
|
357
|
+
if (!src) {
|
|
358
|
+
return null;
|
|
359
|
+
}
|
|
360
|
+
return /* @__PURE__ */ import_react.default.createElement("iframe", { src, width: "100%", height: "100%", style: { border: "none" } });
|
|
361
|
+
};
|
|
362
|
+
const AudioPreviewer = ({ file }) => {
|
|
363
|
+
const { t } = (0, import_react_i18next.useTranslation)();
|
|
364
|
+
const src = getFileUrl(file);
|
|
365
|
+
if (!src) {
|
|
366
|
+
return null;
|
|
367
|
+
}
|
|
368
|
+
return /* @__PURE__ */ import_react.default.createElement("audio", { controls: true }, /* @__PURE__ */ import_react.default.createElement("source", { src, type: (file == null ? void 0 : file.type) || (file == null ? void 0 : file.mimetype) }), t("Your browser does not support the audio tag."));
|
|
369
|
+
};
|
|
370
|
+
const VideoPreviewer = ({ file }) => {
|
|
371
|
+
const { t } = (0, import_react_i18next.useTranslation)();
|
|
372
|
+
const src = getFileUrl(file);
|
|
373
|
+
if (!src) {
|
|
374
|
+
return null;
|
|
375
|
+
}
|
|
376
|
+
return /* @__PURE__ */ import_react.default.createElement("video", { controls: true, width: "100%", height: "100%" }, /* @__PURE__ */ import_react.default.createElement("source", { src, type: (file == null ? void 0 : file.type) || (file == null ? void 0 : file.mimetype) }), t("Your browser does not support the video tag."));
|
|
377
|
+
};
|
|
378
|
+
const UnsupportedPreviewer = (props) => {
|
|
379
|
+
const { t } = (0, import_react_i18next.useTranslation)();
|
|
380
|
+
const { file } = props;
|
|
381
|
+
return /* @__PURE__ */ import_react.default.createElement(
|
|
382
|
+
import_antd.Alert,
|
|
383
|
+
{
|
|
384
|
+
type: "warning",
|
|
385
|
+
description: /* @__PURE__ */ import_react.default.createElement(import_react_i18next.Trans, { ns: import_locale.NAMESPACE }, "File type is not supported for previewing, please ", props.onDownload ? /* @__PURE__ */ import_react.default.createElement("a", { onClick: () => {
|
|
386
|
+
var _a;
|
|
387
|
+
return (_a = props.onDownload) == null ? void 0 : _a.call(props, file);
|
|
388
|
+
}, style: { textDecoration: "underline", cursor: "pointer" } }, "download it to preview") : /* @__PURE__ */ import_react.default.createElement("span", null, "download it to preview")),
|
|
389
|
+
showIcon: true
|
|
390
|
+
}
|
|
391
|
+
);
|
|
392
|
+
};
|
|
393
|
+
filePreviewTypes.add({
|
|
394
|
+
match() {
|
|
395
|
+
return true;
|
|
396
|
+
},
|
|
397
|
+
Previewer: wrapWithModalPreviewer(UnsupportedPreviewer)
|
|
398
|
+
});
|
|
399
|
+
filePreviewTypes.add({
|
|
400
|
+
match(file) {
|
|
401
|
+
return matchMimetype(file, "image/*");
|
|
402
|
+
},
|
|
403
|
+
getThumbnailURL(file) {
|
|
404
|
+
return getPreviewFileUrl(file);
|
|
405
|
+
},
|
|
406
|
+
Previewer: ImagePreviewer
|
|
407
|
+
});
|
|
408
|
+
filePreviewTypes.add({
|
|
409
|
+
match(file) {
|
|
410
|
+
return ["text/plain", "application/pdf", "application/json"].some((type) => matchMimetype(file, type));
|
|
411
|
+
},
|
|
412
|
+
Previewer: wrapWithModalPreviewer(IframePreviewer)
|
|
413
|
+
});
|
|
414
|
+
filePreviewTypes.add({
|
|
415
|
+
match(file) {
|
|
416
|
+
return matchMimetype(file, "audio/*");
|
|
417
|
+
},
|
|
418
|
+
Previewer: wrapWithModalPreviewer(AudioPreviewer)
|
|
419
|
+
});
|
|
420
|
+
filePreviewTypes.add({
|
|
421
|
+
match(file) {
|
|
422
|
+
return matchMimetype(file, "video/*");
|
|
423
|
+
},
|
|
424
|
+
Previewer: wrapWithModalPreviewer(VideoPreviewer)
|
|
425
|
+
});
|
|
426
|
+
filePreviewTypes.add({
|
|
427
|
+
match(file) {
|
|
428
|
+
return isActiveContentFile(file, getFileUrl(file));
|
|
429
|
+
},
|
|
430
|
+
Previewer: wrapWithModalPreviewer(UnsupportedPreviewer)
|
|
431
|
+
});
|
|
432
|
+
const FilePreviewRenderer = (props) => {
|
|
433
|
+
const normalized = normalizePreviewFile(props.file);
|
|
434
|
+
if (!normalized) {
|
|
435
|
+
return null;
|
|
436
|
+
}
|
|
437
|
+
const { Previewer } = filePreviewTypes.getTypeByFile(normalized) ?? {};
|
|
438
|
+
if (!Previewer) {
|
|
439
|
+
return null;
|
|
440
|
+
}
|
|
441
|
+
return /* @__PURE__ */ import_react.default.createElement(Previewer, { ...props, file: normalized });
|
|
442
|
+
};
|
|
443
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
444
|
+
0 && (module.exports = {
|
|
445
|
+
FilePreviewRenderer,
|
|
446
|
+
FilePreviewTypes,
|
|
447
|
+
filePreviewTypes,
|
|
448
|
+
getDownloadFileName,
|
|
449
|
+
getFallbackIcon,
|
|
450
|
+
getFileExt,
|
|
451
|
+
getFileName,
|
|
452
|
+
getFileUrl,
|
|
453
|
+
getPreviewFileUrl,
|
|
454
|
+
getPreviewThumbnailUrl,
|
|
455
|
+
isActiveContentFile,
|
|
456
|
+
matchMimetype,
|
|
457
|
+
normalizePreviewFile,
|
|
458
|
+
wrapWithModalPreviewer
|
|
459
|
+
});
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/plugin-file-manager",
|
|
3
|
-
"version": "2.1.0-alpha.
|
|
3
|
+
"version": "2.1.0-alpha.40",
|
|
4
4
|
"displayName": "File manager",
|
|
5
5
|
"displayName.ru-RU": "Менеджер файлов",
|
|
6
6
|
"displayName.zh-CN": "文件管理器",
|
|
7
7
|
"description": "Provides files storage services with files collection template and attachment field.",
|
|
8
8
|
"description.ru-RU": "Предоставляет сервисы хранения файлов, шаблон коллекции файлов и поле вложений.",
|
|
9
9
|
"description.zh-CN": "提供文件存储服务,并提供了文件表模板和附件字段。",
|
|
10
|
-
"license": "
|
|
10
|
+
"license": "Apache-2.0",
|
|
11
11
|
"main": "./dist/server/index.js",
|
|
12
12
|
"homepage": "https://docs.nocobase.com/handbook/file-manager",
|
|
13
13
|
"homepage.ru-RU": "https://docs-ru.nocobase.com/handbook/file-manager",
|
|
@@ -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",
|
|
@@ -46,7 +45,11 @@
|
|
|
46
45
|
"peerDependencies": {
|
|
47
46
|
"@nocobase/actions": "2.x",
|
|
48
47
|
"@nocobase/client": "2.x",
|
|
48
|
+
"@nocobase/client-v2": "2.x",
|
|
49
49
|
"@nocobase/database": "2.x",
|
|
50
|
+
"@nocobase/flow-engine": "2.x",
|
|
51
|
+
"@nocobase/plugin-data-source-main": "2.x",
|
|
52
|
+
"@nocobase/plugin-environment-variables": "2.x",
|
|
50
53
|
"@nocobase/server": "2.x",
|
|
51
54
|
"@nocobase/test": "2.x",
|
|
52
55
|
"@nocobase/utils": "2.x"
|
|
@@ -55,5 +58,5 @@
|
|
|
55
58
|
"Collections",
|
|
56
59
|
"Collection fields"
|
|
57
60
|
],
|
|
58
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "e73f99dd0abefe847f2e50ff0fea1f41a82fd048"
|
|
59
62
|
}
|
|
@@ -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
|
-
};
|