@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
|
@@ -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-
|
|
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-21T22:22:23.730Z"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(
|
|
1
|
+
(()=>{var e={186:(e,r,i)=>{var t=i(17);var n=i(147);var a=parseInt("0777",8);e.exports=mkdirP.mkdirp=mkdirP.mkdirP=mkdirP;function mkdirP(e,r,i,f){if(typeof r==="function"){i=r;r={}}else if(!r||typeof r!=="object"){r={mode:r}}var c=r.mode;var o=r.fs||n;if(c===undefined){c=a}if(!f)f=null;var s=i||function(){};e=t.resolve(e);o.mkdir(e,c,(function(i){if(!i){f=f||e;return s(null,f)}switch(i.code){case"ENOENT":if(t.dirname(e)===e)return s(i);mkdirP(t.dirname(e),r,(function(i,t){if(i)s(i,t);else mkdirP(e,r,s,t)}));break;default:o.stat(e,(function(e,r){if(e||!r.isDirectory())s(i,f);else s(null,f)}));break}}))}mkdirP.sync=function sync(e,r,i){if(!r||typeof r!=="object"){r={mode:r}}var f=r.mode;var c=r.fs||n;if(f===undefined){f=a}if(!i)i=null;e=t.resolve(e);try{c.mkdirSync(e,f);i=i||e}catch(n){switch(n.code){case"ENOENT":i=sync(t.dirname(e),r,i);sync(e,r,i);break;default:var o;try{o=c.statSync(e)}catch(e){throw n}if(!o.isDirectory())throw n;break}}return i}},147:e=>{"use strict";e.exports=require("fs")},17:e=>{"use strict";e.exports=require("path")}};var r={};function __nccwpck_require__(i){var t=r[i];if(t!==undefined){return t.exports}var n=r[i]={exports:{}};var a=true;try{e[i](n,n.exports,__nccwpck_require__);a=false}finally{if(a)delete r[i]}return n.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var i=__nccwpck_require__(186);module.exports=i})();
|
|
@@ -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-
|
|
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-21T22:22:27.900Z"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(
|
|
1
|
+
(()=>{var e={821:function(e){(function(r,i,t){if(true&&e.exports)e.exports=t();else if(typeof define==="function"&&define.amd)define(t);else i[r]=t()})("urljoin",this,(function(){function normalize(e){var r=[];if(e.length===0){return""}if(typeof e[0]!=="string"){throw new TypeError("Url must be a string. Received "+e[0])}if(e[0].match(/^[^/:]+:\/*$/)&&e.length>1){var i=e.shift();e[0]=i+e[0]}if(e[0].match(/^file:\/\/\//)){e[0]=e[0].replace(/^([^/:]+):\/*/,"$1:///")}else{e[0]=e[0].replace(/^([^/:]+):\/*/,"$1://")}for(var t=0;t<e.length;t++){var n=e[t];if(typeof n!=="string"){throw new TypeError("Url must be a string. Received "+n)}if(n===""){continue}if(t>0){n=n.replace(/^[\/]+/,"")}if(t<e.length-1){n=n.replace(/[\/]+$/,"")}else{n=n.replace(/[\/]+$/,"/")}r.push(n)}var a=r.join("/");a=a.replace(/\/(\?|&|#[^!])/g,"$1");var f=a.split("?");a=f.shift()+(f.length>0?"?":"")+f.join("&");return a}return function(){var e;if(typeof arguments[0]==="object"){e=arguments[0]}else{e=[].slice.call(arguments)}return normalize(e)}}))}};var r={};function __nccwpck_require__(i){var t=r[i];if(t!==undefined){return t.exports}var n=r[i]={exports:{}};var a=true;try{e[i].call(n.exports,n,n.exports,__nccwpck_require__);a=false}finally{if(a)delete r[i]}return n.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var i=__nccwpck_require__(821);module.exports=i})();
|
|
@@ -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-
|
|
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-21T22:22:23.548Z"}
|
package/dist/server/index.d.ts
CHANGED
|
@@ -10,5 +10,5 @@ import { StorageEngine } from 'multer';
|
|
|
10
10
|
export * from '../constants';
|
|
11
11
|
export { AttachmentModel, default, PluginFileManagerServer, StorageModel } from './server';
|
|
12
12
|
export { cloudFilenameGetter } from './utils';
|
|
13
|
-
export { StorageType } from './storages';
|
|
13
|
+
export { StorageType, GetFileStreamOptions } from './storages';
|
|
14
14
|
export { StorageEngine };
|
package/dist/server/index.js
CHANGED
|
@@ -38,6 +38,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
38
38
|
var server_exports = {};
|
|
39
39
|
__export(server_exports, {
|
|
40
40
|
AttachmentModel: () => import_server.AttachmentModel,
|
|
41
|
+
GetFileStreamOptions: () => import_storages.GetFileStreamOptions,
|
|
41
42
|
PluginFileManagerServer: () => import_server.PluginFileManagerServer,
|
|
42
43
|
StorageEngine: () => import_multer.StorageEngine,
|
|
43
44
|
StorageModel: () => import_server.StorageModel,
|
|
@@ -54,6 +55,7 @@ var import_storages = require("./storages");
|
|
|
54
55
|
// Annotate the CommonJS export names for ESM import in node:
|
|
55
56
|
0 && (module.exports = {
|
|
56
57
|
AttachmentModel,
|
|
58
|
+
GetFileStreamOptions,
|
|
57
59
|
PluginFileManagerServer,
|
|
58
60
|
StorageEngine,
|
|
59
61
|
StorageModel,
|
package/dist/server/server.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { Model, Transactionable } from '@nocobase/database';
|
|
|
11
11
|
import { Plugin } from '@nocobase/server';
|
|
12
12
|
import { Registry } from '@nocobase/utils';
|
|
13
13
|
import { Readable } from 'stream';
|
|
14
|
-
import { AttachmentModel, StorageClassType, StorageModel } from './storages';
|
|
14
|
+
import { AttachmentModel, GetFileStreamOptions, StorageClassType, StorageModel } from './storages';
|
|
15
15
|
export type * from './storages';
|
|
16
16
|
export type FileRecordOptions = {
|
|
17
17
|
collectionName: string;
|
|
@@ -50,7 +50,7 @@ export declare class PluginFileManagerServer extends Plugin {
|
|
|
50
50
|
load(): Promise<void>;
|
|
51
51
|
getFileURL(file: AttachmentModel, preview?: boolean): Promise<any>;
|
|
52
52
|
isPublicAccessStorage(storageName: any): Promise<boolean>;
|
|
53
|
-
getFileStream(file: AttachmentModel): Promise<{
|
|
53
|
+
getFileStream(file: AttachmentModel, options?: GetFileStreamOptions): Promise<{
|
|
54
54
|
stream: Readable;
|
|
55
55
|
contentType?: string;
|
|
56
56
|
}>;
|
package/dist/server/server.js
CHANGED
|
@@ -324,7 +324,7 @@ class PluginFileManagerServer extends import_server.Plugin {
|
|
|
324
324
|
}
|
|
325
325
|
return !!((_a = storage.options) == null ? void 0 : _a.public);
|
|
326
326
|
}
|
|
327
|
-
async getFileStream(file) {
|
|
327
|
+
async getFileStream(file, options) {
|
|
328
328
|
if (!file.storageId) {
|
|
329
329
|
throw new Error("File storageId not found");
|
|
330
330
|
}
|
|
@@ -340,7 +340,7 @@ class PluginFileManagerServer extends import_server.Plugin {
|
|
|
340
340
|
if (!storageInstance) {
|
|
341
341
|
throw new Error(`[file-manager] storage type "${storage.type}" is not defined`);
|
|
342
342
|
}
|
|
343
|
-
return storageInstance.getFileStream(file);
|
|
343
|
+
return storageInstance.getFileStream(file, options);
|
|
344
344
|
}
|
|
345
345
|
}
|
|
346
346
|
var server_default = PluginFileManagerServer;
|
|
@@ -50,7 +50,7 @@ export declare abstract class StorageType {
|
|
|
50
50
|
storageId: number;
|
|
51
51
|
};
|
|
52
52
|
getFileURL(file: AttachmentModel, preview?: boolean): string | Promise<string>;
|
|
53
|
-
getFileStream(file: AttachmentModel): Promise<{
|
|
53
|
+
getFileStream(file: AttachmentModel, options?: GetFileStreamOptions): Promise<{
|
|
54
54
|
stream: Readable;
|
|
55
55
|
contentType?: string;
|
|
56
56
|
}>;
|
|
@@ -58,3 +58,6 @@ export declare abstract class StorageType {
|
|
|
58
58
|
export type StorageClassType = {
|
|
59
59
|
new (storage: StorageModel): StorageType;
|
|
60
60
|
} & typeof StorageType;
|
|
61
|
+
export type GetFileStreamOptions = {
|
|
62
|
+
requestOptions?: any;
|
|
63
|
+
};
|
|
@@ -88,12 +88,13 @@ class StorageType {
|
|
|
88
88
|
].filter(Boolean);
|
|
89
89
|
return (0, import_url_join.default)(keys);
|
|
90
90
|
}
|
|
91
|
-
async getFileStream(file) {
|
|
91
|
+
async getFileStream(file, options) {
|
|
92
92
|
var _a;
|
|
93
93
|
try {
|
|
94
94
|
const fileURL = await this.getFileURL(file);
|
|
95
95
|
const requestOptions = {
|
|
96
96
|
...(_a = this.storage.settings) == null ? void 0 : _a.requestOptions,
|
|
97
|
+
...(options == null ? void 0 : options.requestOptions) ?? {},
|
|
97
98
|
responseType: "stream",
|
|
98
99
|
validateStatus: (status) => status === 200,
|
|
99
100
|
timeout: 3e4
|
|
@@ -52,11 +52,15 @@ var import_constants = require("../../constants");
|
|
|
52
52
|
var import_utils2 = require("../utils");
|
|
53
53
|
const DEFAULT_BASE_URL = "/storage/uploads";
|
|
54
54
|
function getDocumentRoot(storage) {
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
var _a;
|
|
56
|
+
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
|
+
if (import_path.default.isAbsolute(raw)) {
|
|
58
|
+
return raw;
|
|
59
|
+
}
|
|
60
|
+
return (0, import_utils2.normalizeDocumentRoot)(raw);
|
|
57
61
|
}
|
|
58
62
|
function resolveSafePath(documentRoot, filePath, filename) {
|
|
59
|
-
const root =
|
|
63
|
+
const root = (0, import_utils2.normalizeDocumentRoot)(documentRoot);
|
|
60
64
|
const target = import_path.default.resolve(root, filePath || "", filename || "");
|
|
61
65
|
const relative = import_path.default.relative(root, target);
|
|
62
66
|
if (relative.startsWith("..") || import_path.default.isAbsolute(relative)) {
|
|
@@ -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
|
}
|
package/dist/server/utils.d.ts
CHANGED
|
@@ -12,3 +12,4 @@ export declare const diskFilenameGetter: (storage: any) => (req: any, file: any,
|
|
|
12
12
|
export declare function getFileKey(record: any): any;
|
|
13
13
|
export declare function ensureUrlEncoded(value: any): any;
|
|
14
14
|
export declare function encodeURL(url: any): any;
|
|
15
|
+
export declare function normalizeDocumentRoot(documentRoot?: string): string;
|
package/dist/server/utils.js
CHANGED
|
@@ -41,7 +41,8 @@ __export(utils_exports, {
|
|
|
41
41
|
encodeURL: () => encodeURL,
|
|
42
42
|
ensureUrlEncoded: () => ensureUrlEncoded,
|
|
43
43
|
getFileKey: () => getFileKey,
|
|
44
|
-
getFilename: () => getFilename
|
|
44
|
+
getFilename: () => getFilename,
|
|
45
|
+
normalizeDocumentRoot: () => normalizeDocumentRoot
|
|
45
46
|
});
|
|
46
47
|
module.exports = __toCommonJS(utils_exports);
|
|
47
48
|
var import_utils = require("@nocobase/utils");
|
|
@@ -140,6 +141,23 @@ function encodeURL(url) {
|
|
|
140
141
|
return url;
|
|
141
142
|
}
|
|
142
143
|
}
|
|
144
|
+
function isStorageRelativeDocumentRoot(documentRoot) {
|
|
145
|
+
return documentRoot === "storage" || documentRoot.startsWith("storage/") || documentRoot === "./storage" || documentRoot.startsWith("./storage/");
|
|
146
|
+
}
|
|
147
|
+
function normalizeDocumentRoot(documentRoot) {
|
|
148
|
+
if (!documentRoot) {
|
|
149
|
+
return (0, import_utils.storagePathJoin)("uploads");
|
|
150
|
+
}
|
|
151
|
+
if (import_path.default.isAbsolute(documentRoot)) {
|
|
152
|
+
return documentRoot;
|
|
153
|
+
}
|
|
154
|
+
const normalizedDocumentRoot = documentRoot.replace(/\\/g, "/");
|
|
155
|
+
if (isStorageRelativeDocumentRoot(normalizedDocumentRoot)) {
|
|
156
|
+
const relativePath = normalizedDocumentRoot.replace(/^\.?\/?storage(?:\/|$)/, "").replace(/^[/\\]+/, "");
|
|
157
|
+
return relativePath ? (0, import_utils.storagePathJoin)(relativePath) : (0, import_utils.storagePathJoin)();
|
|
158
|
+
}
|
|
159
|
+
return import_path.default.resolve(process.cwd(), documentRoot);
|
|
160
|
+
}
|
|
143
161
|
// Annotate the CommonJS export names for ESM import in node:
|
|
144
162
|
0 && (module.exports = {
|
|
145
163
|
cloudFilenameGetter,
|
|
@@ -147,5 +165,6 @@ function encodeURL(url) {
|
|
|
147
165
|
encodeURL,
|
|
148
166
|
ensureUrlEncoded,
|
|
149
167
|
getFileKey,
|
|
150
|
-
getFilename
|
|
168
|
+
getFilename,
|
|
169
|
+
normalizeDocumentRoot
|
|
151
170
|
});
|
|
@@ -0,0 +1,9 @@
|
|
|
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 declare const NAMESPACE = "file-manager";
|
|
@@ -0,0 +1,36 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
import React from 'react';
|
|
10
|
+
export interface FilePreviewerProps {
|
|
11
|
+
file: any;
|
|
12
|
+
index: number;
|
|
13
|
+
list: any[];
|
|
14
|
+
open?: boolean;
|
|
15
|
+
onOpenChange?: (open: boolean) => void;
|
|
16
|
+
onSwitchIndex?: (index: number) => void;
|
|
17
|
+
onClose?: () => void;
|
|
18
|
+
onDownload: (file: any) => void;
|
|
19
|
+
}
|
|
20
|
+
export interface FilePreviewType {
|
|
21
|
+
match(file: any): boolean;
|
|
22
|
+
getThumbnailURL?: (file: any) => string | null;
|
|
23
|
+
Previewer?: React.ComponentType<FilePreviewerProps>;
|
|
24
|
+
}
|
|
25
|
+
export declare class FilePreviewTypes {
|
|
26
|
+
types: FilePreviewType[];
|
|
27
|
+
add(type: FilePreviewType): void;
|
|
28
|
+
getTypeByFile(file: any): Omit<FilePreviewType, 'match'> | undefined;
|
|
29
|
+
}
|
|
30
|
+
export declare const filePreviewTypes: FilePreviewTypes;
|
|
31
|
+
export declare function normalizePreviewFile(file: any): any;
|
|
32
|
+
export declare function getPreviewFileUrl(file: any): any;
|
|
33
|
+
export declare function getFileUrl(file: any): any;
|
|
34
|
+
export declare function matchMimetype(file: any, type: string): any;
|
|
35
|
+
export declare const getFileExt: (file: any, url?: string) => string;
|
|
36
|
+
export declare const isActiveContentFile: (file: any, url?: string) => boolean;
|
|
37
|
+
export declare const getFileName: (file: any, url?: string) => any;
|
|
38
|
+
export declare const getDownloadFileName: (file: any, url?: string) => string;
|
|
39
|
+
export declare const getFallbackIcon: (file: any, url?: string) => string;
|
|
40
|
+
export declare const getPreviewThumbnailUrl: (file: any) => string;
|
|
41
|
+
export declare const wrapWithModalPreviewer: (Previewer: React.ComponentType<FilePreviewerProps>) => (props: FilePreviewerProps) => React.JSX.Element;
|
|
42
|
+
export declare const FilePreviewRenderer: (props: FilePreviewerProps) => React.JSX.Element;
|