@webiny/api-file-manager 0.0.0-ee-vpcs.549378cf03
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +17 -0
- package/handlers/download/index.d.ts +3 -0
- package/handlers/download/index.js +132 -0
- package/handlers/download/index.js.map +1 -0
- package/handlers/manage/index.d.ts +5 -0
- package/handlers/manage/index.js +71 -0
- package/handlers/manage/index.js.map +1 -0
- package/handlers/transform/index.d.ts +2 -0
- package/handlers/transform/index.js +91 -0
- package/handlers/transform/index.js.map +1 -0
- package/handlers/transform/loaders/imageLoader.d.ts +30 -0
- package/handlers/transform/loaders/imageLoader.js +105 -0
- package/handlers/transform/loaders/imageLoader.js.map +1 -0
- package/handlers/transform/loaders/index.d.ts +8 -0
- package/handlers/transform/loaders/index.js +13 -0
- package/handlers/transform/loaders/index.js.map +1 -0
- package/handlers/transform/loaders/sanitizeImageTransformations.d.ts +11 -0
- package/handlers/transform/loaders/sanitizeImageTransformations.js +58 -0
- package/handlers/transform/loaders/sanitizeImageTransformations.js.map +1 -0
- package/handlers/transform/managers/imageManager.d.ts +15 -0
- package/handlers/transform/managers/imageManager.js +63 -0
- package/handlers/transform/managers/imageManager.js.map +1 -0
- package/handlers/transform/managers/index.d.ts +5 -0
- package/handlers/transform/managers/index.js +13 -0
- package/handlers/transform/managers/index.js.map +1 -0
- package/handlers/transform/optimizeImage.d.ts +3 -0
- package/handlers/transform/optimizeImage.js +48 -0
- package/handlers/transform/optimizeImage.js.map +1 -0
- package/handlers/transform/transformImage.d.ts +10 -0
- package/handlers/transform/transformImage.js +30 -0
- package/handlers/transform/transformImage.js.map +1 -0
- package/handlers/transform/utils.d.ts +12 -0
- package/handlers/transform/utils.js +46 -0
- package/handlers/transform/utils.js.map +1 -0
- package/handlers/types.d.ts +8 -0
- package/handlers/types.js +5 -0
- package/handlers/types.js.map +1 -0
- package/handlers/utils/getEnvironment.d.ts +5 -0
- package/handlers/utils/getEnvironment.js +13 -0
- package/handlers/utils/getEnvironment.js.map +1 -0
- package/handlers/utils/getObjectParams.d.ts +9 -0
- package/handlers/utils/getObjectParams.js +25 -0
- package/handlers/utils/getObjectParams.js.map +1 -0
- package/handlers/utils/index.d.ts +2 -0
- package/handlers/utils/index.js +23 -0
- package/handlers/utils/index.js.map +1 -0
- package/package.json +76 -0
- package/plugins/crud/files/validation.d.ts +3 -0
- package/plugins/crud/files/validation.js +41 -0
- package/plugins/crud/files/validation.js.map +1 -0
- package/plugins/crud/files.crud.d.ts +4 -0
- package/plugins/crud/files.crud.js +431 -0
- package/plugins/crud/files.crud.js.map +1 -0
- package/plugins/crud/settings.crud.d.ts +5 -0
- package/plugins/crud/settings.crud.js +116 -0
- package/plugins/crud/settings.crud.js.map +1 -0
- package/plugins/crud/system.crud.d.ts +4 -0
- package/plugins/crud/system.crud.js +153 -0
- package/plugins/crud/system.crud.js.map +1 -0
- package/plugins/crud/utils/checkBasePermissions.d.ts +5 -0
- package/plugins/crud/utils/checkBasePermissions.js +33 -0
- package/plugins/crud/utils/checkBasePermissions.js.map +1 -0
- package/plugins/crud/utils/createFileModel.d.ts +5 -0
- package/plugins/crud/utils/createFileModel.js +77 -0
- package/plugins/crud/utils/createFileModel.js.map +1 -0
- package/plugins/crud/utils/lifecycleEvents.d.ts +6 -0
- package/plugins/crud/utils/lifecycleEvents.js +38 -0
- package/plugins/crud/utils/lifecycleEvents.js.map +1 -0
- package/plugins/definitions/FilePhysicalStoragePlugin.d.ts +21 -0
- package/plugins/definitions/FilePhysicalStoragePlugin.js +42 -0
- package/plugins/definitions/FilePhysicalStoragePlugin.js.map +1 -0
- package/plugins/definitions/FilePlugin.d.ts +136 -0
- package/plugins/definitions/FilePlugin.js +70 -0
- package/plugins/definitions/FilePlugin.js.map +1 -0
- package/plugins/definitions/FileStorageTransformPlugin.d.ts +34 -0
- package/plugins/definitions/FileStorageTransformPlugin.js +51 -0
- package/plugins/definitions/FileStorageTransformPlugin.js.map +1 -0
- package/plugins/definitions/FilesStorageOperationsProviderPlugin.d.ts +9 -0
- package/plugins/definitions/FilesStorageOperationsProviderPlugin.js +17 -0
- package/plugins/definitions/FilesStorageOperationsProviderPlugin.js.map +1 -0
- package/plugins/definitions/InstallationPlugin.d.ts +19 -0
- package/plugins/definitions/InstallationPlugin.js +42 -0
- package/plugins/definitions/InstallationPlugin.js.map +1 -0
- package/plugins/definitions/SettingsStorageOperationsProviderPlugin.d.ts +9 -0
- package/plugins/definitions/SettingsStorageOperationsProviderPlugin.js +17 -0
- package/plugins/definitions/SettingsStorageOperationsProviderPlugin.js.map +1 -0
- package/plugins/definitions/SystemStorageOperationsProviderPlugin.d.ts +9 -0
- package/plugins/definitions/SystemStorageOperationsProviderPlugin.js +17 -0
- package/plugins/definitions/SystemStorageOperationsProviderPlugin.js.map +1 -0
- package/plugins/graphql.d.ts +4 -0
- package/plugins/graphql.js +290 -0
- package/plugins/graphql.js.map +1 -0
- package/plugins/index.d.ts +2 -0
- package/plugins/index.js +24 -0
- package/plugins/index.js.map +1 -0
- package/plugins/storage/FileStorage.d.ts +30 -0
- package/plugins/storage/FileStorage.js +103 -0
- package/plugins/storage/FileStorage.js.map +1 -0
- package/plugins/storage/index.d.ts +4 -0
- package/plugins/storage/index.js +26 -0
- package/plugins/storage/index.js.map +1 -0
- package/types.d.ts +361 -0
- package/types.js +5 -0
- package/types.js.map +1 -0
- package/utils.d.ts +4 -0
- package/utils.js +16 -0
- package/utils.js.map +1 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
+
|
|
12
|
+
var _apiSecurity = require("@webiny/api-security");
|
|
13
|
+
|
|
14
|
+
var _apiUpgrade = require("@webiny/api-upgrade");
|
|
15
|
+
|
|
16
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
17
|
+
|
|
18
|
+
var _api = require("@webiny/api");
|
|
19
|
+
|
|
20
|
+
var _utils = require("../../utils");
|
|
21
|
+
|
|
22
|
+
var _InstallationPlugin = require("../definitions/InstallationPlugin");
|
|
23
|
+
|
|
24
|
+
var _SystemStorageOperationsProviderPlugin = require("../definitions/SystemStorageOperationsProviderPlugin");
|
|
25
|
+
|
|
26
|
+
const systemCrudContextPlugin = new _api.ContextPlugin(async context => {
|
|
27
|
+
const pluginType = _SystemStorageOperationsProviderPlugin.SystemStorageOperationsProviderPlugin.type;
|
|
28
|
+
const providerPlugin = context.plugins.byType(pluginType).find(() => true);
|
|
29
|
+
|
|
30
|
+
if (!providerPlugin) {
|
|
31
|
+
throw new _error.default(`Missing "${pluginType}" plugin.`, "PLUGIN_NOT_FOUND", {
|
|
32
|
+
type: pluginType
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const storageOperations = await providerPlugin.provide({
|
|
37
|
+
context
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
if (!context.fileManager) {
|
|
41
|
+
context.fileManager = {};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const getTenantId = () => {
|
|
45
|
+
return context.tenancy.getCurrentTenant().id;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
context.fileManager.system = {
|
|
49
|
+
async getVersion() {
|
|
50
|
+
const system = await storageOperations.get();
|
|
51
|
+
return system ? system.version : null;
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
async setVersion(version) {
|
|
55
|
+
const system = await storageOperations.get();
|
|
56
|
+
|
|
57
|
+
if (system) {
|
|
58
|
+
const data = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, system), {}, {
|
|
59
|
+
tenant: system.tenant || getTenantId(),
|
|
60
|
+
version
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
try {
|
|
64
|
+
await storageOperations.update({
|
|
65
|
+
original: system,
|
|
66
|
+
data
|
|
67
|
+
});
|
|
68
|
+
return;
|
|
69
|
+
} catch (ex) {
|
|
70
|
+
throw new _error.default("Could not update the system data.", "SYSTEM_UPDATE_ERROR", {
|
|
71
|
+
data
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const data = {
|
|
77
|
+
version,
|
|
78
|
+
tenant: getTenantId()
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
try {
|
|
82
|
+
await storageOperations.create({
|
|
83
|
+
data
|
|
84
|
+
});
|
|
85
|
+
return;
|
|
86
|
+
} catch (ex) {
|
|
87
|
+
throw new _error.default("Could not create the system data.", "SYSTEM_CREATE_ERROR", {
|
|
88
|
+
data
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
|
|
93
|
+
async install({
|
|
94
|
+
srcPrefix
|
|
95
|
+
}) {
|
|
96
|
+
const identity = context.security.getIdentity();
|
|
97
|
+
|
|
98
|
+
if (!identity) {
|
|
99
|
+
throw new _apiSecurity.NotAuthorizedError();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const {
|
|
103
|
+
fileManager
|
|
104
|
+
} = context;
|
|
105
|
+
const version = await fileManager.system.getVersion();
|
|
106
|
+
|
|
107
|
+
if (version) {
|
|
108
|
+
throw new _error.default("File Manager is already installed.", "FILES_INSTALL_ABORTED");
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const data = {};
|
|
112
|
+
|
|
113
|
+
if (srcPrefix) {
|
|
114
|
+
data.srcPrefix = srcPrefix;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const installationPlugins = context.plugins.byType(_InstallationPlugin.InstallationPlugin.type);
|
|
118
|
+
await (0, _utils.executeCallbacks)(installationPlugins, "beforeInstall", {
|
|
119
|
+
context
|
|
120
|
+
});
|
|
121
|
+
await fileManager.settings.createSettings(data);
|
|
122
|
+
await fileManager.system.setVersion(context.WEBINY_VERSION);
|
|
123
|
+
await (0, _utils.executeCallbacks)(installationPlugins, "afterInstall", {
|
|
124
|
+
context
|
|
125
|
+
});
|
|
126
|
+
return true;
|
|
127
|
+
},
|
|
128
|
+
|
|
129
|
+
async upgrade(version) {
|
|
130
|
+
const identity = context.security.getIdentity();
|
|
131
|
+
|
|
132
|
+
if (!identity) {
|
|
133
|
+
throw new _apiSecurity.NotAuthorizedError();
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const upgradePlugins = context.plugins.byType("api-upgrade").filter(pl => pl.app === "file-manager");
|
|
137
|
+
const plugin = (0, _apiUpgrade.getApplicablePlugin)({
|
|
138
|
+
deployedVersion: context.WEBINY_VERSION,
|
|
139
|
+
installedAppVersion: await this.getVersion(),
|
|
140
|
+
upgradePlugins,
|
|
141
|
+
upgradeToVersion: version
|
|
142
|
+
});
|
|
143
|
+
await plugin.apply(context); // Store new app version
|
|
144
|
+
|
|
145
|
+
await context.fileManager.system.setVersion(version);
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
};
|
|
150
|
+
});
|
|
151
|
+
systemCrudContextPlugin.name = "FileManagerSystemCrud";
|
|
152
|
+
var _default = systemCrudContextPlugin;
|
|
153
|
+
exports.default = _default;
|
|
@@ -0,0 +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;;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,EAElBM,IAFkB,CAEb,MAAM,IAFO,CAAvB;;EAIA,IAAI,CAACH,cAAL,EAAqB;IACjB,MAAM,IAAII,cAAJ,CAAiB,YAAWP,UAAW,WAAvC,EAAmD,kBAAnD,EAAuE;MACzEE,IAAI,EAAEF;IADmE,CAAvE,CAAN;EAGH;;EAED,MAAMQ,iBAAiB,GAAG,MAAML,cAAc,CAACM,OAAf,CAAuB;IACnDV;EADmD,CAAvB,CAAhC;;EAIA,IAAI,CAACA,OAAO,CAACW,WAAb,EAA0B;IACtBX,OAAO,CAACW,WAAR,GAAsB,EAAtB;EACH;;EAED,MAAMC,WAAW,GAAG,MAAc;IAC9B,OAAOZ,OAAO,CAACa,OAAR,CAAgBC,gBAAhB,GAAmCC,EAA1C;EACH,CAFD;;EAIAf,OAAO,CAACW,WAAR,CAAoBK,MAApB,GAA6B;IACzB,MAAMC,UAAN,GAAmB;MACf,MAAMD,MAAM,GAAG,MAAMP,iBAAiB,CAACS,GAAlB,EAArB;MAEA,OAAOF,MAAM,GAAGA,MAAM,CAACG,OAAV,GAAoB,IAAjC;IACH,CALwB;;IAMzB,MAAMC,UAAN,CAAiBD,OAAjB,EAAkC;MAC9B,MAAMH,MAAM,GAAG,MAAMP,iBAAiB,CAACS,GAAlB,EAArB;;MAEA,IAAIF,MAAJ,EAAY;QACR,MAAMK,IAAuB,+DACtBL,MADsB;UAEzBM,MAAM,EAAEN,MAAM,CAACM,MAAP,IAAiBV,WAAW,EAFX;UAGzBO;QAHyB,EAA7B;;QAKA,IAAI;UACA,MAAMV,iBAAiB,CAACc,MAAlB,CAAyB;YAC3BC,QAAQ,EAAER,MADiB;YAE3BK;UAF2B,CAAzB,CAAN;UAIA;QACH,CAND,CAME,OAAOI,EAAP,EAAW;UACT,MAAM,IAAIjB,cAAJ,CACF,mCADE,EAEF,qBAFE,EAGF;YACIa;UADJ,CAHE,CAAN;QAOH;MACJ;;MAED,MAAMA,IAAuB,GAAG;QAC5BF,OAD4B;QAE5BG,MAAM,EAAEV,WAAW;MAFS,CAAhC;;MAIA,IAAI;QACA,MAAMH,iBAAiB,CAACiB,MAAlB,CAAyB;UAC3BL;QAD2B,CAAzB,CAAN;QAGA;MACH,CALD,CAKE,OAAOI,EAAP,EAAW;QACT,MAAM,IAAIjB,cAAJ,CAAgB,mCAAhB,EAAqD,qBAArD,EAA4E;UAC9Ea;QAD8E,CAA5E,CAAN;MAGH;IACJ,CA9CwB;;IA+CzB,MAAMM,OAAN,CAAc;MAAEC;IAAF,CAAd,EAA6B;MACzB,MAAMC,QAAQ,GAAG7B,OAAO,CAAC8B,QAAR,CAAiBC,WAAjB,EAAjB;;MACA,IAAI,CAACF,QAAL,EAAe;QACX,MAAM,IAAIG,+BAAJ,EAAN;MACH;;MACD,MAAM;QAAErB;MAAF,IAAkBX,OAAxB;MACA,MAAMmB,OAAO,GAAG,MAAMR,WAAW,CAACK,MAAZ,CAAmBC,UAAnB,EAAtB;;MAEA,IAAIE,OAAJ,EAAa;QACT,MAAM,IAAIX,cAAJ,CACF,oCADE,EAEF,uBAFE,CAAN;MAIH;;MAED,MAAMa,IAAkC,GAAG,EAA3C;;MAEA,IAAIO,SAAJ,EAAe;QACXP,IAAI,CAACO,SAAL,GAAiBA,SAAjB;MACH;;MAED,MAAMK,mBAAmB,GAAGjC,OAAO,CAACK,OAAR,CAAgBC,MAAhB,CACxB4B,sCAAA,CAAmB/B,IADK,CAA5B;MAIA,MAAM,IAAAgC,uBAAA,EACFF,mBADE,EAEF,eAFE,EAGF;QACIjC;MADJ,CAHE,CAAN;MAQA,MAAMW,WAAW,CAACyB,QAAZ,CAAqBC,cAArB,CAAoChB,IAApC,CAAN;MAEA,MAAMV,WAAW,CAACK,MAAZ,CAAmBI,UAAnB,CAA8BpB,OAAO,CAACsC,cAAtC,CAAN;MAEA,MAAM,IAAAH,uBAAA,EACFF,mBADE,EAEF,cAFE,EAGF;QACIjC;MADJ,CAHE,CAAN;MAQA,OAAO,IAAP;IACH,CA7FwB;;IA8FzB,MAAMuC,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"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _apiSecurity = require("@webiny/api-security");
|
|
9
|
+
|
|
10
|
+
var _default = async (context, check = {}) => {
|
|
11
|
+
await context.i18n.checkI18NContentPermission();
|
|
12
|
+
const filePermission = await context.security.getPermission("fm.file");
|
|
13
|
+
|
|
14
|
+
if (!filePermission) {
|
|
15
|
+
throw new _apiSecurity.NotAuthorizedError();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (check.rwd && !hasRwd(filePermission, check.rwd)) {
|
|
19
|
+
throw new _apiSecurity.NotAuthorizedError();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return filePermission;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
exports.default = _default;
|
|
26
|
+
|
|
27
|
+
const hasRwd = (filesFilePermission, rwd) => {
|
|
28
|
+
if (typeof filesFilePermission.rwd !== "string") {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return filesFilePermission.rwd.includes(rwd);
|
|
33
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["context","check","i18n","checkI18NContentPermission","filePermission","security","getPermission","NotAuthorizedError","rwd","hasRwd","filesFilePermission","includes"],"sources":["checkBasePermissions.ts"],"sourcesContent":["import { FileManagerContext, FilePermission } from \"~/types\";\nimport { NotAuthorizedError } from \"@webiny/api-security\";\n\nexport default async (\n context: FileManagerContext,\n check: { rwd?: string } = {}\n): Promise<FilePermission> => {\n await context.i18n.checkI18NContentPermission();\n const filePermission = await context.security.getPermission<FilePermission>(\"fm.file\");\n if (!filePermission) {\n throw new NotAuthorizedError();\n }\n if (check.rwd && !hasRwd(filePermission, check.rwd)) {\n throw new NotAuthorizedError();\n }\n\n return filePermission;\n};\n\nconst hasRwd = (filesFilePermission: FilePermission, rwd: string): boolean => {\n if (typeof filesFilePermission.rwd !== \"string\") {\n return true;\n }\n\n return filesFilePermission.rwd.includes(rwd);\n};\n"],"mappings":";;;;;;;AACA;;eAEe,OACXA,OADW,EAEXC,KAAuB,GAAG,EAFf,KAGe;EAC1B,MAAMD,OAAO,CAACE,IAAR,CAAaC,0BAAb,EAAN;EACA,MAAMC,cAAc,GAAG,MAAMJ,OAAO,CAACK,QAAR,CAAiBC,aAAjB,CAA+C,SAA/C,CAA7B;;EACA,IAAI,CAACF,cAAL,EAAqB;IACjB,MAAM,IAAIG,+BAAJ,EAAN;EACH;;EACD,IAAIN,KAAK,CAACO,GAAN,IAAa,CAACC,MAAM,CAACL,cAAD,EAAiBH,KAAK,CAACO,GAAvB,CAAxB,EAAqD;IACjD,MAAM,IAAID,+BAAJ,EAAN;EACH;;EAED,OAAOH,cAAP;AACH,C;;;;AAED,MAAMK,MAAM,GAAG,CAACC,mBAAD,EAAsCF,GAAtC,KAA+D;EAC1E,IAAI,OAAOE,mBAAmB,CAACF,GAA3B,KAAmC,QAAvC,EAAiD;IAC7C,OAAO,IAAP;EACH;;EAED,OAAOE,mBAAmB,CAACF,GAApB,CAAwBG,QAAxB,CAAiCH,GAAjC,CAAP;AACH,CAND"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _fields = require("@commodo/fields");
|
|
9
|
+
|
|
10
|
+
var _commodoFieldsObject = require("commodo-fields-object");
|
|
11
|
+
|
|
12
|
+
var _validation = require("@webiny/validation");
|
|
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
|
+
*/
|
|
27
|
+
var _default = (create = true) => {
|
|
28
|
+
return (0, _fields.withFields)({
|
|
29
|
+
key: (0, _fields.string)({
|
|
30
|
+
validation: _validation.validation.create(`${create ? "required," : ""}maxLength:1000`)
|
|
31
|
+
}),
|
|
32
|
+
name: (0, _fields.string)({
|
|
33
|
+
validation: _validation.validation.create("maxLength:1000")
|
|
34
|
+
}),
|
|
35
|
+
size: (0, _fields.number)(),
|
|
36
|
+
type: (0, _fields.string)({
|
|
37
|
+
validation: _validation.validation.create("maxLength:255")
|
|
38
|
+
}),
|
|
39
|
+
meta: (0, _commodoFieldsObject.object)({
|
|
40
|
+
value: {
|
|
41
|
+
private: false
|
|
42
|
+
}
|
|
43
|
+
}),
|
|
44
|
+
tags: (0, _fields.onSet)(value => {
|
|
45
|
+
if (!Array.isArray(value)) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return value.map(item => item.toLowerCase());
|
|
50
|
+
})((0, _fields.string)({
|
|
51
|
+
list: true,
|
|
52
|
+
validation: tags => {
|
|
53
|
+
if (!Array.isArray(tags)) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (tags.length > 15) {
|
|
58
|
+
throw Error("You cannot set more than 15 tags.");
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
for (let i = 0; i < tags.length; i++) {
|
|
62
|
+
const tag = tags[i];
|
|
63
|
+
|
|
64
|
+
if (typeof tag !== "string") {
|
|
65
|
+
throw Error("Tag must be typeof string.");
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (tag.length > 50) {
|
|
69
|
+
throw Error(`Tag ${tag} is more than 50 characters long.`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}))
|
|
74
|
+
})();
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
exports.default = _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["create","withFields","key","string","validation","name","size","number","type","meta","object","value","private","tags","onSet","Array","isArray","map","item","toLowerCase","list","length","Error","i","tag"],"sources":["createFileModel.ts"],"sourcesContent":["/**\n * Package @commodo/fields does not have types\n */\n// @ts-ignore\nimport { withFields, string, number, onSet } from \"@commodo/fields\";\n/**\n * Package commodo-fields-object does not have types\n */\n// @ts-ignore\nimport { object } from \"commodo-fields-object\";\nimport { validation } from \"@webiny/validation\";\n\n/**\n * TODO @ts-refactor change for JOI or some other validation library\n */\nexport default (create = true) => {\n return withFields({\n key: string({\n validation: validation.create(`${create ? \"required,\" : \"\"}maxLength:1000`)\n }),\n name: string({ validation: validation.create(\"maxLength:1000\") }),\n size: number(),\n type: string({ validation: validation.create(\"maxLength:255\") }),\n meta: object({ value: { private: false } }),\n tags: onSet((value: string[]) => {\n if (!Array.isArray(value)) {\n return null;\n }\n\n return value.map(item => item.toLowerCase());\n })(\n string({\n list: true,\n validation: (tags: string[]) => {\n if (!Array.isArray(tags)) {\n return;\n }\n\n if (tags.length > 15) {\n throw Error(\"You cannot set more than 15 tags.\");\n }\n\n for (let i = 0; i < tags.length; i++) {\n const tag = tags[i];\n if (typeof tag !== \"string\") {\n throw Error(\"Tag must be typeof string.\");\n }\n\n if (tag.length > 50) {\n throw Error(`Tag ${tag} is more than 50 characters long.`);\n }\n }\n }\n })\n )\n })();\n};\n"],"mappings":";;;;;;;AAIA;;AAKA;;AACA;;AAVA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAIA;AACA;AACA;eACe,CAACA,MAAM,GAAG,IAAV,KAAmB;EAC9B,OAAO,IAAAC,kBAAA,EAAW;IACdC,GAAG,EAAE,IAAAC,cAAA,EAAO;MACRC,UAAU,EAAEA,sBAAA,CAAWJ,MAAX,CAAmB,GAAEA,MAAM,GAAG,WAAH,GAAiB,EAAG,gBAA/C;IADJ,CAAP,CADS;IAIdK,IAAI,EAAE,IAAAF,cAAA,EAAO;MAAEC,UAAU,EAAEA,sBAAA,CAAWJ,MAAX,CAAkB,gBAAlB;IAAd,CAAP,CAJQ;IAKdM,IAAI,EAAE,IAAAC,cAAA,GALQ;IAMdC,IAAI,EAAE,IAAAL,cAAA,EAAO;MAAEC,UAAU,EAAEA,sBAAA,CAAWJ,MAAX,CAAkB,eAAlB;IAAd,CAAP,CANQ;IAOdS,IAAI,EAAE,IAAAC,2BAAA,EAAO;MAAEC,KAAK,EAAE;QAAEC,OAAO,EAAE;MAAX;IAAT,CAAP,CAPQ;IAQdC,IAAI,EAAE,IAAAC,aAAA,EAAOH,KAAD,IAAqB;MAC7B,IAAI,CAACI,KAAK,CAACC,OAAN,CAAcL,KAAd,CAAL,EAA2B;QACvB,OAAO,IAAP;MACH;;MAED,OAAOA,KAAK,CAACM,GAAN,CAAUC,IAAI,IAAIA,IAAI,CAACC,WAAL,EAAlB,CAAP;IACH,CANK,EAOF,IAAAhB,cAAA,EAAO;MACHiB,IAAI,EAAE,IADH;MAEHhB,UAAU,EAAGS,IAAD,IAAoB;QAC5B,IAAI,CAACE,KAAK,CAACC,OAAN,CAAcH,IAAd,CAAL,EAA0B;UACtB;QACH;;QAED,IAAIA,IAAI,CAACQ,MAAL,GAAc,EAAlB,EAAsB;UAClB,MAAMC,KAAK,CAAC,mCAAD,CAAX;QACH;;QAED,KAAK,IAAIC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGV,IAAI,CAACQ,MAAzB,EAAiCE,CAAC,EAAlC,EAAsC;UAClC,MAAMC,GAAG,GAAGX,IAAI,CAACU,CAAD,CAAhB;;UACA,IAAI,OAAOC,GAAP,KAAe,QAAnB,EAA6B;YACzB,MAAMF,KAAK,CAAC,4BAAD,CAAX;UACH;;UAED,IAAIE,GAAG,CAACH,MAAJ,GAAa,EAAjB,EAAqB;YACjB,MAAMC,KAAK,CAAE,OAAME,GAAI,mCAAZ,CAAX;UACH;QACJ;MACJ;IArBE,CAAP,CAPE;EARQ,CAAX,GAAP;AAwCH,C"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { FilePlugin, FilePluginParams } from "../../definitions/FilePlugin";
|
|
2
|
+
import { FileManagerContext } from "../../../types";
|
|
3
|
+
export declare const runLifecycleEvent: (hook: keyof FilePluginParams, params: {
|
|
4
|
+
context: FileManagerContext;
|
|
5
|
+
plugins: FilePlugin[];
|
|
6
|
+
} & Record<string, any>) => Promise<void>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.runLifecycleEvent = void 0;
|
|
9
|
+
|
|
10
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
11
|
+
|
|
12
|
+
const _excluded = ["plugins"];
|
|
13
|
+
|
|
14
|
+
// TODO @ts-refactor introduce pubsub methods
|
|
15
|
+
const runLifecycleEvent = async (hook, params) => {
|
|
16
|
+
const {
|
|
17
|
+
plugins
|
|
18
|
+
} = params,
|
|
19
|
+
rest = (0, _objectWithoutProperties2.default)(params, _excluded);
|
|
20
|
+
|
|
21
|
+
if (plugins.length === 0) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
for (const plugin of plugins) {
|
|
26
|
+
if (!plugin[hook]) {
|
|
27
|
+
continue;
|
|
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
|
+
|
|
33
|
+
|
|
34
|
+
await plugin[hook](rest);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
exports.runLifecycleEvent = runLifecycleEvent;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["runLifecycleEvent","hook","params","plugins","rest","length","plugin"],"sources":["lifecycleEvents.ts"],"sourcesContent":["// TODO @ts-refactor introduce pubsub methods\nimport { FilePlugin, FilePluginParams } from \"~/plugins/definitions/FilePlugin\";\nimport { FileManagerContext } from \"~/types\";\n\nexport const runLifecycleEvent = async (\n hook: keyof FilePluginParams,\n params: { context: FileManagerContext; plugins: FilePlugin[] } & Record<string, any>\n): Promise<void> => {\n const { plugins, ...rest } = params;\n if (plugins.length === 0) {\n return;\n }\n for (const plugin of plugins) {\n if (!plugin[hook]) {\n continue;\n }\n /**\n * Keep any because we do not know which hook needs to be executed. This will be removed, so it does not matter.\n */\n await plugin[hook](rest as any);\n }\n};\n"],"mappings":";;;;;;;;;;;;;AAAA;AAIO,MAAMA,iBAAiB,GAAG,OAC7BC,IAD6B,EAE7BC,MAF6B,KAGb;EAChB,MAAM;IAAEC;EAAF,IAAuBD,MAA7B;EAAA,MAAoBE,IAApB,0CAA6BF,MAA7B;;EACA,IAAIC,OAAO,CAACE,MAAR,KAAmB,CAAvB,EAA0B;IACtB;EACH;;EACD,KAAK,MAAMC,MAAX,IAAqBH,OAArB,EAA8B;IAC1B,IAAI,CAACG,MAAM,CAACL,IAAD,CAAX,EAAmB;MACf;IACH;IACD;AACR;AACA;;;IACQ,MAAMK,MAAM,CAACL,IAAD,CAAN,CAAaG,IAAb,CAAN;EACH;AACJ,CAjBM"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Plugin } from "@webiny/plugins";
|
|
3
|
+
import { FileManagerSettings } from "../../types";
|
|
4
|
+
export interface FilePhysicalStoragePluginParams<U extends FilePhysicalStoragePluginUploadParams, D extends FilePhysicalStoragePluginDeleteParams> {
|
|
5
|
+
upload: (args: U) => Promise<any>;
|
|
6
|
+
delete: (args: D) => Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
export interface FilePhysicalStoragePluginUploadParams {
|
|
9
|
+
settings: FileManagerSettings;
|
|
10
|
+
buffer: Buffer;
|
|
11
|
+
}
|
|
12
|
+
export interface FilePhysicalStoragePluginDeleteParams {
|
|
13
|
+
key: string;
|
|
14
|
+
}
|
|
15
|
+
export declare class FilePhysicalStoragePlugin<U extends FilePhysicalStoragePluginUploadParams = FilePhysicalStoragePluginUploadParams, D extends FilePhysicalStoragePluginDeleteParams = FilePhysicalStoragePluginDeleteParams> extends Plugin {
|
|
16
|
+
static readonly type: string;
|
|
17
|
+
private readonly _params;
|
|
18
|
+
constructor(params: FilePhysicalStoragePluginParams<U, D>);
|
|
19
|
+
upload(params: U): Promise<any>;
|
|
20
|
+
delete(params: D): Promise<any>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.FilePhysicalStoragePlugin = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _plugins = require("@webiny/plugins");
|
|
13
|
+
|
|
14
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
15
|
+
|
|
16
|
+
class FilePhysicalStoragePlugin extends _plugins.Plugin {
|
|
17
|
+
constructor(params) {
|
|
18
|
+
super();
|
|
19
|
+
(0, _defineProperty2.default)(this, "_params", void 0);
|
|
20
|
+
this._params = params;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async upload(params) {
|
|
24
|
+
if (!this._params.upload) {
|
|
25
|
+
throw new _error.default(`You must define the "upload" method of this plugin.`, "UPLOAD_METHOD_ERROR");
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return this._params.upload(params);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async delete(params) {
|
|
32
|
+
if (!this._params.delete) {
|
|
33
|
+
throw new _error.default(`You must define the "delete" method of this plugin.`, "DELETE_METHOD_ERROR");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return this._params.delete(params);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
exports.FilePhysicalStoragePlugin = FilePhysicalStoragePlugin;
|
|
42
|
+
(0, _defineProperty2.default)(FilePhysicalStoragePlugin, "type", "api-file-manager-storage");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["FilePhysicalStoragePlugin","Plugin","constructor","params","_params","upload","WebinyError","delete"],"sources":["FilePhysicalStoragePlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport WebinyError from \"@webiny/error\";\nimport { FileManagerSettings } from \"~/types\";\n\nexport interface FilePhysicalStoragePluginParams<\n U extends FilePhysicalStoragePluginUploadParams,\n D extends FilePhysicalStoragePluginDeleteParams\n> {\n upload: (args: U) => Promise<any>;\n delete: (args: D) => Promise<void>;\n}\n\nexport interface FilePhysicalStoragePluginUploadParams {\n settings: FileManagerSettings;\n buffer: Buffer;\n}\n\nexport interface FilePhysicalStoragePluginDeleteParams {\n key: string;\n}\n\nexport class FilePhysicalStoragePlugin<\n U extends FilePhysicalStoragePluginUploadParams = FilePhysicalStoragePluginUploadParams,\n D extends FilePhysicalStoragePluginDeleteParams = FilePhysicalStoragePluginDeleteParams\n> extends Plugin {\n public static override readonly type: string = \"api-file-manager-storage\";\n private readonly _params: FilePhysicalStoragePluginParams<U, D>;\n\n public constructor(params: FilePhysicalStoragePluginParams<U, D>) {\n super();\n this._params = params;\n }\n\n public async upload(params: U): Promise<any> {\n if (!this._params.upload) {\n throw new WebinyError(\n `You must define the \"upload\" method of this plugin.`,\n \"UPLOAD_METHOD_ERROR\"\n );\n }\n return this._params.upload(params);\n }\n\n public async delete(params: D): Promise<any> {\n if (!this._params.delete) {\n throw new WebinyError(\n `You must define the \"delete\" method of this plugin.`,\n \"DELETE_METHOD_ERROR\"\n );\n }\n return this._params.delete(params);\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AAoBO,MAAMA,yBAAN,SAGGC,eAHH,CAGU;EAINC,WAAW,CAACC,MAAD,EAAgD;IAC9D;IAD8D;IAE9D,KAAKC,OAAL,GAAeD,MAAf;EACH;;EAEkB,MAANE,MAAM,CAACF,MAAD,EAA0B;IACzC,IAAI,CAAC,KAAKC,OAAL,CAAaC,MAAlB,EAA0B;MACtB,MAAM,IAAIC,cAAJ,CACD,qDADC,EAEF,qBAFE,CAAN;IAIH;;IACD,OAAO,KAAKF,OAAL,CAAaC,MAAb,CAAoBF,MAApB,CAAP;EACH;;EAEkB,MAANI,MAAM,CAACJ,MAAD,EAA0B;IACzC,IAAI,CAAC,KAAKC,OAAL,CAAaG,MAAlB,EAA0B;MACtB,MAAM,IAAID,cAAJ,CACD,qDADC,EAEF,qBAFE,CAAN;IAIH;;IACD,OAAO,KAAKF,OAAL,CAAaG,MAAb,CAAoBJ,MAApB,CAAP;EACH;;AA3BY;;;8BAHJH,yB,UAIsC,0B"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { Plugin } from "@webiny/plugins";
|
|
2
|
+
import { File, FileManagerContext } from "../../types";
|
|
3
|
+
/**
|
|
4
|
+
* Parameters for beforeCreate lifecycle.
|
|
5
|
+
*/
|
|
6
|
+
export interface BeforeCreateParams {
|
|
7
|
+
context: FileManagerContext;
|
|
8
|
+
/**
|
|
9
|
+
* Data to be inserted into the storage.
|
|
10
|
+
*/
|
|
11
|
+
data: File;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Parameters for afterCreate lifecycle.
|
|
15
|
+
*/
|
|
16
|
+
export interface AfterCreateParams {
|
|
17
|
+
context: FileManagerContext;
|
|
18
|
+
/**
|
|
19
|
+
* Data that was inserted into the storage.
|
|
20
|
+
*/
|
|
21
|
+
data: File;
|
|
22
|
+
/**
|
|
23
|
+
* Result of the storage operations create method.
|
|
24
|
+
* Possibly changed something on the "data".
|
|
25
|
+
*/
|
|
26
|
+
file: File;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Parameters for beforeUpdate lifecycle.
|
|
30
|
+
*/
|
|
31
|
+
export interface BeforeUpdateParams {
|
|
32
|
+
context: FileManagerContext;
|
|
33
|
+
/**
|
|
34
|
+
* Original file from the storage.
|
|
35
|
+
*/
|
|
36
|
+
original: File;
|
|
37
|
+
/**
|
|
38
|
+
* Data to be updated to the storage.
|
|
39
|
+
*/
|
|
40
|
+
data: File;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Parameters for afterUpdate lifecycle.
|
|
44
|
+
*/
|
|
45
|
+
export interface AfterUpdateParams {
|
|
46
|
+
context: FileManagerContext;
|
|
47
|
+
/**
|
|
48
|
+
* Original file from the storage.
|
|
49
|
+
*/
|
|
50
|
+
original: File;
|
|
51
|
+
/**
|
|
52
|
+
* Data that was updated in the storage.
|
|
53
|
+
*/
|
|
54
|
+
data: File;
|
|
55
|
+
/**
|
|
56
|
+
* Result of the storage operations update method.
|
|
57
|
+
* Possibly changed something on the "data".
|
|
58
|
+
*/
|
|
59
|
+
file: File;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Parameters for beforeBatchCreate lifecycle.
|
|
63
|
+
*/
|
|
64
|
+
export interface BeforeBatchCreateParams {
|
|
65
|
+
context: FileManagerContext;
|
|
66
|
+
/**
|
|
67
|
+
* Files to be inserted into the storage.
|
|
68
|
+
*/
|
|
69
|
+
data: File[];
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Parameters for afterBatchCreate lifecycle.
|
|
73
|
+
*/
|
|
74
|
+
export interface AfterBatchCreateParams {
|
|
75
|
+
context: FileManagerContext;
|
|
76
|
+
/**
|
|
77
|
+
* Files that were inserted into the storage.
|
|
78
|
+
*/
|
|
79
|
+
data: File[];
|
|
80
|
+
/**
|
|
81
|
+
* Results of the insert.
|
|
82
|
+
*/
|
|
83
|
+
files: File[];
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Parameters for beforeDelete lifecycle.
|
|
87
|
+
*/
|
|
88
|
+
export interface BeforeDeleteParams {
|
|
89
|
+
context: FileManagerContext;
|
|
90
|
+
/**
|
|
91
|
+
* File to be deleted from the storage.
|
|
92
|
+
*/
|
|
93
|
+
file: File;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Parameters for afterDelete lifecycle.
|
|
97
|
+
*/
|
|
98
|
+
export interface AfterDeleteParams {
|
|
99
|
+
context: FileManagerContext;
|
|
100
|
+
/**
|
|
101
|
+
* File that was deleted from the storage.
|
|
102
|
+
*/
|
|
103
|
+
file: File;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Definition for the constructor parameters of the FilePlugin.
|
|
107
|
+
*
|
|
108
|
+
* @category FilePlugin
|
|
109
|
+
*/
|
|
110
|
+
export interface FilePluginParams {
|
|
111
|
+
beforeCreate?: (params: BeforeCreateParams) => Promise<void>;
|
|
112
|
+
afterCreate?: (params: AfterCreateParams) => Promise<void>;
|
|
113
|
+
beforeUpdate?: (params: BeforeUpdateParams) => Promise<void>;
|
|
114
|
+
afterUpdate?: (params: AfterUpdateParams) => Promise<void>;
|
|
115
|
+
beforeBatchCreate?: (params: BeforeBatchCreateParams) => Promise<void>;
|
|
116
|
+
afterBatchCreate?: (params: AfterBatchCreateParams) => Promise<void>;
|
|
117
|
+
beforeDelete?: (params: BeforeDeleteParams) => Promise<void>;
|
|
118
|
+
afterDelete?: (params: AfterDeleteParams) => Promise<void>;
|
|
119
|
+
}
|
|
120
|
+
export declare class FilePlugin extends Plugin {
|
|
121
|
+
static readonly type: string;
|
|
122
|
+
private readonly _params;
|
|
123
|
+
constructor(params?: FilePluginParams);
|
|
124
|
+
beforeCreate(params: BeforeCreateParams): Promise<void>;
|
|
125
|
+
afterCreate(params: AfterCreateParams): Promise<void>;
|
|
126
|
+
beforeUpdate(params: BeforeUpdateParams): Promise<void>;
|
|
127
|
+
afterUpdate(params: AfterUpdateParams): Promise<void>;
|
|
128
|
+
beforeBatchCreate(params: BeforeBatchCreateParams): Promise<void>;
|
|
129
|
+
afterBatchCreate(params: AfterBatchCreateParams): Promise<void>;
|
|
130
|
+
beforeDelete(params: BeforeDeleteParams): Promise<void>;
|
|
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
|
+
*/
|
|
135
|
+
private _execute;
|
|
136
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.FilePlugin = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _plugins = require("@webiny/plugins");
|
|
13
|
+
|
|
14
|
+
class FilePlugin extends _plugins.Plugin {
|
|
15
|
+
constructor(params) {
|
|
16
|
+
super();
|
|
17
|
+
(0, _defineProperty2.default)(this, "_params", void 0);
|
|
18
|
+
this._params = params || {};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async beforeCreate(params) {
|
|
22
|
+
await this._execute("beforeCreate", params);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async afterCreate(params) {
|
|
26
|
+
await this._execute("afterCreate", params);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async beforeUpdate(params) {
|
|
30
|
+
await this._execute("beforeUpdate", params);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async afterUpdate(params) {
|
|
34
|
+
await this._execute("afterUpdate", params);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async beforeBatchCreate(params) {
|
|
38
|
+
await this._execute("beforeBatchCreate", params);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async afterBatchCreate(params) {
|
|
42
|
+
await this._execute("afterBatchCreate", params);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async beforeDelete(params) {
|
|
46
|
+
await this._execute("beforeDelete", params);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async afterDelete(params) {
|
|
50
|
+
await this._execute("afterDelete", params);
|
|
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
|
+
|
|
56
|
+
|
|
57
|
+
async _execute(callback, params) {
|
|
58
|
+
const cb = this._params[callback];
|
|
59
|
+
|
|
60
|
+
if (typeof cb !== "function") {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
await cb(params);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
exports.FilePlugin = FilePlugin;
|
|
70
|
+
(0, _defineProperty2.default)(FilePlugin, "type", "fm.file");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["FilePlugin","Plugin","constructor","params","_params","beforeCreate","_execute","afterCreate","beforeUpdate","afterUpdate","beforeBatchCreate","afterBatchCreate","beforeDelete","afterDelete","callback","cb"],"sources":["FilePlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { File, FileManagerContext } from \"~/types\";\n\n/**\n * Parameters for beforeCreate lifecycle.\n */\nexport interface BeforeCreateParams {\n context: FileManagerContext;\n /**\n * Data to be inserted into the storage.\n */\n data: File;\n}\n/**\n * Parameters for afterCreate lifecycle.\n */\nexport interface AfterCreateParams {\n context: FileManagerContext;\n /**\n * Data that was inserted into the storage.\n */\n data: File;\n /**\n * Result of the storage operations create method.\n * Possibly changed something on the \"data\".\n */\n file: File;\n}\n/**\n * Parameters for beforeUpdate lifecycle.\n */\nexport interface BeforeUpdateParams {\n context: FileManagerContext;\n /**\n * Original file from the storage.\n */\n original: File;\n /**\n * Data to be updated to the storage.\n */\n data: File;\n}\n/**\n * Parameters for afterUpdate lifecycle.\n */\nexport interface AfterUpdateParams {\n context: FileManagerContext;\n /**\n * Original file from the storage.\n */\n original: File;\n /**\n * Data that was updated in the storage.\n */\n data: File;\n /**\n * Result of the storage operations update method.\n * Possibly changed something on the \"data\".\n */\n file: File;\n}\n/**\n * Parameters for beforeBatchCreate lifecycle.\n */\nexport interface BeforeBatchCreateParams {\n context: FileManagerContext;\n /**\n * Files to be inserted into the storage.\n */\n data: File[];\n}\n\n/**\n * Parameters for afterBatchCreate lifecycle.\n */\nexport interface AfterBatchCreateParams {\n context: FileManagerContext;\n /**\n * Files that were inserted into the storage.\n */\n data: File[];\n /**\n * Results of the insert.\n */\n files: File[];\n}\n/**\n * Parameters for beforeDelete lifecycle.\n */\nexport interface BeforeDeleteParams {\n context: FileManagerContext;\n /**\n * File to be deleted from the storage.\n */\n file: File;\n}\n/**\n * Parameters for afterDelete lifecycle.\n */\nexport interface AfterDeleteParams {\n context: FileManagerContext;\n /**\n * File that was deleted from the storage.\n */\n file: File;\n}\n\n/**\n * Definition for the constructor parameters of the FilePlugin.\n *\n * @category FilePlugin\n */\nexport interface FilePluginParams {\n beforeCreate?: (params: BeforeCreateParams) => Promise<void>;\n afterCreate?: (params: AfterCreateParams) => Promise<void>;\n beforeUpdate?: (params: BeforeUpdateParams) => Promise<void>;\n afterUpdate?: (params: AfterUpdateParams) => Promise<void>;\n beforeBatchCreate?: (params: BeforeBatchCreateParams) => Promise<void>;\n afterBatchCreate?: (params: AfterBatchCreateParams) => Promise<void>;\n beforeDelete?: (params: BeforeDeleteParams) => Promise<void>;\n afterDelete?: (params: AfterDeleteParams) => Promise<void>;\n}\n\nexport class FilePlugin extends Plugin {\n public static override readonly type: string = \"fm.file\";\n private readonly _params: FilePluginParams;\n\n public constructor(params?: FilePluginParams) {\n super();\n this._params = params || ({} as any);\n }\n\n public async beforeCreate(params: BeforeCreateParams): Promise<void> {\n await this._execute(\"beforeCreate\", params);\n }\n\n public async afterCreate(params: AfterCreateParams): Promise<void> {\n await this._execute(\"afterCreate\", params);\n }\n\n public async beforeUpdate(params: BeforeUpdateParams): Promise<void> {\n await this._execute(\"beforeUpdate\", params);\n }\n\n public async afterUpdate(params: AfterUpdateParams): Promise<void> {\n await this._execute(\"afterUpdate\", params);\n }\n\n public async beforeBatchCreate(params: BeforeBatchCreateParams): Promise<void> {\n await this._execute(\"beforeBatchCreate\", params);\n }\n\n public async afterBatchCreate(params: AfterBatchCreateParams): Promise<void> {\n await this._execute(\"afterBatchCreate\", params);\n }\n\n public async beforeDelete(params: BeforeDeleteParams): Promise<void> {\n await this._execute(\"beforeDelete\", params);\n }\n\n public async afterDelete(params: AfterDeleteParams): Promise<void> {\n await this._execute(\"afterDelete\", params);\n }\n /**\n * Keep any here because it can be a number of params. Method is internal so no need to complicate the code.\n */\n private async _execute(callback: keyof FilePluginParams, params: any): Promise<void> {\n const cb = this._params[callback];\n if (typeof cb !== \"function\") {\n return;\n }\n await cb(params);\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AA2HO,MAAMA,UAAN,SAAyBC,eAAzB,CAAgC;EAI5BC,WAAW,CAACC,MAAD,EAA4B;IAC1C;IAD0C;IAE1C,KAAKC,OAAL,GAAeD,MAAM,IAAK,EAA1B;EACH;;EAEwB,MAAZE,YAAY,CAACF,MAAD,EAA4C;IACjE,MAAM,KAAKG,QAAL,CAAc,cAAd,EAA8BH,MAA9B,CAAN;EACH;;EAEuB,MAAXI,WAAW,CAACJ,MAAD,EAA2C;IAC/D,MAAM,KAAKG,QAAL,CAAc,aAAd,EAA6BH,MAA7B,CAAN;EACH;;EAEwB,MAAZK,YAAY,CAACL,MAAD,EAA4C;IACjE,MAAM,KAAKG,QAAL,CAAc,cAAd,EAA8BH,MAA9B,CAAN;EACH;;EAEuB,MAAXM,WAAW,CAACN,MAAD,EAA2C;IAC/D,MAAM,KAAKG,QAAL,CAAc,aAAd,EAA6BH,MAA7B,CAAN;EACH;;EAE6B,MAAjBO,iBAAiB,CAACP,MAAD,EAAiD;IAC3E,MAAM,KAAKG,QAAL,CAAc,mBAAd,EAAmCH,MAAnC,CAAN;EACH;;EAE4B,MAAhBQ,gBAAgB,CAACR,MAAD,EAAgD;IACzE,MAAM,KAAKG,QAAL,CAAc,kBAAd,EAAkCH,MAAlC,CAAN;EACH;;EAEwB,MAAZS,YAAY,CAACT,MAAD,EAA4C;IACjE,MAAM,KAAKG,QAAL,CAAc,cAAd,EAA8BH,MAA9B,CAAN;EACH;;EAEuB,MAAXU,WAAW,CAACV,MAAD,EAA2C;IAC/D,MAAM,KAAKG,QAAL,CAAc,aAAd,EAA6BH,MAA7B,CAAN;EACH;EACD;AACJ;AACA;;;EAC0B,MAARG,QAAQ,CAACQ,QAAD,EAAmCX,MAAnC,EAA+D;IACjF,MAAMY,EAAE,GAAG,KAAKX,OAAL,CAAaU,QAAb,CAAX;;IACA,IAAI,OAAOC,EAAP,KAAc,UAAlB,EAA8B;MAC1B;IACH;;IACD,MAAMA,EAAE,CAACZ,MAAD,CAAR;EACH;;AAjDkC;;;8BAA1BH,U,UACsC,S"}
|