@webiny/api-file-manager 5.23.0 → 5.24.0-beta.0
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/handlers/download/index.d.ts +5 -1
- package/handlers/download/index.js +22 -17
- package/handlers/manage/index.d.ts +2 -1
- package/handlers/manage/index.js +17 -16
- package/handlers/transform/index.d.ts +2 -1
- package/handlers/transform/index.js +7 -4
- package/handlers/transform/loaders/imageLoader.d.ts +25 -9
- package/handlers/transform/loaders/imageLoader.js +2 -2
- package/handlers/transform/loaders/index.d.ts +4 -9
- package/handlers/transform/loaders/sanitizeImageTransformations.d.ts +7 -3
- package/handlers/transform/loaders/sanitizeImageTransformations.js +27 -20
- package/handlers/transform/managers/imageManager.d.ts +12 -6
- package/handlers/transform/managers/imageManager.js +16 -19
- package/handlers/transform/managers/index.d.ts +2 -6
- package/handlers/transform/optimizeImage.d.ts +2 -1
- package/handlers/transform/optimizeImage.js +3 -0
- package/handlers/transform/transformImage.d.ts +5 -4
- package/handlers/transform/transformImage.js +3 -3
- package/handlers/transform/utils.d.ts +2 -2
- package/handlers/types.d.ts +33 -0
- package/handlers/types.js +5 -0
- package/handlers/utils/createHandler.d.ts +16 -16
- package/handlers/utils/createHandler.js +43 -42
- package/handlers/utils/getObjectParams.d.ts +3 -4
- package/handlers/utils/getObjectParams.js +0 -2
- package/handlers/utils/index.d.ts +1 -1
- package/handlers/utils/index.js +17 -7
- package/package.json +17 -17
- package/plugins/crud/settings.crud.js +1 -0
- package/plugins/crud/utils/createFileModel.d.ts +3 -0
- package/plugins/crud/utils/createFileModel.js +13 -0
- package/plugins/crud/utils/lifecycleEvents.d.ts +2 -2
- package/plugins/crud/utils/lifecycleEvents.js +5 -0
- package/plugins/definitions/FilePhysicalStoragePlugin.d.ts +9 -10
- package/plugins/definitions/FilePlugin.d.ts +5 -2
- package/plugins/definitions/FilePlugin.js +4 -0
- package/plugins/definitions/FileStorageTransformPlugin.d.ts +8 -8
- package/plugins/definitions/FilesStorageOperationsProviderPlugin.d.ts +2 -2
- package/plugins/definitions/InstallationPlugin.d.ts +8 -8
- package/plugins/definitions/SettingsStorageOperationsProviderPlugin.d.ts +2 -2
- package/plugins/definitions/SystemStorageOperationsProviderPlugin.d.ts +2 -2
- package/plugins/graphql.js +7 -0
- package/plugins/storage/FileStorage.d.ts +23 -24
- package/plugins/storage/FileStorage.js +8 -9
- package/plugins/storage/index.js +4 -0
- package/types.d.ts +1 -1
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { HandlerPlugin } from "@webiny/handler/types";
|
|
2
2
|
import { ArgsContext } from "@webiny/handler-args/types";
|
|
3
|
-
|
|
3
|
+
import { DownloadHandlerEventArgs } from "../types";
|
|
4
|
+
import { ClientContext } from "@webiny/handler-client/types";
|
|
5
|
+
interface Context extends ClientContext, ArgsContext<DownloadHandlerEventArgs> {
|
|
6
|
+
}
|
|
7
|
+
declare const _default: () => HandlerPlugin<Context>;
|
|
4
8
|
export default _default;
|
|
@@ -25,7 +25,6 @@ const DEFAULT_CACHE_MAX_AGE = 30758400; // 1 year
|
|
|
25
25
|
* Based on given path, extracts file key and additional options sent via query params.
|
|
26
26
|
* @param event
|
|
27
27
|
*/
|
|
28
|
-
|
|
29
28
|
const extractFilenameOptions = event => {
|
|
30
29
|
const path = (0, _sanitizeFilename.default)(event.pathParameters.path);
|
|
31
30
|
return {
|
|
@@ -42,8 +41,7 @@ const getS3Object = async (event, s3, context) => {
|
|
|
42
41
|
extension
|
|
43
42
|
} = extractFilenameOptions(event);
|
|
44
43
|
|
|
45
|
-
for (
|
|
46
|
-
const loader = _loaders.default[i];
|
|
44
|
+
for (const loader of _loaders.default) {
|
|
47
45
|
const canProcess = loader.canProcess({
|
|
48
46
|
context,
|
|
49
47
|
s3,
|
|
@@ -54,17 +52,19 @@ const getS3Object = async (event, s3, context) => {
|
|
|
54
52
|
}
|
|
55
53
|
});
|
|
56
54
|
|
|
57
|
-
if (canProcess) {
|
|
58
|
-
|
|
59
|
-
context,
|
|
60
|
-
s3,
|
|
61
|
-
options,
|
|
62
|
-
file: {
|
|
63
|
-
name: filename,
|
|
64
|
-
extension
|
|
65
|
-
}
|
|
66
|
-
});
|
|
55
|
+
if (!canProcess) {
|
|
56
|
+
continue;
|
|
67
57
|
}
|
|
58
|
+
|
|
59
|
+
return loader.process({
|
|
60
|
+
context,
|
|
61
|
+
s3,
|
|
62
|
+
options,
|
|
63
|
+
file: {
|
|
64
|
+
name: filename,
|
|
65
|
+
extension
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
68
|
} // If no processors handled the file request, just return the S3 object by default.
|
|
69
69
|
|
|
70
70
|
|
|
@@ -80,8 +80,7 @@ var _default = () => ({
|
|
|
80
80
|
name: "handler-download-file",
|
|
81
81
|
|
|
82
82
|
async handle(context) {
|
|
83
|
-
const
|
|
84
|
-
const handler = (0, _utils.createHandler)(async event => {
|
|
83
|
+
const eventHandler = async event => {
|
|
85
84
|
const {
|
|
86
85
|
region
|
|
87
86
|
} = (0, _utils.getEnvironment)();
|
|
@@ -95,6 +94,9 @@ var _default = () => ({
|
|
|
95
94
|
|
|
96
95
|
if (object.ContentLength < MAX_RETURN_CONTENT_LENGTH) {
|
|
97
96
|
return {
|
|
97
|
+
/**
|
|
98
|
+
* It is safe to cast as buffer or unknown
|
|
99
|
+
*/
|
|
98
100
|
data: object.Body,
|
|
99
101
|
headers: {
|
|
100
102
|
"Content-Type": object.ContentType,
|
|
@@ -111,13 +113,16 @@ var _default = () => ({
|
|
|
111
113
|
Key: params.Key
|
|
112
114
|
}).promise();
|
|
113
115
|
return {
|
|
116
|
+
data: null,
|
|
114
117
|
statusCode: 301,
|
|
115
118
|
headers: {
|
|
116
119
|
Location: `https://${params.Bucket}.s3.amazonaws.com/${params.Key}`
|
|
117
120
|
}
|
|
118
121
|
};
|
|
119
|
-
}
|
|
120
|
-
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const handler = (0, _utils.createHandler)(eventHandler);
|
|
125
|
+
return await handler(context.invocationArgs);
|
|
121
126
|
}
|
|
122
127
|
|
|
123
128
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { HandlerPlugin } from "@webiny/handler/types";
|
|
2
2
|
import { ArgsContext } from "@webiny/handler-args/types";
|
|
3
|
-
|
|
3
|
+
import { ManageHandlerEventArgs } from "../types";
|
|
4
|
+
declare const _default: () => HandlerPlugin<ArgsContext<ManageHandlerEventArgs>>;
|
|
4
5
|
export default _default;
|
package/handlers/manage/index.js
CHANGED
|
@@ -20,8 +20,9 @@ var _default = () => ({
|
|
|
20
20
|
name: "handler-download-file",
|
|
21
21
|
|
|
22
22
|
async handle(context) {
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
// TODO @ts-refactor check in createHandler for returns types that eventHandler must return
|
|
24
|
+
// @ts-ignore
|
|
25
|
+
const eventHandler = async event => {
|
|
25
26
|
const keys = [];
|
|
26
27
|
|
|
27
28
|
for (let i = 0; i < event.Records.length; i++) {
|
|
@@ -39,30 +40,30 @@ var _default = () => ({
|
|
|
39
40
|
region
|
|
40
41
|
});
|
|
41
42
|
|
|
42
|
-
for (
|
|
43
|
-
const key = keys[i];
|
|
44
|
-
|
|
43
|
+
for (const key of keys) {
|
|
45
44
|
const extension = _path.default.extname(key);
|
|
46
45
|
|
|
47
|
-
for (
|
|
48
|
-
const manager = _managers.default[j];
|
|
46
|
+
for (const manager of _managers.default) {
|
|
49
47
|
const canProcess = manager.canProcess({
|
|
50
|
-
s3,
|
|
51
48
|
key,
|
|
52
49
|
extension
|
|
53
50
|
});
|
|
54
51
|
|
|
55
|
-
if (canProcess) {
|
|
56
|
-
|
|
57
|
-
s3,
|
|
58
|
-
key,
|
|
59
|
-
extension
|
|
60
|
-
});
|
|
52
|
+
if (!canProcess) {
|
|
53
|
+
continue;
|
|
61
54
|
}
|
|
55
|
+
|
|
56
|
+
await manager.process({
|
|
57
|
+
s3,
|
|
58
|
+
key,
|
|
59
|
+
extension
|
|
60
|
+
});
|
|
62
61
|
}
|
|
63
62
|
}
|
|
64
|
-
}
|
|
65
|
-
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const handler = (0, _utils.createHandler)(eventHandler);
|
|
66
|
+
return await handler(context.invocationArgs);
|
|
66
67
|
}
|
|
67
68
|
|
|
68
69
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { HandlerPlugin } from "@webiny/handler/types";
|
|
2
2
|
import { ArgsContext } from "@webiny/handler-args/types";
|
|
3
|
-
|
|
3
|
+
import { TransformHandlerEventArgs } from "../types";
|
|
4
|
+
declare const _default: () => HandlerPlugin<ArgsContext<TransformHandlerEventArgs>>;
|
|
4
5
|
export default _default;
|
|
@@ -28,8 +28,9 @@ var _default = () => ({
|
|
|
28
28
|
name: "handler-download-file",
|
|
29
29
|
|
|
30
30
|
async handle(context) {
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
// TODO @ts-refactor check in createHandler for returns types that eventHandler must return
|
|
32
|
+
// @ts-ignore
|
|
33
|
+
const eventHandler = async ({
|
|
33
34
|
body: {
|
|
34
35
|
transformations,
|
|
35
36
|
key
|
|
@@ -87,8 +88,10 @@ var _default = () => ({
|
|
|
87
88
|
message: e.message
|
|
88
89
|
};
|
|
89
90
|
}
|
|
90
|
-
}
|
|
91
|
-
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const handler = (0, _utils.createHandler)(eventHandler);
|
|
94
|
+
return await handler(context.invocationArgs);
|
|
92
95
|
}
|
|
93
96
|
|
|
94
97
|
});
|
|
@@ -1,13 +1,29 @@
|
|
|
1
|
+
import { ClientContext } from "@webiny/handler-client/types";
|
|
2
|
+
import S3 from "aws-sdk/clients/s3";
|
|
3
|
+
interface File {
|
|
4
|
+
extension: string;
|
|
5
|
+
name: string;
|
|
6
|
+
}
|
|
7
|
+
interface Options {
|
|
8
|
+
width: string;
|
|
9
|
+
}
|
|
10
|
+
export interface CanProcessParams {
|
|
11
|
+
s3: S3;
|
|
12
|
+
file: File;
|
|
13
|
+
options: Options;
|
|
14
|
+
context: ClientContext;
|
|
15
|
+
}
|
|
16
|
+
export interface ProcessParams {
|
|
17
|
+
s3: S3;
|
|
18
|
+
file: File;
|
|
19
|
+
options: Options;
|
|
20
|
+
context: ClientContext;
|
|
21
|
+
}
|
|
1
22
|
declare const _default: {
|
|
2
|
-
canProcess: (
|
|
3
|
-
process({ s3, file, options, context }: {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
options: any;
|
|
7
|
-
context: any;
|
|
8
|
-
}): Promise<{
|
|
9
|
-
object: any;
|
|
10
|
-
params: any;
|
|
23
|
+
canProcess: (params: CanProcessParams) => boolean;
|
|
24
|
+
process({ s3, file, options, context }: ProcessParams): Promise<{
|
|
25
|
+
object: import("aws-sdk/lib/request").PromiseResult<S3.GetObjectOutput, import("aws-sdk/lib/error").AWSError>;
|
|
26
|
+
params: import("../../utils/getObjectParams").ObjectParamsResponse;
|
|
11
27
|
}>;
|
|
12
28
|
};
|
|
13
29
|
export default _default;
|
|
@@ -33,8 +33,8 @@ const callImageTransformerLambda = async ({
|
|
|
33
33
|
};
|
|
34
34
|
|
|
35
35
|
var _default = {
|
|
36
|
-
canProcess:
|
|
37
|
-
return _utils2.SUPPORTED_IMAGES.includes(
|
|
36
|
+
canProcess: params => {
|
|
37
|
+
return _utils2.SUPPORTED_IMAGES.includes(params.file.extension);
|
|
38
38
|
},
|
|
39
39
|
|
|
40
40
|
async process({
|
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
declare const _default: {
|
|
2
|
-
canProcess: (
|
|
3
|
-
process({ s3, file, options, context }: {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
options: any;
|
|
7
|
-
context: any;
|
|
8
|
-
}): Promise<{
|
|
9
|
-
object: any;
|
|
10
|
-
params: any;
|
|
2
|
+
canProcess: (params: import("./imageLoader").CanProcessParams) => boolean;
|
|
3
|
+
process({ s3, file, options, context }: import("./imageLoader").ProcessParams): Promise<{
|
|
4
|
+
object: import("aws-sdk/lib/request").PromiseResult<import("aws-sdk/clients/s3").GetObjectOutput, import("aws-sdk/lib/error").AWSError>;
|
|
5
|
+
params: import("../../utils/getObjectParams").ObjectParamsResponse;
|
|
11
6
|
}>;
|
|
12
7
|
}[];
|
|
13
8
|
export default _default;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
}
|
|
1
|
+
export interface SanitizeImageArgs {
|
|
2
|
+
width?: string;
|
|
3
|
+
}
|
|
4
|
+
export interface SanitizeImageTransformations {
|
|
5
|
+
width: number;
|
|
6
|
+
}
|
|
7
|
+
declare const _default: (args: SanitizeImageArgs) => SanitizeImageTransformations;
|
|
4
8
|
/**
|
|
5
9
|
* Takes only allowed transformations into consideration, and discards the rest.
|
|
6
10
|
*/
|
|
@@ -5,43 +5,50 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
const SUPPORTED_IMAGE_RESIZE_WIDTHS = [100, 300, 500, 750, 1000, 1500, 2500];
|
|
8
|
+
|
|
8
9
|
/**
|
|
9
10
|
* Takes only allowed transformations into consideration, and discards the rest.
|
|
10
11
|
*/
|
|
11
|
-
|
|
12
12
|
var _default = args => {
|
|
13
13
|
const transformations = {};
|
|
14
14
|
|
|
15
|
-
if (args) {
|
|
16
|
-
|
|
15
|
+
if (!args || !args.width) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
transformations.width = SUPPORTED_IMAGE_RESIZE_WIDTHS[0];
|
|
20
|
-
let i = SUPPORTED_IMAGE_RESIZE_WIDTHS.length;
|
|
19
|
+
const width = parseInt(args.width);
|
|
21
20
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
break;
|
|
26
|
-
}
|
|
21
|
+
if (width <= 0) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
27
24
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
transformations.width = SUPPORTED_IMAGE_RESIZE_WIDTHS[i + 1];
|
|
25
|
+
transformations.width = SUPPORTED_IMAGE_RESIZE_WIDTHS[0];
|
|
26
|
+
let i = SUPPORTED_IMAGE_RESIZE_WIDTHS.length;
|
|
31
27
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
28
|
+
while (i >= 0) {
|
|
29
|
+
if (width === SUPPORTED_IMAGE_RESIZE_WIDTHS[i]) {
|
|
30
|
+
transformations.width = SUPPORTED_IMAGE_RESIZE_WIDTHS[i];
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
35
33
|
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
if (width > SUPPORTED_IMAGE_RESIZE_WIDTHS[i]) {
|
|
35
|
+
// Use next larger width. If there isn't any, use current.
|
|
36
|
+
transformations.width = SUPPORTED_IMAGE_RESIZE_WIDTHS[i + 1];
|
|
38
37
|
|
|
39
|
-
|
|
38
|
+
if (!transformations.width) {
|
|
39
|
+
transformations.width = SUPPORTED_IMAGE_RESIZE_WIDTHS[i];
|
|
40
40
|
}
|
|
41
|
+
|
|
42
|
+
break;
|
|
41
43
|
}
|
|
44
|
+
|
|
45
|
+
i--;
|
|
42
46
|
}
|
|
43
47
|
|
|
44
48
|
if (Object.keys(transformations).length > 0) {
|
|
49
|
+
/**
|
|
50
|
+
* It is safe to cast.
|
|
51
|
+
*/
|
|
45
52
|
return transformations;
|
|
46
53
|
}
|
|
47
54
|
|
|
@@ -1,9 +1,15 @@
|
|
|
1
|
+
import S3 from "aws-sdk/clients/s3";
|
|
2
|
+
export interface ImageManagerCanProcessParams {
|
|
3
|
+
key: string;
|
|
4
|
+
extension: string;
|
|
5
|
+
}
|
|
6
|
+
export interface ImageManagerProcessParams {
|
|
7
|
+
s3: S3;
|
|
8
|
+
key: string;
|
|
9
|
+
extension: string;
|
|
10
|
+
}
|
|
1
11
|
declare const _default: {
|
|
2
|
-
canProcess: (
|
|
3
|
-
process({ s3, key, extension }:
|
|
4
|
-
s3: any;
|
|
5
|
-
key: any;
|
|
6
|
-
extension: any;
|
|
7
|
-
}): Promise<void>;
|
|
12
|
+
canProcess: (params: ImageManagerCanProcessParams) => boolean;
|
|
13
|
+
process({ s3, key, extension }: ImageManagerProcessParams): Promise<void>;
|
|
8
14
|
};
|
|
9
15
|
export default _default;
|
|
@@ -10,21 +10,17 @@ var _utils = require("../../utils");
|
|
|
10
10
|
var _utils2 = require("../utils");
|
|
11
11
|
|
|
12
12
|
var _default = {
|
|
13
|
-
canProcess:
|
|
13
|
+
canProcess: params => {
|
|
14
14
|
const {
|
|
15
15
|
key,
|
|
16
16
|
extension
|
|
17
|
-
} =
|
|
17
|
+
} = params;
|
|
18
18
|
|
|
19
|
-
if (
|
|
19
|
+
if (_utils2.SUPPORTED_IMAGES.includes(extension) === false) {
|
|
20
20
|
return false;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return true;
|
|
23
|
+
return key.startsWith(_utils2.OPTIMIZED_IMAGE_PREFIX) || key.startsWith(_utils2.OPTIMIZED_TRANSFORMED_IMAGE_PREFIX);
|
|
28
24
|
},
|
|
29
25
|
|
|
30
26
|
async process({
|
|
@@ -37,17 +33,18 @@ var _default = {
|
|
|
37
33
|
key
|
|
38
34
|
}))).promise(); // 2. Search for all transformed images and delete those too.
|
|
39
35
|
|
|
40
|
-
if (_utils2.SUPPORTED_TRANSFORMABLE_IMAGES.includes(extension)) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
36
|
+
if (_utils2.SUPPORTED_TRANSFORMABLE_IMAGES.includes(extension) === false) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const env = (0, _utils.getEnvironment)();
|
|
41
|
+
const imagesList = await s3.listObjects({
|
|
42
|
+
Bucket: env.bucket,
|
|
43
|
+
Prefix: (0, _utils2.getOptimizedTransformedImageKeyPrefix)(key)
|
|
44
|
+
}).promise();
|
|
45
|
+
|
|
46
|
+
for (const imageObject of imagesList.Contents) {
|
|
47
|
+
await s3.deleteObject((0, _utils.getObjectParams)(imageObject.Key)).promise();
|
|
51
48
|
}
|
|
52
49
|
}
|
|
53
50
|
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
declare const _default: {
|
|
2
|
-
canProcess: (
|
|
3
|
-
process({ s3, key, extension }:
|
|
4
|
-
s3: any;
|
|
5
|
-
key: any;
|
|
6
|
-
extension: any;
|
|
7
|
-
}): Promise<void>;
|
|
2
|
+
canProcess: (params: import("./imageManager").ImageManagerCanProcessParams) => boolean;
|
|
3
|
+
process({ s3, key, extension }: import("./imageManager").ImageManagerProcessParams): Promise<void>;
|
|
8
4
|
}[];
|
|
9
5
|
export default _default;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import { Body } from "aws-sdk/clients/s3";
|
|
2
|
+
interface Transformation {
|
|
3
|
+
width: string;
|
|
4
|
+
}
|
|
5
|
+
declare const _default: (buffer: Body, transformations: Transformation) => Promise<Body>;
|
|
2
6
|
/**
|
|
3
7
|
* Only processing "width" at the moment.
|
|
4
8
|
* Check "sanitizeImageTransformations.js" to allow additional image processing transformations.
|
|
5
|
-
* @param buffer
|
|
6
|
-
* @param transformations
|
|
7
|
-
* @returns {Promise<Buffer>}
|
|
8
9
|
*/
|
|
9
10
|
export default _default;
|
|
@@ -9,14 +9,14 @@ exports.default = void 0;
|
|
|
9
9
|
|
|
10
10
|
var _sharp = _interopRequireDefault(require("sharp"));
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Sharp is included in the AWS Lambda layer
|
|
14
|
+
*/
|
|
12
15
|
// @ts-ignore
|
|
13
16
|
|
|
14
17
|
/**
|
|
15
18
|
* Only processing "width" at the moment.
|
|
16
19
|
* Check "sanitizeImageTransformations.js" to allow additional image processing transformations.
|
|
17
|
-
* @param buffer
|
|
18
|
-
* @param transformations
|
|
19
|
-
* @returns {Promise<Buffer>}
|
|
20
20
|
*/
|
|
21
21
|
var _default = async (buffer, transformations) => {
|
|
22
22
|
const {
|
|
@@ -2,8 +2,8 @@ declare const SUPPORTED_IMAGES: string[];
|
|
|
2
2
|
declare const SUPPORTED_TRANSFORMABLE_IMAGES: string[];
|
|
3
3
|
declare const OPTIMIZED_TRANSFORMED_IMAGE_PREFIX = "img-o-t-";
|
|
4
4
|
declare const OPTIMIZED_IMAGE_PREFIX = "img-o-";
|
|
5
|
-
declare const getOptimizedImageKeyPrefix: (key:
|
|
6
|
-
declare const getOptimizedTransformedImageKeyPrefix: (key:
|
|
5
|
+
declare const getOptimizedImageKeyPrefix: (key: string) => string;
|
|
6
|
+
declare const getOptimizedTransformedImageKeyPrefix: (key: string) => string;
|
|
7
7
|
interface GetImageKeyParams {
|
|
8
8
|
key: string;
|
|
9
9
|
transformations?: any;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export interface HandlerEventArgs {
|
|
2
|
+
httpMethod: "POST" | "OPTIONS";
|
|
3
|
+
}
|
|
4
|
+
interface S3Record {
|
|
5
|
+
s3: {
|
|
6
|
+
object: {
|
|
7
|
+
key?: string;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export interface ManageHandlerEventArgs extends HandlerEventArgs {
|
|
12
|
+
Records: S3Record[];
|
|
13
|
+
}
|
|
14
|
+
export interface DownloadHandlerEventArgs extends HandlerEventArgs {
|
|
15
|
+
pathParameters: {
|
|
16
|
+
path: string;
|
|
17
|
+
};
|
|
18
|
+
queryStringParameters?: {
|
|
19
|
+
width: string;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export interface TransformHandlerEventArgs extends HandlerEventArgs {
|
|
23
|
+
body: {
|
|
24
|
+
key: string;
|
|
25
|
+
transformations: {
|
|
26
|
+
width: string;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export interface HandlerHeaders {
|
|
31
|
+
[key: string]: string | boolean;
|
|
32
|
+
}
|
|
33
|
+
export {};
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { HandlerEventArgs, HandlerHeaders } from "../types";
|
|
2
|
+
import { Body } from "aws-sdk/clients/s3";
|
|
3
|
+
interface EventHandlerResponse {
|
|
4
|
+
data: Body;
|
|
5
|
+
statusCode?: number;
|
|
6
|
+
headers: HandlerHeaders;
|
|
7
|
+
}
|
|
8
|
+
export interface EventHandlerCallable<T> {
|
|
9
|
+
(event: T): Promise<EventHandlerResponse>;
|
|
10
|
+
}
|
|
11
|
+
export declare const createHandler: <T extends HandlerEventArgs>(eventHandler: EventHandlerCallable<T>) => (event: T) => Promise<{
|
|
12
|
+
isBase64Encoded: boolean;
|
|
3
13
|
statusCode: number;
|
|
4
14
|
headers: {
|
|
5
|
-
|
|
6
|
-
"Access-Control-Allow-Origin": string;
|
|
7
|
-
"Access-Control-Allow-Credentials": boolean;
|
|
15
|
+
[x: string]: string | boolean;
|
|
8
16
|
};
|
|
9
|
-
|
|
10
|
-
} | {
|
|
11
|
-
isBase64Encoded: boolean;
|
|
12
|
-
statusCode: any;
|
|
13
|
-
headers: any;
|
|
14
|
-
body: any;
|
|
17
|
+
body: string;
|
|
15
18
|
} | {
|
|
16
19
|
statusCode: number;
|
|
17
|
-
headers:
|
|
18
|
-
"Access-Control-Allow-Origin": string;
|
|
19
|
-
"Access-Control-Allow-Credentials": boolean;
|
|
20
|
-
};
|
|
20
|
+
headers: HandlerHeaders;
|
|
21
21
|
body: string;
|
|
22
22
|
isBase64Encoded?: undefined;
|
|
23
23
|
}>;
|
|
24
|
-
export
|
|
24
|
+
export {};
|
|
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.
|
|
8
|
+
exports.createHandler = void 0;
|
|
9
9
|
|
|
10
10
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
11
|
|
|
@@ -15,7 +15,6 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* We need to respond with adequate CORS headers.
|
|
18
|
-
* @type {{"Access-Control-Allow-Origin": string, "Access-Control-Allow-Credentials": boolean}}
|
|
19
18
|
*/
|
|
20
19
|
const baseHeaders = {
|
|
21
20
|
"Access-Control-Allow-Origin": "*",
|
|
@@ -23,46 +22,48 @@ const baseHeaders = {
|
|
|
23
22
|
};
|
|
24
23
|
const DEFAULT_CACHE_MAX_AGE = 30758400; // 1 year
|
|
25
24
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
25
|
+
const createHandler = eventHandler => {
|
|
26
|
+
return async event => {
|
|
27
|
+
if (event.httpMethod === "OPTIONS") {
|
|
28
|
+
return {
|
|
29
|
+
body: "",
|
|
30
|
+
statusCode: 204,
|
|
31
|
+
headers: _objectSpread(_objectSpread({}, baseHeaders), {}, {
|
|
32
|
+
"Cache-Control": "public, max-age=" + DEFAULT_CACHE_MAX_AGE
|
|
33
|
+
})
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
37
|
+
try {
|
|
38
|
+
const {
|
|
39
|
+
data,
|
|
40
|
+
statusCode,
|
|
41
|
+
headers = {}
|
|
42
|
+
} = await eventHandler(event);
|
|
43
|
+
const isBuffer = Buffer.isBuffer(data);
|
|
44
|
+
const body = isBuffer ? data.toString("base64") : JSON.stringify({
|
|
45
|
+
error: false,
|
|
46
|
+
data,
|
|
47
|
+
message: null
|
|
48
|
+
});
|
|
49
|
+
return {
|
|
50
|
+
isBase64Encoded: isBuffer,
|
|
51
|
+
statusCode: statusCode || 200,
|
|
52
|
+
headers: _objectSpread(_objectSpread({}, baseHeaders), headers),
|
|
53
|
+
body
|
|
54
|
+
};
|
|
55
|
+
} catch (e) {
|
|
56
|
+
return {
|
|
57
|
+
statusCode: 500,
|
|
58
|
+
headers: baseHeaders,
|
|
59
|
+
body: JSON.stringify({
|
|
60
|
+
error: true,
|
|
61
|
+
data: null,
|
|
62
|
+
message: e.message
|
|
63
|
+
})
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
};
|
|
66
67
|
};
|
|
67
68
|
|
|
68
|
-
exports.
|
|
69
|
+
exports.createHandler = createHandler;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
export interface ObjectParamsResponse {
|
|
2
2
|
Bucket: string;
|
|
3
3
|
Key: string;
|
|
4
|
-
}
|
|
4
|
+
}
|
|
5
|
+
declare const _default: (filename: string) => ObjectParamsResponse;
|
|
5
6
|
/**
|
|
6
7
|
* Returns website's Bucket and file's Key values.
|
|
7
|
-
* @param filename
|
|
8
|
-
* @returns {{Bucket: string, Key: string}}
|
|
9
8
|
*/
|
|
10
9
|
export default _default;
|
package/handlers/utils/index.js
CHANGED
|
@@ -5,12 +5,10 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
});
|
|
8
|
+
var _exportNames = {
|
|
9
|
+
getEnvironment: true,
|
|
10
|
+
getObjectParams: true
|
|
11
|
+
};
|
|
14
12
|
Object.defineProperty(exports, "getEnvironment", {
|
|
15
13
|
enumerable: true,
|
|
16
14
|
get: function () {
|
|
@@ -26,6 +24,18 @@ Object.defineProperty(exports, "getObjectParams", {
|
|
|
26
24
|
|
|
27
25
|
var _getEnvironment = _interopRequireDefault(require("./getEnvironment"));
|
|
28
26
|
|
|
29
|
-
var _createHandler =
|
|
27
|
+
var _createHandler = require("./createHandler");
|
|
28
|
+
|
|
29
|
+
Object.keys(_createHandler).forEach(function (key) {
|
|
30
|
+
if (key === "default" || key === "__esModule") return;
|
|
31
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
32
|
+
if (key in exports && exports[key] === _createHandler[key]) return;
|
|
33
|
+
Object.defineProperty(exports, key, {
|
|
34
|
+
enumerable: true,
|
|
35
|
+
get: function () {
|
|
36
|
+
return _createHandler[key];
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
});
|
|
30
40
|
|
|
31
41
|
var _getObjectParams = _interopRequireDefault(require("./getObjectParams"));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-file-manager",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.24.0-beta.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fm:base"
|
|
@@ -20,18 +20,18 @@
|
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@babel/runtime": "7.16.7",
|
|
22
22
|
"@commodo/fields": "1.1.2-beta.20",
|
|
23
|
-
"@webiny/api-i18n-content": "5.
|
|
24
|
-
"@webiny/api-security": "5.
|
|
25
|
-
"@webiny/api-tenancy": "5.
|
|
26
|
-
"@webiny/api-upgrade": "5.
|
|
27
|
-
"@webiny/error": "5.
|
|
28
|
-
"@webiny/handler": "5.
|
|
29
|
-
"@webiny/handler-args": "5.
|
|
30
|
-
"@webiny/handler-client": "5.
|
|
31
|
-
"@webiny/handler-graphql": "5.
|
|
32
|
-
"@webiny/plugins": "5.
|
|
33
|
-
"@webiny/project-utils": "5.
|
|
34
|
-
"@webiny/validation": "5.
|
|
23
|
+
"@webiny/api-i18n-content": "5.24.0-beta.0",
|
|
24
|
+
"@webiny/api-security": "5.24.0-beta.0",
|
|
25
|
+
"@webiny/api-tenancy": "5.24.0-beta.0",
|
|
26
|
+
"@webiny/api-upgrade": "5.24.0-beta.0",
|
|
27
|
+
"@webiny/error": "5.24.0-beta.0",
|
|
28
|
+
"@webiny/handler": "5.24.0-beta.0",
|
|
29
|
+
"@webiny/handler-args": "5.24.0-beta.0",
|
|
30
|
+
"@webiny/handler-client": "5.24.0-beta.0",
|
|
31
|
+
"@webiny/handler-graphql": "5.24.0-beta.0",
|
|
32
|
+
"@webiny/plugins": "5.24.0-beta.0",
|
|
33
|
+
"@webiny/project-utils": "5.24.0-beta.0",
|
|
34
|
+
"@webiny/validation": "5.24.0-beta.0",
|
|
35
35
|
"aws-sdk": "2.1066.0",
|
|
36
36
|
"commodo-fields-object": "1.0.6",
|
|
37
37
|
"mdbid": "1.0.0",
|
|
@@ -45,9 +45,9 @@
|
|
|
45
45
|
"@babel/plugin-transform-runtime": "^7.16.4",
|
|
46
46
|
"@babel/preset-env": "^7.16.4",
|
|
47
47
|
"@babel/preset-typescript": "^7.16.0",
|
|
48
|
-
"@webiny/api-i18n": "^5.
|
|
49
|
-
"@webiny/api-i18n-ddb": "^5.
|
|
50
|
-
"@webiny/cli": "^5.
|
|
48
|
+
"@webiny/api-i18n": "^5.24.0-beta.0",
|
|
49
|
+
"@webiny/api-i18n-ddb": "^5.24.0-beta.0",
|
|
50
|
+
"@webiny/cli": "^5.24.0-beta.0",
|
|
51
51
|
"jest": "^26.6.3",
|
|
52
52
|
"rimraf": "^3.0.2",
|
|
53
53
|
"ttypescript": "^1.5.12",
|
|
@@ -72,5 +72,5 @@
|
|
|
72
72
|
]
|
|
73
73
|
}
|
|
74
74
|
},
|
|
75
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "05b90b92bbaf2ef3adf275d008c4641580cf5f42"
|
|
76
76
|
}
|
|
@@ -23,6 +23,7 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
|
23
23
|
|
|
24
24
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
25
25
|
|
|
26
|
+
// TODO @ts-refactor verify that this is not used and remove it
|
|
26
27
|
const SETTINGS_KEY = "file-manager";
|
|
27
28
|
exports.SETTINGS_KEY = SETTINGS_KEY;
|
|
28
29
|
const CreateDataModel = (0, _fields.withFields)({
|
|
@@ -11,6 +11,19 @@ var _commodoFieldsObject = require("commodo-fields-object");
|
|
|
11
11
|
|
|
12
12
|
var _validation = require("@webiny/validation");
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Package @commodo/fields does not have types
|
|
16
|
+
*/
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Package commodo-fields-object does not have types
|
|
21
|
+
*/
|
|
22
|
+
// @ts-ignore
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* TODO @ts-refactor change for JOI or some other validation library
|
|
26
|
+
*/
|
|
14
27
|
var _default = (create = true) => {
|
|
15
28
|
return (0, _fields.withFields)({
|
|
16
29
|
key: (0, _fields.string)({
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { FilePlugin } from "../../definitions/FilePlugin";
|
|
1
|
+
import { FilePlugin, FilePluginParams } from "../../definitions/FilePlugin";
|
|
2
2
|
import { FileManagerContext } from "../../../types";
|
|
3
|
-
export declare const runLifecycleEvent: (hook:
|
|
3
|
+
export declare const runLifecycleEvent: (hook: keyof FilePluginParams, params: {
|
|
4
4
|
context: FileManagerContext;
|
|
5
5
|
plugins: FilePlugin[];
|
|
6
6
|
} & Record<string, any>) => Promise<void>;
|
|
@@ -11,6 +11,7 @@ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/h
|
|
|
11
11
|
|
|
12
12
|
const _excluded = ["plugins"];
|
|
13
13
|
|
|
14
|
+
// TODO @ts-refactor introduce pubsub methods
|
|
14
15
|
const runLifecycleEvent = async (hook, params) => {
|
|
15
16
|
const {
|
|
16
17
|
plugins
|
|
@@ -25,6 +26,10 @@ const runLifecycleEvent = async (hook, params) => {
|
|
|
25
26
|
if (!plugin[hook]) {
|
|
26
27
|
continue;
|
|
27
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Keep any because we do not know which hook needs to be executed. This will be removed, so it does not matter.
|
|
31
|
+
*/
|
|
32
|
+
|
|
28
33
|
|
|
29
34
|
await plugin[hook](rest);
|
|
30
35
|
}
|
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Plugin } from "@webiny/plugins";
|
|
3
3
|
import { FileManagerSettings } from "../../types";
|
|
4
|
-
export interface
|
|
5
|
-
upload: (args:
|
|
6
|
-
delete: (args:
|
|
4
|
+
export interface FilePhysicalStoragePluginParams<U extends FilePhysicalStoragePluginUploadParams, D extends FilePhysicalStoragePluginDeleteParams> {
|
|
5
|
+
upload: (args: U) => Promise<any>;
|
|
6
|
+
delete: (args: D) => Promise<void>;
|
|
7
7
|
}
|
|
8
|
-
export interface
|
|
8
|
+
export interface FilePhysicalStoragePluginUploadParams {
|
|
9
9
|
settings: FileManagerSettings;
|
|
10
10
|
buffer: Buffer;
|
|
11
|
-
[key: string]: any;
|
|
12
11
|
}
|
|
13
|
-
export interface
|
|
12
|
+
export interface FilePhysicalStoragePluginDeleteParams {
|
|
14
13
|
key: string;
|
|
15
14
|
}
|
|
16
|
-
export declare class FilePhysicalStoragePlugin extends Plugin {
|
|
15
|
+
export declare class FilePhysicalStoragePlugin<U extends FilePhysicalStoragePluginUploadParams = FilePhysicalStoragePluginUploadParams, D extends FilePhysicalStoragePluginDeleteParams = FilePhysicalStoragePluginDeleteParams> extends Plugin {
|
|
17
16
|
static readonly type = "api-file-manager-storage";
|
|
18
17
|
private readonly _params;
|
|
19
|
-
constructor(params:
|
|
20
|
-
upload(params:
|
|
21
|
-
delete(params:
|
|
18
|
+
constructor(params: FilePhysicalStoragePluginParams<U, D>);
|
|
19
|
+
upload(params: U): Promise<any>;
|
|
20
|
+
delete(params: D): Promise<any>;
|
|
22
21
|
}
|
|
@@ -107,7 +107,7 @@ export interface AfterDeleteParams {
|
|
|
107
107
|
*
|
|
108
108
|
* @category FilePlugin
|
|
109
109
|
*/
|
|
110
|
-
export interface
|
|
110
|
+
export interface FilePluginParams {
|
|
111
111
|
beforeCreate?: (params: BeforeCreateParams) => Promise<void>;
|
|
112
112
|
afterCreate?: (params: AfterCreateParams) => Promise<void>;
|
|
113
113
|
beforeUpdate?: (params: BeforeUpdateParams) => Promise<void>;
|
|
@@ -120,7 +120,7 @@ export interface Params {
|
|
|
120
120
|
export declare class FilePlugin extends Plugin {
|
|
121
121
|
static readonly type = "fm.file";
|
|
122
122
|
private readonly _params;
|
|
123
|
-
constructor(params?:
|
|
123
|
+
constructor(params?: FilePluginParams);
|
|
124
124
|
beforeCreate(params: BeforeCreateParams): Promise<void>;
|
|
125
125
|
afterCreate(params: AfterCreateParams): Promise<void>;
|
|
126
126
|
beforeUpdate(params: BeforeUpdateParams): Promise<void>;
|
|
@@ -129,5 +129,8 @@ export declare class FilePlugin extends Plugin {
|
|
|
129
129
|
afterBatchCreate(params: AfterBatchCreateParams): Promise<void>;
|
|
130
130
|
beforeDelete(params: BeforeDeleteParams): Promise<void>;
|
|
131
131
|
afterDelete(params: AfterDeleteParams): Promise<void>;
|
|
132
|
+
/**
|
|
133
|
+
* Keep any here because it can be a number of params. Method is internal so no need to complicate the code.
|
|
134
|
+
*/
|
|
132
135
|
private _execute;
|
|
133
136
|
}
|
|
@@ -49,6 +49,10 @@ class FilePlugin extends _plugins.Plugin {
|
|
|
49
49
|
async afterDelete(params) {
|
|
50
50
|
await this._execute("afterDelete", params);
|
|
51
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Keep any here because it can be a number of params. Method is internal so no need to complicate the code.
|
|
54
|
+
*/
|
|
55
|
+
|
|
52
56
|
|
|
53
57
|
async _execute(callback, params) {
|
|
54
58
|
if (typeof this._params[callback] !== "function") {
|
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
import { Plugin } from "@webiny/plugins";
|
|
2
2
|
import { File } from "../../types";
|
|
3
|
-
export interface
|
|
3
|
+
export interface FileStorageTransformPluginToParams {
|
|
4
4
|
/**
|
|
5
5
|
* File that is being sent to the storage operations method.
|
|
6
6
|
*/
|
|
7
7
|
file: File & Record<string, any>;
|
|
8
8
|
}
|
|
9
|
-
export interface
|
|
9
|
+
export interface FileStorageTransformPluginFromParams {
|
|
10
10
|
/**
|
|
11
11
|
* File that was fetched from the storage operations method.
|
|
12
12
|
*/
|
|
13
13
|
file: File & Record<string, any>;
|
|
14
14
|
}
|
|
15
|
-
export interface
|
|
16
|
-
toStorage?: (params:
|
|
17
|
-
fromStorage?: (params:
|
|
15
|
+
export interface FileStorageTransformPluginParams {
|
|
16
|
+
toStorage?: (params: FileStorageTransformPluginToParams) => Promise<File & Record<string, any>>;
|
|
17
|
+
fromStorage?: (params: FileStorageTransformPluginFromParams) => Promise<File & Record<string, any>>;
|
|
18
18
|
}
|
|
19
19
|
export declare class FileStorageTransformPlugin extends Plugin {
|
|
20
20
|
static readonly type = "fm.files.storage.transform";
|
|
21
21
|
private readonly _params;
|
|
22
|
-
constructor(params:
|
|
22
|
+
constructor(params: FileStorageTransformPluginParams);
|
|
23
23
|
/**
|
|
24
24
|
* Transform the file value into something that can be stored.
|
|
25
25
|
* Be aware that you must return the whole file object.
|
|
26
26
|
*/
|
|
27
|
-
toStorage(params:
|
|
27
|
+
toStorage(params: FileStorageTransformPluginToParams): Promise<File & Record<string, any>>;
|
|
28
28
|
/**
|
|
29
29
|
* Transform the file value from the storage type to one required by our system.
|
|
30
30
|
* Be aware that you must return the whole file object.
|
|
31
31
|
* This method MUST reverse what ever toStorage method changed on the file object.
|
|
32
32
|
*/
|
|
33
|
-
fromStorage(params:
|
|
33
|
+
fromStorage(params: FileStorageTransformPluginFromParams): Promise<File & Record<string, any>>;
|
|
34
34
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Plugin } from "@webiny/plugins";
|
|
2
2
|
import { FileManagerContext, FileManagerFilesStorageOperations } from "../../types";
|
|
3
|
-
export interface
|
|
3
|
+
export interface FilesStorageOperationsProviderPluginParams {
|
|
4
4
|
context: FileManagerContext;
|
|
5
5
|
}
|
|
6
6
|
export declare abstract class FilesStorageOperationsProviderPlugin extends Plugin {
|
|
7
7
|
static readonly type = "fm.storageOperationsProvider.files";
|
|
8
|
-
abstract provide(params:
|
|
8
|
+
abstract provide(params: FilesStorageOperationsProviderPluginParams): Promise<FileManagerFilesStorageOperations>;
|
|
9
9
|
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { FileManagerContext } from "../../types";
|
|
2
2
|
import { Plugin } from "@webiny/plugins";
|
|
3
|
-
export
|
|
4
|
-
export interface Params {
|
|
3
|
+
export interface InstallationPluginParams {
|
|
5
4
|
context: FileManagerContext;
|
|
6
5
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
export declare type CallbackFunction<TParams> = (params: TParams) => Promise<void>;
|
|
7
|
+
interface InstallationPluginConfig {
|
|
8
|
+
beforeInstall?: CallbackFunction<InstallationPluginParams>;
|
|
9
|
+
afterInstall?: CallbackFunction<InstallationPluginParams>;
|
|
10
10
|
}
|
|
11
11
|
export declare abstract class InstallationPlugin extends Plugin {
|
|
12
12
|
static readonly type = "fm.install";
|
|
13
13
|
private readonly _config;
|
|
14
|
-
constructor(config?: Partial<
|
|
15
|
-
beforeInstall(params:
|
|
16
|
-
afterInstall(params:
|
|
14
|
+
constructor(config?: Partial<InstallationPluginConfig>);
|
|
15
|
+
beforeInstall(params: InstallationPluginParams): Promise<void>;
|
|
16
|
+
afterInstall(params: InstallationPluginParams): Promise<void>;
|
|
17
17
|
private _execute;
|
|
18
18
|
}
|
|
19
19
|
export {};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Plugin } from "@webiny/plugins";
|
|
2
2
|
import { FileManagerContext, FileManagerSettingsStorageOperations } from "../../types";
|
|
3
|
-
export interface
|
|
3
|
+
export interface SettingsStorageOperationsProviderPluginParams {
|
|
4
4
|
context: FileManagerContext;
|
|
5
5
|
}
|
|
6
6
|
export declare abstract class SettingsStorageOperationsProviderPlugin extends Plugin {
|
|
7
7
|
static readonly type = "fm.storageOperationsProvider.settings";
|
|
8
|
-
abstract provide(params:
|
|
8
|
+
abstract provide(params: SettingsStorageOperationsProviderPluginParams): Promise<FileManagerSettingsStorageOperations>;
|
|
9
9
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Plugin } from "@webiny/plugins";
|
|
2
2
|
import { FileManagerContext, FileManagerSystemStorageOperations } from "../../types";
|
|
3
|
-
export interface
|
|
3
|
+
export interface SystemStorageOperationsProviderPluginParams {
|
|
4
4
|
context: FileManagerContext;
|
|
5
5
|
}
|
|
6
6
|
export declare abstract class SystemStorageOperationsProviderPlugin extends Plugin {
|
|
7
7
|
static readonly type = "fm.storageOperationsProvider.system";
|
|
8
|
-
abstract provide(params:
|
|
8
|
+
abstract provide(params: SystemStorageOperationsProviderPluginParams): Promise<FileManagerSystemStorageOperations>;
|
|
9
9
|
}
|
package/plugins/graphql.js
CHANGED
|
@@ -8,6 +8,11 @@ exports.default = void 0;
|
|
|
8
8
|
var _handlerGraphql = require("@webiny/handler-graphql");
|
|
9
9
|
|
|
10
10
|
const emptyResolver = () => ({});
|
|
11
|
+
/**
|
|
12
|
+
* Use any because it really can be any.
|
|
13
|
+
* TODO @ts-refactor maybe use generics at some point?
|
|
14
|
+
*/
|
|
15
|
+
|
|
11
16
|
|
|
12
17
|
const resolve = async fn => {
|
|
13
18
|
try {
|
|
@@ -99,11 +104,13 @@ const plugin = {
|
|
|
99
104
|
type FileManagerSettings {
|
|
100
105
|
uploadMinFileSize: Number
|
|
101
106
|
uploadMaxFileSize: Number
|
|
107
|
+
srcPrefix: String
|
|
102
108
|
}
|
|
103
109
|
|
|
104
110
|
input FileManagerSettingsInput {
|
|
105
111
|
uploadMinFileSize: Number
|
|
106
112
|
uploadMaxFileSize: Number
|
|
113
|
+
srcPrefix: String
|
|
107
114
|
}
|
|
108
115
|
|
|
109
116
|
type FileManagerSettingsResponse {
|
|
@@ -1,31 +1,30 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { FileManagerContext } from "../../types";
|
|
3
|
-
export declare type
|
|
4
|
-
|
|
5
|
-
type: string;
|
|
6
|
-
size: number;
|
|
3
|
+
export declare type Result = Record<string, any>;
|
|
4
|
+
export interface FileStorageUploadParams {
|
|
7
5
|
buffer: Buffer;
|
|
8
|
-
|
|
9
|
-
hideInFileManager?: boolean;
|
|
6
|
+
hideInFileManager: boolean | string;
|
|
10
7
|
tags?: string[];
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
delete: (args: {
|
|
16
|
-
key: string;
|
|
17
|
-
}) => Promise<void>;
|
|
8
|
+
size: number;
|
|
9
|
+
name: string;
|
|
10
|
+
keyPrefix: string;
|
|
11
|
+
type: string;
|
|
18
12
|
}
|
|
19
|
-
export
|
|
20
|
-
|
|
13
|
+
export interface FileStorageDeleteParams {
|
|
14
|
+
id: string;
|
|
15
|
+
key: string;
|
|
16
|
+
}
|
|
17
|
+
export interface FileStorageUploadMultipleParams {
|
|
18
|
+
files: FileStorageUploadParams[];
|
|
19
|
+
}
|
|
20
|
+
export interface FileStorageParams {
|
|
21
21
|
context: FileManagerContext;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}): Promise<boolean>;
|
|
22
|
+
}
|
|
23
|
+
export declare class FileStorage {
|
|
24
|
+
private readonly storagePlugin;
|
|
25
|
+
private readonly context;
|
|
26
|
+
constructor({ context }: FileStorageParams);
|
|
27
|
+
upload(params: FileStorageUploadParams): Promise<Result>;
|
|
28
|
+
uploadFiles(params: FileStorageUploadMultipleParams): Promise<import("../../types").File[]>;
|
|
29
|
+
delete(params: FileStorageDeleteParams): Promise<boolean>;
|
|
31
30
|
}
|
|
@@ -32,12 +32,12 @@ class FileStorage {
|
|
|
32
32
|
this.context = context;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
async upload(
|
|
35
|
+
async upload(params) {
|
|
36
36
|
const settings = await this.context.fileManager.settings.getSettings(); // Add file to cloud storage.
|
|
37
37
|
|
|
38
38
|
const {
|
|
39
39
|
file: fileData
|
|
40
|
-
} = await this.storagePlugin.upload(_objectSpread(_objectSpread({},
|
|
40
|
+
} = await this.storagePlugin.upload(_objectSpread(_objectSpread({}, params), {}, {
|
|
41
41
|
settings
|
|
42
42
|
}));
|
|
43
43
|
const {
|
|
@@ -46,19 +46,18 @@ class FileStorage {
|
|
|
46
46
|
|
|
47
47
|
return await fileManager.files.createFile(_objectSpread(_objectSpread({}, fileData), {}, {
|
|
48
48
|
meta: {
|
|
49
|
-
private: Boolean(
|
|
49
|
+
private: Boolean(params.hideInFileManager)
|
|
50
50
|
},
|
|
51
|
-
tags: Array.isArray(
|
|
51
|
+
tags: Array.isArray(params.tags) ? params.tags : []
|
|
52
52
|
}));
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
async uploadFiles(
|
|
55
|
+
async uploadFiles(params) {
|
|
56
56
|
const settings = await this.context.fileManager.settings.getSettings(); // Upload files to cloud storage.
|
|
57
57
|
|
|
58
58
|
const promises = [];
|
|
59
59
|
|
|
60
|
-
for (
|
|
61
|
-
const item = args.files[i];
|
|
60
|
+
for (const item of params.files) {
|
|
62
61
|
promises.push(this.storagePlugin.upload(_objectSpread(_objectSpread({}, item), {}, {
|
|
63
62
|
settings
|
|
64
63
|
})));
|
|
@@ -74,11 +73,11 @@ class FileStorage {
|
|
|
74
73
|
return fileManager.files.createFilesInBatch(filesData);
|
|
75
74
|
}
|
|
76
75
|
|
|
77
|
-
async delete(
|
|
76
|
+
async delete(params) {
|
|
78
77
|
const {
|
|
79
78
|
id,
|
|
80
79
|
key
|
|
81
|
-
} =
|
|
80
|
+
} = params;
|
|
82
81
|
const {
|
|
83
82
|
fileManager
|
|
84
83
|
} = this.context; // Delete file from cloud storage.
|
package/plugins/storage/index.js
CHANGED
|
@@ -11,6 +11,10 @@ var _FileStorage = require("./FileStorage");
|
|
|
11
11
|
|
|
12
12
|
const fileStorageContextPlugin = new _handler.ContextPlugin(async context => {
|
|
13
13
|
if (!context.fileManager) {
|
|
14
|
+
/**
|
|
15
|
+
* We need to define the fileManager initial property as empty object.
|
|
16
|
+
* When casting as FileManagerContext, typescript is complaining.
|
|
17
|
+
*/
|
|
14
18
|
context.fileManager = {};
|
|
15
19
|
}
|
|
16
20
|
|
package/types.d.ts
CHANGED
|
@@ -294,7 +294,7 @@ export interface FileManagerFilesStorageOperationsListParams {
|
|
|
294
294
|
* @category FilesStorageOperations
|
|
295
295
|
* @category FilesStorageOperationsParams
|
|
296
296
|
*/
|
|
297
|
-
interface FileManagerFilesStorageOperationsListResponseMeta {
|
|
297
|
+
export interface FileManagerFilesStorageOperationsListResponseMeta {
|
|
298
298
|
hasMoreItems: boolean;
|
|
299
299
|
totalCount: number;
|
|
300
300
|
cursor: string;
|