@nocobase/plugin-file-manager 1.7.0-beta.2 → 1.7.0-beta.21
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.d.ts +13 -0
- package/dist/client/index.js +1 -1
- package/dist/{server/FileModel.d.ts → common/constants.d.ts} +1 -4
- package/dist/common/constants.js +36 -0
- package/dist/externalVersion.js +10 -10
- package/dist/locale/de-DE.json +1 -1
- package/dist/locale/it-IT.json +4 -7
- package/dist/locale/ja-JP.json +1 -1
- package/dist/locale/nl-NL.json +35 -17
- package/dist/locale/zh-CN.json +1 -1
- package/dist/node_modules/@aws-sdk/client-s3/dist-cjs/index.js +834 -834
- package/dist/node_modules/@aws-sdk/client-s3/package.json +1 -1
- package/dist/node_modules/mime-match/package.json +1 -1
- package/dist/node_modules/mkdirp/package.json +1 -1
- package/dist/node_modules/multer-aliyun-oss/index.js +3 -3
- package/dist/node_modules/multer-aliyun-oss/package.json +1 -1
- package/dist/node_modules/multer-cos/index.js +5 -5
- package/dist/node_modules/multer-cos/package.json +1 -1
- package/dist/node_modules/multer-s3/index.js +837 -837
- package/dist/node_modules/multer-s3/package.json +1 -1
- package/dist/node_modules/url-join/.travis.yml +5 -0
- package/dist/node_modules/url-join/LICENSE +21 -0
- package/dist/node_modules/url-join/bin/changelog +28 -0
- package/dist/node_modules/url-join/lib/url-join.js +1 -0
- package/dist/node_modules/url-join/package.json +1 -0
- package/dist/node_modules/url-join/test/tests.js +151 -0
- package/dist/server/actions/attachments.d.ts +0 -11
- package/dist/server/actions/attachments.js +10 -39
- package/dist/server/actions/index.js +19 -0
- package/dist/server/actions/storages.js +4 -1
- package/dist/server/collections/storages.js +8 -4
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +3 -0
- package/dist/server/server.d.ts +6 -6
- package/dist/server/server.js +110 -56
- package/dist/server/storages/index.d.ts +11 -5
- package/dist/server/storages/index.js +49 -2
- package/dist/server/storages/local.d.ts +1 -1
- package/dist/server/storages/local.js +12 -5
- package/dist/server/storages/s3.d.ts +4 -0
- package/dist/server/storages/s3.js +36 -12
- package/dist/server/storages/tx-cos.js +4 -4
- package/dist/server/utils.d.ts +3 -1
- package/dist/server/utils.js +25 -2
- package/package.json +8 -7
- package/dist/server/FileModel.js +0 -58
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"multer-s3","version":"3.0.1","description":"Streaming multer storage engine for AWS S3","main":"index.js","scripts":{"test":"standard && mocha test/basic.js"},"engines":{"node":">= 12.0.0"},"repository":{"type":"git","url":"git+https://github.com/badunk/multer-s3.git"},"keywords":["multer","s3","amazon","aws"],"author":"badunk","license":"MIT","bugs":{"url":"https://github.com/badunk/multer-s3/issues"},"homepage":"https://github.com/badunk/multer-s3#readme","dependencies":{"@aws-sdk/lib-storage":"^3.46.0","file-type":"^3.3.0","html-comment-regex":"^1.1.2","run-parallel":"^1.1.6"},"peerDependencies":{"@aws-sdk/client-s3":"^3.0.0"},"devDependencies":{"express":"^4.13.1","form-data":"^1.0.0-rc3","mocha":"^2.2.5","multer":"^1.1.0","on-finished":"^2.3.0","standard":"^5.4.1","xtend":"^4.0.1"},"_lastModified":"2025-
|
|
1
|
+
{"name":"multer-s3","version":"3.0.1","description":"Streaming multer storage engine for AWS S3","main":"index.js","scripts":{"test":"standard && mocha test/basic.js"},"engines":{"node":">= 12.0.0"},"repository":{"type":"git","url":"git+https://github.com/badunk/multer-s3.git"},"keywords":["multer","s3","amazon","aws"],"author":"badunk","license":"MIT","bugs":{"url":"https://github.com/badunk/multer-s3/issues"},"homepage":"https://github.com/badunk/multer-s3#readme","dependencies":{"@aws-sdk/lib-storage":"^3.46.0","file-type":"^3.3.0","html-comment-regex":"^1.1.2","run-parallel":"^1.1.6"},"peerDependencies":{"@aws-sdk/client-s3":"^3.0.0"},"devDependencies":{"express":"^4.13.1","form-data":"^1.0.0-rc3","mocha":"^2.2.5","multer":"^1.1.0","on-finished":"^2.3.0","standard":"^5.4.1","xtend":"^4.0.1"},"_lastModified":"2025-04-23T10:32:07.754Z"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2015 José F. Romaniello
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
var changelog = require('conventional-changelog');
|
|
4
|
+
var semver_regex = /\bv?(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)(?:-[\da-z\-]+(?:\.[\da-z\-]+)*)?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?\b/ig;
|
|
5
|
+
|
|
6
|
+
const commitPartial = ` - {{header}}
|
|
7
|
+
|
|
8
|
+
{{~!-- commit hash --}} {{#if @root.linkReferences}}([{{hash}}]({{#if @root.host}}{{@root.host}}/{{/if}}{{#if @root.owner}}{{@root.owner}}/{{/if}}{{@root.repository}}/{{@root.commit}}/{{hash}})){{else}}{{hash~}}{{/if}}
|
|
9
|
+
|
|
10
|
+
{{~!-- commit references --}}{{#if references}}, closes{{~#each references}} {{#if @root.linkReferences}}[{{#if this.owner}}{{this.owner}}/{{/if}}{{this.repository}}#{{this.issue}}]({{#if @root.host}}{{@root.host}}/{{/if}}{{#if this.repository}}{{#if this.owner}}{{this.owner}}/{{/if}}{{this.repository}}{{else}}{{#if @root.owner}}{{@root.owner}}/{{/if}}{{@root.repository}}{{/if}}/{{@root.issue}}/{{this.issue}}){{else}}{{#if this.owner}}{{this.owner}}/{{/if}}{{this.repository}}#{{this.issue}}{{/if}}{{/each}}{{/if}}
|
|
11
|
+
`;
|
|
12
|
+
|
|
13
|
+
const headerPartial = `## {{version}}{{#if title}} "{{title}}"{{/if}}{{#if date}} - {{date}}{{/if}}
|
|
14
|
+
`;
|
|
15
|
+
|
|
16
|
+
changelog({
|
|
17
|
+
releaseCount: 19,
|
|
18
|
+
// preset: 'jshint'
|
|
19
|
+
}, null, null, null, {
|
|
20
|
+
transform: function (commit) {
|
|
21
|
+
if (commit.header && semver_regex.exec(commit.header)) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
return commit;
|
|
25
|
+
},
|
|
26
|
+
commitPartial: commitPartial,
|
|
27
|
+
headerPartial: headerPartial
|
|
28
|
+
}).pipe(process.stdout);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(){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 f=r.join("/");f=f.replace(/\/(\?|&|#[^!])/g,"$1");var a=f.split("?");f=a.shift()+(a.length>0?"?":"")+a.join("&");return f}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 f=true;try{e[i].call(n.exports,n,n.exports,__nccwpck_require__);f=false}finally{if(f)delete r[i]}return n.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var i=__nccwpck_require__(821);module.exports=i})();
|
|
@@ -0,0 +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":"2025-04-23T10:32:00.093Z"}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
var urljoin = require('../lib/url-join');
|
|
2
|
+
var assert = require('assert');
|
|
3
|
+
|
|
4
|
+
describe('url join', function () {
|
|
5
|
+
it('should work for simple case', function () {
|
|
6
|
+
urljoin('http://www.google.com/', 'foo/bar', '?test=123')
|
|
7
|
+
.should.eql('http://www.google.com/foo/bar?test=123');
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it('should work for simple case with new syntax', function () {
|
|
11
|
+
urljoin(['http://www.google.com/', 'foo/bar', '?test=123'])
|
|
12
|
+
.should.eql('http://www.google.com/foo/bar?test=123');
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('should work for hashbang urls', function () {
|
|
16
|
+
urljoin(['http://www.google.com', '#!', 'foo/bar', '?test=123'])
|
|
17
|
+
.should.eql('http://www.google.com/#!/foo/bar?test=123');
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('should be able to join protocol', function () {
|
|
21
|
+
urljoin('http:', 'www.google.com/', 'foo/bar', '?test=123')
|
|
22
|
+
.should.eql('http://www.google.com/foo/bar?test=123');
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('should be able to join protocol with slashes', function () {
|
|
26
|
+
urljoin('http://', 'www.google.com/', 'foo/bar', '?test=123')
|
|
27
|
+
.should.eql('http://www.google.com/foo/bar?test=123');
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('should remove extra slashes', function () {
|
|
31
|
+
urljoin('http:', 'www.google.com///', 'foo/bar', '?test=123')
|
|
32
|
+
.should.eql('http://www.google.com/foo/bar?test=123');
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('should not remove extra slashes in an encoded URL', function () {
|
|
36
|
+
urljoin('http:', 'www.google.com///', 'foo/bar', '?url=http%3A//Ftest.com')
|
|
37
|
+
.should.eql('http://www.google.com/foo/bar?url=http%3A//Ftest.com');
|
|
38
|
+
|
|
39
|
+
urljoin('http://a.com/23d04b3/', '/b/c.html')
|
|
40
|
+
.should.eql('http://a.com/23d04b3/b/c.html')
|
|
41
|
+
.should.not.eql('http://a.com/23d04b3//b/c.html');
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('should support anchors in urls', function () {
|
|
45
|
+
urljoin('http:', 'www.google.com///', 'foo/bar', '?test=123', '#faaaaa')
|
|
46
|
+
.should.eql('http://www.google.com/foo/bar?test=123#faaaaa');
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('should support protocol-relative urls', function () {
|
|
50
|
+
urljoin('//www.google.com', 'foo/bar', '?test=123')
|
|
51
|
+
.should.eql('//www.google.com/foo/bar?test=123')
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('should support file protocol urls', function () {
|
|
55
|
+
urljoin('file:/', 'android_asset', 'foo/bar')
|
|
56
|
+
.should.eql('file://android_asset/foo/bar')
|
|
57
|
+
|
|
58
|
+
urljoin('file:', '/android_asset', 'foo/bar')
|
|
59
|
+
.should.eql('file://android_asset/foo/bar')
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('should support absolute file protocol urls', function () {
|
|
63
|
+
urljoin('file:', '///android_asset', 'foo/bar')
|
|
64
|
+
.should.eql('file:///android_asset/foo/bar')
|
|
65
|
+
|
|
66
|
+
urljoin('file:///', 'android_asset', 'foo/bar')
|
|
67
|
+
.should.eql('file:///android_asset/foo/bar')
|
|
68
|
+
|
|
69
|
+
urljoin('file:///', '//android_asset', 'foo/bar')
|
|
70
|
+
.should.eql('file:///android_asset/foo/bar')
|
|
71
|
+
|
|
72
|
+
urljoin('file:///android_asset', 'foo/bar')
|
|
73
|
+
.should.eql('file:///android_asset/foo/bar')
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('should merge multiple query params properly', function () {
|
|
77
|
+
urljoin('http:', 'www.google.com///', 'foo/bar', '?test=123', '?key=456')
|
|
78
|
+
.should.eql('http://www.google.com/foo/bar?test=123&key=456');
|
|
79
|
+
|
|
80
|
+
urljoin('http:', 'www.google.com///', 'foo/bar', '?test=123', '?boom=value', '&key=456')
|
|
81
|
+
.should.eql('http://www.google.com/foo/bar?test=123&boom=value&key=456');
|
|
82
|
+
|
|
83
|
+
urljoin('http://example.org/x', '?a=1', '?b=2', '?c=3', '?d=4')
|
|
84
|
+
.should.eql('http://example.org/x?a=1&b=2&c=3&d=4');
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('should merge slashes in paths correctly', function () {
|
|
88
|
+
urljoin('http://example.org', 'a//', 'b//', 'A//', 'B//')
|
|
89
|
+
.should.eql('http://example.org/a/b/A/B/');
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('should merge colons in paths correctly', function () {
|
|
93
|
+
urljoin('http://example.org/', ':foo:', 'bar')
|
|
94
|
+
.should.eql('http://example.org/:foo:/bar');
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('should merge just a simple path without URL correctly', function() {
|
|
98
|
+
urljoin('/', 'test')
|
|
99
|
+
.should.eql('/test');
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('should fail with segments that are not string', function() {
|
|
103
|
+
assert.throws(() => urljoin(true),
|
|
104
|
+
/Url must be a string. Received true/);
|
|
105
|
+
assert.throws(() => urljoin('http://blabla.com/', 1),
|
|
106
|
+
/Url must be a string. Received 1/);
|
|
107
|
+
assert.throws(() => urljoin('http://blabla.com/', undefined, 'test'),
|
|
108
|
+
/Url must be a string. Received undefined/);
|
|
109
|
+
assert.throws(() => urljoin('http://blabla.com/', null, 'test'),
|
|
110
|
+
/Url must be a string. Received null/);
|
|
111
|
+
assert.throws(() => urljoin('http://blabla.com/', { foo: 123 }, 'test'),
|
|
112
|
+
/Url must be a string. Received \[object Object\]/);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('should merge a path with colon properly', function(){
|
|
116
|
+
urljoin('/users/:userId', '/cars/:carId')
|
|
117
|
+
.should.eql('/users/:userId/cars/:carId');
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('should merge slashes in protocol correctly', function () {
|
|
121
|
+
urljoin('http://example.org', 'a')
|
|
122
|
+
.should.eql('http://example.org/a');
|
|
123
|
+
urljoin('http:', '//example.org', 'a')
|
|
124
|
+
.should.eql('http://example.org/a');
|
|
125
|
+
urljoin('http:///example.org', 'a')
|
|
126
|
+
.should.eql('http://example.org/a');
|
|
127
|
+
urljoin('file:///example.org', 'a')
|
|
128
|
+
.should.eql('file:///example.org/a');
|
|
129
|
+
|
|
130
|
+
urljoin('file:example.org', 'a')
|
|
131
|
+
.should.eql('file://example.org/a');
|
|
132
|
+
|
|
133
|
+
urljoin('file:/', 'example.org', 'a')
|
|
134
|
+
.should.eql('file://example.org/a');
|
|
135
|
+
urljoin('file:', '/example.org', 'a')
|
|
136
|
+
.should.eql('file://example.org/a');
|
|
137
|
+
urljoin('file:', '//example.org', 'a')
|
|
138
|
+
.should.eql('file://example.org/a');
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('should skip empty strings', function() {
|
|
142
|
+
urljoin('http://foobar.com', '', 'test')
|
|
143
|
+
.should.eql('http://foobar.com/test');
|
|
144
|
+
urljoin('', 'http://foobar.com', '', 'test')
|
|
145
|
+
.should.eql('http://foobar.com/test');
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it('should return an empty string if no arguments are supplied', function() {
|
|
149
|
+
urljoin().should.eql('');
|
|
150
|
+
});
|
|
151
|
+
});
|
|
@@ -7,15 +7,4 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
import { Context, Next } from '@nocobase/actions';
|
|
10
|
-
export declare function getFileData(ctx: Context): {
|
|
11
|
-
title: string;
|
|
12
|
-
filename: string;
|
|
13
|
-
extname: string;
|
|
14
|
-
path: any;
|
|
15
|
-
size: any;
|
|
16
|
-
url: string;
|
|
17
|
-
mimetype: any;
|
|
18
|
-
meta: unknown;
|
|
19
|
-
storageId: any;
|
|
20
|
-
};
|
|
21
10
|
export declare function createMiddleware(ctx: Context, next: Next): Promise<any>;
|
|
@@ -36,12 +36,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
36
36
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
37
37
|
var attachments_exports = {};
|
|
38
38
|
__export(attachments_exports, {
|
|
39
|
-
createMiddleware: () => createMiddleware
|
|
40
|
-
getFileData: () => getFileData
|
|
39
|
+
createMiddleware: () => createMiddleware
|
|
41
40
|
});
|
|
42
41
|
module.exports = __toCommonJS(attachments_exports);
|
|
43
42
|
var import_utils = require("@nocobase/utils");
|
|
44
|
-
var import_path = __toESM(require("path"));
|
|
45
43
|
var import__ = __toESM(require(".."));
|
|
46
44
|
var import_constants = require("../../constants");
|
|
47
45
|
var Rules = __toESM(require("../rules"));
|
|
@@ -53,35 +51,6 @@ function getFileFilter(storage) {
|
|
|
53
51
|
cb(null, result);
|
|
54
52
|
};
|
|
55
53
|
}
|
|
56
|
-
function getFileData(ctx) {
|
|
57
|
-
const { [import_constants.FILE_FIELD_NAME]: file, storage } = ctx;
|
|
58
|
-
if (!file) {
|
|
59
|
-
return ctx.throw(400, "file validation failed");
|
|
60
|
-
}
|
|
61
|
-
const StorageType = ctx.app.pm.get(import__.default).storageTypes.get(storage.type);
|
|
62
|
-
const { [StorageType.filenameKey || "filename"]: name } = file;
|
|
63
|
-
const filename = import_path.default.basename(name);
|
|
64
|
-
const extname = import_path.default.extname(filename);
|
|
65
|
-
const path = (storage.path || "").replace(/^\/|\/$/g, "");
|
|
66
|
-
const baseUrl = storage.baseUrl.replace(/\/+$/, "");
|
|
67
|
-
const pathname = [path, filename].filter(Boolean).join("/");
|
|
68
|
-
const storageInstance = new StorageType(storage);
|
|
69
|
-
return {
|
|
70
|
-
title: Buffer.from(file.originalname, "latin1").toString("utf8").replace(extname, ""),
|
|
71
|
-
filename,
|
|
72
|
-
extname,
|
|
73
|
-
// TODO(feature): 暂时两者相同,后面 storage.path 模版化以后,这里只是 file 实际的 path
|
|
74
|
-
path,
|
|
75
|
-
size: file.size,
|
|
76
|
-
// 直接缓存起来
|
|
77
|
-
url: `${baseUrl}/${pathname}`,
|
|
78
|
-
mimetype: file.mimetype,
|
|
79
|
-
// @ts-ignore
|
|
80
|
-
meta: ctx.request.body,
|
|
81
|
-
storageId: storage.id,
|
|
82
|
-
...storageInstance.getFileData ? storageInstance.getFileData(file) : {}
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
54
|
async function multipart(ctx, next) {
|
|
86
55
|
const { storage } = ctx;
|
|
87
56
|
if (!storage) {
|
|
@@ -114,7 +83,11 @@ async function multipart(ctx, next) {
|
|
|
114
83
|
ctx.logger.error(err);
|
|
115
84
|
return ctx.throw(500, err);
|
|
116
85
|
}
|
|
117
|
-
const
|
|
86
|
+
const { [import_constants.FILE_FIELD_NAME]: file } = ctx;
|
|
87
|
+
if (!file) {
|
|
88
|
+
return ctx.throw(400, "file validation failed");
|
|
89
|
+
}
|
|
90
|
+
const values = storageInstance.getFileData(file, ctx.request.body);
|
|
118
91
|
ctx.action.mergeParams({
|
|
119
92
|
values
|
|
120
93
|
});
|
|
@@ -128,11 +101,10 @@ async function createMiddleware(ctx, next) {
|
|
|
128
101
|
if (((_a = collection == null ? void 0 : collection.options) == null ? void 0 : _a.template) !== "file" || !["upload", "create"].includes(actionName)) {
|
|
129
102
|
return next();
|
|
130
103
|
}
|
|
131
|
-
const storageName = ((_c = (_b = ctx.db.getFieldByPath(attachmentField)) == null ? void 0 : _b.options) == null ? void 0 : _c.storage) || collection.options.storage;
|
|
132
|
-
const StorageRepo = ctx.db.getRepository("storages");
|
|
133
|
-
const storage = await StorageRepo.findOne({ filter: storageName ? { name: storageName } : { default: true } });
|
|
134
104
|
const plugin = ctx.app.pm.get(import__.default);
|
|
135
|
-
ctx.storage
|
|
105
|
+
const storageName = ((_c = (_b = ctx.db.getFieldByPath(attachmentField)) == null ? void 0 : _b.options) == null ? void 0 : _c.storage) || collection.options.storage;
|
|
106
|
+
const storages = Array.from(plugin.storagesCache.values());
|
|
107
|
+
ctx.storage = storages.find((item) => item.name === storageName) || storages.find((item) => item.default);
|
|
136
108
|
if (ctx == null ? void 0 : ctx.request.is("multipart/*")) {
|
|
137
109
|
await multipart(ctx, next);
|
|
138
110
|
} else {
|
|
@@ -141,6 +113,5 @@ async function createMiddleware(ctx, next) {
|
|
|
141
113
|
}
|
|
142
114
|
// Annotate the CommonJS export names for ESM import in node:
|
|
143
115
|
0 && (module.exports = {
|
|
144
|
-
createMiddleware
|
|
145
|
-
getFileData
|
|
116
|
+
createMiddleware
|
|
146
117
|
});
|
|
@@ -49,4 +49,23 @@ function actions_default({ app }) {
|
|
|
49
49
|
});
|
|
50
50
|
app.resourcer.use(import_attachments.createMiddleware, { tag: "createMiddleware", after: "auth" });
|
|
51
51
|
app.resourcer.registerActionHandler("upload", import_actions.default.create);
|
|
52
|
+
app.resourcer.use(
|
|
53
|
+
async (ctx, next) => {
|
|
54
|
+
var _a;
|
|
55
|
+
await next();
|
|
56
|
+
try {
|
|
57
|
+
const { resourceName, actionName } = ctx.action;
|
|
58
|
+
const collection = ctx.db.getCollection(resourceName);
|
|
59
|
+
if (((_a = collection == null ? void 0 : collection.options) == null ? void 0 : _a.template) !== "file") {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (actionName === "create" || actionName === "upload") {
|
|
63
|
+
ctx.body = await ctx.body.reload();
|
|
64
|
+
}
|
|
65
|
+
} catch (error) {
|
|
66
|
+
console.log(error);
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
{ before: "dataWrapping" }
|
|
70
|
+
);
|
|
52
71
|
}
|
|
@@ -41,6 +41,7 @@ __export(storages_exports, {
|
|
|
41
41
|
module.exports = __toCommonJS(storages_exports);
|
|
42
42
|
var import__ = __toESM(require(".."));
|
|
43
43
|
async function getBasicInfo(context, next) {
|
|
44
|
+
var _a, _b;
|
|
44
45
|
const { storagesCache } = context.app.pm.get(import__.default);
|
|
45
46
|
let result;
|
|
46
47
|
const { filterByTk } = context.action.params;
|
|
@@ -58,7 +59,9 @@ async function getBasicInfo(context, next) {
|
|
|
58
59
|
title: result.title,
|
|
59
60
|
name: result.name,
|
|
60
61
|
type: result.type,
|
|
61
|
-
rules: result.rules
|
|
62
|
+
rules: result.rules,
|
|
63
|
+
baseUrl: (_a = result.options) == null ? void 0 : _a.baseUrl,
|
|
64
|
+
public: (_b = result.options) == null ? void 0 : _b.public
|
|
62
65
|
};
|
|
63
66
|
next();
|
|
64
67
|
}
|
|
@@ -41,14 +41,16 @@ var storages_default = (0, import_database.defineCollection)({
|
|
|
41
41
|
comment: "\u5B58\u50A8\u5F15\u64CE\u540D\u79F0",
|
|
42
42
|
type: "string",
|
|
43
43
|
name: "title",
|
|
44
|
-
translation: true
|
|
44
|
+
translation: true,
|
|
45
|
+
trim: true
|
|
45
46
|
},
|
|
46
47
|
{
|
|
47
48
|
title: "\u82F1\u6587\u6807\u8BC6",
|
|
48
49
|
// comment: '英文标识,用于代码层面配置',
|
|
49
50
|
type: "uid",
|
|
50
51
|
name: "name",
|
|
51
|
-
unique: true
|
|
52
|
+
unique: true,
|
|
53
|
+
trim: true
|
|
52
54
|
},
|
|
53
55
|
{
|
|
54
56
|
comment: "\u7C7B\u578B\u6807\u8BC6\uFF0C\u5982 local/ali-oss \u7B49",
|
|
@@ -71,13 +73,15 @@ var storages_default = (0, import_database.defineCollection)({
|
|
|
71
73
|
comment: "\u5B58\u50A8\u76F8\u5BF9\u8DEF\u5F84\u6A21\u677F",
|
|
72
74
|
type: "text",
|
|
73
75
|
name: "path",
|
|
74
|
-
defaultValue: ""
|
|
76
|
+
defaultValue: "",
|
|
77
|
+
trim: true
|
|
75
78
|
},
|
|
76
79
|
{
|
|
77
80
|
comment: "\u8BBF\u95EE\u5730\u5740\u524D\u7F00",
|
|
78
81
|
type: "string",
|
|
79
82
|
name: "baseUrl",
|
|
80
|
-
defaultValue: ""
|
|
83
|
+
defaultValue: "",
|
|
84
|
+
trim: true
|
|
81
85
|
},
|
|
82
86
|
// TODO(feature): 需要使用一个实现了可设置默认值的字段
|
|
83
87
|
{
|
package/dist/server/index.d.ts
CHANGED
|
@@ -9,5 +9,6 @@
|
|
|
9
9
|
import { StorageEngine } from 'multer';
|
|
10
10
|
export * from '../constants';
|
|
11
11
|
export { AttachmentModel, default, PluginFileManagerServer, StorageModel } from './server';
|
|
12
|
+
export { cloudFilenameGetter } from './utils';
|
|
12
13
|
export { StorageType } from './storages';
|
|
13
14
|
export { StorageEngine };
|
package/dist/server/index.js
CHANGED
|
@@ -42,12 +42,14 @@ __export(server_exports, {
|
|
|
42
42
|
StorageEngine: () => import_multer.StorageEngine,
|
|
43
43
|
StorageModel: () => import_server.StorageModel,
|
|
44
44
|
StorageType: () => import_storages.StorageType,
|
|
45
|
+
cloudFilenameGetter: () => import_utils.cloudFilenameGetter,
|
|
45
46
|
default: () => import_server.default
|
|
46
47
|
});
|
|
47
48
|
module.exports = __toCommonJS(server_exports);
|
|
48
49
|
var import_multer = require("multer");
|
|
49
50
|
__reExport(server_exports, require("../constants"), module.exports);
|
|
50
51
|
var import_server = __toESM(require("./server"));
|
|
52
|
+
var import_utils = require("./utils");
|
|
51
53
|
var import_storages = require("./storages");
|
|
52
54
|
// Annotate the CommonJS export names for ESM import in node:
|
|
53
55
|
0 && (module.exports = {
|
|
@@ -56,5 +58,6 @@ var import_storages = require("./storages");
|
|
|
56
58
|
StorageEngine,
|
|
57
59
|
StorageModel,
|
|
58
60
|
StorageType,
|
|
61
|
+
cloudFilenameGetter,
|
|
59
62
|
...require("../constants")
|
|
60
63
|
});
|
package/dist/server/server.d.ts
CHANGED
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
|
+
import { Model, Transactionable } from '@nocobase/database';
|
|
9
10
|
import { Plugin } from '@nocobase/server';
|
|
10
11
|
import { Registry } from '@nocobase/utils';
|
|
11
|
-
import { Model, Transactionable } from '@nocobase/database';
|
|
12
12
|
import { AttachmentModel, StorageClassType, StorageModel } from './storages';
|
|
13
13
|
export type * from './storages';
|
|
14
14
|
export type FileRecordOptions = {
|
|
@@ -33,12 +33,11 @@ export declare class PluginFileManagerServer extends Plugin {
|
|
|
33
33
|
title: string;
|
|
34
34
|
filename: string;
|
|
35
35
|
extname: string;
|
|
36
|
-
path:
|
|
36
|
+
path: string;
|
|
37
37
|
size: any;
|
|
38
|
-
url: string;
|
|
39
38
|
mimetype: any;
|
|
40
|
-
meta:
|
|
41
|
-
storageId:
|
|
39
|
+
meta: {};
|
|
40
|
+
storageId: number;
|
|
42
41
|
}>;
|
|
43
42
|
loadStorages(options?: {
|
|
44
43
|
transaction: any;
|
|
@@ -47,6 +46,7 @@ export declare class PluginFileManagerServer extends Plugin {
|
|
|
47
46
|
handleSyncMessage(message: any): Promise<void>;
|
|
48
47
|
beforeLoad(): Promise<void>;
|
|
49
48
|
load(): Promise<void>;
|
|
50
|
-
getFileURL(file: AttachmentModel):
|
|
49
|
+
getFileURL(file: AttachmentModel, preview?: boolean): Promise<string>;
|
|
50
|
+
isPublicAccessStorage(storageName: any): Promise<boolean>;
|
|
51
51
|
}
|
|
52
52
|
export default PluginFileManagerServer;
|