@webiny/api-file-manager 5.33.5 → 5.34.0-beta.1
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.js +1 -1
- package/handlers/manage/index.js +1 -1
- package/handlers/transform/index.js +4 -8
- package/handlers/transform/index.js.map +1 -1
- package/handlers/transform/loaders/imageLoader.js +1 -1
- package/handlers/transform/loaders/index.js +1 -1
- package/handlers/transform/managers/index.js +1 -1
- package/handlers/transform/optimizeImage.js +1 -1
- package/handlers/transform/transformImage.js +1 -1
- package/handlers/transform/utils.js +1 -1
- package/handlers/utils/getObjectParams.js +1 -1
- package/handlers/utils/index.js +1 -1
- package/package.json +23 -23
- package/plugins/crud/files/validation.js +1 -1
- package/plugins/crud/files.crud.js +19 -25
- package/plugins/crud/files.crud.js.map +1 -1
- package/plugins/crud/settings.crud.js +7 -7
- package/plugins/crud/settings.crud.js.map +1 -1
- package/plugins/crud/system.crud.js +3 -7
- package/plugins/crud/system.crud.js.map +1 -1
- package/plugins/crud/utils/lifecycleEvents.js +1 -1
- package/plugins/definitions/FilePhysicalStoragePlugin.js +1 -1
- package/plugins/definitions/FilePlugin.js +1 -1
- package/plugins/definitions/FileStorageTransformPlugin.js +1 -1
- package/plugins/definitions/FilesStorageOperationsProviderPlugin.js +1 -1
- package/plugins/definitions/InstallationPlugin.js +1 -1
- package/plugins/definitions/SettingsStorageOperationsProviderPlugin.js +1 -1
- package/plugins/definitions/SystemStorageOperationsProviderPlugin.js +1 -1
- package/plugins/index.js +1 -1
- package/plugins/storage/FileStorage.js +6 -8
- package/plugins/storage/FileStorage.js.map +1 -1
package/handlers/manage/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
4
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.createTransformFilePlugins = void 0;
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
11
|
|
|
12
12
|
var _s = _interopRequireDefault(require("aws-sdk/clients/s3"));
|
|
13
13
|
|
|
@@ -21,10 +21,6 @@ var _utils2 = require("./utils");
|
|
|
21
21
|
|
|
22
22
|
var _handler = require("@webiny/handler");
|
|
23
23
|
|
|
24
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
25
|
-
|
|
26
|
-
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; }
|
|
27
|
-
|
|
28
24
|
const createTransformFilePlugins = () => {
|
|
29
25
|
return [(0, _handler.createEvent)(async ({
|
|
30
26
|
payload
|
|
@@ -59,7 +55,7 @@ const createTransformFilePlugins = () => {
|
|
|
59
55
|
} catch (e) {
|
|
60
56
|
// If not found, try to create it by loading the initially uploaded image.
|
|
61
57
|
optimizedImageObject = await s3.getObject(params.initial).promise();
|
|
62
|
-
await s3.putObject(
|
|
58
|
+
await s3.putObject((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params.optimized), {}, {
|
|
63
59
|
ContentType: optimizedImageObject.ContentType,
|
|
64
60
|
Body: await (0, _optimizeImage.default)(optimizedImageObject.Body, optimizedImageObject.ContentType)
|
|
65
61
|
})).promise();
|
|
@@ -75,7 +71,7 @@ const createTransformFilePlugins = () => {
|
|
|
75
71
|
} // 3. If transformations requested, apply them in save it into the bucket.
|
|
76
72
|
|
|
77
73
|
|
|
78
|
-
await s3.putObject(
|
|
74
|
+
await s3.putObject((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params.optimizedTransformed), {}, {
|
|
79
75
|
ContentType: optimizedImageObject.ContentType,
|
|
80
76
|
Body: await (0, _transformImage.default)(optimizedImageObject.Body, transformations)
|
|
81
77
|
})).promise();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createTransformFilePlugins","createEvent","payload","body","key","transformations","env","getEnvironment","s3","S3","region","optimizedImageObject","params","initial","getObjectParams","optimized","getImageKey","optimizedTransformed","getObject","promise","e","putObject","ContentType","Body","optimizeImage","error","message","transformImage"],"sources":["index.ts"],"sourcesContent":["import S3 from \"aws-sdk/clients/s3\";\nimport transformImage from \"./transformImage\";\nimport optimizeImage from \"./optimizeImage\";\nimport { getEnvironment, getObjectParams } from \"../utils\";\nimport { getImageKey } from \"./utils\";\nimport { TransformHandlerEventPayload } from \"~/handlers/types\";\nimport { createEvent } from \"@webiny/handler\";\n\nexport const createTransformFilePlugins = () => {\n return [\n createEvent<TransformHandlerEventPayload>(async ({ payload }) => {\n const { body } = payload;\n const { key, transformations } = body;\n try {\n const env = getEnvironment();\n const s3 = new S3({ region: env.region });\n\n let optimizedImageObject: S3.Types.GetObjectOutput;\n\n const params = {\n initial: getObjectParams(key),\n optimized: getObjectParams(getImageKey({ key })),\n optimizedTransformed: getObjectParams(getImageKey({ key, transformations }))\n };\n\n // 1. Get optimized image.\n try {\n optimizedImageObject = await s3.getObject(params.optimized).promise();\n } catch (e) {\n // If not found, try to create it by loading the initially uploaded image.\n optimizedImageObject = await s3.getObject(params.initial).promise();\n\n await s3\n .putObject({\n ...params.optimized,\n ContentType: optimizedImageObject.ContentType,\n Body: await optimizeImage(\n optimizedImageObject.Body as Buffer,\n optimizedImageObject.ContentType as string\n )\n })\n .promise();\n\n optimizedImageObject = await s3.getObject(params.optimized).promise();\n }\n\n // 2. If no transformations requested, just exit.\n if (!transformations) {\n return {\n error: false,\n message: \"\"\n };\n }\n\n // 3. If transformations requested, apply them in save it into the bucket.\n await s3\n .putObject({\n ...params.optimizedTransformed,\n ContentType: optimizedImageObject.ContentType,\n Body: await transformImage(\n optimizedImageObject.Body as Buffer,\n transformations\n )\n })\n .promise();\n\n return {\n error: false,\n message: \"\"\n };\n } catch (e) {\n return {\n error: true,\n message: e.message\n };\n }\n })\n ];\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AAEA
|
|
1
|
+
{"version":3,"names":["createTransformFilePlugins","createEvent","payload","body","key","transformations","env","getEnvironment","s3","S3","region","optimizedImageObject","params","initial","getObjectParams","optimized","getImageKey","optimizedTransformed","getObject","promise","e","putObject","ContentType","Body","optimizeImage","error","message","transformImage"],"sources":["index.ts"],"sourcesContent":["import S3 from \"aws-sdk/clients/s3\";\nimport transformImage from \"./transformImage\";\nimport optimizeImage from \"./optimizeImage\";\nimport { getEnvironment, getObjectParams } from \"../utils\";\nimport { getImageKey } from \"./utils\";\nimport { TransformHandlerEventPayload } from \"~/handlers/types\";\nimport { createEvent } from \"@webiny/handler\";\n\nexport const createTransformFilePlugins = () => {\n return [\n createEvent<TransformHandlerEventPayload>(async ({ payload }) => {\n const { body } = payload;\n const { key, transformations } = body;\n try {\n const env = getEnvironment();\n const s3 = new S3({ region: env.region });\n\n let optimizedImageObject: S3.Types.GetObjectOutput;\n\n const params = {\n initial: getObjectParams(key),\n optimized: getObjectParams(getImageKey({ key })),\n optimizedTransformed: getObjectParams(getImageKey({ key, transformations }))\n };\n\n // 1. Get optimized image.\n try {\n optimizedImageObject = await s3.getObject(params.optimized).promise();\n } catch (e) {\n // If not found, try to create it by loading the initially uploaded image.\n optimizedImageObject = await s3.getObject(params.initial).promise();\n\n await s3\n .putObject({\n ...params.optimized,\n ContentType: optimizedImageObject.ContentType,\n Body: await optimizeImage(\n optimizedImageObject.Body as Buffer,\n optimizedImageObject.ContentType as string\n )\n })\n .promise();\n\n optimizedImageObject = await s3.getObject(params.optimized).promise();\n }\n\n // 2. If no transformations requested, just exit.\n if (!transformations) {\n return {\n error: false,\n message: \"\"\n };\n }\n\n // 3. If transformations requested, apply them in save it into the bucket.\n await s3\n .putObject({\n ...params.optimizedTransformed,\n ContentType: optimizedImageObject.ContentType,\n Body: await transformImage(\n optimizedImageObject.Body as Buffer,\n transformations\n )\n })\n .promise();\n\n return {\n error: false,\n message: \"\"\n };\n } catch (e) {\n return {\n error: true,\n message: e.message\n };\n }\n })\n ];\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AAEO,MAAMA,0BAA0B,GAAG,MAAM;EAC5C,OAAO,CACH,IAAAC,oBAAA,EAA0C,OAAO;IAAEC;EAAF,CAAP,KAAuB;IAC7D,MAAM;MAAEC;IAAF,IAAWD,OAAjB;IACA,MAAM;MAAEE,GAAF;MAAOC;IAAP,IAA2BF,IAAjC;;IACA,IAAI;MACA,MAAMG,GAAG,GAAG,IAAAC,qBAAA,GAAZ;MACA,MAAMC,EAAE,GAAG,IAAIC,UAAJ,CAAO;QAAEC,MAAM,EAAEJ,GAAG,CAACI;MAAd,CAAP,CAAX;MAEA,IAAIC,oBAAJ;MAEA,MAAMC,MAAM,GAAG;QACXC,OAAO,EAAE,IAAAC,sBAAA,EAAgBV,GAAhB,CADE;QAEXW,SAAS,EAAE,IAAAD,sBAAA,EAAgB,IAAAE,mBAAA,EAAY;UAAEZ;QAAF,CAAZ,CAAhB,CAFA;QAGXa,oBAAoB,EAAE,IAAAH,sBAAA,EAAgB,IAAAE,mBAAA,EAAY;UAAEZ,GAAF;UAAOC;QAAP,CAAZ,CAAhB;MAHX,CAAf,CANA,CAYA;;MACA,IAAI;QACA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|
-
"version": "5.
|
|
3
|
+
"version": "5.34.0-beta.1",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fm:base"
|
|
@@ -18,36 +18,36 @@
|
|
|
18
18
|
],
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@babel/runtime": "7.
|
|
21
|
+
"@babel/runtime": "7.19.0",
|
|
22
22
|
"@commodo/fields": "1.1.2-beta.20",
|
|
23
|
-
"@webiny/api": "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-aws": "5.
|
|
30
|
-
"@webiny/handler-client": "5.
|
|
31
|
-
"@webiny/handler-graphql": "5.
|
|
32
|
-
"@webiny/plugins": "5.
|
|
33
|
-
"@webiny/project-utils": "5.
|
|
34
|
-
"@webiny/validation": "5.
|
|
35
|
-
"aws-sdk": "2.
|
|
23
|
+
"@webiny/api": "5.34.0-beta.1",
|
|
24
|
+
"@webiny/api-security": "5.34.0-beta.1",
|
|
25
|
+
"@webiny/api-tenancy": "5.34.0-beta.1",
|
|
26
|
+
"@webiny/api-upgrade": "5.34.0-beta.1",
|
|
27
|
+
"@webiny/error": "5.34.0-beta.1",
|
|
28
|
+
"@webiny/handler": "5.34.0-beta.1",
|
|
29
|
+
"@webiny/handler-aws": "5.34.0-beta.1",
|
|
30
|
+
"@webiny/handler-client": "5.34.0-beta.1",
|
|
31
|
+
"@webiny/handler-graphql": "5.34.0-beta.1",
|
|
32
|
+
"@webiny/plugins": "5.34.0-beta.1",
|
|
33
|
+
"@webiny/project-utils": "5.34.0-beta.1",
|
|
34
|
+
"@webiny/validation": "5.34.0-beta.1",
|
|
35
|
+
"aws-sdk": "2.1230.0",
|
|
36
36
|
"commodo-fields-object": "1.0.6",
|
|
37
37
|
"mdbid": "1.0.0",
|
|
38
38
|
"object-hash": "2.2.0",
|
|
39
39
|
"sanitize-filename": "1.6.3"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@babel/cli": "^7.
|
|
43
|
-
"@babel/core": "^7.
|
|
42
|
+
"@babel/cli": "^7.19.3",
|
|
43
|
+
"@babel/core": "^7.19.3",
|
|
44
44
|
"@babel/plugin-proposal-object-rest-spread": "^7.16.0",
|
|
45
45
|
"@babel/plugin-transform-runtime": "^7.16.4",
|
|
46
|
-
"@babel/preset-env": "^7.
|
|
47
|
-
"@babel/preset-typescript": "^7.
|
|
48
|
-
"@webiny/api-i18n": "^5.
|
|
49
|
-
"@webiny/api-i18n-ddb": "^5.
|
|
50
|
-
"@webiny/cli": "^5.
|
|
46
|
+
"@babel/preset-env": "^7.19.4",
|
|
47
|
+
"@babel/preset-typescript": "^7.18.6",
|
|
48
|
+
"@webiny/api-i18n": "^5.34.0-beta.1",
|
|
49
|
+
"@webiny/api-i18n-ddb": "^5.34.0-beta.1",
|
|
50
|
+
"@webiny/cli": "^5.34.0-beta.1",
|
|
51
51
|
"jest": "^28.1.0",
|
|
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": "1ee2a7338a865a67e24eb42d16bf0b6091195286"
|
|
76
76
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
4
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.default = void 0;
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
11
|
|
|
12
12
|
var _mdbid = _interopRequireDefault(require("mdbid"));
|
|
13
13
|
|
|
@@ -27,10 +27,10 @@ var _error = _interopRequireDefault(require("@webiny/error"));
|
|
|
27
27
|
|
|
28
28
|
var _lifecycleEvents = require("./utils/lifecycleEvents");
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Package mdbid does not have types.
|
|
32
|
+
*/
|
|
33
|
+
// @ts-ignore
|
|
34
34
|
const BATCH_CREATE_MAX_FILES = 20;
|
|
35
35
|
/**
|
|
36
36
|
* If permission is limited to "own" files only, check that current identity owns the file.
|
|
@@ -111,11 +111,10 @@ const filesContextCrudPlugin = new _api.ContextPlugin(async context => {
|
|
|
111
111
|
const identity = context.security.getIdentity();
|
|
112
112
|
const tenant = context.tenancy.getCurrentTenant();
|
|
113
113
|
const id = (0, _mdbid.default)();
|
|
114
|
-
|
|
115
|
-
const file = _objectSpread(_objectSpread({}, input), {}, {
|
|
114
|
+
const file = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, input), {}, {
|
|
116
115
|
tags: Array.isArray(input.tags) ? input.tags : [],
|
|
117
116
|
id,
|
|
118
|
-
meta:
|
|
117
|
+
meta: (0, _objectSpread2.default)({
|
|
119
118
|
private: false
|
|
120
119
|
}, input.meta || {}),
|
|
121
120
|
tenant: tenant.id,
|
|
@@ -146,7 +145,7 @@ const filesContextCrudPlugin = new _api.ContextPlugin(async context => {
|
|
|
146
145
|
});
|
|
147
146
|
return result;
|
|
148
147
|
} catch (ex) {
|
|
149
|
-
throw new _error.default(ex.message || "Could not create a file.", ex.code || "CREATE_FILE_ERROR",
|
|
148
|
+
throw new _error.default(ex.message || "Could not create a file.", ex.code || "CREATE_FILE_ERROR", (0, _objectSpread2.default)((0, _objectSpread2.default)({}, ex.data || {}), {}, {
|
|
150
149
|
file
|
|
151
150
|
}));
|
|
152
151
|
}
|
|
@@ -169,8 +168,7 @@ const filesContextCrudPlugin = new _api.ContextPlugin(async context => {
|
|
|
169
168
|
}
|
|
170
169
|
|
|
171
170
|
checkOwnership(original, permission, context);
|
|
172
|
-
|
|
173
|
-
const file = _objectSpread(_objectSpread(_objectSpread({}, original), input), {}, {
|
|
171
|
+
const file = (0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, original), input), {}, {
|
|
174
172
|
tags: Array.isArray(input.tags) ? input.tags : Array.isArray(original.tags) ? original.tags : [],
|
|
175
173
|
id: original.id,
|
|
176
174
|
webinyVersion: context.WEBINY_VERSION
|
|
@@ -196,7 +194,7 @@ const filesContextCrudPlugin = new _api.ContextPlugin(async context => {
|
|
|
196
194
|
});
|
|
197
195
|
return result;
|
|
198
196
|
} catch (ex) {
|
|
199
|
-
throw new _error.default(ex.message || "Could not update a file.", ex.code || "UPDATE_FILE_ERROR",
|
|
197
|
+
throw new _error.default(ex.message || "Could not update a file.", ex.code || "UPDATE_FILE_ERROR", (0, _objectSpread2.default)((0, _objectSpread2.default)({}, ex.data || {}), {}, {
|
|
200
198
|
original,
|
|
201
199
|
file
|
|
202
200
|
}));
|
|
@@ -236,7 +234,7 @@ const filesContextCrudPlugin = new _api.ContextPlugin(async context => {
|
|
|
236
234
|
file
|
|
237
235
|
});
|
|
238
236
|
} catch (ex) {
|
|
239
|
-
throw new _error.default(ex.message || "Could not delete a file.", ex.code || "DELETE_FILE_ERROR",
|
|
237
|
+
throw new _error.default(ex.message || "Could not delete a file.", ex.code || "DELETE_FILE_ERROR", (0, _objectSpread2.default)((0, _objectSpread2.default)({}, ex.data || {}), {}, {
|
|
240
238
|
id,
|
|
241
239
|
file
|
|
242
240
|
}));
|
|
@@ -269,9 +267,9 @@ const filesContextCrudPlugin = new _api.ContextPlugin(async context => {
|
|
|
269
267
|
type: identity.type
|
|
270
268
|
};
|
|
271
269
|
const files = inputs.map(input => {
|
|
272
|
-
return
|
|
270
|
+
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, input), {}, {
|
|
273
271
|
tags: Array.isArray(input.tags) ? input.tags : [],
|
|
274
|
-
meta:
|
|
272
|
+
meta: (0, _objectSpread2.default)({
|
|
275
273
|
private: false
|
|
276
274
|
}, input.meta || {}),
|
|
277
275
|
id: (0, _mdbid.default)(),
|
|
@@ -300,7 +298,7 @@ const filesContextCrudPlugin = new _api.ContextPlugin(async context => {
|
|
|
300
298
|
});
|
|
301
299
|
return results;
|
|
302
300
|
} catch (ex) {
|
|
303
|
-
throw new _error.default(ex.message || "Could not create a batch of files.", ex.code || "CREATE_FILES_ERROR",
|
|
301
|
+
throw new _error.default(ex.message || "Could not create a batch of files.", ex.code || "CREATE_FILES_ERROR", (0, _objectSpread2.default)((0, _objectSpread2.default)({}, ex.data || {}), {}, {
|
|
304
302
|
files
|
|
305
303
|
}));
|
|
306
304
|
}
|
|
@@ -320,8 +318,7 @@ const filesContextCrudPlugin = new _api.ContextPlugin(async context => {
|
|
|
320
318
|
where: initialWhere,
|
|
321
319
|
sort: initialSort
|
|
322
320
|
} = params;
|
|
323
|
-
|
|
324
|
-
const where = _objectSpread(_objectSpread({}, initialWhere), {}, {
|
|
321
|
+
const where = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, initialWhere), {}, {
|
|
325
322
|
private: false,
|
|
326
323
|
locale: getLocaleCode(context),
|
|
327
324
|
tenant: context.tenancy.getCurrentTenant().id
|
|
@@ -330,7 +327,6 @@ const filesContextCrudPlugin = new _api.ContextPlugin(async context => {
|
|
|
330
327
|
* Always override the createdBy received from the user, if any.
|
|
331
328
|
*/
|
|
332
329
|
|
|
333
|
-
|
|
334
330
|
if (permission.own === true) {
|
|
335
331
|
const identity = context.security.getIdentity();
|
|
336
332
|
where.createdBy = identity.id;
|
|
@@ -384,7 +380,7 @@ const filesContextCrudPlugin = new _api.ContextPlugin(async context => {
|
|
|
384
380
|
sort
|
|
385
381
|
});
|
|
386
382
|
} catch (ex) {
|
|
387
|
-
throw new _error.default(ex.message || "Could not list files by given parameters.", ex.code || "FILE_TAG_SEARCH_ERROR",
|
|
383
|
+
throw new _error.default(ex.message || "Could not list files by given parameters.", ex.code || "FILE_TAG_SEARCH_ERROR", (0, _objectSpread2.default)((0, _objectSpread2.default)({}, ex.data || {}), {}, {
|
|
388
384
|
where,
|
|
389
385
|
after,
|
|
390
386
|
limit,
|
|
@@ -399,12 +395,10 @@ const filesContextCrudPlugin = new _api.ContextPlugin(async context => {
|
|
|
399
395
|
limit
|
|
400
396
|
}) {
|
|
401
397
|
await (0, _checkBasePermissions.default)(context);
|
|
402
|
-
|
|
403
|
-
const where = _objectSpread(_objectSpread({}, initialWhere), {}, {
|
|
398
|
+
const where = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, initialWhere), {}, {
|
|
404
399
|
tenant: context.tenancy.getCurrentTenant().id,
|
|
405
400
|
locale: getLocaleCode(context)
|
|
406
401
|
});
|
|
407
|
-
|
|
408
402
|
const params = {
|
|
409
403
|
where,
|
|
410
404
|
limit: limit || 100000,
|
|
@@ -424,7 +418,7 @@ const filesContextCrudPlugin = new _api.ContextPlugin(async context => {
|
|
|
424
418
|
|
|
425
419
|
return tags.sort();
|
|
426
420
|
} catch (ex) {
|
|
427
|
-
throw new _error.default(ex.message || "Could not search for tags.", ex.code || "FILE_TAG_SEARCH_ERROR",
|
|
421
|
+
throw new _error.default(ex.message || "Could not search for tags.", ex.code || "FILE_TAG_SEARCH_ERROR", (0, _objectSpread2.default)((0, _objectSpread2.default)({}, ex.data || {}), {}, {
|
|
428
422
|
params
|
|
429
423
|
}));
|
|
430
424
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["BATCH_CREATE_MAX_FILES","checkOwnership","file","permission","context","own","identity","security","getIdentity","createdBy","id","NotAuthorizedError","getLocaleCode","i18n","WebinyError","locale","getContentLocale","code","filesContextCrudPlugin","ContextPlugin","pluginType","FilesStorageOperationsProviderPlugin","type","providerPlugin","plugins","byType","find","storageOperations","provide","fileManager","filePlugins","FilePlugin","files","getFile","checkBasePermissions","rwd","get","where","tenant","tenancy","getCurrentTenant","NotFoundError","createFile","input","mdbid","tags","Array","isArray","meta","private","createdOn","Date","toISOString","displayName","webinyVersion","WEBINY_VERSION","runLifecycleEvent","data","result","create","ex","message","updateFile","original","update","deleteFile","delete","createFilesInBatch","inputs","length","map","results","createBatch","listFiles","params","limit","search","types","ids","after","initialWhere","sort","initialSort","type_in","tag_in","tag","toLowerCase","id_in","list","listTags","name"],"sources":["files.crud.ts"],"sourcesContent":["/**\n * Package mdbid does not have types.\n */\n// @ts-ignore\nimport mdbid from \"mdbid\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport { NotAuthorizedError } from \"@webiny/api-security\";\nimport {\n CreatedBy,\n File,\n FileManagerContext,\n FileManagerFilesStorageOperationsListParamsWhere,\n FileManagerFilesStorageOperationsTagsParamsWhere,\n FilePermission,\n FilesListOpts\n} from \"~/types\";\nimport checkBasePermissions from \"./utils/checkBasePermissions\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { FilePlugin } from \"~/plugins/definitions/FilePlugin\";\nimport { FilesStorageOperationsProviderPlugin } from \"~/plugins/definitions/FilesStorageOperationsProviderPlugin\";\nimport WebinyError from \"@webiny/error\";\nimport { runLifecycleEvent } from \"~/plugins/crud/utils/lifecycleEvents\";\n\nconst BATCH_CREATE_MAX_FILES = 20;\n\n/**\n * If permission is limited to \"own\" files only, check that current identity owns the file.\n */\nconst checkOwnership = (file: File, permission: FilePermission, context: FileManagerContext) => {\n if (permission?.own === true) {\n const identity = context.security.getIdentity();\n if (file.createdBy.id !== identity.id) {\n throw new NotAuthorizedError();\n }\n }\n};\n\nconst getLocaleCode = (context: FileManagerContext): string => {\n if (!context.i18n) {\n throw new WebinyError(\"Missing i18n on the FileManagerContext.\", \"MISSING_I18N\");\n }\n\n const locale = context.i18n.getContentLocale();\n if (!locale) {\n throw new WebinyError(\n \"Missing content locale on the FileManagerContext.\",\n \"MISSING_I18N_CONTENT_LOCALE\"\n );\n }\n\n if (!locale.code) {\n throw new WebinyError(\n \"Missing content locale code on the FileManagerContext.\",\n \"MISSING_I18N_CONTENT_LOCALE_CODE\"\n );\n }\n return locale.code;\n};\n\nconst filesContextCrudPlugin = new ContextPlugin<FileManagerContext>(async context => {\n const pluginType = FilesStorageOperationsProviderPlugin.type;\n\n const providerPlugin = context.plugins\n .byType<FilesStorageOperationsProviderPlugin>(pluginType)\n .find(() => true);\n\n if (!providerPlugin) {\n throw new WebinyError(`Missing \"${pluginType}\" plugin.`, \"PLUGIN_NOT_FOUND\", {\n type: pluginType\n });\n }\n\n const storageOperations = await providerPlugin.provide({\n context\n });\n\n if (!context.fileManager) {\n context.fileManager = {} as any;\n }\n\n const filePlugins = context.plugins.byType<FilePlugin>(FilePlugin.type);\n\n context.fileManager.files = {\n async getFile(id: string) {\n const permission = await checkBasePermissions(context, { rwd: \"r\" });\n\n const file = await storageOperations.get({\n where: {\n id,\n tenant: context.tenancy.getCurrentTenant().id,\n locale: getLocaleCode(context)\n }\n });\n\n if (!file) {\n throw new NotFoundError(`File with id \"${id}\" does not exists.`);\n }\n\n checkOwnership(file, permission, context);\n\n return file;\n },\n async createFile(input) {\n await checkBasePermissions(context, { rwd: \"w\" });\n const identity = context.security.getIdentity();\n const tenant = context.tenancy.getCurrentTenant();\n\n const id = mdbid();\n\n const file: File = {\n ...input,\n tags: Array.isArray(input.tags) ? input.tags : [],\n id,\n meta: {\n private: false,\n ...(input.meta || {})\n },\n tenant: tenant.id,\n createdOn: new Date().toISOString(),\n createdBy: {\n id: identity.id,\n displayName: identity.displayName,\n type: identity.type\n },\n locale: getLocaleCode(context),\n webinyVersion: context.WEBINY_VERSION\n };\n\n try {\n await runLifecycleEvent(\"beforeCreate\", {\n context,\n plugins: filePlugins,\n data: file\n });\n const result = await storageOperations.create({\n file\n });\n await runLifecycleEvent(\"afterCreate\", {\n context,\n plugins: filePlugins,\n data: file,\n file: result\n });\n return result;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create a file.\",\n ex.code || \"CREATE_FILE_ERROR\",\n {\n ...(ex.data || {}),\n file\n }\n );\n }\n },\n async updateFile(id, input) {\n const permission = await checkBasePermissions(context, { rwd: \"w\" });\n\n const original = await storageOperations.get({\n where: {\n id,\n tenant: context.tenancy.getCurrentTenant().id,\n locale: getLocaleCode(context)\n }\n });\n\n if (!original) {\n throw new NotFoundError(`File with id \"${id}\" does not exists.`);\n }\n\n checkOwnership(original, permission, context);\n\n const file: File = {\n ...original,\n ...input,\n tags: Array.isArray(input.tags)\n ? input.tags\n : Array.isArray(original.tags)\n ? original.tags\n : [],\n id: original.id,\n webinyVersion: context.WEBINY_VERSION\n };\n\n try {\n await runLifecycleEvent(\"beforeUpdate\", {\n context,\n plugins: filePlugins,\n original,\n data: file\n });\n const result = await storageOperations.update({\n original,\n file\n });\n await runLifecycleEvent(\"afterUpdate\", {\n context,\n plugins: filePlugins,\n original,\n data: file,\n file: result\n });\n return result;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update a file.\",\n ex.code || \"UPDATE_FILE_ERROR\",\n {\n ...(ex.data || {}),\n original,\n file\n }\n );\n }\n },\n async deleteFile(id) {\n const permission = await checkBasePermissions(context, { rwd: \"d\" });\n\n const file = await storageOperations.get({\n where: {\n id,\n tenant: context.tenancy.getCurrentTenant().id,\n locale: getLocaleCode(context)\n }\n });\n if (!file) {\n throw new NotFoundError(`File with id \"${id}\" does not exists.`);\n }\n\n checkOwnership(file, permission, context);\n\n try {\n await runLifecycleEvent(\"beforeDelete\", {\n context,\n plugins: filePlugins,\n file\n });\n await storageOperations.delete({\n file\n });\n await runLifecycleEvent(\"afterDelete\", {\n context,\n plugins: filePlugins,\n file\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete a file.\",\n ex.code || \"DELETE_FILE_ERROR\",\n {\n ...(ex.data || {}),\n id,\n file\n }\n );\n }\n\n return true;\n },\n async createFilesInBatch(inputs) {\n if (!Array.isArray(inputs)) {\n throw new WebinyError(`\"data\" must be an array.`, \"CREATE_FILES_NON_ARRAY\");\n }\n\n if (inputs.length === 0) {\n throw new WebinyError(\n `\"data\" argument must contain at least one file.`,\n \"CREATE_FILES_MIN_FILES\"\n );\n }\n\n if (inputs.length > BATCH_CREATE_MAX_FILES) {\n throw new WebinyError(\n `\"data\" argument must not contain more than ${BATCH_CREATE_MAX_FILES} files.`,\n \"CREATE_FILES_MAX_FILES\"\n );\n }\n\n await checkBasePermissions(context, { rwd: \"w\" });\n\n const identity = context.security.getIdentity();\n const tenant = context.tenancy.getCurrentTenant();\n const createdBy: CreatedBy = {\n id: identity.id,\n displayName: identity.displayName,\n type: identity.type\n };\n\n const files: File[] = inputs.map(input => {\n return {\n ...input,\n tags: Array.isArray(input.tags) ? input.tags : [],\n meta: {\n private: false,\n ...(input.meta || {})\n },\n id: mdbid(),\n tenant: tenant.id,\n createdOn: new Date().toISOString(),\n createdBy,\n locale: getLocaleCode(context),\n webinyVersion: context.WEBINY_VERSION\n };\n });\n\n try {\n await runLifecycleEvent(\"beforeBatchCreate\", {\n context,\n plugins: filePlugins,\n data: files\n });\n const results = await storageOperations.createBatch({\n files\n });\n await runLifecycleEvent(\"afterBatchCreate\", {\n context,\n plugins: filePlugins,\n data: files,\n files: results\n });\n return results;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create a batch of files.\",\n ex.code || \"CREATE_FILES_ERROR\",\n {\n ...(ex.data || {}),\n files\n }\n );\n }\n },\n async listFiles(params: FilesListOpts = {}) {\n const permission = await checkBasePermissions(context, { rwd: \"r\" });\n\n const {\n limit = 40,\n search = \"\",\n types = [],\n tags = [],\n ids = [],\n after = null,\n where: initialWhere,\n sort: initialSort\n } = params;\n\n const where: FileManagerFilesStorageOperationsListParamsWhere = {\n ...initialWhere,\n private: false,\n locale: getLocaleCode(context),\n tenant: context.tenancy.getCurrentTenant().id\n };\n /**\n * Always override the createdBy received from the user, if any.\n */\n if (permission.own === true) {\n const identity = context.security.getIdentity();\n where.createdBy = identity.id;\n }\n /**\n * We need to map the old GraphQL definition to the new one.\n * That GQL definition is marked as deprecated.\n */\n /**\n * To have standardized where objects across the applications, we transform the types into type_in.\n */\n if (Array.isArray(types) && types.length > 0 && !where.type_in) {\n where.type_in = types;\n }\n /**\n * We are assigning search to tag and name search.\n * This should be treated as OR condition in the storage operations.\n */\n if (search && !where.search) {\n where.search = search;\n }\n /**\n * Same as on types/type_in.\n */\n if (Array.isArray(tags) && tags.length > 0 && !where.tag_in) {\n where.tag_in = tags.map(tag => tag.toLowerCase());\n }\n /**\n * Same as on types/type_in.\n */\n if (Array.isArray(ids) && ids.length > 0 && !where.id_in) {\n where.id_in = ids;\n }\n\n const sort =\n Array.isArray(initialSort) && initialSort.length > 0 ? initialSort : [\"id_DESC\"];\n try {\n return await storageOperations.list({\n where,\n after,\n limit,\n sort\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not list files by given parameters.\",\n ex.code || \"FILE_TAG_SEARCH_ERROR\",\n {\n ...(ex.data || {}),\n where,\n after,\n limit,\n sort\n }\n );\n }\n },\n async listTags({ where: initialWhere, after, limit }) {\n await checkBasePermissions(context);\n\n const where: FileManagerFilesStorageOperationsTagsParamsWhere = {\n ...initialWhere,\n tenant: context.tenancy.getCurrentTenant().id,\n locale: getLocaleCode(context)\n };\n\n const params = {\n where,\n limit: limit || 100000,\n after\n };\n\n try {\n const [tags] = await storageOperations.tags(params);\n if (Array.isArray(tags) === false) {\n return [];\n }\n /**\n * just to keep it standardized, sort by the tag ASC\n */\n return tags.sort();\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not search for tags.\",\n ex.code || \"FILE_TAG_SEARCH_ERROR\",\n {\n ...(ex.data || {}),\n params\n }\n );\n }\n }\n };\n});\n\nfilesContextCrudPlugin.name = \"FileManagerFilesCrud\";\n\nexport default filesContextCrudPlugin;\n"],"mappings":";;;;;;;;;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ACXrC,KADW;QAEXsC,KAAK,EAAEA,KAAK,IAAI,MAFL;QAGXI;MAHW,CAAf;;MAMA,IAAI;QACA,MAAM,CAAClC,IAAD,IAAS,MAAMlB,iBAAiB,CAACkB,IAAlB,CAAuB6B,MAAvB,CAArB;;QACA,IAAI5B,KAAK,CAACC,OAAN,CAAcF,IAAd,MAAwB,KAA5B,EAAmC;UAC/B,OAAO,EAAP;QACH;QACD;AAChB;AACA;;;QACgB,OAAOA,IAAI,CAACoC,IAAL,EAAP;MACH,CATD,CASE,OAAOrB,EAAP,EAAW;QACT,MAAM,IAAI9C,cAAJ,CACF8C,EAAE,CAACC,OAAH,IAAc,4BADZ,EAEFD,EAAE,CAAC3C,IAAH,IAAW,uBAFT,kCAIM2C,EAAE,CAACH,IAAH,IAAW,EAJjB;UAKEiB;QALF,GAAN;MAQH;IACJ;;EA5WuB,CAA5B;AA8WH,CArY8B,CAA/B;AAuYAxD,sBAAsB,CAACwE,IAAvB,GAA8B,sBAA9B;eAEexE,sB"}
|
|
1
|
+
{"version":3,"names":["BATCH_CREATE_MAX_FILES","checkOwnership","file","permission","context","own","identity","security","getIdentity","createdBy","id","NotAuthorizedError","getLocaleCode","i18n","WebinyError","locale","getContentLocale","code","filesContextCrudPlugin","ContextPlugin","pluginType","FilesStorageOperationsProviderPlugin","type","providerPlugin","plugins","byType","find","storageOperations","provide","fileManager","filePlugins","FilePlugin","files","getFile","checkBasePermissions","rwd","get","where","tenant","tenancy","getCurrentTenant","NotFoundError","createFile","input","mdbid","tags","Array","isArray","meta","private","createdOn","Date","toISOString","displayName","webinyVersion","WEBINY_VERSION","runLifecycleEvent","data","result","create","ex","message","updateFile","original","update","deleteFile","delete","createFilesInBatch","inputs","length","map","results","createBatch","listFiles","params","limit","search","types","ids","after","initialWhere","sort","initialSort","type_in","tag_in","tag","toLowerCase","id_in","list","listTags","name"],"sources":["files.crud.ts"],"sourcesContent":["/**\n * Package mdbid does not have types.\n */\n// @ts-ignore\nimport mdbid from \"mdbid\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport { NotAuthorizedError } from \"@webiny/api-security\";\nimport {\n CreatedBy,\n File,\n FileManagerContext,\n FileManagerFilesStorageOperationsListParamsWhere,\n FileManagerFilesStorageOperationsTagsParamsWhere,\n FilePermission,\n FilesListOpts\n} from \"~/types\";\nimport checkBasePermissions from \"./utils/checkBasePermissions\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { FilePlugin } from \"~/plugins/definitions/FilePlugin\";\nimport { FilesStorageOperationsProviderPlugin } from \"~/plugins/definitions/FilesStorageOperationsProviderPlugin\";\nimport WebinyError from \"@webiny/error\";\nimport { runLifecycleEvent } from \"~/plugins/crud/utils/lifecycleEvents\";\n\nconst BATCH_CREATE_MAX_FILES = 20;\n\n/**\n * If permission is limited to \"own\" files only, check that current identity owns the file.\n */\nconst checkOwnership = (file: File, permission: FilePermission, context: FileManagerContext) => {\n if (permission?.own === true) {\n const identity = context.security.getIdentity();\n if (file.createdBy.id !== identity.id) {\n throw new NotAuthorizedError();\n }\n }\n};\n\nconst getLocaleCode = (context: FileManagerContext): string => {\n if (!context.i18n) {\n throw new WebinyError(\"Missing i18n on the FileManagerContext.\", \"MISSING_I18N\");\n }\n\n const locale = context.i18n.getContentLocale();\n if (!locale) {\n throw new WebinyError(\n \"Missing content locale on the FileManagerContext.\",\n \"MISSING_I18N_CONTENT_LOCALE\"\n );\n }\n\n if (!locale.code) {\n throw new WebinyError(\n \"Missing content locale code on the FileManagerContext.\",\n \"MISSING_I18N_CONTENT_LOCALE_CODE\"\n );\n }\n return locale.code;\n};\n\nconst filesContextCrudPlugin = new ContextPlugin<FileManagerContext>(async context => {\n const pluginType = FilesStorageOperationsProviderPlugin.type;\n\n const providerPlugin = context.plugins\n .byType<FilesStorageOperationsProviderPlugin>(pluginType)\n .find(() => true);\n\n if (!providerPlugin) {\n throw new WebinyError(`Missing \"${pluginType}\" plugin.`, \"PLUGIN_NOT_FOUND\", {\n type: pluginType\n });\n }\n\n const storageOperations = await providerPlugin.provide({\n context\n });\n\n if (!context.fileManager) {\n context.fileManager = {} as any;\n }\n\n const filePlugins = context.plugins.byType<FilePlugin>(FilePlugin.type);\n\n context.fileManager.files = {\n async getFile(id: string) {\n const permission = await checkBasePermissions(context, { rwd: \"r\" });\n\n const file = await storageOperations.get({\n where: {\n id,\n tenant: context.tenancy.getCurrentTenant().id,\n locale: getLocaleCode(context)\n }\n });\n\n if (!file) {\n throw new NotFoundError(`File with id \"${id}\" does not exists.`);\n }\n\n checkOwnership(file, permission, context);\n\n return file;\n },\n async createFile(input) {\n await checkBasePermissions(context, { rwd: \"w\" });\n const identity = context.security.getIdentity();\n const tenant = context.tenancy.getCurrentTenant();\n\n const id = mdbid();\n\n const file: File = {\n ...input,\n tags: Array.isArray(input.tags) ? input.tags : [],\n id,\n meta: {\n private: false,\n ...(input.meta || {})\n },\n tenant: tenant.id,\n createdOn: new Date().toISOString(),\n createdBy: {\n id: identity.id,\n displayName: identity.displayName,\n type: identity.type\n },\n locale: getLocaleCode(context),\n webinyVersion: context.WEBINY_VERSION\n };\n\n try {\n await runLifecycleEvent(\"beforeCreate\", {\n context,\n plugins: filePlugins,\n data: file\n });\n const result = await storageOperations.create({\n file\n });\n await runLifecycleEvent(\"afterCreate\", {\n context,\n plugins: filePlugins,\n data: file,\n file: result\n });\n return result;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create a file.\",\n ex.code || \"CREATE_FILE_ERROR\",\n {\n ...(ex.data || {}),\n file\n }\n );\n }\n },\n async updateFile(id, input) {\n const permission = await checkBasePermissions(context, { rwd: \"w\" });\n\n const original = await storageOperations.get({\n where: {\n id,\n tenant: context.tenancy.getCurrentTenant().id,\n locale: getLocaleCode(context)\n }\n });\n\n if (!original) {\n throw new NotFoundError(`File with id \"${id}\" does not exists.`);\n }\n\n checkOwnership(original, permission, context);\n\n const file: File = {\n ...original,\n ...input,\n tags: Array.isArray(input.tags)\n ? input.tags\n : Array.isArray(original.tags)\n ? original.tags\n : [],\n id: original.id,\n webinyVersion: context.WEBINY_VERSION\n };\n\n try {\n await runLifecycleEvent(\"beforeUpdate\", {\n context,\n plugins: filePlugins,\n original,\n data: file\n });\n const result = await storageOperations.update({\n original,\n file\n });\n await runLifecycleEvent(\"afterUpdate\", {\n context,\n plugins: filePlugins,\n original,\n data: file,\n file: result\n });\n return result;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update a file.\",\n ex.code || \"UPDATE_FILE_ERROR\",\n {\n ...(ex.data || {}),\n original,\n file\n }\n );\n }\n },\n async deleteFile(id) {\n const permission = await checkBasePermissions(context, { rwd: \"d\" });\n\n const file = await storageOperations.get({\n where: {\n id,\n tenant: context.tenancy.getCurrentTenant().id,\n locale: getLocaleCode(context)\n }\n });\n if (!file) {\n throw new NotFoundError(`File with id \"${id}\" does not exists.`);\n }\n\n checkOwnership(file, permission, context);\n\n try {\n await runLifecycleEvent(\"beforeDelete\", {\n context,\n plugins: filePlugins,\n file\n });\n await storageOperations.delete({\n file\n });\n await runLifecycleEvent(\"afterDelete\", {\n context,\n plugins: filePlugins,\n file\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete a file.\",\n ex.code || \"DELETE_FILE_ERROR\",\n {\n ...(ex.data || {}),\n id,\n file\n }\n );\n }\n\n return true;\n },\n async createFilesInBatch(inputs) {\n if (!Array.isArray(inputs)) {\n throw new WebinyError(`\"data\" must be an array.`, \"CREATE_FILES_NON_ARRAY\");\n }\n\n if (inputs.length === 0) {\n throw new WebinyError(\n `\"data\" argument must contain at least one file.`,\n \"CREATE_FILES_MIN_FILES\"\n );\n }\n\n if (inputs.length > BATCH_CREATE_MAX_FILES) {\n throw new WebinyError(\n `\"data\" argument must not contain more than ${BATCH_CREATE_MAX_FILES} files.`,\n \"CREATE_FILES_MAX_FILES\"\n );\n }\n\n await checkBasePermissions(context, { rwd: \"w\" });\n\n const identity = context.security.getIdentity();\n const tenant = context.tenancy.getCurrentTenant();\n const createdBy: CreatedBy = {\n id: identity.id,\n displayName: identity.displayName,\n type: identity.type\n };\n\n const files: File[] = inputs.map(input => {\n return {\n ...input,\n tags: Array.isArray(input.tags) ? input.tags : [],\n meta: {\n private: false,\n ...(input.meta || {})\n },\n id: mdbid(),\n tenant: tenant.id,\n createdOn: new Date().toISOString(),\n createdBy,\n locale: getLocaleCode(context),\n webinyVersion: context.WEBINY_VERSION\n };\n });\n\n try {\n await runLifecycleEvent(\"beforeBatchCreate\", {\n context,\n plugins: filePlugins,\n data: files\n });\n const results = await storageOperations.createBatch({\n files\n });\n await runLifecycleEvent(\"afterBatchCreate\", {\n context,\n plugins: filePlugins,\n data: files,\n files: results\n });\n return results;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create a batch of files.\",\n ex.code || \"CREATE_FILES_ERROR\",\n {\n ...(ex.data || {}),\n files\n }\n );\n }\n },\n async listFiles(params: FilesListOpts = {}) {\n const permission = await checkBasePermissions(context, { rwd: \"r\" });\n\n const {\n limit = 40,\n search = \"\",\n types = [],\n tags = [],\n ids = [],\n after = null,\n where: initialWhere,\n sort: initialSort\n } = params;\n\n const where: FileManagerFilesStorageOperationsListParamsWhere = {\n ...initialWhere,\n private: false,\n locale: getLocaleCode(context),\n tenant: context.tenancy.getCurrentTenant().id\n };\n /**\n * Always override the createdBy received from the user, if any.\n */\n if (permission.own === true) {\n const identity = context.security.getIdentity();\n where.createdBy = identity.id;\n }\n /**\n * We need to map the old GraphQL definition to the new one.\n * That GQL definition is marked as deprecated.\n */\n /**\n * To have standardized where objects across the applications, we transform the types into type_in.\n */\n if (Array.isArray(types) && types.length > 0 && !where.type_in) {\n where.type_in = types;\n }\n /**\n * We are assigning search to tag and name search.\n * This should be treated as OR condition in the storage operations.\n */\n if (search && !where.search) {\n where.search = search;\n }\n /**\n * Same as on types/type_in.\n */\n if (Array.isArray(tags) && tags.length > 0 && !where.tag_in) {\n where.tag_in = tags.map(tag => tag.toLowerCase());\n }\n /**\n * Same as on types/type_in.\n */\n if (Array.isArray(ids) && ids.length > 0 && !where.id_in) {\n where.id_in = ids;\n }\n\n const sort =\n Array.isArray(initialSort) && initialSort.length > 0 ? initialSort : [\"id_DESC\"];\n try {\n return await storageOperations.list({\n where,\n after,\n limit,\n sort\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not list files by given parameters.\",\n ex.code || \"FILE_TAG_SEARCH_ERROR\",\n {\n ...(ex.data || {}),\n where,\n after,\n limit,\n sort\n }\n );\n }\n },\n async listTags({ where: initialWhere, after, limit }) {\n await checkBasePermissions(context);\n\n const where: FileManagerFilesStorageOperationsTagsParamsWhere = {\n ...initialWhere,\n tenant: context.tenancy.getCurrentTenant().id,\n locale: getLocaleCode(context)\n };\n\n const params = {\n where,\n limit: limit || 100000,\n after\n };\n\n try {\n const [tags] = await storageOperations.tags(params);\n if (Array.isArray(tags) === false) {\n return [];\n }\n /**\n * just to keep it standardized, sort by the tag ASC\n */\n return tags.sort();\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not search for tags.\",\n ex.code || \"FILE_TAG_SEARCH_ERROR\",\n {\n ...(ex.data || {}),\n params\n }\n );\n }\n }\n };\n});\n\nfilesContextCrudPlugin.name = \"FileManagerFilesCrud\";\n\nexport default filesContextCrudPlugin;\n"],"mappings":";;;;;;;;;;;AAIA;;AACA;;AACA;;AAUA;;AACA;;AACA;;AACA;;AACA;;AACA;;AArBA;AACA;AACA;AACA;AAoBA,MAAMA,sBAAsB,GAAG,EAA/B;AAEA;AACA;AACA;;AACA,MAAMC,cAAc,GAAG,CAACC,IAAD,EAAaC,UAAb,EAAyCC,OAAzC,KAAyE;EAC5F,IAAI,CAAAD,UAAU,SAAV,IAAAA,UAAU,WAAV,YAAAA,UAAU,CAAEE,GAAZ,MAAoB,IAAxB,EAA8B;IAC1B,MAAMC,QAAQ,GAAGF,OAAO,CAACG,QAAR,CAAiBC,WAAjB,EAAjB;;IACA,IAAIN,IAAI,CAACO,SAAL,CAAeC,EAAf,KAAsBJ,QA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EAAE,CAAC3C,IAAH,IAAW,uBAFT,8DAIM2C,EAAE,CAACH,IAAH,IAAW,EAJjB;UAKEiB;QALF,GAAN;MAQH;IACJ;;EA5WuB,CAA5B;AA8WH,CArY8B,CAA/B;AAuYAxD,sBAAsB,CAACwE,IAAvB,GAA8B,sBAA9B;eAEexE,sB"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
4
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.default = exports.SETTINGS_KEY = void 0;
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
11
|
|
|
12
12
|
var _fields = require("@commodo/fields");
|
|
13
13
|
|
|
@@ -19,10 +19,10 @@ var _error = _interopRequireDefault(require("@webiny/error"));
|
|
|
19
19
|
|
|
20
20
|
var _api = require("@webiny/api");
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Package @commodo/fields does not have types.
|
|
24
|
+
*/
|
|
25
|
+
// @ts-ignore
|
|
26
26
|
// TODO @ts-refactor verify that this is not used and remove it
|
|
27
27
|
const SETTINGS_KEY = "file-manager";
|
|
28
28
|
exports.SETTINGS_KEY = SETTINGS_KEY;
|
|
@@ -100,7 +100,7 @@ const settingsCrudContextPlugin = new _api.ContextPlugin(async context => {
|
|
|
100
100
|
});
|
|
101
101
|
return storageOperations.update({
|
|
102
102
|
original: existingSettings,
|
|
103
|
-
data:
|
|
103
|
+
data: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, existingSettings), updatedSettings)
|
|
104
104
|
});
|
|
105
105
|
},
|
|
106
106
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["SETTINGS_KEY","CreateDataModel","withFields","uploadMinFileSize","number","value","validation","create","uploadMaxFileSize","srcPrefix","onSet","endsWith","string","UpdateDataModel","settingsCrudContextPlugin","ContextPlugin","context","pluginType","SettingsStorageOperationsProviderPlugin","type","providerPlugin","plugins","byType","find","WebinyError","storageOperations","provide","fileManager","settings","getSettings","get","createSettings","data","populate","validate","settingsData","toJSON","updateSettings","updatedValue","existingSettings","updatedSettings","onlyDirty","update","original","deleteSettings","delete","name"],"sources":["settings.crud.ts"],"sourcesContent":["/**\n * Package @commodo/fields does not have types.\n */\n// @ts-ignore\nimport { withFields, string, number, onSet } from \"@commodo/fields\";\nimport { validation } from \"@webiny/validation\";\nimport { FileManagerContext, FileManagerSettings } from \"~/types\";\nimport { SettingsStorageOperationsProviderPlugin } from \"~/plugins/definitions/SettingsStorageOperationsProviderPlugin\";\nimport WebinyError from \"@webiny/error\";\nimport { ContextPlugin } from \"@webiny/api\";\n\n// TODO @ts-refactor verify that this is not used and remove it\nexport const SETTINGS_KEY = \"file-manager\";\n\nconst CreateDataModel = withFields({\n uploadMinFileSize: number({ value: 0, validation: validation.create(\"gte:0\") }),\n uploadMaxFileSize: number({ value: 26214401 }),\n srcPrefix: onSet((value?: string) => {\n // Make sure srcPrefix always ends with forward slash.\n if (typeof value === \"string\") {\n return value.endsWith(\"/\") ? value : value + \"/\";\n }\n return value;\n })(string({ value: \"/files/\" }))\n})();\n\nconst UpdateDataModel = withFields({\n uploadMinFileSize: number({\n validation: validation.create(\"gte:0\")\n }),\n uploadMaxFileSize: number(),\n srcPrefix: onSet((value?: string) => {\n // Make sure srcPrefix always ends with forward slash.\n if (typeof value === \"string\") {\n return value.endsWith(\"/\") ? value : value + \"/\";\n }\n return value;\n })(string())\n})();\n\nconst settingsCrudContextPlugin = new ContextPlugin<FileManagerContext>(async context => {\n const pluginType = SettingsStorageOperationsProviderPlugin.type;\n\n const providerPlugin = context.plugins\n .byType<SettingsStorageOperationsProviderPlugin>(pluginType)\n .find(() => true);\n\n if (!providerPlugin) {\n throw new WebinyError(`Missing \"${pluginType}\" plugin.`, \"PLUGIN_NOT_FOUND\", {\n type: pluginType\n });\n }\n\n const storageOperations = await providerPlugin.provide({\n context\n });\n\n if (!context.fileManager) {\n context.fileManager = {} as any;\n }\n\n context.fileManager.settings = {\n async getSettings() {\n return storageOperations.get();\n },\n async createSettings(data) {\n const settings = new CreateDataModel().populate(data);\n await settings.validate();\n\n const settingsData: FileManagerSettings = await settings.toJSON();\n\n return storageOperations.create({\n data: settingsData\n });\n },\n async updateSettings(data) {\n const updatedValue = new UpdateDataModel().populate(data);\n await updatedValue.validate();\n\n const existingSettings = (await storageOperations.get()) as FileManagerSettings;\n\n const updatedSettings: Partial<FileManagerSettings> = await updatedValue.toJSON({\n onlyDirty: true\n });\n\n return storageOperations.update({\n original: existingSettings,\n data: {\n ...existingSettings,\n ...updatedSettings\n }\n });\n },\n async deleteSettings() {\n await storageOperations.delete();\n\n return true;\n }\n };\n});\n\nsettingsCrudContextPlugin.name = \"FileMangerSettingsCrud\";\n\nexport default settingsCrudContextPlugin;\n"],"mappings":";;;;;;;;;;;AAIA;;AACA;;AAEA;;AACA;;AACA
|
|
1
|
+
{"version":3,"names":["SETTINGS_KEY","CreateDataModel","withFields","uploadMinFileSize","number","value","validation","create","uploadMaxFileSize","srcPrefix","onSet","endsWith","string","UpdateDataModel","settingsCrudContextPlugin","ContextPlugin","context","pluginType","SettingsStorageOperationsProviderPlugin","type","providerPlugin","plugins","byType","find","WebinyError","storageOperations","provide","fileManager","settings","getSettings","get","createSettings","data","populate","validate","settingsData","toJSON","updateSettings","updatedValue","existingSettings","updatedSettings","onlyDirty","update","original","deleteSettings","delete","name"],"sources":["settings.crud.ts"],"sourcesContent":["/**\n * Package @commodo/fields does not have types.\n */\n// @ts-ignore\nimport { withFields, string, number, onSet } from \"@commodo/fields\";\nimport { validation } from \"@webiny/validation\";\nimport { FileManagerContext, FileManagerSettings } from \"~/types\";\nimport { SettingsStorageOperationsProviderPlugin } from \"~/plugins/definitions/SettingsStorageOperationsProviderPlugin\";\nimport WebinyError from \"@webiny/error\";\nimport { ContextPlugin } from \"@webiny/api\";\n\n// TODO @ts-refactor verify that this is not used and remove it\nexport const SETTINGS_KEY = \"file-manager\";\n\nconst CreateDataModel = withFields({\n uploadMinFileSize: number({ value: 0, validation: validation.create(\"gte:0\") }),\n uploadMaxFileSize: number({ value: 26214401 }),\n srcPrefix: onSet((value?: string) => {\n // Make sure srcPrefix always ends with forward slash.\n if (typeof value === \"string\") {\n return value.endsWith(\"/\") ? value : value + \"/\";\n }\n return value;\n })(string({ value: \"/files/\" }))\n})();\n\nconst UpdateDataModel = withFields({\n uploadMinFileSize: number({\n validation: validation.create(\"gte:0\")\n }),\n uploadMaxFileSize: number(),\n srcPrefix: onSet((value?: string) => {\n // Make sure srcPrefix always ends with forward slash.\n if (typeof value === \"string\") {\n return value.endsWith(\"/\") ? value : value + \"/\";\n }\n return value;\n })(string())\n})();\n\nconst settingsCrudContextPlugin = new ContextPlugin<FileManagerContext>(async context => {\n const pluginType = SettingsStorageOperationsProviderPlugin.type;\n\n const providerPlugin = context.plugins\n .byType<SettingsStorageOperationsProviderPlugin>(pluginType)\n .find(() => true);\n\n if (!providerPlugin) {\n throw new WebinyError(`Missing \"${pluginType}\" plugin.`, \"PLUGIN_NOT_FOUND\", {\n type: pluginType\n });\n }\n\n const storageOperations = await providerPlugin.provide({\n context\n });\n\n if (!context.fileManager) {\n context.fileManager = {} as any;\n }\n\n context.fileManager.settings = {\n async getSettings() {\n return storageOperations.get();\n },\n async createSettings(data) {\n const settings = new CreateDataModel().populate(data);\n await settings.validate();\n\n const settingsData: FileManagerSettings = await settings.toJSON();\n\n return storageOperations.create({\n data: settingsData\n });\n },\n async updateSettings(data) {\n const updatedValue = new UpdateDataModel().populate(data);\n await updatedValue.validate();\n\n const existingSettings = (await storageOperations.get()) as FileManagerSettings;\n\n const updatedSettings: Partial<FileManagerSettings> = await updatedValue.toJSON({\n onlyDirty: true\n });\n\n return storageOperations.update({\n original: existingSettings,\n data: {\n ...existingSettings,\n ...updatedSettings\n }\n });\n },\n async deleteSettings() {\n await storageOperations.delete();\n\n return true;\n }\n };\n});\n\nsettingsCrudContextPlugin.name = \"FileMangerSettingsCrud\";\n\nexport default settingsCrudContextPlugin;\n"],"mappings":";;;;;;;;;;;AAIA;;AACA;;AAEA;;AACA;;AACA;;AATA;AACA;AACA;AACA;AAQA;AACO,MAAMA,YAAY,GAAG,cAArB;;AAEP,MAAMC,eAAe,GAAG,IAAAC,kBAAA,EAAW;EAC/BC,iBAAiB,EAAE,IAAAC,cAAA,EAAO;IAAEC,KAAK,EAAE,CAAT;IAAYC,UAAU,EAAEA,sBAAA,CAAWC,MAAX,CAAkB,OAAlB;EAAxB,CAAP,CADY;EAE/BC,iBAAiB,EAAE,IAAAJ,cAAA,EAAO;IAAEC,KAAK,EAAE;EAAT,CAAP,CAFY;EAG/BI,SAAS,EAAE,IAAAC,aAAA,EAAOL,KAAD,IAAoB;IACjC;IACA,IAAI,OAAOA,KAAP,KAAiB,QAArB,EAA+B;MAC3B,OAAOA,KAAK,CAACM,QAAN,CAAe,GAAf,IAAsBN,KAAtB,GAA8BA,KAAK,GAAG,GAA7C;IACH;;IACD,OAAOA,KAAP;EACH,CANU,EAMR,IAAAO,cAAA,EAAO;IAAEP,KAAK,EAAE;EAAT,CAAP,CANQ;AAHoB,CAAX,GAAxB;AAYA,MAAMQ,eAAe,GAAG,IAAAX,kBAAA,EAAW;EAC/BC,iBAAiB,EAAE,IAAAC,cAAA,EAAO;IACtBE,UAAU,EAAEA,sBAAA,CAAWC,MAAX,CAAkB,OAAlB;EADU,CAAP,CADY;EAI/BC,iBAAiB,EAAE,IAAAJ,cAAA,GAJY;EAK/BK,SAAS,EAAE,IAAAC,aAAA,EAAOL,KAAD,IAAoB;IACjC;IACA,IAAI,OAAOA,KAAP,KA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IAArB,EAA2B;MACvB,MAAMM,YAAY,GAAG,IAAIzB,eAAJ,GAAsBoB,QAAtB,CAA+BD,IAA/B,CAArB;MACA,MAAMM,YAAY,CAACJ,QAAb,EAAN;MAEA,MAAMK,gBAAgB,GAAI,MAAMd,iBAAiB,CAACK,GAAlB,EAAhC;MAEA,MAAMU,eAA6C,GAAG,MAAMF,YAAY,CAACF,MAAb,CAAoB;QAC5EK,SAAS,EAAE;MADiE,CAApB,CAA5D;MAIA,OAAOhB,iBAAiB,CAACiB,MAAlB,CAAyB;QAC5BC,QAAQ,EAAEJ,gBADkB;QAE5BP,IAAI,8DACGO,gBADH,GAEGC,eAFH;MAFwB,CAAzB,CAAP;IAOH,CA/B0B;;IAgC3B,MAAMI,cAAN,GAAuB;MACnB,MAAMnB,iBAAiB,CAACoB,MAAlB,EAAN;MAEA,OAAO,IAAP;IACH;;EApC0B,CAA/B;AAsCH,CA3DiC,CAAlC;AA6DA/B,yBAAyB,CAACgC,IAA1B,GAAiC,wBAAjC;eAEehC,yB"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
4
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.default = void 0;
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
11
|
|
|
12
12
|
var _apiSecurity = require("@webiny/api-security");
|
|
13
13
|
|
|
@@ -23,10 +23,6 @@ var _InstallationPlugin = require("../definitions/InstallationPlugin");
|
|
|
23
23
|
|
|
24
24
|
var _SystemStorageOperationsProviderPlugin = require("../definitions/SystemStorageOperationsProviderPlugin");
|
|
25
25
|
|
|
26
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
27
|
-
|
|
28
|
-
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; }
|
|
29
|
-
|
|
30
26
|
const systemCrudContextPlugin = new _api.ContextPlugin(async context => {
|
|
31
27
|
const pluginType = _SystemStorageOperationsProviderPlugin.SystemStorageOperationsProviderPlugin.type;
|
|
32
28
|
const providerPlugin = context.plugins.byType(pluginType).find(() => true);
|
|
@@ -59,7 +55,7 @@ const systemCrudContextPlugin = new _api.ContextPlugin(async context => {
|
|
|
59
55
|
const system = await storageOperations.get();
|
|
60
56
|
|
|
61
57
|
if (system) {
|
|
62
|
-
const data =
|
|
58
|
+
const data = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, system), {}, {
|
|
63
59
|
tenant: system.tenant || getTenantId(),
|
|
64
60
|
version
|
|
65
61
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["systemCrudContextPlugin","ContextPlugin","context","pluginType","SystemStorageOperationsProviderPlugin","type","providerPlugin","plugins","byType","find","WebinyError","storageOperations","provide","fileManager","getTenantId","tenancy","getCurrentTenant","id","system","getVersion","get","version","setVersion","data","tenant","update","original","ex","create","install","srcPrefix","identity","security","getIdentity","NotAuthorizedError","installationPlugins","InstallationPlugin","executeCallbacks","settings","createSettings","WEBINY_VERSION","upgrade","upgradePlugins","filter","pl","app","plugin","getApplicablePlugin","deployedVersion","installedAppVersion","upgradeToVersion","apply","name"],"sources":["system.crud.ts"],"sourcesContent":["import { NotAuthorizedError } from \"@webiny/api-security\";\nimport { getApplicablePlugin } from \"@webiny/api-upgrade\";\nimport { FileManagerContext, FileManagerSettings, FileManagerSystem } from \"~/types\";\nimport { UpgradePlugin } from \"@webiny/api-upgrade/types\";\nimport WebinyError from \"@webiny/error\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { executeCallbacks } from \"~/utils\";\nimport { InstallationPlugin } from \"~/plugins/definitions/InstallationPlugin\";\nimport { SystemStorageOperationsProviderPlugin } from \"~/plugins/definitions/SystemStorageOperationsProviderPlugin\";\n\nconst systemCrudContextPlugin = new ContextPlugin<FileManagerContext>(async context => {\n const pluginType = SystemStorageOperationsProviderPlugin.type;\n const providerPlugin = context.plugins\n .byType<SystemStorageOperationsProviderPlugin>(pluginType)\n .find(() => true);\n\n if (!providerPlugin) {\n throw new WebinyError(`Missing \"${pluginType}\" plugin.`, \"PLUGIN_NOT_FOUND\", {\n type: pluginType\n });\n }\n\n const storageOperations = await providerPlugin.provide({\n context\n });\n\n if (!context.fileManager) {\n context.fileManager = {} as any;\n }\n\n const getTenantId = (): string => {\n return context.tenancy.getCurrentTenant().id;\n };\n\n context.fileManager.system = {\n async getVersion() {\n const system = await storageOperations.get();\n\n return system ? system.version : null;\n },\n async setVersion(version: string) {\n const system = await storageOperations.get();\n\n if (system) {\n const data: FileManagerSystem = {\n ...system,\n tenant: system.tenant || getTenantId(),\n version\n };\n try {\n await storageOperations.update({\n original: system,\n data\n });\n return;\n } catch (ex) {\n throw new WebinyError(\n \"Could not update the system data.\",\n \"SYSTEM_UPDATE_ERROR\",\n {\n data\n }\n );\n }\n }\n\n const data: FileManagerSystem = {\n version,\n tenant: getTenantId()\n };\n try {\n await storageOperations.create({\n data\n });\n return;\n } catch (ex) {\n throw new WebinyError(\"Could not create the system data.\", \"SYSTEM_CREATE_ERROR\", {\n data\n });\n }\n },\n async install({ srcPrefix }) {\n const identity = context.security.getIdentity();\n if (!identity) {\n throw new NotAuthorizedError();\n }\n const { fileManager } = context;\n const version = await fileManager.system.getVersion();\n\n if (version) {\n throw new WebinyError(\n \"File Manager is already installed.\",\n \"FILES_INSTALL_ABORTED\"\n );\n }\n\n const data: Partial<FileManagerSettings> = {};\n\n if (srcPrefix) {\n data.srcPrefix = srcPrefix;\n }\n\n const installationPlugins = context.plugins.byType<InstallationPlugin>(\n InstallationPlugin.type\n );\n\n await executeCallbacks<InstallationPlugin[\"beforeInstall\"]>(\n installationPlugins,\n \"beforeInstall\",\n {\n context\n }\n );\n\n await fileManager.settings.createSettings(data);\n\n await fileManager.system.setVersion(context.WEBINY_VERSION);\n\n await executeCallbacks<InstallationPlugin[\"afterInstall\"]>(\n installationPlugins,\n \"afterInstall\",\n {\n context\n }\n );\n\n return true;\n },\n async upgrade(version) {\n const identity = context.security.getIdentity();\n if (!identity) {\n throw new NotAuthorizedError();\n }\n\n const upgradePlugins = context.plugins\n .byType<UpgradePlugin>(\"api-upgrade\")\n .filter(pl => pl.app === \"file-manager\");\n\n const plugin = getApplicablePlugin({\n deployedVersion: context.WEBINY_VERSION,\n installedAppVersion: await this.getVersion(),\n upgradePlugins,\n upgradeToVersion: version\n });\n\n await plugin.apply(context);\n\n // Store new app version\n await context.fileManager.system.setVersion(version);\n\n return true;\n }\n };\n});\n\nsystemCrudContextPlugin.name = \"FileManagerSystemCrud\";\n\nexport default systemCrudContextPlugin;\n"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AAGA;;AACA;;AACA;;AACA;;AACA
|
|
1
|
+
{"version":3,"names":["systemCrudContextPlugin","ContextPlugin","context","pluginType","SystemStorageOperationsProviderPlugin","type","providerPlugin","plugins","byType","find","WebinyError","storageOperations","provide","fileManager","getTenantId","tenancy","getCurrentTenant","id","system","getVersion","get","version","setVersion","data","tenant","update","original","ex","create","install","srcPrefix","identity","security","getIdentity","NotAuthorizedError","installationPlugins","InstallationPlugin","executeCallbacks","settings","createSettings","WEBINY_VERSION","upgrade","upgradePlugins","filter","pl","app","plugin","getApplicablePlugin","deployedVersion","installedAppVersion","upgradeToVersion","apply","name"],"sources":["system.crud.ts"],"sourcesContent":["import { NotAuthorizedError } from \"@webiny/api-security\";\nimport { getApplicablePlugin } from \"@webiny/api-upgrade\";\nimport { FileManagerContext, FileManagerSettings, FileManagerSystem } from \"~/types\";\nimport { UpgradePlugin } from \"@webiny/api-upgrade/types\";\nimport WebinyError from \"@webiny/error\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { executeCallbacks } from \"~/utils\";\nimport { InstallationPlugin } from \"~/plugins/definitions/InstallationPlugin\";\nimport { SystemStorageOperationsProviderPlugin } from \"~/plugins/definitions/SystemStorageOperationsProviderPlugin\";\n\nconst systemCrudContextPlugin = new ContextPlugin<FileManagerContext>(async context => {\n const pluginType = SystemStorageOperationsProviderPlugin.type;\n const providerPlugin = context.plugins\n .byType<SystemStorageOperationsProviderPlugin>(pluginType)\n .find(() => true);\n\n if (!providerPlugin) {\n throw new WebinyError(`Missing \"${pluginType}\" plugin.`, \"PLUGIN_NOT_FOUND\", {\n type: pluginType\n });\n }\n\n const storageOperations = await providerPlugin.provide({\n context\n });\n\n if (!context.fileManager) {\n context.fileManager = {} as any;\n }\n\n const getTenantId = (): string => {\n return context.tenancy.getCurrentTenant().id;\n };\n\n context.fileManager.system = {\n async getVersion() {\n const system = await storageOperations.get();\n\n return system ? system.version : null;\n },\n async setVersion(version: string) {\n const system = await storageOperations.get();\n\n if (system) {\n const data: FileManagerSystem = {\n ...system,\n tenant: system.tenant || getTenantId(),\n version\n };\n try {\n await storageOperations.update({\n original: system,\n data\n });\n return;\n } catch (ex) {\n throw new WebinyError(\n \"Could not update the system data.\",\n \"SYSTEM_UPDATE_ERROR\",\n {\n data\n }\n );\n }\n }\n\n const data: FileManagerSystem = {\n version,\n tenant: getTenantId()\n };\n try {\n await storageOperations.create({\n data\n });\n return;\n } catch (ex) {\n throw new WebinyError(\"Could not create the system data.\", \"SYSTEM_CREATE_ERROR\", {\n data\n });\n }\n },\n async install({ srcPrefix }) {\n const identity = context.security.getIdentity();\n if (!identity) {\n throw new NotAuthorizedError();\n }\n const { fileManager } = context;\n const version = await fileManager.system.getVersion();\n\n if (version) {\n throw new WebinyError(\n \"File Manager is already installed.\",\n \"FILES_INSTALL_ABORTED\"\n );\n }\n\n const data: Partial<FileManagerSettings> = {};\n\n if (srcPrefix) {\n data.srcPrefix = srcPrefix;\n }\n\n const installationPlugins = context.plugins.byType<InstallationPlugin>(\n InstallationPlugin.type\n );\n\n await executeCallbacks<InstallationPlugin[\"beforeInstall\"]>(\n installationPlugins,\n \"beforeInstall\",\n {\n context\n }\n );\n\n await fileManager.settings.createSettings(data);\n\n await fileManager.system.setVersion(context.WEBINY_VERSION);\n\n await executeCallbacks<InstallationPlugin[\"afterInstall\"]>(\n installationPlugins,\n \"afterInstall\",\n {\n context\n }\n );\n\n return true;\n },\n async upgrade(version) {\n const identity = context.security.getIdentity();\n if (!identity) {\n throw new NotAuthorizedError();\n }\n\n const upgradePlugins = context.plugins\n .byType<UpgradePlugin>(\"api-upgrade\")\n .filter(pl => pl.app === \"file-manager\");\n\n const plugin = getApplicablePlugin({\n deployedVersion: context.WEBINY_VERSION,\n installedAppVersion: await this.getVersion(),\n upgradePlugins,\n upgradeToVersion: version\n });\n\n await plugin.apply(context);\n\n // Store new app version\n await context.fileManager.system.setVersion(version);\n\n return true;\n }\n };\n});\n\nsystemCrudContextPlugin.name = \"FileManagerSystemCrud\";\n\nexport default systemCrudContextPlugin;\n"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AAGA;;AACA;;AACA;;AACA;;AACA;;AAEA,MAAMA,uBAAuB,GAAG,IAAIC,kBAAJ,CAAsC,MAAMC,OAAN,IAAiB;EACnF,MAAMC,UAAU,GAAGC,4EAAA,CAAsCC,IAAzD;EACA,MAAMC,cAAc,GAAGJ,OAAO,CAACK,OAAR,CAClBC,MADkB,CAC4BL,UAD5B,E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AMuC,OAAN,CAAcpB,OAAd,EAAuB;MACnB,MAAMU,QAAQ,GAAG7B,OAAO,CAAC8B,QAAR,CAAiBC,WAAjB,EAAjB;;MACA,IAAI,CAACF,QAAL,EAAe;QACX,MAAM,IAAIG,+BAAJ,EAAN;MACH;;MAED,MAAMQ,cAAc,GAAGxC,OAAO,CAACK,OAAR,CAClBC,MADkB,CACI,aADJ,EAElBmC,MAFkB,CAEXC,EAAE,IAAIA,EAAE,CAACC,GAAH,KAAW,cAFN,CAAvB;MAIA,MAAMC,MAAM,GAAG,IAAAC,+BAAA,EAAoB;QAC/BC,eAAe,EAAE9C,OAAO,CAACsC,cADM;QAE/BS,mBAAmB,EAAE,MAAM,KAAK9B,UAAL,EAFI;QAG/BuB,cAH+B;QAI/BQ,gBAAgB,EAAE7B;MAJa,CAApB,CAAf;MAOA,MAAMyB,MAAM,CAACK,KAAP,CAAajD,OAAb,CAAN,CAjBmB,CAmBnB;;MACA,MAAMA,OAAO,CAACW,WAAR,CAAoBK,MAApB,CAA2BI,UAA3B,CAAsCD,OAAtC,CAAN;MAEA,OAAO,IAAP;IACH;;EArHwB,CAA7B;AAuHH,CA/I+B,CAAhC;AAiJArB,uBAAuB,CAACoD,IAAxB,GAA+B,uBAA/B;eAEepD,uB"}
|
package/plugins/index.js
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
4
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.FileStorage = void 0;
|
|
9
9
|
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
+
|
|
10
12
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
13
|
|
|
12
14
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
15
|
|
|
14
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
15
|
-
|
|
16
|
-
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; }
|
|
17
|
-
|
|
18
16
|
const storagePluginType = "api-file-manager-storage";
|
|
19
17
|
|
|
20
18
|
class FileStorage {
|
|
@@ -43,14 +41,14 @@ class FileStorage {
|
|
|
43
41
|
|
|
44
42
|
const {
|
|
45
43
|
file: fileData
|
|
46
|
-
} = await this.storagePlugin.upload(
|
|
44
|
+
} = await this.storagePlugin.upload((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
|
|
47
45
|
settings
|
|
48
46
|
}));
|
|
49
47
|
const {
|
|
50
48
|
fileManager
|
|
51
49
|
} = this.context; // Save file in DB.
|
|
52
50
|
|
|
53
|
-
return await fileManager.files.createFile(
|
|
51
|
+
return await fileManager.files.createFile((0, _objectSpread2.default)((0, _objectSpread2.default)({}, fileData), {}, {
|
|
54
52
|
meta: {
|
|
55
53
|
private: Boolean(params.hideInFileManager)
|
|
56
54
|
},
|
|
@@ -69,7 +67,7 @@ class FileStorage {
|
|
|
69
67
|
const promises = [];
|
|
70
68
|
|
|
71
69
|
for (const item of params.files) {
|
|
72
|
-
promises.push(this.storagePlugin.upload(
|
|
70
|
+
promises.push(this.storagePlugin.upload((0, _objectSpread2.default)((0, _objectSpread2.default)({}, item), {}, {
|
|
73
71
|
settings
|
|
74
72
|
})));
|
|
75
73
|
} // Wait for all to resolve.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["storagePluginType","FileStorage","constructor","context","storagePlugin","plugins","byType","pop","WebinyError","upload","params","settings","fileManager","getSettings","file","fileData","files","createFile","meta","private","Boolean","hideInFileManager","tags","Array","isArray","uploadFiles","promises","item","push","uploadFileResponses","Promise","all","filesData","map","response","createFilesInBatch","delete","id","key","deleteFile"],"sources":["FileStorage.ts"],"sourcesContent":["import { FileManagerContext } from \"~/types\";\nimport WebinyError from \"@webiny/error\";\nimport { FilePhysicalStoragePlugin } from \"~/plugins/definitions/FilePhysicalStoragePlugin\";\n\nexport type Result = Record<string, any>;\n\nconst storagePluginType = \"api-file-manager-storage\";\n\nexport interface FileStorageUploadParams {\n buffer: Buffer;\n hideInFileManager: boolean | string;\n tags?: string[];\n size: number;\n name: string;\n keyPrefix: string;\n type: string;\n}\nexport interface FileStorageDeleteParams {\n id: string;\n key: string;\n}\n\nexport interface FileStorageUploadMultipleParams {\n files: FileStorageUploadParams[];\n}\n\nexport interface FileStorageParams {\n context: FileManagerContext;\n}\nexport class FileStorage {\n private readonly storagePlugin: FilePhysicalStoragePlugin;\n private readonly context: FileManagerContext;\n\n constructor({ context }: FileStorageParams) {\n const storagePlugin = context.plugins\n .byType<FilePhysicalStoragePlugin>(storagePluginType)\n .pop();\n if (!storagePlugin) {\n throw new WebinyError(\n `Missing plugin of type \"${storagePluginType}\".`,\n \"STORAGE_PLUGIN_ERROR\"\n );\n }\n this.storagePlugin = storagePlugin;\n this.context = context;\n }\n\n async upload(params: FileStorageUploadParams): Promise<Result> {\n const settings = await this.context.fileManager.settings.getSettings();\n if (!settings) {\n throw new WebinyError(\"Missing File Manager Settings.\", \"FILE_MANAGER_ERROR\");\n }\n // Add file to cloud storage.\n const { file: fileData } = await this.storagePlugin.upload({\n ...params,\n settings\n });\n\n const { fileManager } = this.context;\n\n // Save file in DB.\n return await fileManager.files.createFile({\n ...(fileData as any),\n meta: {\n private: Boolean(params.hideInFileManager)\n },\n tags: Array.isArray(params.tags) ? params.tags : []\n });\n }\n\n async uploadFiles(params: FileStorageUploadMultipleParams) {\n const settings = await this.context.fileManager.settings.getSettings();\n if (!settings) {\n throw new WebinyError(\"Missing File Manager Settings.\", \"FILE_MANAGER_ERROR\");\n }\n // Upload files to cloud storage.\n const promises = [];\n for (const item of params.files) {\n promises.push(\n this.storagePlugin.upload({\n ...item,\n settings\n })\n );\n }\n // Wait for all to resolve.\n const uploadFileResponses = await Promise.all(promises);\n\n const filesData = uploadFileResponses.map(response => response.file);\n\n const { fileManager } = this.context;\n // Save files in DB.\n return fileManager.files.createFilesInBatch(filesData);\n }\n\n async delete(params: FileStorageDeleteParams) {\n const { id, key } = params;\n const { fileManager } = this.context;\n // Delete file from cloud storage.\n await this.storagePlugin.delete({\n key\n });\n // Delete file from the DB.\n return await fileManager.files.deleteFile(id);\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["storagePluginType","FileStorage","constructor","context","storagePlugin","plugins","byType","pop","WebinyError","upload","params","settings","fileManager","getSettings","file","fileData","files","createFile","meta","private","Boolean","hideInFileManager","tags","Array","isArray","uploadFiles","promises","item","push","uploadFileResponses","Promise","all","filesData","map","response","createFilesInBatch","delete","id","key","deleteFile"],"sources":["FileStorage.ts"],"sourcesContent":["import { FileManagerContext } from \"~/types\";\nimport WebinyError from \"@webiny/error\";\nimport { FilePhysicalStoragePlugin } from \"~/plugins/definitions/FilePhysicalStoragePlugin\";\n\nexport type Result = Record<string, any>;\n\nconst storagePluginType = \"api-file-manager-storage\";\n\nexport interface FileStorageUploadParams {\n buffer: Buffer;\n hideInFileManager: boolean | string;\n tags?: string[];\n size: number;\n name: string;\n keyPrefix: string;\n type: string;\n}\nexport interface FileStorageDeleteParams {\n id: string;\n key: string;\n}\n\nexport interface FileStorageUploadMultipleParams {\n files: FileStorageUploadParams[];\n}\n\nexport interface FileStorageParams {\n context: FileManagerContext;\n}\nexport class FileStorage {\n private readonly storagePlugin: FilePhysicalStoragePlugin;\n private readonly context: FileManagerContext;\n\n constructor({ context }: FileStorageParams) {\n const storagePlugin = context.plugins\n .byType<FilePhysicalStoragePlugin>(storagePluginType)\n .pop();\n if (!storagePlugin) {\n throw new WebinyError(\n `Missing plugin of type \"${storagePluginType}\".`,\n \"STORAGE_PLUGIN_ERROR\"\n );\n }\n this.storagePlugin = storagePlugin;\n this.context = context;\n }\n\n async upload(params: FileStorageUploadParams): Promise<Result> {\n const settings = await this.context.fileManager.settings.getSettings();\n if (!settings) {\n throw new WebinyError(\"Missing File Manager Settings.\", \"FILE_MANAGER_ERROR\");\n }\n // Add file to cloud storage.\n const { file: fileData } = await this.storagePlugin.upload({\n ...params,\n settings\n });\n\n const { fileManager } = this.context;\n\n // Save file in DB.\n return await fileManager.files.createFile({\n ...(fileData as any),\n meta: {\n private: Boolean(params.hideInFileManager)\n },\n tags: Array.isArray(params.tags) ? params.tags : []\n });\n }\n\n async uploadFiles(params: FileStorageUploadMultipleParams) {\n const settings = await this.context.fileManager.settings.getSettings();\n if (!settings) {\n throw new WebinyError(\"Missing File Manager Settings.\", \"FILE_MANAGER_ERROR\");\n }\n // Upload files to cloud storage.\n const promises = [];\n for (const item of params.files) {\n promises.push(\n this.storagePlugin.upload({\n ...item,\n settings\n })\n );\n }\n // Wait for all to resolve.\n const uploadFileResponses = await Promise.all(promises);\n\n const filesData = uploadFileResponses.map(response => response.file);\n\n const { fileManager } = this.context;\n // Save files in DB.\n return fileManager.files.createFilesInBatch(filesData);\n }\n\n async delete(params: FileStorageDeleteParams) {\n const { id, key } = params;\n const { fileManager } = this.context;\n // Delete file from cloud storage.\n await this.storagePlugin.delete({\n key\n });\n // Delete file from the DB.\n return await fileManager.files.deleteFile(id);\n }\n}\n"],"mappings":";;;;;;;;;;;;;AACA;;AAKA,MAAMA,i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