@strapi/upload 0.0.0 → 5.0.0-beta.11

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.
Files changed (217) hide show
  1. package/README.md +1 -1
  2. package/dist/_chunks/ca-B2_I-q1t.mjs +121 -0
  3. package/dist/_chunks/ca-B2_I-q1t.mjs.map +1 -0
  4. package/dist/_chunks/ca-BUpuZx8N.js +121 -0
  5. package/dist/_chunks/ca-BUpuZx8N.js.map +1 -0
  6. package/dist/_chunks/de-A7mEKx6c.mjs +107 -0
  7. package/dist/_chunks/de-A7mEKx6c.mjs.map +1 -0
  8. package/dist/_chunks/de-uGb_Pkq7.js +107 -0
  9. package/dist/_chunks/de-uGb_Pkq7.js.map +1 -0
  10. package/dist/_chunks/dk-BPfkJb9q.mjs +103 -0
  11. package/dist/_chunks/dk-BPfkJb9q.mjs.map +1 -0
  12. package/dist/_chunks/dk-Cd8oFO-O.js +103 -0
  13. package/dist/_chunks/dk-Cd8oFO-O.js.map +1 -0
  14. package/dist/_chunks/en-BcOqhiNe.js +144 -0
  15. package/dist/_chunks/en-BcOqhiNe.js.map +1 -0
  16. package/dist/_chunks/en-oDx2Gnre.mjs +144 -0
  17. package/dist/_chunks/en-oDx2Gnre.mjs.map +1 -0
  18. package/dist/_chunks/es-CuWi2pOn.mjs +120 -0
  19. package/dist/_chunks/es-CuWi2pOn.mjs.map +1 -0
  20. package/dist/_chunks/es-DWFtw_h4.js +120 -0
  21. package/dist/_chunks/es-DWFtw_h4.js.map +1 -0
  22. package/dist/_chunks/fr-BN6ndmWf.mjs +144 -0
  23. package/dist/_chunks/fr-BN6ndmWf.mjs.map +1 -0
  24. package/dist/_chunks/fr-D2bop66d.js +144 -0
  25. package/dist/_chunks/fr-D2bop66d.js.map +1 -0
  26. package/dist/_chunks/graphql-DnH9sdRy.js +71 -0
  27. package/dist/_chunks/graphql-DnH9sdRy.js.map +1 -0
  28. package/dist/_chunks/graphql-_gnSn8ak.mjs +71 -0
  29. package/dist/_chunks/graphql-_gnSn8ak.mjs.map +1 -0
  30. package/dist/_chunks/he-BpxHjaZg.js +76 -0
  31. package/dist/_chunks/he-BpxHjaZg.js.map +1 -0
  32. package/dist/_chunks/he-C9ZOXBB-.mjs +76 -0
  33. package/dist/_chunks/he-C9ZOXBB-.mjs.map +1 -0
  34. package/dist/_chunks/index-BWEiF7F9.mjs +224 -0
  35. package/dist/_chunks/index-BWEiF7F9.mjs.map +1 -0
  36. package/dist/_chunks/index-BzCW755q.js +846 -0
  37. package/dist/_chunks/index-BzCW755q.js.map +1 -0
  38. package/dist/_chunks/index-CP63dxDX.js +229 -0
  39. package/dist/_chunks/index-CP63dxDX.js.map +1 -0
  40. package/dist/_chunks/index-D0KZEEft.mjs +262 -0
  41. package/dist/_chunks/index-D0KZEEft.mjs.map +1 -0
  42. package/dist/_chunks/index-D8coUSPo.mjs +6590 -0
  43. package/dist/_chunks/index-D8coUSPo.mjs.map +1 -0
  44. package/dist/_chunks/index-DNIvA1Nj.js +2685 -0
  45. package/dist/_chunks/index-DNIvA1Nj.js.map +1 -0
  46. package/dist/_chunks/index-DiLPfkYT.js +6616 -0
  47. package/dist/_chunks/index-DiLPfkYT.js.map +1 -0
  48. package/dist/_chunks/index-aW1eiyyQ.mjs +2675 -0
  49. package/dist/_chunks/index-aW1eiyyQ.mjs.map +1 -0
  50. package/dist/_chunks/index-fL1FyELt.js +266 -0
  51. package/dist/_chunks/index-fL1FyELt.js.map +1 -0
  52. package/dist/_chunks/index-rHnhydEZ.mjs +825 -0
  53. package/dist/_chunks/index-rHnhydEZ.mjs.map +1 -0
  54. package/dist/_chunks/it-B7rmoZNx.mjs +76 -0
  55. package/dist/_chunks/it-B7rmoZNx.mjs.map +1 -0
  56. package/dist/_chunks/it-BKCWXl8t.js +76 -0
  57. package/dist/_chunks/it-BKCWXl8t.js.map +1 -0
  58. package/dist/_chunks/ja-DlaJTi_3.mjs +76 -0
  59. package/dist/_chunks/ja-DlaJTi_3.mjs.map +1 -0
  60. package/dist/_chunks/ja-ajHzIJz6.js +76 -0
  61. package/dist/_chunks/ja-ajHzIJz6.js.map +1 -0
  62. package/dist/_chunks/ko-Pzj-818C.js +106 -0
  63. package/dist/_chunks/ko-Pzj-818C.js.map +1 -0
  64. package/dist/_chunks/ko-vJl9kPpn.mjs +106 -0
  65. package/dist/_chunks/ko-vJl9kPpn.mjs.map +1 -0
  66. package/dist/_chunks/ms-CqwG8v8l.mjs +68 -0
  67. package/dist/_chunks/ms-CqwG8v8l.mjs.map +1 -0
  68. package/dist/_chunks/ms-h3gjldBy.js +68 -0
  69. package/dist/_chunks/ms-h3gjldBy.js.map +1 -0
  70. package/dist/_chunks/pl-Cj8jChOO.mjs +105 -0
  71. package/dist/_chunks/pl-Cj8jChOO.mjs.map +1 -0
  72. package/dist/_chunks/pl-esgZ7ltN.js +105 -0
  73. package/dist/_chunks/pl-esgZ7ltN.js.map +1 -0
  74. package/dist/_chunks/pt-BR-B4LJHJIp.mjs +76 -0
  75. package/dist/_chunks/pt-BR-B4LJHJIp.mjs.map +1 -0
  76. package/dist/_chunks/pt-BR-Cazr7Z5I.js +76 -0
  77. package/dist/_chunks/pt-BR-Cazr7Z5I.js.map +1 -0
  78. package/dist/_chunks/pt-CNOOM_7x.mjs +76 -0
  79. package/dist/_chunks/pt-CNOOM_7x.mjs.map +1 -0
  80. package/dist/_chunks/pt-cbUnkHM5.js +76 -0
  81. package/dist/_chunks/pt-cbUnkHM5.js.map +1 -0
  82. package/dist/_chunks/ru-DqglvSUC.mjs +76 -0
  83. package/dist/_chunks/ru-DqglvSUC.mjs.map +1 -0
  84. package/dist/_chunks/ru-H6MzFUxp.js +76 -0
  85. package/dist/_chunks/ru-H6MzFUxp.js.map +1 -0
  86. package/dist/_chunks/sk-CZxC4dFY.js +122 -0
  87. package/dist/_chunks/sk-CZxC4dFY.js.map +1 -0
  88. package/dist/_chunks/sk-Dgpb3lnz.mjs +122 -0
  89. package/dist/_chunks/sk-Dgpb3lnz.mjs.map +1 -0
  90. package/dist/_chunks/th-C6unJZ8j.js +76 -0
  91. package/dist/_chunks/th-C6unJZ8j.js.map +1 -0
  92. package/dist/_chunks/th-DRfzuiFf.mjs +76 -0
  93. package/dist/_chunks/th-DRfzuiFf.mjs.map +1 -0
  94. package/dist/_chunks/tr--GzWXE_A.mjs +122 -0
  95. package/dist/_chunks/tr--GzWXE_A.mjs.map +1 -0
  96. package/dist/_chunks/tr-CY6AwX50.js +122 -0
  97. package/dist/_chunks/tr-CY6AwX50.js.map +1 -0
  98. package/dist/_chunks/uk-BniyNsD4.js +73 -0
  99. package/dist/_chunks/uk-BniyNsD4.js.map +1 -0
  100. package/dist/_chunks/uk-DVMT2Piq.mjs +73 -0
  101. package/dist/_chunks/uk-DVMT2Piq.mjs.map +1 -0
  102. package/dist/_chunks/zh-CsZw0IpM.js +129 -0
  103. package/dist/_chunks/zh-CsZw0IpM.js.map +1 -0
  104. package/dist/_chunks/zh-HOnih0is.mjs +129 -0
  105. package/dist/_chunks/zh-HOnih0is.mjs.map +1 -0
  106. package/dist/_chunks/zh-Hans-Cpmhg8uH.mjs +152 -0
  107. package/dist/_chunks/zh-Hans-Cpmhg8uH.mjs.map +1 -0
  108. package/dist/_chunks/zh-Hans-k_xAc6nm.js +152 -0
  109. package/dist/_chunks/zh-Hans-k_xAc6nm.js.map +1 -0
  110. package/dist/admin/index.js +5 -0
  111. package/dist/admin/index.js.map +1 -0
  112. package/dist/admin/index.mjs +6 -0
  113. package/dist/admin/index.mjs.map +1 -0
  114. package/dist/server/index.js +4 -0
  115. package/dist/server/index.js.map +1 -0
  116. package/dist/server/index.mjs +5 -0
  117. package/dist/server/index.mjs.map +1 -0
  118. package/dist/server/src/bootstrap.d.ts +5 -0
  119. package/dist/server/src/bootstrap.d.ts.map +1 -0
  120. package/dist/server/src/config.d.ts +10 -0
  121. package/dist/server/src/config.d.ts.map +1 -0
  122. package/dist/server/src/constants.d.ts +20 -0
  123. package/dist/server/src/constants.d.ts.map +1 -0
  124. package/dist/server/src/content-types/file.d.ts +110 -0
  125. package/dist/server/src/content-types/file.d.ts.map +1 -0
  126. package/dist/server/src/content-types/folder.d.ts +61 -0
  127. package/dist/server/src/content-types/folder.d.ts.map +1 -0
  128. package/dist/server/src/content-types/index.d.ts +170 -0
  129. package/dist/server/src/content-types/index.d.ts.map +1 -0
  130. package/dist/server/src/controllers/admin-file.d.ts +16 -0
  131. package/dist/server/src/controllers/admin-file.d.ts.map +1 -0
  132. package/dist/server/src/controllers/admin-folder-file.d.ts +7 -0
  133. package/dist/server/src/controllers/admin-folder-file.d.ts.map +1 -0
  134. package/dist/server/src/controllers/admin-folder.d.ts +10 -0
  135. package/dist/server/src/controllers/admin-folder.d.ts.map +1 -0
  136. package/dist/server/src/controllers/admin-settings.d.ts +7 -0
  137. package/dist/server/src/controllers/admin-settings.d.ts.map +1 -0
  138. package/dist/server/src/controllers/admin-upload.d.ts +9 -0
  139. package/dist/server/src/controllers/admin-upload.d.ts.map +1 -0
  140. package/dist/server/src/controllers/content-api.d.ts +15 -0
  141. package/dist/server/src/controllers/content-api.d.ts.map +1 -0
  142. package/dist/server/src/controllers/index.d.ts +53 -0
  143. package/dist/server/src/controllers/index.d.ts.map +1 -0
  144. package/dist/server/src/controllers/utils/find-entity-and-check-permissions.d.ts +6 -0
  145. package/dist/server/src/controllers/utils/find-entity-and-check-permissions.d.ts.map +1 -0
  146. package/dist/server/src/controllers/utils/folders.d.ts +4 -0
  147. package/dist/server/src/controllers/utils/folders.d.ts.map +1 -0
  148. package/dist/server/src/controllers/validation/admin/configureView.d.ts +15 -0
  149. package/dist/server/src/controllers/validation/admin/configureView.d.ts.map +1 -0
  150. package/dist/server/src/controllers/validation/admin/folder-file.d.ts +3 -0
  151. package/dist/server/src/controllers/validation/admin/folder-file.d.ts.map +1 -0
  152. package/dist/server/src/controllers/validation/admin/folder.d.ts +3 -0
  153. package/dist/server/src/controllers/validation/admin/folder.d.ts.map +1 -0
  154. package/dist/server/src/controllers/validation/admin/settings.d.ts +18 -0
  155. package/dist/server/src/controllers/validation/admin/settings.d.ts.map +1 -0
  156. package/dist/server/src/controllers/validation/admin/upload.d.ts +109 -0
  157. package/dist/server/src/controllers/validation/admin/upload.d.ts.map +1 -0
  158. package/dist/server/src/controllers/validation/admin/utils.d.ts +3 -0
  159. package/dist/server/src/controllers/validation/admin/utils.d.ts.map +1 -0
  160. package/dist/server/src/controllers/validation/content-api/upload.d.ts +91 -0
  161. package/dist/server/src/controllers/validation/content-api/upload.d.ts.map +1 -0
  162. package/dist/server/src/controllers/view-configuration.d.ts +7 -0
  163. package/dist/server/src/controllers/view-configuration.d.ts.map +1 -0
  164. package/dist/server/src/graphql.d.ts +5 -0
  165. package/dist/server/src/graphql.d.ts.map +1 -0
  166. package/dist/server/src/index.d.ts +432 -0
  167. package/dist/server/src/index.d.ts.map +1 -0
  168. package/dist/server/src/middlewares/upload.d.ts +9 -0
  169. package/dist/server/src/middlewares/upload.d.ts.map +1 -0
  170. package/dist/server/src/register.d.ts +8 -0
  171. package/dist/server/src/register.d.ts.map +1 -0
  172. package/dist/server/src/routes/admin.d.ts +17 -0
  173. package/dist/server/src/routes/admin.d.ts.map +1 -0
  174. package/dist/server/src/routes/content-api.d.ts +9 -0
  175. package/dist/server/src/routes/content-api.d.ts.map +1 -0
  176. package/dist/server/src/routes/index.d.ts +43 -0
  177. package/dist/server/src/routes/index.d.ts.map +1 -0
  178. package/dist/server/src/routes/view-configuration.d.ts +17 -0
  179. package/dist/server/src/routes/view-configuration.d.ts.map +1 -0
  180. package/dist/server/src/services/api-upload-folder.d.ts +5 -0
  181. package/dist/server/src/services/api-upload-folder.d.ts.map +1 -0
  182. package/dist/server/src/services/extensions/content-manager/entity-manager.d.ts +15 -0
  183. package/dist/server/src/services/extensions/content-manager/entity-manager.d.ts.map +1 -0
  184. package/dist/server/src/services/extensions/content-manager/index.d.ts +4 -0
  185. package/dist/server/src/services/extensions/content-manager/index.d.ts.map +1 -0
  186. package/dist/server/src/services/extensions/core/entity-service.d.ts +4 -0
  187. package/dist/server/src/services/extensions/core/entity-service.d.ts.map +1 -0
  188. package/dist/server/src/services/extensions/core/index.d.ts +4 -0
  189. package/dist/server/src/services/extensions/core/index.d.ts.map +1 -0
  190. package/dist/server/src/services/extensions/index.d.ts +8 -0
  191. package/dist/server/src/services/extensions/index.d.ts.map +1 -0
  192. package/dist/server/src/services/extensions/utils.d.ts +14 -0
  193. package/dist/server/src/services/extensions/utils.d.ts.map +1 -0
  194. package/dist/server/src/services/file.d.ts +8 -0
  195. package/dist/server/src/services/file.d.ts.map +1 -0
  196. package/dist/server/src/services/folder.d.ts +32 -0
  197. package/dist/server/src/services/folder.d.ts.map +1 -0
  198. package/dist/server/src/services/image-manipulation.d.ts +20 -0
  199. package/dist/server/src/services/image-manipulation.d.ts.map +1 -0
  200. package/dist/server/src/services/index.d.ts +153 -0
  201. package/dist/server/src/services/index.d.ts.map +1 -0
  202. package/dist/server/src/services/metrics.d.ts +8 -0
  203. package/dist/server/src/services/metrics.d.ts.map +1 -0
  204. package/dist/server/src/services/provider.d.ts +10 -0
  205. package/dist/server/src/services/provider.d.ts.map +1 -0
  206. package/dist/server/src/services/upload.d.ts +67 -0
  207. package/dist/server/src/services/upload.d.ts.map +1 -0
  208. package/dist/server/src/services/weekly-metrics.d.ts +17 -0
  209. package/dist/server/src/services/weekly-metrics.d.ts.map +1 -0
  210. package/dist/server/src/types.d.ts +75 -0
  211. package/dist/server/src/types.d.ts.map +1 -0
  212. package/dist/server/src/utils/cron.d.ts +3 -0
  213. package/dist/server/src/utils/cron.d.ts.map +1 -0
  214. package/dist/server/src/utils/index.d.ts +23 -0
  215. package/dist/server/src/utils/index.d.ts.map +1 -0
  216. package/package.json +96 -7
  217. package/strapi-server.js +3 -0
@@ -0,0 +1,2685 @@
1
+ "use strict";
2
+ const _ = require("lodash");
3
+ const utils = require("@strapi/utils");
4
+ const range = require("koa-range");
5
+ const koaStatic = require("koa-static");
6
+ const fp = require("lodash/fp");
7
+ const os = require("os");
8
+ const path = require("path");
9
+ const crypto = require("crypto");
10
+ const fs = require("fs");
11
+ const fse = require("fs-extra");
12
+ const mimeTypes = require("mime-types");
13
+ const sharp = require("sharp");
14
+ const dateFns = require("date-fns");
15
+ const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
16
+ const ___default = /* @__PURE__ */ _interopDefault(_);
17
+ const utils__default = /* @__PURE__ */ _interopDefault(utils);
18
+ const range__default = /* @__PURE__ */ _interopDefault(range);
19
+ const koaStatic__default = /* @__PURE__ */ _interopDefault(koaStatic);
20
+ const os__default = /* @__PURE__ */ _interopDefault(os);
21
+ const path__default = /* @__PURE__ */ _interopDefault(path);
22
+ const crypto__default = /* @__PURE__ */ _interopDefault(crypto);
23
+ const fs__default = /* @__PURE__ */ _interopDefault(fs);
24
+ const fse__default = /* @__PURE__ */ _interopDefault(fse);
25
+ const sharp__default = /* @__PURE__ */ _interopDefault(sharp);
26
+ const registerUploadMiddleware = ({ strapi: strapi2 }) => {
27
+ strapi2.server.app.on("error", (err) => {
28
+ if (err.code === "EPIPE") {
29
+ return;
30
+ }
31
+ strapi2.server.app.onerror(err);
32
+ });
33
+ const localServerConfig = strapi2.config.get("plugin::upload.providerOptions.localServer", {});
34
+ strapi2.server.routes([
35
+ {
36
+ method: "GET",
37
+ path: "/uploads/(.*)",
38
+ handler: [range__default.default, koaStatic__default.default(strapi2.dirs.static.public, { defer: true, ...localServerConfig })],
39
+ config: { auth: false }
40
+ }
41
+ ]);
42
+ };
43
+ const paths = {
44
+ "/upload": {
45
+ post: {
46
+ description: "Upload files",
47
+ responses: {
48
+ "200": {
49
+ description: "response",
50
+ content: {
51
+ "application/json": {
52
+ schema: {
53
+ type: "array",
54
+ items: {
55
+ $ref: "#/components/schemas/UploadFile"
56
+ }
57
+ }
58
+ }
59
+ }
60
+ }
61
+ },
62
+ summary: "",
63
+ tags: [
64
+ "Upload - File"
65
+ ],
66
+ requestBody: {
67
+ description: "Upload files",
68
+ required: true,
69
+ content: {
70
+ "multipart/form-data": {
71
+ schema: {
72
+ required: [
73
+ "files"
74
+ ],
75
+ type: "object",
76
+ properties: {
77
+ path: {
78
+ type: "string",
79
+ description: "The folder where the file(s) will be uploaded to (only supported on strapi-provider-upload-aws-s3)."
80
+ },
81
+ refId: {
82
+ type: "string",
83
+ description: "The ID of the entry which the file(s) will be linked to"
84
+ },
85
+ ref: {
86
+ type: "string",
87
+ description: "The unique ID (uid) of the model which the file(s) will be linked to (api::restaurant.restaurant)."
88
+ },
89
+ field: {
90
+ type: "string",
91
+ description: "The field of the entry which the file(s) will be precisely linked to."
92
+ },
93
+ files: {
94
+ type: "array",
95
+ items: {
96
+ type: "string",
97
+ format: "binary"
98
+ }
99
+ }
100
+ }
101
+ }
102
+ }
103
+ }
104
+ }
105
+ }
106
+ },
107
+ "/upload?id={id}": {
108
+ post: {
109
+ parameters: [
110
+ {
111
+ name: "id",
112
+ "in": "query",
113
+ description: "File id",
114
+ required: true,
115
+ schema: {
116
+ type: "string"
117
+ }
118
+ }
119
+ ],
120
+ description: "Upload file information",
121
+ responses: {
122
+ "200": {
123
+ description: "response",
124
+ content: {
125
+ "application/json": {
126
+ schema: {
127
+ type: "array",
128
+ items: {
129
+ $ref: "#/components/schemas/UploadFile"
130
+ }
131
+ }
132
+ }
133
+ }
134
+ }
135
+ },
136
+ summary: "",
137
+ tags: [
138
+ "Upload - File"
139
+ ],
140
+ requestBody: {
141
+ description: "Upload files",
142
+ required: true,
143
+ content: {
144
+ "multipart/form-data": {
145
+ schema: {
146
+ type: "object",
147
+ properties: {
148
+ fileInfo: {
149
+ type: "object",
150
+ properties: {
151
+ name: {
152
+ type: "string"
153
+ },
154
+ alternativeText: {
155
+ type: "string"
156
+ },
157
+ caption: {
158
+ type: "string"
159
+ }
160
+ }
161
+ },
162
+ files: {
163
+ type: "string",
164
+ format: "binary"
165
+ }
166
+ }
167
+ }
168
+ }
169
+ }
170
+ }
171
+ }
172
+ },
173
+ "/upload/files": {
174
+ get: {
175
+ tags: [
176
+ "Upload - File"
177
+ ],
178
+ responses: {
179
+ "200": {
180
+ description: "Get a list of files",
181
+ content: {
182
+ "application/json": {
183
+ schema: {
184
+ type: "array",
185
+ items: {
186
+ $ref: "#/components/schemas/UploadFile"
187
+ }
188
+ }
189
+ }
190
+ }
191
+ }
192
+ }
193
+ }
194
+ },
195
+ "/upload/files/{id}": {
196
+ get: {
197
+ parameters: [
198
+ {
199
+ name: "id",
200
+ "in": "path",
201
+ description: "",
202
+ deprecated: false,
203
+ required: true,
204
+ schema: {
205
+ type: "string"
206
+ }
207
+ }
208
+ ],
209
+ tags: [
210
+ "Upload - File"
211
+ ],
212
+ responses: {
213
+ "200": {
214
+ description: "Get a specific file",
215
+ content: {
216
+ "application/json": {
217
+ schema: {
218
+ $ref: "#/components/schemas/UploadFile"
219
+ }
220
+ }
221
+ }
222
+ }
223
+ }
224
+ },
225
+ "delete": {
226
+ parameters: [
227
+ {
228
+ name: "id",
229
+ "in": "path",
230
+ description: "",
231
+ deprecated: false,
232
+ required: true,
233
+ schema: {
234
+ type: "string"
235
+ }
236
+ }
237
+ ],
238
+ tags: [
239
+ "Upload - File"
240
+ ],
241
+ responses: {
242
+ "200": {
243
+ description: "Delete a file",
244
+ content: {
245
+ "application/json": {
246
+ schema: {
247
+ $ref: "#/components/schemas/UploadFile"
248
+ }
249
+ }
250
+ }
251
+ }
252
+ }
253
+ }
254
+ }
255
+ };
256
+ const components = {
257
+ schemas: {
258
+ UploadFile: {
259
+ properties: {
260
+ id: {
261
+ type: "number"
262
+ },
263
+ name: {
264
+ type: "string"
265
+ },
266
+ alternativeText: {
267
+ type: "string"
268
+ },
269
+ caption: {
270
+ type: "string"
271
+ },
272
+ width: {
273
+ type: "number",
274
+ format: "integer"
275
+ },
276
+ height: {
277
+ type: "number",
278
+ format: "integer"
279
+ },
280
+ formats: {
281
+ type: "number"
282
+ },
283
+ hash: {
284
+ type: "string"
285
+ },
286
+ ext: {
287
+ type: "string"
288
+ },
289
+ mime: {
290
+ type: "string"
291
+ },
292
+ size: {
293
+ type: "number",
294
+ format: "double"
295
+ },
296
+ url: {
297
+ type: "string"
298
+ },
299
+ previewUrl: {
300
+ type: "string"
301
+ },
302
+ provider: {
303
+ type: "string"
304
+ },
305
+ provider_metadata: {
306
+ type: "object"
307
+ },
308
+ createdAt: {
309
+ type: "string",
310
+ format: "date-time"
311
+ },
312
+ updatedAt: {
313
+ type: "string",
314
+ format: "date-time"
315
+ }
316
+ }
317
+ }
318
+ }
319
+ };
320
+ const spec = {
321
+ paths,
322
+ components
323
+ };
324
+ const { PayloadTooLargeError } = utils.errors;
325
+ const { bytesToHumanReadable, kbytesToBytes } = utils.file;
326
+ async function register({ strapi: strapi2 }) {
327
+ strapi2.plugin("upload").provider = createProvider(strapi2.config.get("plugin::upload"));
328
+ await registerUploadMiddleware({ strapi: strapi2 });
329
+ if (strapi2.plugin("graphql")) {
330
+ const { installGraphqlExtension } = await Promise.resolve().then(() => require("./graphql-DnH9sdRy.js"));
331
+ installGraphqlExtension({ strapi: strapi2 });
332
+ }
333
+ if (strapi2.plugin("documentation")) {
334
+ strapi2.plugin("documentation").service("override").registerOverride(spec, {
335
+ pluginOrigin: "upload",
336
+ excludeFromGeneration: ["upload"]
337
+ });
338
+ }
339
+ }
340
+ const createProvider = (config2) => {
341
+ const { providerOptions, actionOptions = {} } = config2;
342
+ const providerName = ___default.default.toLower(config2.provider);
343
+ let provider2;
344
+ let modulePath;
345
+ try {
346
+ modulePath = require.resolve(`@strapi/provider-upload-${providerName}`);
347
+ } catch (error) {
348
+ if (typeof error === "object" && error !== null && "code" in error && error.code === "MODULE_NOT_FOUND") {
349
+ modulePath = providerName;
350
+ } else {
351
+ throw error;
352
+ }
353
+ }
354
+ try {
355
+ provider2 = require(modulePath);
356
+ } catch (err) {
357
+ const newError = new Error(`Could not load upload provider "${providerName}".`);
358
+ if (err instanceof Error) {
359
+ newError.stack = err.stack;
360
+ }
361
+ throw newError;
362
+ }
363
+ const providerInstance = provider2.init(providerOptions);
364
+ if (!providerInstance.delete) {
365
+ throw new Error(`The upload provider "${providerName}" doesn't implement the delete method.`);
366
+ }
367
+ if (!providerInstance.upload && !providerInstance.uploadStream) {
368
+ throw new Error(
369
+ `The upload provider "${providerName}" doesn't implement the uploadStream nor the upload method.`
370
+ );
371
+ }
372
+ if (!providerInstance.uploadStream) {
373
+ process.emitWarning(
374
+ `The upload provider "${providerName}" doesn't implement the uploadStream function. Strapi will fallback on the upload method. Some performance issues may occur.`
375
+ );
376
+ }
377
+ const wrappedProvider = ___default.default.mapValues(providerInstance, (method, methodName) => {
378
+ return async (file2, options = actionOptions[methodName]) => providerInstance[methodName](file2, options);
379
+ });
380
+ return Object.assign(Object.create(baseProvider), wrappedProvider);
381
+ };
382
+ const baseProvider = {
383
+ extend(obj) {
384
+ Object.assign(this, obj);
385
+ },
386
+ checkFileSize(file2, { sizeLimit }) {
387
+ if (sizeLimit && kbytesToBytes(file2.size) > sizeLimit) {
388
+ throw new PayloadTooLargeError(
389
+ `${file2.originalFilename} exceeds size limit of ${bytesToHumanReadable(sizeLimit)}.`
390
+ );
391
+ }
392
+ },
393
+ getSignedUrl(file2) {
394
+ return file2;
395
+ },
396
+ isPrivate() {
397
+ return false;
398
+ }
399
+ };
400
+ const getService = (name) => {
401
+ return strapi.plugin("upload").service(name);
402
+ };
403
+ const ACTIONS = {
404
+ read: "plugin::upload.read",
405
+ readSettings: "plugin::upload.settings.read",
406
+ create: "plugin::upload.assets.create",
407
+ update: "plugin::upload.assets.update",
408
+ download: "plugin::upload.assets.download",
409
+ copyLink: "plugin::upload.assets.copy-link",
410
+ configureView: "plugin::upload.configure-view"
411
+ };
412
+ const ALLOWED_SORT_STRINGS = [
413
+ "createdAt:DESC",
414
+ "createdAt:ASC",
415
+ "name:ASC",
416
+ "name:DESC",
417
+ "updatedAt:DESC",
418
+ "updatedAt:ASC"
419
+ ];
420
+ const ALLOWED_WEBHOOK_EVENTS = {
421
+ MEDIA_CREATE: "media.create",
422
+ MEDIA_UPDATE: "media.update",
423
+ MEDIA_DELETE: "media.delete"
424
+ };
425
+ const FOLDER_MODEL_UID = "plugin::upload.folder";
426
+ const FILE_MODEL_UID = "plugin::upload.file";
427
+ const API_UPLOAD_FOLDER_BASE_NAME = "API Uploads";
428
+ async function bootstrap({ strapi: strapi2 }) {
429
+ const defaultConfig = {
430
+ settings: {
431
+ sizeOptimization: true,
432
+ responsiveDimensions: true,
433
+ autoOrientation: false
434
+ },
435
+ view_configuration: {
436
+ pageSize: 10,
437
+ sort: ALLOWED_SORT_STRINGS[0]
438
+ }
439
+ };
440
+ for (const [key, defaultValue] of Object.entries(defaultConfig)) {
441
+ const configurator = strapi2.store({ type: "plugin", name: "upload", key });
442
+ const config2 = await configurator.get({});
443
+ if (config2 && Object.keys(defaultValue).every((key2) => Object.prototype.hasOwnProperty.call(config2, key2))) {
444
+ continue;
445
+ }
446
+ await configurator.set({
447
+ value: Object.assign(defaultValue, config2 || {})
448
+ });
449
+ }
450
+ await registerPermissionActions();
451
+ await registerWebhookEvents();
452
+ await getService("weeklyMetrics").registerCron();
453
+ getService("metrics").sendUploadPluginMetrics();
454
+ if (strapi2.config.get("plugin::upload.signAdminURLsOnly", false)) {
455
+ getService("extensions").contentManager.entityManager.addSignedFileUrlsToAdmin();
456
+ } else {
457
+ getService("extensions").core.entityService.addSignedFileUrlsToEntityService();
458
+ }
459
+ }
460
+ const registerWebhookEvents = async () => Object.entries(ALLOWED_WEBHOOK_EVENTS).forEach(([key, value]) => {
461
+ strapi.get("webhookStore").addAllowedEvent(key, value);
462
+ });
463
+ const registerPermissionActions = async () => {
464
+ const actions = [
465
+ {
466
+ section: "plugins",
467
+ displayName: "Access the Media Library",
468
+ uid: "read",
469
+ pluginName: "upload"
470
+ },
471
+ {
472
+ section: "plugins",
473
+ displayName: "Create (upload)",
474
+ uid: "assets.create",
475
+ subCategory: "assets",
476
+ pluginName: "upload"
477
+ },
478
+ {
479
+ section: "plugins",
480
+ displayName: "Update (crop, details, replace) + delete",
481
+ uid: "assets.update",
482
+ subCategory: "assets",
483
+ pluginName: "upload"
484
+ },
485
+ {
486
+ section: "plugins",
487
+ displayName: "Download",
488
+ uid: "assets.download",
489
+ subCategory: "assets",
490
+ pluginName: "upload"
491
+ },
492
+ {
493
+ section: "plugins",
494
+ displayName: "Copy link",
495
+ uid: "assets.copy-link",
496
+ subCategory: "assets",
497
+ pluginName: "upload"
498
+ },
499
+ {
500
+ section: "plugins",
501
+ displayName: "Configure view",
502
+ uid: "configure-view",
503
+ pluginName: "upload"
504
+ },
505
+ {
506
+ section: "settings",
507
+ displayName: "Access the Media Library settings page",
508
+ uid: "settings.read",
509
+ category: "media library",
510
+ pluginName: "upload"
511
+ }
512
+ ];
513
+ await strapi.service("admin::permission").actionProvider.registerMany(actions);
514
+ };
515
+ const file$1 = {
516
+ schema: {
517
+ collectionName: "files",
518
+ info: {
519
+ singularName: "file",
520
+ pluralName: "files",
521
+ displayName: "File",
522
+ description: ""
523
+ },
524
+ options: {},
525
+ pluginOptions: {
526
+ "content-manager": {
527
+ visible: false
528
+ },
529
+ "content-type-builder": {
530
+ visible: false
531
+ }
532
+ },
533
+ attributes: {
534
+ name: {
535
+ type: "string",
536
+ configurable: false,
537
+ required: true
538
+ },
539
+ alternativeText: {
540
+ type: "string",
541
+ configurable: false
542
+ },
543
+ caption: {
544
+ type: "string",
545
+ configurable: false
546
+ },
547
+ width: {
548
+ type: "integer",
549
+ configurable: false
550
+ },
551
+ height: {
552
+ type: "integer",
553
+ configurable: false
554
+ },
555
+ formats: {
556
+ type: "json",
557
+ configurable: false
558
+ },
559
+ hash: {
560
+ type: "string",
561
+ configurable: false,
562
+ required: true
563
+ },
564
+ ext: {
565
+ type: "string",
566
+ configurable: false
567
+ },
568
+ mime: {
569
+ type: "string",
570
+ configurable: false,
571
+ required: true
572
+ },
573
+ size: {
574
+ type: "decimal",
575
+ configurable: false,
576
+ required: true
577
+ },
578
+ url: {
579
+ type: "string",
580
+ configurable: false,
581
+ required: true
582
+ },
583
+ previewUrl: {
584
+ type: "string",
585
+ configurable: false
586
+ },
587
+ provider: {
588
+ type: "string",
589
+ configurable: false,
590
+ required: true
591
+ },
592
+ provider_metadata: {
593
+ type: "json",
594
+ configurable: false
595
+ },
596
+ related: {
597
+ type: "relation",
598
+ relation: "morphToMany",
599
+ configurable: false
600
+ },
601
+ folder: {
602
+ type: "relation",
603
+ relation: "manyToOne",
604
+ target: FOLDER_MODEL_UID,
605
+ inversedBy: "files",
606
+ private: true
607
+ },
608
+ folderPath: {
609
+ type: "string",
610
+ minLength: 1,
611
+ required: true,
612
+ private: true,
613
+ searchable: false
614
+ }
615
+ },
616
+ // experimental feature:
617
+ indexes: [
618
+ {
619
+ name: "upload_files_folder_path_index",
620
+ columns: ["folder_path"],
621
+ type: null
622
+ },
623
+ {
624
+ name: `upload_files_created_at_index`,
625
+ columns: ["created_at"],
626
+ type: null
627
+ },
628
+ {
629
+ name: `upload_files_updated_at_index`,
630
+ columns: ["updated_at"],
631
+ type: null
632
+ },
633
+ {
634
+ name: `upload_files_name_index`,
635
+ columns: ["name"],
636
+ type: null
637
+ },
638
+ {
639
+ name: `upload_files_size_index`,
640
+ columns: ["size"],
641
+ type: null
642
+ },
643
+ {
644
+ name: `upload_files_ext_index`,
645
+ columns: ["ext"],
646
+ type: null
647
+ }
648
+ ]
649
+ }
650
+ };
651
+ const folder$1 = {
652
+ schema: {
653
+ collectionName: "upload_folders",
654
+ info: {
655
+ singularName: "folder",
656
+ pluralName: "folders",
657
+ displayName: "Folder"
658
+ },
659
+ options: {},
660
+ pluginOptions: {
661
+ "content-manager": {
662
+ visible: false
663
+ },
664
+ "content-type-builder": {
665
+ visible: false
666
+ }
667
+ },
668
+ attributes: {
669
+ name: {
670
+ type: "string",
671
+ minLength: 1,
672
+ required: true
673
+ },
674
+ pathId: {
675
+ type: "integer",
676
+ unique: true,
677
+ required: true
678
+ },
679
+ parent: {
680
+ type: "relation",
681
+ relation: "manyToOne",
682
+ target: FOLDER_MODEL_UID,
683
+ inversedBy: "children"
684
+ },
685
+ children: {
686
+ type: "relation",
687
+ relation: "oneToMany",
688
+ target: FOLDER_MODEL_UID,
689
+ mappedBy: "parent"
690
+ },
691
+ files: {
692
+ type: "relation",
693
+ relation: "oneToMany",
694
+ target: FILE_MODEL_UID,
695
+ mappedBy: "folder"
696
+ },
697
+ path: {
698
+ type: "string",
699
+ minLength: 1,
700
+ required: true
701
+ }
702
+ },
703
+ // experimental feature:
704
+ indexes: [
705
+ {
706
+ name: "upload_folders_path_id_index",
707
+ columns: ["path_id"],
708
+ type: "unique"
709
+ },
710
+ {
711
+ name: "upload_folders_path_index",
712
+ columns: ["path"],
713
+ type: "unique"
714
+ }
715
+ ]
716
+ }
717
+ };
718
+ const contentTypes = {
719
+ file: file$1,
720
+ folder: folder$1
721
+ };
722
+ const provider = ({ strapi: strapi2 }) => ({
723
+ async checkFileSize(file2) {
724
+ const { sizeLimit } = strapi2.config.get("plugin::upload");
725
+ await strapi2.plugin("upload").provider.checkFileSize(file2, { sizeLimit });
726
+ },
727
+ async upload(file2) {
728
+ if (fp.isFunction(strapi2.plugin("upload").provider.uploadStream)) {
729
+ file2.stream = file2.getStream();
730
+ await strapi2.plugin("upload").provider.uploadStream(file2);
731
+ delete file2.stream;
732
+ if ("filepath" in file2) {
733
+ delete file2.filepath;
734
+ }
735
+ } else {
736
+ file2.buffer = await utils.file.streamToBuffer(file2.getStream());
737
+ await strapi2.plugin("upload").provider.upload(file2);
738
+ delete file2.buffer;
739
+ if ("filepath" in file2) {
740
+ delete file2.filepath;
741
+ }
742
+ }
743
+ }
744
+ });
745
+ const { UPDATED_BY_ATTRIBUTE, CREATED_BY_ATTRIBUTE } = utils.contentTypes.constants;
746
+ const { MEDIA_CREATE, MEDIA_UPDATE, MEDIA_DELETE } = ALLOWED_WEBHOOK_EVENTS;
747
+ const { ApplicationError, NotFoundError } = utils.errors;
748
+ const { bytesToKbytes: bytesToKbytes$1 } = utils.file;
749
+ const upload = ({ strapi: strapi2 }) => {
750
+ const randomSuffix = () => crypto__default.default.randomBytes(5).toString("hex");
751
+ const generateFileName = (name) => {
752
+ const baseName = utils.strings.nameToSlug(name, { separator: "_", lowercase: false });
753
+ return `${baseName}_${randomSuffix()}`;
754
+ };
755
+ const sendMediaMetrics = (data) => {
756
+ if (___default.default.has(data, "caption") && !___default.default.isEmpty(data.caption)) {
757
+ strapi2.telemetry.send("didSaveMediaWithCaption");
758
+ }
759
+ if (___default.default.has(data, "alternativeText") && !___default.default.isEmpty(data.alternativeText)) {
760
+ strapi2.telemetry.send("didSaveMediaWithAlternativeText");
761
+ }
762
+ };
763
+ const createAndAssignTmpWorkingDirectoryToFiles = async (files) => {
764
+ const tmpWorkingDirectory = await fse__default.default.mkdtemp(path__default.default.join(os__default.default.tmpdir(), "strapi-upload-"));
765
+ if (Array.isArray(files)) {
766
+ files.forEach((file2) => {
767
+ file2.tmpWorkingDirectory = tmpWorkingDirectory;
768
+ });
769
+ } else {
770
+ files.tmpWorkingDirectory = tmpWorkingDirectory;
771
+ }
772
+ return tmpWorkingDirectory;
773
+ };
774
+ function filenameReservedRegex() {
775
+ return /[<>:"/\\|?*\u0000-\u001F]/g;
776
+ }
777
+ function windowsReservedNameRegex() {
778
+ return /^(con|prn|aux|nul|com\d|lpt\d)$/i;
779
+ }
780
+ function isValidFilename(string) {
781
+ if (!string || string.length > 255) {
782
+ return false;
783
+ }
784
+ if (filenameReservedRegex().test(string) || windowsReservedNameRegex().test(string)) {
785
+ return false;
786
+ }
787
+ if (string === "." || string === "..") {
788
+ return false;
789
+ }
790
+ return true;
791
+ }
792
+ async function emitEvent(event, data) {
793
+ const modelDef = strapi2.getModel(FILE_MODEL_UID);
794
+ const sanitizedData = await utils.sanitize.sanitizers.defaultSanitizeOutput(
795
+ {
796
+ schema: modelDef,
797
+ getModel(uid) {
798
+ return strapi2.getModel(uid);
799
+ }
800
+ },
801
+ data
802
+ );
803
+ strapi2.eventHub.emit(event, { media: sanitizedData });
804
+ }
805
+ async function formatFileInfo({ filename, type, size }, fileInfo = {}, metas = {}) {
806
+ const fileService = getService("file");
807
+ if (!isValidFilename(filename)) {
808
+ throw new ApplicationError("File name contains invalid characters");
809
+ }
810
+ let ext = path__default.default.extname(filename);
811
+ if (!ext) {
812
+ ext = `.${mimeTypes.extension(type)}`;
813
+ }
814
+ const usedName = (fileInfo.name || filename).normalize();
815
+ const basename = path__default.default.basename(usedName, ext);
816
+ if (!isValidFilename(filename)) {
817
+ throw new ApplicationError("File name contains invalid characters");
818
+ }
819
+ const entity = {
820
+ name: usedName,
821
+ alternativeText: fileInfo.alternativeText,
822
+ caption: fileInfo.caption,
823
+ folder: fileInfo.folder,
824
+ folderPath: await fileService.getFolderPath(fileInfo.folder),
825
+ hash: generateFileName(basename),
826
+ ext,
827
+ mime: type,
828
+ size: bytesToKbytes$1(size),
829
+ sizeInBytes: size
830
+ };
831
+ const { refId, ref, field } = metas;
832
+ if (refId && ref && field) {
833
+ entity.related = [
834
+ {
835
+ id: refId,
836
+ __type: ref,
837
+ __pivot: { field }
838
+ }
839
+ ];
840
+ }
841
+ if (metas.path) {
842
+ entity.path = metas.path;
843
+ }
844
+ if (metas.tmpWorkingDirectory) {
845
+ entity.tmpWorkingDirectory = metas.tmpWorkingDirectory;
846
+ }
847
+ return entity;
848
+ }
849
+ async function enhanceAndValidateFile(file2, fileInfo, metas) {
850
+ const currentFile = await formatFileInfo(
851
+ {
852
+ filename: file2.originalFilename ?? "unamed",
853
+ type: file2.mimetype ?? "application/octet-stream",
854
+ size: file2.size
855
+ },
856
+ fileInfo,
857
+ {
858
+ ...metas,
859
+ tmpWorkingDirectory: file2.tmpWorkingDirectory
860
+ }
861
+ );
862
+ currentFile.filepath = file2.filepath;
863
+ currentFile.getStream = () => fs__default.default.createReadStream(file2.filepath);
864
+ const { optimize: optimize2, isImage: isImage2, isFaultyImage: isFaultyImage2, isOptimizableImage: isOptimizableImage2 } = strapi2.plugin("upload").service("image-manipulation");
865
+ if (await isImage2(currentFile)) {
866
+ if (await isFaultyImage2(currentFile)) {
867
+ throw new ApplicationError("File is not a valid image");
868
+ }
869
+ if (await isOptimizableImage2(currentFile)) {
870
+ return optimize2(currentFile);
871
+ }
872
+ }
873
+ return currentFile;
874
+ }
875
+ async function upload2({
876
+ data,
877
+ files
878
+ }, opts) {
879
+ const { user } = opts ?? {};
880
+ const tmpWorkingDirectory = await createAndAssignTmpWorkingDirectoryToFiles(files);
881
+ let uploadedFiles = [];
882
+ try {
883
+ const { fileInfo, ...metas } = data;
884
+ const fileArray = Array.isArray(files) ? files : [files];
885
+ const fileInfoArray = Array.isArray(fileInfo) ? fileInfo : [fileInfo];
886
+ const doUpload = async (file2, fileInfo2) => {
887
+ const fileData = await enhanceAndValidateFile(file2, fileInfo2, metas);
888
+ return uploadFileAndPersist(fileData, { user });
889
+ };
890
+ uploadedFiles = await Promise.all(
891
+ fileArray.map((file2, idx) => doUpload(file2, fileInfoArray[idx] || {}))
892
+ );
893
+ } finally {
894
+ await fse__default.default.remove(tmpWorkingDirectory);
895
+ }
896
+ return uploadedFiles;
897
+ }
898
+ async function uploadImage(fileData) {
899
+ const { getDimensions: getDimensions2, generateThumbnail: generateThumbnail2, generateResponsiveFormats: generateResponsiveFormats2, isResizableImage: isResizableImage2 } = getService("image-manipulation");
900
+ const { width, height } = await getDimensions2(fileData);
901
+ ___default.default.assign(fileData, {
902
+ width,
903
+ height
904
+ });
905
+ const uploadThumbnail = async (thumbnailFile) => {
906
+ await getService("provider").upload(thumbnailFile);
907
+ ___default.default.set(fileData, "formats.thumbnail", thumbnailFile);
908
+ };
909
+ const uploadResponsiveFormat = async (format) => {
910
+ const { key, file: file2 } = format;
911
+ await getService("provider").upload(file2);
912
+ ___default.default.set(fileData, ["formats", key], file2);
913
+ };
914
+ const uploadPromises = [];
915
+ uploadPromises.push(getService("provider").upload(fileData));
916
+ if (await isResizableImage2(fileData)) {
917
+ const thumbnailFile = await generateThumbnail2(fileData);
918
+ if (thumbnailFile) {
919
+ uploadPromises.push(uploadThumbnail(thumbnailFile));
920
+ }
921
+ const formats = await generateResponsiveFormats2(fileData);
922
+ if (Array.isArray(formats) && formats.length > 0) {
923
+ for (const format of formats) {
924
+ if (!format)
925
+ continue;
926
+ uploadPromises.push(uploadResponsiveFormat(format));
927
+ }
928
+ }
929
+ }
930
+ await Promise.all(uploadPromises);
931
+ }
932
+ async function uploadFileAndPersist(fileData, opts) {
933
+ const { user } = opts ?? {};
934
+ const config2 = strapi2.config.get("plugin::upload");
935
+ const { isImage: isImage2 } = getService("image-manipulation");
936
+ await getService("provider").checkFileSize(fileData);
937
+ if (await isImage2(fileData)) {
938
+ await uploadImage(fileData);
939
+ } else {
940
+ await getService("provider").upload(fileData);
941
+ }
942
+ ___default.default.set(fileData, "provider", config2.provider);
943
+ return add(fileData, { user });
944
+ }
945
+ async function updateFileInfo(id, { name, alternativeText, caption, folder: folder2 }, opts) {
946
+ const { user } = opts ?? {};
947
+ const dbFile = await findOne(id);
948
+ if (!dbFile) {
949
+ throw new NotFoundError();
950
+ }
951
+ const fileService = getService("file");
952
+ const newName = ___default.default.isNil(name) ? dbFile.name : name;
953
+ const newInfos = {
954
+ name: newName,
955
+ alternativeText: ___default.default.isNil(alternativeText) ? dbFile.alternativeText : alternativeText,
956
+ caption: ___default.default.isNil(caption) ? dbFile.caption : caption,
957
+ folder: ___default.default.isUndefined(folder2) ? dbFile.folder : folder2,
958
+ folderPath: ___default.default.isUndefined(folder2) ? dbFile.path : await fileService.getFolderPath(folder2)
959
+ };
960
+ return update2(id, newInfos, { user });
961
+ }
962
+ async function replace(id, { data, file: file2 }, opts) {
963
+ const { user } = opts ?? {};
964
+ const config2 = strapi2.config.get("plugin::upload");
965
+ const { isImage: isImage2 } = getService("image-manipulation");
966
+ const dbFile = await findOne(id);
967
+ if (!dbFile) {
968
+ throw new NotFoundError();
969
+ }
970
+ const tmpWorkingDirectory = await createAndAssignTmpWorkingDirectoryToFiles(file2);
971
+ let fileData;
972
+ try {
973
+ const { fileInfo } = data;
974
+ fileData = await enhanceAndValidateFile(file2, fileInfo);
975
+ ___default.default.assign(fileData, {
976
+ hash: dbFile.hash,
977
+ ext: dbFile.ext
978
+ });
979
+ if (dbFile.provider === config2.provider) {
980
+ await strapi2.plugin("upload").provider.delete(dbFile);
981
+ if (dbFile.formats) {
982
+ await Promise.all(
983
+ Object.keys(dbFile.formats).map((key) => {
984
+ return strapi2.plugin("upload").provider.delete(dbFile.formats[key]);
985
+ })
986
+ );
987
+ }
988
+ }
989
+ ___default.default.set(fileData, "formats", {});
990
+ if (await isImage2(fileData)) {
991
+ await uploadImage(fileData);
992
+ } else {
993
+ await getService("provider").upload(fileData);
994
+ }
995
+ ___default.default.set(fileData, "provider", config2.provider);
996
+ } finally {
997
+ await fse__default.default.remove(tmpWorkingDirectory);
998
+ }
999
+ return update2(id, fileData, { user });
1000
+ }
1001
+ async function update2(id, values, opts) {
1002
+ const { user } = opts ?? {};
1003
+ const fileValues = { ...values };
1004
+ if (user) {
1005
+ Object.assign(fileValues, {
1006
+ [UPDATED_BY_ATTRIBUTE]: user.id
1007
+ });
1008
+ }
1009
+ sendMediaMetrics(fileValues);
1010
+ const res = await strapi2.db.query(FILE_MODEL_UID).update({ where: { id }, data: fileValues });
1011
+ await emitEvent(MEDIA_UPDATE, res);
1012
+ return res;
1013
+ }
1014
+ async function add(values, opts) {
1015
+ const { user } = opts ?? {};
1016
+ const fileValues = { ...values };
1017
+ if (user) {
1018
+ Object.assign(fileValues, {
1019
+ [UPDATED_BY_ATTRIBUTE]: user.id,
1020
+ [CREATED_BY_ATTRIBUTE]: user.id
1021
+ });
1022
+ }
1023
+ sendMediaMetrics(fileValues);
1024
+ const res = await strapi2.db.query(FILE_MODEL_UID).create({ data: fileValues });
1025
+ await emitEvent(MEDIA_CREATE, res);
1026
+ return res;
1027
+ }
1028
+ function findOne(id, populate = {}) {
1029
+ const query = strapi2.get("query-params").transform(FILE_MODEL_UID, {
1030
+ populate
1031
+ });
1032
+ return strapi2.db.query(FILE_MODEL_UID).findOne({
1033
+ where: { id },
1034
+ ...query
1035
+ });
1036
+ }
1037
+ function findMany(query = {}) {
1038
+ return strapi2.db.query(FILE_MODEL_UID).findMany(strapi2.get("query-params").transform(FILE_MODEL_UID, query));
1039
+ }
1040
+ function findPage(query = {}) {
1041
+ return strapi2.db.query(FILE_MODEL_UID).findPage(strapi2.get("query-params").transform(FILE_MODEL_UID, query));
1042
+ }
1043
+ async function remove(file2) {
1044
+ const config2 = strapi2.config.get("plugin::upload");
1045
+ if (file2.provider === config2.provider) {
1046
+ await strapi2.plugin("upload").provider.delete(file2);
1047
+ if (file2.formats) {
1048
+ const keys = Object.keys(file2.formats);
1049
+ await Promise.all(
1050
+ keys.map((key) => {
1051
+ return strapi2.plugin("upload").provider.delete(file2.formats[key]);
1052
+ })
1053
+ );
1054
+ }
1055
+ }
1056
+ const media = await strapi2.db.query(FILE_MODEL_UID).findOne({
1057
+ where: { id: file2.id }
1058
+ });
1059
+ await emitEvent(MEDIA_DELETE, media);
1060
+ return strapi2.db.query(FILE_MODEL_UID).delete({ where: { id: file2.id } });
1061
+ }
1062
+ async function getSettings() {
1063
+ const res = await strapi2.store({ type: "plugin", name: "upload", key: "settings" }).get({});
1064
+ return res;
1065
+ }
1066
+ function setSettings(value) {
1067
+ if (value.responsiveDimensions === true) {
1068
+ strapi2.telemetry.send("didEnableResponsiveDimensions");
1069
+ } else {
1070
+ strapi2.telemetry.send("didDisableResponsiveDimensions");
1071
+ }
1072
+ return strapi2.store({ type: "plugin", name: "upload", key: "settings" }).set({ value });
1073
+ }
1074
+ async function getConfiguration() {
1075
+ const res = await strapi2.store({
1076
+ type: "plugin",
1077
+ name: "upload",
1078
+ key: "view_configuration"
1079
+ }).get({});
1080
+ return res;
1081
+ }
1082
+ function setConfiguration(value) {
1083
+ return strapi2.store({ type: "plugin", name: "upload", key: "view_configuration" }).set({
1084
+ value
1085
+ });
1086
+ }
1087
+ return {
1088
+ formatFileInfo,
1089
+ upload: upload2,
1090
+ updateFileInfo,
1091
+ replace,
1092
+ findOne,
1093
+ findMany,
1094
+ findPage,
1095
+ remove,
1096
+ getSettings,
1097
+ setSettings,
1098
+ getConfiguration,
1099
+ setConfiguration,
1100
+ /**
1101
+ * exposed for testing only
1102
+ * @internal
1103
+ */
1104
+ _uploadImage: uploadImage
1105
+ };
1106
+ };
1107
+ const { bytesToKbytes } = utils.file;
1108
+ const FORMATS_TO_RESIZE = ["jpeg", "png", "webp", "tiff", "gif"];
1109
+ const FORMATS_TO_PROCESS = ["jpeg", "png", "webp", "tiff", "svg", "gif", "avif"];
1110
+ const FORMATS_TO_OPTIMIZE = ["jpeg", "png", "webp", "tiff", "avif"];
1111
+ const isOptimizableFormat = (format) => format !== void 0 && FORMATS_TO_OPTIMIZE.includes(format);
1112
+ const writeStreamToFile = (stream, path2) => new Promise((resolve, reject) => {
1113
+ const writeStream = fs__default.default.createWriteStream(path2);
1114
+ stream.on("error", reject);
1115
+ stream.pipe(writeStream);
1116
+ writeStream.on("close", resolve);
1117
+ writeStream.on("error", reject);
1118
+ });
1119
+ const getMetadata = (file2) => {
1120
+ if (!file2.filepath) {
1121
+ return new Promise((resolve, reject) => {
1122
+ const pipeline = sharp__default.default();
1123
+ pipeline.metadata().then(resolve).catch(reject);
1124
+ file2.getStream().pipe(pipeline);
1125
+ });
1126
+ }
1127
+ return sharp__default.default(file2.filepath).metadata();
1128
+ };
1129
+ const getDimensions = async (file2) => {
1130
+ const { width = null, height = null } = await getMetadata(file2);
1131
+ return { width, height };
1132
+ };
1133
+ const THUMBNAIL_RESIZE_OPTIONS = {
1134
+ width: 245,
1135
+ height: 156,
1136
+ fit: "inside"
1137
+ };
1138
+ const resizeFileTo = async (file2, options, {
1139
+ name,
1140
+ hash
1141
+ }) => {
1142
+ const filePath = file2.tmpWorkingDirectory ? path.join(file2.tmpWorkingDirectory, hash) : hash;
1143
+ let newInfo;
1144
+ if (!file2.filepath) {
1145
+ const transform = sharp__default.default().resize(options).on("info", (info) => {
1146
+ newInfo = info;
1147
+ });
1148
+ await writeStreamToFile(file2.getStream().pipe(transform), filePath);
1149
+ } else {
1150
+ newInfo = await sharp__default.default(file2.filepath).resize(options).toFile(filePath);
1151
+ }
1152
+ const { width, height, size } = newInfo ?? {};
1153
+ const newFile = {
1154
+ name,
1155
+ hash,
1156
+ ext: file2.ext,
1157
+ mime: file2.mime,
1158
+ filepath: filePath,
1159
+ path: file2.path || null,
1160
+ getStream: () => fs__default.default.createReadStream(filePath)
1161
+ };
1162
+ Object.assign(newFile, {
1163
+ width,
1164
+ height,
1165
+ size: size ? bytesToKbytes(size) : 0,
1166
+ sizeInBytes: size
1167
+ });
1168
+ return newFile;
1169
+ };
1170
+ const generateThumbnail = async (file2) => {
1171
+ if (file2.width && file2.height && (file2.width > THUMBNAIL_RESIZE_OPTIONS.width || file2.height > THUMBNAIL_RESIZE_OPTIONS.height)) {
1172
+ return resizeFileTo(file2, THUMBNAIL_RESIZE_OPTIONS, {
1173
+ name: `thumbnail_${file2.name}`,
1174
+ hash: `thumbnail_${file2.hash}`
1175
+ });
1176
+ }
1177
+ return null;
1178
+ };
1179
+ const optimize = async (file2) => {
1180
+ const { sizeOptimization = false, autoOrientation = false } = await getService("upload").getSettings() ?? {};
1181
+ const { format, size } = await getMetadata(file2);
1182
+ if ((sizeOptimization || autoOrientation) && isOptimizableFormat(format)) {
1183
+ let transformer;
1184
+ if (!file2.filepath) {
1185
+ transformer = sharp__default.default();
1186
+ } else {
1187
+ transformer = sharp__default.default(file2.filepath);
1188
+ }
1189
+ transformer[format]({ quality: sizeOptimization ? 80 : 100 });
1190
+ if (autoOrientation) {
1191
+ transformer.rotate();
1192
+ }
1193
+ const filePath = file2.tmpWorkingDirectory ? path.join(file2.tmpWorkingDirectory, `optimized-${file2.hash}`) : `optimized-${file2.hash}`;
1194
+ let newInfo;
1195
+ if (!file2.filepath) {
1196
+ transformer.on("info", (info) => {
1197
+ newInfo = info;
1198
+ });
1199
+ await writeStreamToFile(file2.getStream().pipe(transformer), filePath);
1200
+ } else {
1201
+ newInfo = await transformer.toFile(filePath);
1202
+ }
1203
+ const { width: newWidth, height: newHeight, size: newSize } = newInfo ?? {};
1204
+ const newFile = { ...file2 };
1205
+ newFile.getStream = () => fs__default.default.createReadStream(filePath);
1206
+ newFile.filepath = filePath;
1207
+ if (newSize && size && newSize > size) {
1208
+ return file2;
1209
+ }
1210
+ return Object.assign(newFile, {
1211
+ width: newWidth,
1212
+ height: newHeight,
1213
+ size: newSize ? bytesToKbytes(newSize) : 0,
1214
+ sizeInBytes: newSize
1215
+ });
1216
+ }
1217
+ return file2;
1218
+ };
1219
+ const DEFAULT_BREAKPOINTS = {
1220
+ large: 1e3,
1221
+ medium: 750,
1222
+ small: 500
1223
+ };
1224
+ const getBreakpoints = () => strapi.config.get("plugin::upload.breakpoints", DEFAULT_BREAKPOINTS);
1225
+ const generateResponsiveFormats = async (file2) => {
1226
+ const { responsiveDimensions = false } = await getService("upload").getSettings() ?? {};
1227
+ if (!responsiveDimensions)
1228
+ return [];
1229
+ const originalDimensions = await getDimensions(file2);
1230
+ const breakpoints = getBreakpoints();
1231
+ return Promise.all(
1232
+ Object.keys(breakpoints).map((key) => {
1233
+ const breakpoint = breakpoints[key];
1234
+ if (breakpointSmallerThan(breakpoint, originalDimensions)) {
1235
+ return generateBreakpoint(key, { file: file2, breakpoint });
1236
+ }
1237
+ return void 0;
1238
+ })
1239
+ );
1240
+ };
1241
+ const generateBreakpoint = async (key, { file: file2, breakpoint }) => {
1242
+ const newFile = await resizeFileTo(
1243
+ file2,
1244
+ {
1245
+ width: breakpoint,
1246
+ height: breakpoint,
1247
+ fit: "inside"
1248
+ },
1249
+ {
1250
+ name: `${key}_${file2.name}`,
1251
+ hash: `${key}_${file2.hash}`
1252
+ }
1253
+ );
1254
+ return {
1255
+ key,
1256
+ file: newFile
1257
+ };
1258
+ };
1259
+ const breakpointSmallerThan = (breakpoint, { width, height }) => {
1260
+ return breakpoint < (width ?? 0) || breakpoint < (height ?? 0);
1261
+ };
1262
+ const isFaultyImage = async (file2) => {
1263
+ if (!file2.filepath) {
1264
+ return new Promise((resolve, reject) => {
1265
+ const pipeline = sharp__default.default();
1266
+ pipeline.stats().then(resolve).catch(reject);
1267
+ file2.getStream().pipe(pipeline);
1268
+ });
1269
+ }
1270
+ try {
1271
+ await sharp__default.default(file2.filepath).stats();
1272
+ return false;
1273
+ } catch (e) {
1274
+ return true;
1275
+ }
1276
+ };
1277
+ const isOptimizableImage = async (file2) => {
1278
+ let format;
1279
+ try {
1280
+ const metadata = await getMetadata(file2);
1281
+ format = metadata.format;
1282
+ } catch (e) {
1283
+ return false;
1284
+ }
1285
+ return format && FORMATS_TO_OPTIMIZE.includes(format);
1286
+ };
1287
+ const isResizableImage = async (file2) => {
1288
+ let format;
1289
+ try {
1290
+ const metadata = await getMetadata(file2);
1291
+ format = metadata.format;
1292
+ } catch (e) {
1293
+ return false;
1294
+ }
1295
+ return format && FORMATS_TO_RESIZE.includes(format);
1296
+ };
1297
+ const isImage = async (file2) => {
1298
+ let format;
1299
+ try {
1300
+ const metadata = await getMetadata(file2);
1301
+ format = metadata.format;
1302
+ } catch (e) {
1303
+ return false;
1304
+ }
1305
+ return format && FORMATS_TO_PROCESS.includes(format);
1306
+ };
1307
+ const imageManipulation = {
1308
+ isFaultyImage,
1309
+ isOptimizableImage,
1310
+ isResizableImage,
1311
+ isImage,
1312
+ getDimensions,
1313
+ generateResponsiveFormats,
1314
+ generateThumbnail,
1315
+ optimize
1316
+ };
1317
+ const setPathIdAndPath = async (folder2) => {
1318
+ const { max } = await strapi.db.queryBuilder(FOLDER_MODEL_UID).max("pathId").first().execute();
1319
+ const pathId = max + 1;
1320
+ let parentPath = "/";
1321
+ if (folder2.parent) {
1322
+ const parentFolder = await strapi.db.query(FOLDER_MODEL_UID).findOne({ where: { id: folder2.parent } });
1323
+ parentPath = parentFolder.path;
1324
+ }
1325
+ return Object.assign(folder2, {
1326
+ pathId,
1327
+ path: utils.strings.joinBy("/", parentPath, `${pathId}`)
1328
+ });
1329
+ };
1330
+ const create = async (folderData, opts) => {
1331
+ const folderService = getService("folder");
1332
+ const { user } = opts || {};
1333
+ let enrichedFolder = await folderService.setPathIdAndPath(folderData);
1334
+ if (user) {
1335
+ enrichedFolder = await utils.setCreatorFields({ user })(enrichedFolder);
1336
+ }
1337
+ const folder2 = await strapi.db.query(FOLDER_MODEL_UID).create({ data: enrichedFolder });
1338
+ strapi.eventHub.emit("media-folder.create", { folder: folder2 });
1339
+ return folder2;
1340
+ };
1341
+ const deleteByIds$1 = async (ids = []) => {
1342
+ const folders = await strapi.db.query(FOLDER_MODEL_UID).findMany({ where: { id: { $in: ids } } });
1343
+ if (folders.length === 0) {
1344
+ return {
1345
+ folders: [],
1346
+ totalFolderNumber: 0,
1347
+ totalFileNumber: 0
1348
+ };
1349
+ }
1350
+ const pathsToDelete = fp.map("path", folders);
1351
+ const filesToDelete = await strapi.db.query(FILE_MODEL_UID).findMany({
1352
+ where: {
1353
+ $or: pathsToDelete.flatMap((path2) => [
1354
+ { folderPath: { $eq: path2 } },
1355
+ { folderPath: { $startsWith: `${path2}/` } }
1356
+ ])
1357
+ }
1358
+ });
1359
+ await Promise.all(filesToDelete.map((file2) => getService("upload").remove(file2)));
1360
+ const { count: totalFolderNumber } = await strapi.db.query(FOLDER_MODEL_UID).deleteMany({
1361
+ where: {
1362
+ $or: pathsToDelete.flatMap((path2) => [
1363
+ { path: { $eq: path2 } },
1364
+ { path: { $startsWith: `${path2}/` } }
1365
+ ])
1366
+ }
1367
+ });
1368
+ strapi.eventHub.emit("media-folder.delete", { folders });
1369
+ return {
1370
+ folders,
1371
+ totalFolderNumber,
1372
+ totalFileNumber: filesToDelete.length
1373
+ };
1374
+ };
1375
+ const update = async (id, {
1376
+ name,
1377
+ parent
1378
+ }, { user }) => {
1379
+ if (fp.isUndefined(parent)) {
1380
+ const existingFolder = await strapi.db.query(FOLDER_MODEL_UID).findOne({ where: { id } });
1381
+ if (!existingFolder) {
1382
+ return void 0;
1383
+ }
1384
+ const newFolder = utils.setCreatorFields({ user, isEdition: true })({ name, parent });
1385
+ if (fp.isUndefined(parent)) {
1386
+ const folder2 = await strapi.db.query(FOLDER_MODEL_UID).update({ where: { id }, data: newFolder });
1387
+ return folder2;
1388
+ }
1389
+ } else {
1390
+ const trx = await strapi.db.transaction();
1391
+ try {
1392
+ const existingFolder = await strapi.db.queryBuilder(FOLDER_MODEL_UID).select(["pathId", "path"]).where({ id }).transacting(trx.get()).forUpdate().first().execute();
1393
+ const { joinTable } = strapi.db.metadata.get(FOLDER_MODEL_UID).attributes.parent;
1394
+ await strapi.db.queryBuilder(joinTable.name).transacting(trx.get()).delete().where({ [joinTable.joinColumn.name]: id }).execute();
1395
+ if (parent !== null) {
1396
+ await strapi.db.queryBuilder(joinTable.name).transacting(trx.get()).insert({ [joinTable.inverseJoinColumn.name]: parent, [joinTable.joinColumn.name]: id }).where({ [joinTable.joinColumn.name]: id }).execute();
1397
+ }
1398
+ let destinationFolderPath = "/";
1399
+ if (parent !== null) {
1400
+ const destinationFolder = await strapi.db.queryBuilder(FOLDER_MODEL_UID).select("path").where({ id: parent }).transacting(trx.get()).first().execute();
1401
+ destinationFolderPath = destinationFolder.path;
1402
+ }
1403
+ const folderTable = strapi.getModel(FOLDER_MODEL_UID).collectionName;
1404
+ const fileTable = strapi.getModel(FILE_MODEL_UID).collectionName;
1405
+ const folderPathColumnName = (
1406
+ // @ts-expect-error - no dynamic types
1407
+ strapi.db.metadata.get(FILE_MODEL_UID).attributes.folderPath.columnName
1408
+ );
1409
+ const pathColumnName = strapi.db.metadata.get(FOLDER_MODEL_UID).attributes.path.columnName;
1410
+ await strapi.db.getConnection(folderTable).transacting(trx.get()).where(pathColumnName, existingFolder.path).orWhere(pathColumnName, "like", `${existingFolder.path}/%`).update(
1411
+ pathColumnName,
1412
+ strapi.db.connection.raw("REPLACE(??, ?, ?)", [
1413
+ pathColumnName,
1414
+ existingFolder.path,
1415
+ utils.strings.joinBy("/", destinationFolderPath, `${existingFolder.pathId}`)
1416
+ ])
1417
+ );
1418
+ await strapi.db.getConnection(fileTable).transacting(trx.get()).where(folderPathColumnName, existingFolder.path).orWhere(folderPathColumnName, "like", `${existingFolder.path}/%`).update(
1419
+ folderPathColumnName,
1420
+ strapi.db.connection.raw("REPLACE(??, ?, ?)", [
1421
+ folderPathColumnName,
1422
+ existingFolder.path,
1423
+ utils.strings.joinBy("/", destinationFolderPath, `${existingFolder.pathId}`)
1424
+ ])
1425
+ );
1426
+ await trx.commit();
1427
+ } catch (e) {
1428
+ await trx.rollback();
1429
+ throw e;
1430
+ }
1431
+ const newFolder = utils.setCreatorFields({ user, isEdition: true })({ name });
1432
+ const folder2 = await strapi.db.query(FOLDER_MODEL_UID).update({ where: { id }, data: newFolder });
1433
+ strapi.eventHub.emit("media-folder.update", { folder: folder2 });
1434
+ return folder2;
1435
+ }
1436
+ };
1437
+ const exists = async (params = {}) => {
1438
+ const count = await strapi.db.query(FOLDER_MODEL_UID).count({ where: params });
1439
+ return count > 0;
1440
+ };
1441
+ const getStructure = async () => {
1442
+ const { joinTable } = strapi.db.metadata.get(FOLDER_MODEL_UID).attributes.parent;
1443
+ const qb = strapi.db.queryBuilder(FOLDER_MODEL_UID);
1444
+ const alias = qb.getAlias();
1445
+ const folders = await qb.select(["id", "name", `${alias}.${joinTable.inverseJoinColumn.name} as parent`]).join({
1446
+ alias,
1447
+ referencedTable: joinTable.name,
1448
+ referencedColumn: joinTable.joinColumn.name,
1449
+ rootColumn: joinTable.joinColumn.referencedColumn,
1450
+ rootTable: qb.alias
1451
+ }).execute({ mapResults: false });
1452
+ const folderMap = {
1453
+ null: { children: [] }
1454
+ };
1455
+ folders.forEach((f) => {
1456
+ folderMap[f.id] = { ...f, children: [] };
1457
+ });
1458
+ folders.forEach((f) => {
1459
+ const parentId = f.parent || "null";
1460
+ if (!folderMap[parentId]) {
1461
+ folderMap[parentId] = { children: [] };
1462
+ }
1463
+ folderMap[parentId].children.push(folderMap[f.id]);
1464
+ folderMap[parentId].children = fp.sortBy("name", folderMap[parentId].children);
1465
+ delete folderMap[f.id].parent;
1466
+ });
1467
+ return folderMap.null.children;
1468
+ };
1469
+ const folder = {
1470
+ create,
1471
+ exists,
1472
+ deleteByIds: deleteByIds$1,
1473
+ update,
1474
+ setPathIdAndPath,
1475
+ getStructure
1476
+ };
1477
+ const getFolderPath = async (folderId) => {
1478
+ if (!folderId)
1479
+ return "/";
1480
+ const parentFolder = await strapi.db.query(FOLDER_MODEL_UID).findOne({ where: { id: folderId } });
1481
+ return parentFolder.path;
1482
+ };
1483
+ const deleteByIds = async (ids = []) => {
1484
+ const filesToDelete = await strapi.db.query(FILE_MODEL_UID).findMany({ where: { id: { $in: ids } } });
1485
+ await Promise.all(filesToDelete.map((file2) => getService("upload").remove(file2)));
1486
+ return filesToDelete;
1487
+ };
1488
+ const signFileUrls = async (file2) => {
1489
+ const { provider: provider2 } = strapi.plugins.upload;
1490
+ const { provider: providerConfig } = strapi.config.get("plugin::upload");
1491
+ const isPrivate = await provider2.isPrivate();
1492
+ file2.isUrlSigned = false;
1493
+ if (file2.provider !== providerConfig || !isPrivate) {
1494
+ return file2;
1495
+ }
1496
+ const signUrl = async (file22) => {
1497
+ const signedUrl = await provider2.getSignedUrl(file22);
1498
+ file22.url = signedUrl.url;
1499
+ file22.isUrlSigned = true;
1500
+ };
1501
+ const signedFile = fp.cloneDeep(file2);
1502
+ await signUrl(signedFile);
1503
+ if (file2.formats) {
1504
+ await utils.async.map(Object.values(signedFile.formats ?? {}), signUrl);
1505
+ }
1506
+ return signedFile;
1507
+ };
1508
+ const file = { getFolderPath, deleteByIds, signFileUrls };
1509
+ const getWeeklyCronScheduleAt = (date) => `${date.getSeconds()} ${date.getMinutes()} ${date.getHours()} * * ${date.getDay()}`;
1510
+ const ONE_WEEK = 7 * 24 * 60 * 60 * 1e3;
1511
+ const getMetricsStoreValue = async () => {
1512
+ const value = await strapi.store.get({ type: "plugin", name: "upload", key: "metrics" });
1513
+ return fp.defaultTo({}, value);
1514
+ };
1515
+ const setMetricsStoreValue = (value) => strapi.store.set({ type: "plugin", name: "upload", key: "metrics", value });
1516
+ const weeklyMetrics = ({ strapi: strapi2 }) => ({
1517
+ async computeMetrics() {
1518
+ const pathColName = strapi2.db.metadata.get(FOLDER_MODEL_UID).attributes.path.columnName;
1519
+ const folderTable = strapi2.getModel(FOLDER_MODEL_UID).collectionName;
1520
+ let keepOnlySlashesSQLString = "??";
1521
+ const queryParams = [pathColName];
1522
+ for (let i = 0; i < 10; i += 1) {
1523
+ keepOnlySlashesSQLString = `REPLACE(${keepOnlySlashesSQLString}, ?, ?)`;
1524
+ queryParams.push(String(i), "");
1525
+ }
1526
+ const res = await strapi2.db.getConnection(folderTable).select(
1527
+ strapi2.db.connection.raw(
1528
+ `LENGTH(${keepOnlySlashesSQLString}) AS depth, COUNT(*) AS occurence`,
1529
+ queryParams
1530
+ )
1531
+ ).groupBy("depth");
1532
+ const folderLevelsArray = res.map((map) => ({
1533
+ depth: Number(map.depth),
1534
+ occurence: Number(map.occurence)
1535
+ }));
1536
+ let product = 0;
1537
+ let folderNumber = 0;
1538
+ let maxDepth = 0;
1539
+ for (const folderLevel of folderLevelsArray) {
1540
+ product += folderLevel.depth * folderLevel.occurence;
1541
+ folderNumber += folderLevel.occurence;
1542
+ if (folderLevel.depth > maxDepth) {
1543
+ maxDepth = folderLevel.depth;
1544
+ }
1545
+ }
1546
+ const averageDepth = folderNumber !== 0 ? product / folderNumber : 0;
1547
+ let sumOfDeviation = 0;
1548
+ for (const folderLevel of folderLevelsArray) {
1549
+ sumOfDeviation += Math.abs(folderLevel.depth - averageDepth) * folderLevel.occurence;
1550
+ }
1551
+ const averageDeviationDepth = folderNumber !== 0 ? sumOfDeviation / folderNumber : 0;
1552
+ const assetNumber = await strapi2.db.query(FILE_MODEL_UID).count();
1553
+ return {
1554
+ assetNumber,
1555
+ folderNumber,
1556
+ averageDepth,
1557
+ maxDepth,
1558
+ averageDeviationDepth
1559
+ };
1560
+ },
1561
+ async sendMetrics() {
1562
+ const metrics2 = await this.computeMetrics();
1563
+ strapi2.telemetry.send("didSendUploadPropertiesOnceAWeek", {
1564
+ groupProperties: { metrics: metrics2 }
1565
+ });
1566
+ const metricsInfoStored = await getMetricsStoreValue();
1567
+ await setMetricsStoreValue({ ...metricsInfoStored, lastWeeklyUpdate: (/* @__PURE__ */ new Date()).getTime() });
1568
+ },
1569
+ async ensureWeeklyStoredCronSchedule() {
1570
+ const metricsInfoStored = await getMetricsStoreValue();
1571
+ const { weeklySchedule: currentSchedule, lastWeeklyUpdate } = metricsInfoStored;
1572
+ const now = /* @__PURE__ */ new Date();
1573
+ let weeklySchedule = currentSchedule;
1574
+ if (!weeklySchedule || !lastWeeklyUpdate || lastWeeklyUpdate + ONE_WEEK < now.getTime()) {
1575
+ weeklySchedule = getWeeklyCronScheduleAt(dateFns.add(now, { minutes: 5 }));
1576
+ await setMetricsStoreValue({ ...metricsInfoStored, weeklySchedule });
1577
+ return weeklySchedule;
1578
+ }
1579
+ return weeklySchedule;
1580
+ },
1581
+ async registerCron() {
1582
+ const weeklySchedule = await this.ensureWeeklyStoredCronSchedule();
1583
+ strapi2.cron.add({ [weeklySchedule]: this.sendMetrics.bind(this) });
1584
+ }
1585
+ });
1586
+ const getProviderName = () => strapi.config.get("plugin::upload.provider", "local");
1587
+ const isProviderPrivate = async () => strapi.plugin("upload").provider.isPrivate();
1588
+ const metrics = ({ strapi: strapi2 }) => ({
1589
+ async sendUploadPluginMetrics() {
1590
+ const uploadProvider = getProviderName();
1591
+ const privateProvider = await isProviderPrivate();
1592
+ strapi2.telemetry.send("didInitializePluginUpload", {
1593
+ groupProperties: {
1594
+ uploadProvider,
1595
+ privateProvider
1596
+ }
1597
+ });
1598
+ }
1599
+ });
1600
+ const getStore = () => strapi.store({ type: "plugin", name: "upload", key: "api-folder" });
1601
+ const createApiUploadFolder = async () => {
1602
+ let name = API_UPLOAD_FOLDER_BASE_NAME;
1603
+ const folderService = getService("folder");
1604
+ let exists2 = true;
1605
+ let index2 = 1;
1606
+ while (exists2) {
1607
+ exists2 = await folderService.exists({ name, parent: null });
1608
+ if (exists2) {
1609
+ name = `${API_UPLOAD_FOLDER_BASE_NAME} (${index2})`;
1610
+ index2 += 1;
1611
+ }
1612
+ }
1613
+ const folder2 = await folderService.create({ name });
1614
+ await getStore().set({ value: { id: folder2.id } });
1615
+ return folder2;
1616
+ };
1617
+ const getAPIUploadFolder = async () => {
1618
+ const storeValue = await getStore().get({});
1619
+ const folderId = fp.get("id", storeValue);
1620
+ const folder2 = folderId ? await strapi.db.query(FOLDER_MODEL_UID).findOne({ where: { id: folderId } }) : null;
1621
+ return fp.isNil(folder2) ? createApiUploadFolder() : folder2;
1622
+ };
1623
+ const apiUploadFolder = {
1624
+ getAPIUploadFolder
1625
+ };
1626
+ const addSignedFileUrlsToAdmin = async () => {
1627
+ };
1628
+ const entityManager = { addSignedFileUrlsToAdmin };
1629
+ const contentManager = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1630
+ __proto__: null,
1631
+ entityManager
1632
+ }, Symbol.toStringTag, { value: "Module" }));
1633
+ const addSignedFileUrlsToEntityService = async () => {
1634
+ };
1635
+ const entityService = { addSignedFileUrlsToEntityService };
1636
+ const core = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1637
+ __proto__: null,
1638
+ entityService
1639
+ }, Symbol.toStringTag, { value: "Module" }));
1640
+ const extensions = {
1641
+ contentManager,
1642
+ core
1643
+ };
1644
+ const services = {
1645
+ provider,
1646
+ upload,
1647
+ folder,
1648
+ file,
1649
+ weeklyMetrics,
1650
+ metrics,
1651
+ "image-manipulation": imageManipulation,
1652
+ "api-upload-folder": apiUploadFolder,
1653
+ extensions
1654
+ };
1655
+ const routes$3 = {
1656
+ type: "admin",
1657
+ routes: [
1658
+ {
1659
+ method: "GET",
1660
+ path: "/settings",
1661
+ handler: "admin-settings.getSettings",
1662
+ config: {
1663
+ policies: [
1664
+ "admin::isAuthenticatedAdmin",
1665
+ {
1666
+ name: "admin::hasPermissions",
1667
+ config: {
1668
+ actions: ["plugin::upload.settings.read"]
1669
+ }
1670
+ }
1671
+ ]
1672
+ }
1673
+ },
1674
+ {
1675
+ method: "PUT",
1676
+ path: "/settings",
1677
+ handler: "admin-settings.updateSettings",
1678
+ config: {
1679
+ policies: [
1680
+ "admin::isAuthenticatedAdmin",
1681
+ {
1682
+ name: "admin::hasPermissions",
1683
+ config: {
1684
+ actions: ["plugin::upload.settings.read"]
1685
+ }
1686
+ }
1687
+ ]
1688
+ }
1689
+ },
1690
+ {
1691
+ method: "POST",
1692
+ path: "/",
1693
+ handler: "admin-upload.upload",
1694
+ config: {
1695
+ policies: ["admin::isAuthenticatedAdmin"]
1696
+ }
1697
+ },
1698
+ {
1699
+ method: "GET",
1700
+ path: "/files",
1701
+ handler: "admin-file.find",
1702
+ config: {
1703
+ policies: [
1704
+ "admin::isAuthenticatedAdmin",
1705
+ {
1706
+ name: "admin::hasPermissions",
1707
+ config: {
1708
+ actions: ["plugin::upload.read"]
1709
+ }
1710
+ }
1711
+ ]
1712
+ }
1713
+ },
1714
+ {
1715
+ method: "GET",
1716
+ path: "/files/:id",
1717
+ handler: "admin-file.findOne",
1718
+ config: {
1719
+ policies: [
1720
+ "admin::isAuthenticatedAdmin",
1721
+ {
1722
+ name: "admin::hasPermissions",
1723
+ config: {
1724
+ actions: ["plugin::upload.read"]
1725
+ }
1726
+ }
1727
+ ]
1728
+ }
1729
+ },
1730
+ {
1731
+ method: "DELETE",
1732
+ path: "/files/:id",
1733
+ handler: "admin-file.destroy",
1734
+ config: {
1735
+ policies: [
1736
+ "admin::isAuthenticatedAdmin",
1737
+ {
1738
+ name: "admin::hasPermissions",
1739
+ config: {
1740
+ actions: ["plugin::upload.assets.update"]
1741
+ }
1742
+ }
1743
+ ]
1744
+ }
1745
+ },
1746
+ {
1747
+ method: "GET",
1748
+ path: "/folders/:id",
1749
+ handler: "admin-folder.findOne",
1750
+ config: {
1751
+ policies: [
1752
+ "admin::isAuthenticatedAdmin",
1753
+ {
1754
+ name: "admin::hasPermissions",
1755
+ config: {
1756
+ actions: ["plugin::upload.read"]
1757
+ }
1758
+ }
1759
+ ]
1760
+ }
1761
+ },
1762
+ {
1763
+ method: "GET",
1764
+ path: "/folders",
1765
+ handler: "admin-folder.find",
1766
+ config: {
1767
+ policies: [
1768
+ "admin::isAuthenticatedAdmin",
1769
+ {
1770
+ name: "admin::hasPermissions",
1771
+ config: {
1772
+ actions: ["plugin::upload.read"]
1773
+ }
1774
+ }
1775
+ ]
1776
+ }
1777
+ },
1778
+ {
1779
+ method: "POST",
1780
+ path: "/folders",
1781
+ handler: "admin-folder.create",
1782
+ config: {
1783
+ policies: [
1784
+ "admin::isAuthenticatedAdmin",
1785
+ {
1786
+ name: "admin::hasPermissions",
1787
+ config: {
1788
+ actions: ["plugin::upload.assets.create"]
1789
+ }
1790
+ }
1791
+ ]
1792
+ }
1793
+ },
1794
+ {
1795
+ method: "PUT",
1796
+ path: "/folders/:id",
1797
+ handler: "admin-folder.update",
1798
+ config: {
1799
+ policies: [
1800
+ "admin::isAuthenticatedAdmin",
1801
+ {
1802
+ name: "admin::hasPermissions",
1803
+ config: {
1804
+ actions: ["plugin::upload.assets.update"]
1805
+ }
1806
+ }
1807
+ ]
1808
+ }
1809
+ },
1810
+ {
1811
+ method: "GET",
1812
+ path: "/folder-structure",
1813
+ handler: "admin-folder.getStructure",
1814
+ config: {
1815
+ policies: [
1816
+ "admin::isAuthenticatedAdmin",
1817
+ {
1818
+ name: "admin::hasPermissions",
1819
+ config: {
1820
+ actions: ["plugin::upload.read"]
1821
+ }
1822
+ }
1823
+ ]
1824
+ }
1825
+ },
1826
+ {
1827
+ method: "POST",
1828
+ path: "/actions/bulk-delete",
1829
+ handler: "admin-folder-file.deleteMany",
1830
+ config: {
1831
+ policies: [
1832
+ "admin::isAuthenticatedAdmin",
1833
+ {
1834
+ name: "admin::hasPermissions",
1835
+ config: {
1836
+ actions: ["plugin::upload.assets.update"]
1837
+ }
1838
+ }
1839
+ ]
1840
+ }
1841
+ },
1842
+ {
1843
+ method: "POST",
1844
+ path: "/actions/bulk-move",
1845
+ handler: "admin-folder-file.moveMany",
1846
+ config: {
1847
+ policies: [
1848
+ "admin::isAuthenticatedAdmin",
1849
+ {
1850
+ name: "admin::hasPermissions",
1851
+ config: {
1852
+ actions: ["plugin::upload.assets.update"]
1853
+ }
1854
+ }
1855
+ ]
1856
+ }
1857
+ }
1858
+ ]
1859
+ };
1860
+ const routes$2 = {
1861
+ type: "content-api",
1862
+ routes: [
1863
+ {
1864
+ method: "POST",
1865
+ path: "/",
1866
+ handler: "content-api.upload"
1867
+ },
1868
+ {
1869
+ method: "GET",
1870
+ path: "/files",
1871
+ handler: "content-api.find"
1872
+ },
1873
+ {
1874
+ method: "GET",
1875
+ path: "/files/:id",
1876
+ handler: "content-api.findOne"
1877
+ },
1878
+ {
1879
+ method: "DELETE",
1880
+ path: "/files/:id",
1881
+ handler: "content-api.destroy"
1882
+ }
1883
+ ]
1884
+ };
1885
+ const routes$1 = {
1886
+ type: "admin",
1887
+ routes: [
1888
+ {
1889
+ method: "GET",
1890
+ path: "/configuration",
1891
+ handler: "view-configuration.findViewConfiguration",
1892
+ config: {
1893
+ policies: ["admin::isAuthenticatedAdmin"]
1894
+ }
1895
+ },
1896
+ {
1897
+ method: "PUT",
1898
+ path: "/configuration",
1899
+ handler: "view-configuration.updateViewConfiguration",
1900
+ config: {
1901
+ policies: [
1902
+ "admin::isAuthenticatedAdmin",
1903
+ {
1904
+ name: "admin::hasPermissions",
1905
+ config: {
1906
+ actions: [ACTIONS.configureView]
1907
+ }
1908
+ }
1909
+ ]
1910
+ }
1911
+ }
1912
+ ]
1913
+ };
1914
+ const routes = {
1915
+ admin: routes$3,
1916
+ "content-api": routes$2,
1917
+ viewConfiguration: routes$1
1918
+ };
1919
+ const config = {
1920
+ default: {
1921
+ enabled: true,
1922
+ provider: "local",
1923
+ sizeLimit: 1e9,
1924
+ // 1GB
1925
+ actionOptions: {}
1926
+ },
1927
+ validator() {
1928
+ }
1929
+ };
1930
+ const findEntityAndCheckPermissions = async (ability, action, model, id) => {
1931
+ const file2 = await getService("upload").findOne(id, [
1932
+ utils.contentTypes.constants.CREATED_BY_ATTRIBUTE,
1933
+ "folder"
1934
+ ]);
1935
+ if (___default.default.isNil(file2)) {
1936
+ throw new utils.errors.NotFoundError();
1937
+ }
1938
+ const pm = strapi.service("admin::permission").createPermissionsManager({ ability, action, model });
1939
+ const creatorId = ___default.default.get(file2, [utils.contentTypes.constants.CREATED_BY_ATTRIBUTE, "id"]);
1940
+ const author = creatorId ? await strapi.service("admin::user").findOne(creatorId, ["roles"]) : null;
1941
+ const fileWithRoles = ___default.default.set(___default.default.cloneDeep(file2), "createdBy", author);
1942
+ if (pm.ability.cannot(pm.action, pm.toSubject(fileWithRoles))) {
1943
+ throw new utils.errors.ForbiddenError();
1944
+ }
1945
+ return { pm, file: file2 };
1946
+ };
1947
+ const adminFile = {
1948
+ async find(ctx) {
1949
+ const {
1950
+ state: { userAbility }
1951
+ } = ctx;
1952
+ const defaultQuery = { populate: { folder: true } };
1953
+ const pm = strapi.service("admin::permission").createPermissionsManager({
1954
+ ability: userAbility,
1955
+ action: ACTIONS.read,
1956
+ model: FILE_MODEL_UID
1957
+ });
1958
+ if (!pm.isAllowed) {
1959
+ return ctx.forbidden();
1960
+ }
1961
+ await pm.validateQuery(ctx.query);
1962
+ const query = await utils.async.pipe(
1963
+ // Start by sanitizing the incoming query
1964
+ (q) => pm.sanitizeQuery(q),
1965
+ // Add the default query which should not be validated or sanitized
1966
+ (q) => fp.merge(defaultQuery, q),
1967
+ // Add the dynamic filters based on permissions' conditions
1968
+ (q) => pm.addPermissionsQueryTo(q)
1969
+ )(ctx.query);
1970
+ const { results: files, pagination } = await getService("upload").findPage(query);
1971
+ const signedFiles = await utils.async.map(files, getService("file").signFileUrls);
1972
+ const sanitizedFiles = await pm.sanitizeOutput(signedFiles);
1973
+ return { results: sanitizedFiles, pagination };
1974
+ },
1975
+ async findOne(ctx) {
1976
+ const {
1977
+ state: { userAbility },
1978
+ params: { id }
1979
+ } = ctx;
1980
+ const { pm, file: file2 } = await findEntityAndCheckPermissions(
1981
+ userAbility,
1982
+ ACTIONS.read,
1983
+ FILE_MODEL_UID,
1984
+ id
1985
+ );
1986
+ const signedFile = await getService("file").signFileUrls(file2);
1987
+ ctx.body = await pm.sanitizeOutput(signedFile);
1988
+ },
1989
+ async destroy(ctx) {
1990
+ const { id } = ctx.params;
1991
+ const { userAbility } = ctx.state;
1992
+ const { pm, file: file2 } = await findEntityAndCheckPermissions(
1993
+ userAbility,
1994
+ ACTIONS.update,
1995
+ FILE_MODEL_UID,
1996
+ id
1997
+ );
1998
+ const [body] = await Promise.all([
1999
+ pm.sanitizeOutput(file2, { action: ACTIONS.read }),
2000
+ getService("upload").remove(file2)
2001
+ ]);
2002
+ ctx.body = body;
2003
+ }
2004
+ };
2005
+ const folderExists = async (folderId) => {
2006
+ if (fp.isNil(folderId)) {
2007
+ return true;
2008
+ }
2009
+ const exists2 = await getService("folder").exists({ id: folderId });
2010
+ return exists2;
2011
+ };
2012
+ const isFolderOrChild = (folderOrChild, folder2) => folderOrChild.path === folder2.path || folderOrChild.path.startsWith(`${folder2.path}/`);
2013
+ const NO_SLASH_REGEX = /^[^/]+$/;
2014
+ const NO_SPACES_AROUND = /^(?! ).+(?<! )$/;
2015
+ const isNameUniqueInFolder = (id) => {
2016
+ return async function test(name) {
2017
+ const { exists: exists2 } = getService("folder");
2018
+ const filters = { name, parent: this.parent.parent || null };
2019
+ if (id) {
2020
+ filters.id = { $ne: id };
2021
+ if (fp.isUndefined(name)) {
2022
+ const existingFolder = await strapi.db.query(FOLDER_MODEL_UID).findOne({ where: { id } });
2023
+ filters.name = fp.get("name", existingFolder);
2024
+ }
2025
+ }
2026
+ const doesExist = await exists2(filters);
2027
+ return !doesExist;
2028
+ };
2029
+ };
2030
+ const validateCreateFolderSchema = utils.yup.object().shape({
2031
+ name: utils.yup.string().min(1).matches(NO_SLASH_REGEX, "name cannot contain slashes").matches(NO_SPACES_AROUND, "name cannot start or end with a whitespace").required().test("is-folder-unique", "A folder with this name already exists", isNameUniqueInFolder()),
2032
+ parent: utils.yup.strapiID().nullable().test("folder-exists", "parent folder does not exist", folderExists)
2033
+ }).noUnknown().required();
2034
+ const validateUpdateFolderSchema = (id) => utils.yup.object().shape({
2035
+ name: utils.yup.string().min(1).matches(NO_SLASH_REGEX, "name cannot contain slashes").matches(NO_SPACES_AROUND, "name cannot start or end with a whitespace").test(
2036
+ "is-folder-unique",
2037
+ "A folder with this name already exists",
2038
+ isNameUniqueInFolder(id)
2039
+ ),
2040
+ parent: utils.yup.strapiID().nullable().test("folder-exists", "parent folder does not exist", folderExists).test(
2041
+ "dont-move-inside-self",
2042
+ "folder cannot be moved inside itself",
2043
+ async function test(parent) {
2044
+ if (fp.isNil(parent))
2045
+ return true;
2046
+ const destinationFolder = await strapi.db.query(FOLDER_MODEL_UID).findOne({
2047
+ select: ["path"],
2048
+ where: { id: parent }
2049
+ });
2050
+ const currentFolder = await strapi.db.query(FOLDER_MODEL_UID).findOne({
2051
+ select: ["path"],
2052
+ where: { id }
2053
+ });
2054
+ if (!destinationFolder || !currentFolder)
2055
+ return true;
2056
+ return !isFolderOrChild(destinationFolder, currentFolder);
2057
+ }
2058
+ )
2059
+ }).noUnknown().required();
2060
+ const validateCreateFolder = utils.validateYupSchema(validateCreateFolderSchema);
2061
+ const validateUpdateFolder = (id) => utils.validateYupSchema(validateUpdateFolderSchema(id));
2062
+ const adminFolder = {
2063
+ async findOne(ctx) {
2064
+ const { id } = ctx.params;
2065
+ const permissionsManager = strapi.service("admin::permission").createPermissionsManager({
2066
+ ability: ctx.state.userAbility,
2067
+ model: FOLDER_MODEL_UID
2068
+ });
2069
+ await permissionsManager.validateQuery(ctx.query);
2070
+ const query = await permissionsManager.sanitizeQuery(ctx.query);
2071
+ const { results } = await strapi.db.query(FOLDER_MODEL_UID).findPage(
2072
+ strapi.get("query-params").transform(
2073
+ FOLDER_MODEL_UID,
2074
+ fp.defaultsDeep(
2075
+ {
2076
+ filters: { id },
2077
+ populate: {
2078
+ children: {
2079
+ count: true
2080
+ },
2081
+ files: {
2082
+ count: true
2083
+ }
2084
+ }
2085
+ },
2086
+ query
2087
+ )
2088
+ )
2089
+ );
2090
+ if (results.length === 0) {
2091
+ return ctx.notFound("folder not found");
2092
+ }
2093
+ ctx.body = {
2094
+ data: await permissionsManager.sanitizeOutput(results[0])
2095
+ };
2096
+ },
2097
+ async find(ctx) {
2098
+ const permissionsManager = strapi.service("admin::permission").createPermissionsManager({
2099
+ ability: ctx.state.userAbility,
2100
+ model: FOLDER_MODEL_UID
2101
+ });
2102
+ await permissionsManager.validateQuery(ctx.query);
2103
+ const query = await permissionsManager.sanitizeQuery(ctx.query);
2104
+ const results = await strapi.db.query(FOLDER_MODEL_UID).findMany(
2105
+ strapi.get("query-params").transform(
2106
+ FOLDER_MODEL_UID,
2107
+ fp.defaultsDeep(
2108
+ {
2109
+ populate: {
2110
+ children: {
2111
+ count: true
2112
+ },
2113
+ files: {
2114
+ count: true
2115
+ }
2116
+ }
2117
+ },
2118
+ query
2119
+ )
2120
+ )
2121
+ );
2122
+ ctx.body = {
2123
+ data: await permissionsManager.sanitizeOutput(results)
2124
+ };
2125
+ },
2126
+ async create(ctx) {
2127
+ const { user } = ctx.state;
2128
+ const { body } = ctx.request;
2129
+ await validateCreateFolder(body);
2130
+ const folderService = getService("folder");
2131
+ const folder2 = await folderService.create(body, { user });
2132
+ const permissionsManager = strapi.service("admin::permission").createPermissionsManager({
2133
+ ability: ctx.state.userAbility,
2134
+ model: FOLDER_MODEL_UID
2135
+ });
2136
+ ctx.created({
2137
+ data: await permissionsManager.sanitizeOutput(folder2)
2138
+ });
2139
+ },
2140
+ async update(ctx) {
2141
+ const { id } = ctx.params;
2142
+ const { user } = ctx.state;
2143
+ const { body } = ctx.request;
2144
+ const permissionsManager = strapi.service("admin::permission").createPermissionsManager({
2145
+ ability: ctx.state.userAbility,
2146
+ model: FOLDER_MODEL_UID
2147
+ });
2148
+ await validateUpdateFolder(id)(body);
2149
+ const folderService = getService("folder");
2150
+ const updatedFolder = await folderService.update(id, body, { user });
2151
+ if (!updatedFolder) {
2152
+ return ctx.notFound("folder not found");
2153
+ }
2154
+ ctx.body = {
2155
+ data: await permissionsManager.sanitizeOutput(updatedFolder)
2156
+ };
2157
+ },
2158
+ async getStructure(ctx) {
2159
+ const { getStructure: getStructure2 } = getService("folder");
2160
+ const structure = await getStructure2();
2161
+ ctx.body = {
2162
+ data: structure
2163
+ };
2164
+ }
2165
+ };
2166
+ const validateDeleteManyFoldersFilesSchema = utils.yup.object().shape({
2167
+ fileIds: utils.yup.array().of(utils.yup.strapiID().required()),
2168
+ folderIds: utils.yup.array().of(utils.yup.strapiID().required())
2169
+ }).noUnknown().required();
2170
+ const validateStructureMoveManyFoldersFilesSchema = utils.yup.object().shape({
2171
+ destinationFolderId: utils.yup.strapiID().nullable().defined().test("folder-exists", "destination folder does not exist", folderExists),
2172
+ fileIds: utils.yup.array().of(utils.yup.strapiID().required()),
2173
+ folderIds: utils.yup.array().of(utils.yup.strapiID().required())
2174
+ }).noUnknown().required();
2175
+ const validateDuplicatesMoveManyFoldersFilesSchema = utils.yup.object().test("are-folders-unique", "some folders already exist", async function(value) {
2176
+ const { folderIds, destinationFolderId } = value;
2177
+ if (fp.isEmpty(folderIds))
2178
+ return true;
2179
+ const folders = await strapi.db.query(FOLDER_MODEL_UID).findMany({
2180
+ select: ["name"],
2181
+ where: { id: { $in: folderIds } }
2182
+ });
2183
+ const existingFolders = await strapi.db.query(FOLDER_MODEL_UID).findMany({
2184
+ select: ["name"],
2185
+ where: { parent: { id: destinationFolderId } }
2186
+ });
2187
+ const duplicatedNames = fp.intersection(fp.map("name", folders), fp.map("name", existingFolders));
2188
+ if (duplicatedNames.length > 0) {
2189
+ return this.createError({
2190
+ message: `some folders already exists: ${duplicatedNames.join(", ")}`
2191
+ });
2192
+ }
2193
+ return true;
2194
+ });
2195
+ const validateMoveFoldersNotInsideThemselvesSchema = utils.yup.object().test(
2196
+ "dont-move-inside-self",
2197
+ "folders cannot be moved inside themselves or one of its children",
2198
+ async function(value) {
2199
+ const { folderIds, destinationFolderId } = value;
2200
+ if (destinationFolderId === null || fp.isEmpty(folderIds))
2201
+ return true;
2202
+ const destinationFolder = await strapi.db.query(FOLDER_MODEL_UID).findOne({
2203
+ select: ["path"],
2204
+ where: { id: destinationFolderId }
2205
+ });
2206
+ const folders = await strapi.db.query(FOLDER_MODEL_UID).findMany({
2207
+ select: ["name", "path"],
2208
+ where: { id: { $in: folderIds } }
2209
+ });
2210
+ const unmovableFoldersNames = folders.filter((folder2) => isFolderOrChild(destinationFolder, folder2)).map((f) => f.name);
2211
+ if (unmovableFoldersNames.length > 0) {
2212
+ return this.createError({
2213
+ message: `folders cannot be moved inside themselves or one of its children: ${unmovableFoldersNames.join(
2214
+ ", "
2215
+ )}`
2216
+ });
2217
+ }
2218
+ return true;
2219
+ }
2220
+ );
2221
+ const validateDeleteManyFoldersFiles = utils.validateYupSchema(
2222
+ validateDeleteManyFoldersFilesSchema
2223
+ );
2224
+ async function validateMoveManyFoldersFiles(body) {
2225
+ await utils.validateYupSchema(validateStructureMoveManyFoldersFilesSchema)(body);
2226
+ await utils.validateYupSchema(validateDuplicatesMoveManyFoldersFilesSchema)(body);
2227
+ await utils.validateYupSchema(validateMoveFoldersNotInsideThemselvesSchema)(body);
2228
+ }
2229
+ const adminFolderFile = {
2230
+ async deleteMany(ctx) {
2231
+ const { body } = ctx.request;
2232
+ const {
2233
+ state: { userAbility }
2234
+ } = ctx;
2235
+ const pmFolder = strapi.service("admin::permission").createPermissionsManager({
2236
+ ability: ctx.state.userAbility,
2237
+ model: FOLDER_MODEL_UID
2238
+ });
2239
+ const pmFile = strapi.service("admin::permission").createPermissionsManager({
2240
+ ability: userAbility,
2241
+ action: ACTIONS.read,
2242
+ model: FILE_MODEL_UID
2243
+ });
2244
+ await validateDeleteManyFoldersFiles(body);
2245
+ const fileService = getService("file");
2246
+ const folderService = getService("folder");
2247
+ const deletedFiles = await fileService.deleteByIds(body.fileIds);
2248
+ const {
2249
+ folders: deletedFolders,
2250
+ totalFolderNumber,
2251
+ totalFileNumber
2252
+ } = await folderService.deleteByIds(body.folderIds);
2253
+ if (deletedFiles.length + deletedFolders.length > 1) {
2254
+ strapi.telemetry.send("didBulkDeleteMediaLibraryElements", {
2255
+ eventProperties: {
2256
+ rootFolderNumber: deletedFolders.length,
2257
+ rootAssetNumber: deletedFiles.length,
2258
+ totalFolderNumber,
2259
+ totalAssetNumber: totalFileNumber + deletedFiles.length
2260
+ }
2261
+ });
2262
+ }
2263
+ ctx.body = {
2264
+ data: {
2265
+ files: await pmFile.sanitizeOutput(deletedFiles),
2266
+ folders: await pmFolder.sanitizeOutput(deletedFolders)
2267
+ }
2268
+ };
2269
+ },
2270
+ async moveMany(ctx) {
2271
+ const { body } = ctx.request;
2272
+ const {
2273
+ state: { userAbility }
2274
+ } = ctx;
2275
+ const pmFolder = strapi.service("admin::permission").createPermissionsManager({
2276
+ ability: ctx.state.userAbility,
2277
+ model: FOLDER_MODEL_UID
2278
+ });
2279
+ const pmFile = strapi.service("admin::permission").createPermissionsManager({
2280
+ ability: userAbility,
2281
+ action: ACTIONS.read,
2282
+ model: FILE_MODEL_UID
2283
+ });
2284
+ await validateMoveManyFoldersFiles(body);
2285
+ const { folderIds = [], fileIds = [], destinationFolderId } = body;
2286
+ let totalFolderNumber = 0;
2287
+ let totalFileNumber = 0;
2288
+ const trx = await strapi.db.transaction();
2289
+ try {
2290
+ const existingFolders = await strapi.db.queryBuilder(FOLDER_MODEL_UID).select(["id", "pathId", "path"]).where({ id: { $in: folderIds } }).transacting(trx.get()).forUpdate().execute();
2291
+ const existingFiles = await strapi.db.queryBuilder(FILE_MODEL_UID).select(["id"]).where({ id: { $in: fileIds } }).transacting(trx.get()).forUpdate().execute();
2292
+ let destinationFolderPath = "/";
2293
+ if (destinationFolderId !== null) {
2294
+ const destinationFolder = await strapi.db.queryBuilder(FOLDER_MODEL_UID).select("path").where({ id: destinationFolderId }).transacting(trx.get()).first().execute();
2295
+ destinationFolderPath = destinationFolder.path;
2296
+ }
2297
+ const fileTable = strapi.getModel(FILE_MODEL_UID).collectionName;
2298
+ const folderTable = strapi.getModel(FOLDER_MODEL_UID).collectionName;
2299
+ const folderPathColName = (
2300
+ // @ts-expect-error - no dynamic typings for the models
2301
+ strapi.db.metadata.get(FILE_MODEL_UID).attributes.folderPath.columnName
2302
+ );
2303
+ const pathColName = strapi.db.metadata.get(FOLDER_MODEL_UID).attributes.path.columnName;
2304
+ if (existingFolders.length > 0) {
2305
+ const { joinTable } = strapi.db.metadata.get(FOLDER_MODEL_UID).attributes.parent;
2306
+ await strapi.db.queryBuilder(joinTable.name).transacting(trx.get()).delete().where({ [joinTable.joinColumn.name]: { $in: folderIds } }).execute();
2307
+ if (destinationFolderId !== null) {
2308
+ await strapi.db.queryBuilder(joinTable.name).transacting(trx.get()).insert(
2309
+ existingFolders.map((folder2) => ({
2310
+ [joinTable.inverseJoinColumn.name]: destinationFolderId,
2311
+ [joinTable.joinColumn.name]: folder2.id
2312
+ }))
2313
+ ).execute();
2314
+ }
2315
+ for (const existingFolder of existingFolders) {
2316
+ let replaceQuery;
2317
+ switch (strapi.db.dialect.client) {
2318
+ case "sqlite":
2319
+ replaceQuery = "? || SUBSTRING(??, ?)";
2320
+ break;
2321
+ case "postgres":
2322
+ replaceQuery = "CONCAT(?::TEXT, SUBSTRING(??, ?::INTEGER))";
2323
+ break;
2324
+ default:
2325
+ replaceQuery = "CONCAT(?, SUBSTRING(??, ?))";
2326
+ }
2327
+ totalFolderNumber = await strapi.db.getConnection(folderTable).transacting(trx.get()).where(pathColName, existingFolder.path).orWhere(pathColName, "like", `${existingFolder.path}/%`).update(
2328
+ pathColName,
2329
+ strapi.db.connection.raw(replaceQuery, [
2330
+ utils.strings.joinBy("/", destinationFolderPath, `${existingFolder.pathId}`),
2331
+ pathColName,
2332
+ existingFolder.path.length + 1
2333
+ ])
2334
+ );
2335
+ totalFileNumber = await strapi.db.getConnection(fileTable).transacting(trx.get()).where(folderPathColName, existingFolder.path).orWhere(folderPathColName, "like", `${existingFolder.path}/%`).update(
2336
+ folderPathColName,
2337
+ strapi.db.connection.raw(replaceQuery, [
2338
+ utils.strings.joinBy("/", destinationFolderPath, `${existingFolder.pathId}`),
2339
+ folderPathColName,
2340
+ existingFolder.path.length + 1
2341
+ ])
2342
+ );
2343
+ }
2344
+ }
2345
+ if (existingFiles.length > 0) {
2346
+ const fileJoinTable = strapi.db.metadata.get(FILE_MODEL_UID).attributes.folder.joinTable;
2347
+ await strapi.db.queryBuilder(fileJoinTable.name).transacting(trx.get()).delete().where({ [fileJoinTable.joinColumn.name]: { $in: fileIds } }).execute();
2348
+ if (destinationFolderId !== null) {
2349
+ await strapi.db.queryBuilder(fileJoinTable.name).transacting(trx.get()).insert(
2350
+ existingFiles.map((file2) => ({
2351
+ [fileJoinTable.inverseJoinColumn.name]: destinationFolderId,
2352
+ [fileJoinTable.joinColumn.name]: file2.id
2353
+ }))
2354
+ ).execute();
2355
+ }
2356
+ await strapi.db.getConnection(fileTable).transacting(trx.get()).whereIn("id", fileIds).update(folderPathColName, destinationFolderPath);
2357
+ }
2358
+ await trx.commit();
2359
+ } catch (e) {
2360
+ await trx.rollback();
2361
+ throw e;
2362
+ }
2363
+ const updatedFolders = await strapi.db.query(FOLDER_MODEL_UID).findMany({
2364
+ where: { id: { $in: folderIds } }
2365
+ });
2366
+ const updatedFiles = await strapi.db.query(FILE_MODEL_UID).findMany({
2367
+ where: { id: { $in: fileIds } }
2368
+ });
2369
+ strapi.telemetry.send("didBulkMoveMediaLibraryElements", {
2370
+ eventProperties: {
2371
+ rootFolderNumber: updatedFolders.length,
2372
+ rootAssetNumber: updatedFiles.length,
2373
+ totalFolderNumber,
2374
+ totalAssetNumber: totalFileNumber + updatedFiles.length
2375
+ }
2376
+ });
2377
+ ctx.body = {
2378
+ data: {
2379
+ files: await pmFile.sanitizeOutput(updatedFiles),
2380
+ folders: await pmFolder.sanitizeOutput(updatedFolders)
2381
+ }
2382
+ };
2383
+ }
2384
+ };
2385
+ const settingsSchema = utils.yup.object({
2386
+ sizeOptimization: utils.yup.boolean().required(),
2387
+ responsiveDimensions: utils.yup.boolean().required(),
2388
+ autoOrientation: utils.yup.boolean()
2389
+ });
2390
+ const validateSettings = utils.validateYupSchema(settingsSchema);
2391
+ const adminSettings = {
2392
+ async updateSettings(ctx) {
2393
+ const {
2394
+ request: { body },
2395
+ state: { userAbility }
2396
+ } = ctx;
2397
+ if (userAbility.cannot(ACTIONS.readSettings, FILE_MODEL_UID)) {
2398
+ return ctx.forbidden();
2399
+ }
2400
+ const data = await validateSettings(body);
2401
+ await getService("upload").setSettings(data);
2402
+ ctx.body = { data };
2403
+ },
2404
+ async getSettings(ctx) {
2405
+ const {
2406
+ state: { userAbility }
2407
+ } = ctx;
2408
+ if (userAbility.cannot(ACTIONS.readSettings, FILE_MODEL_UID)) {
2409
+ return ctx.forbidden();
2410
+ }
2411
+ const data = await getService("upload").getSettings();
2412
+ ctx.body = { data };
2413
+ }
2414
+ };
2415
+ const fileInfoSchema$1 = utils.yup.object({
2416
+ name: utils.yup.string().nullable(),
2417
+ alternativeText: utils.yup.string().nullable(),
2418
+ caption: utils.yup.string().nullable(),
2419
+ folder: utils.yup.strapiID().nullable().test("folder-exists", "the folder does not exist", async (folderId) => {
2420
+ if (fp.isNil(folderId)) {
2421
+ return true;
2422
+ }
2423
+ const exists2 = await getService("folder").exists({ id: folderId });
2424
+ return exists2;
2425
+ })
2426
+ });
2427
+ const uploadSchema$1 = utils.yup.object({
2428
+ fileInfo: fileInfoSchema$1
2429
+ });
2430
+ const multiUploadSchema$1 = utils.yup.object({
2431
+ fileInfo: utils.yup.array().of(fileInfoSchema$1)
2432
+ });
2433
+ const validateUploadBody$1 = (data = {}, isMulti = false) => {
2434
+ const schema = isMulti ? multiUploadSchema$1 : uploadSchema$1;
2435
+ return utils.validateYupSchema(schema, { strict: false })(data);
2436
+ };
2437
+ const adminUpload = {
2438
+ async updateFileInfo(ctx) {
2439
+ const {
2440
+ state: { userAbility, user },
2441
+ query: { id },
2442
+ request: { body }
2443
+ } = ctx;
2444
+ if (typeof id !== "string") {
2445
+ throw new utils.errors.ValidationError("File id is required");
2446
+ }
2447
+ const uploadService = getService("upload");
2448
+ const { pm } = await findEntityAndCheckPermissions(
2449
+ userAbility,
2450
+ ACTIONS.update,
2451
+ FILE_MODEL_UID,
2452
+ id
2453
+ );
2454
+ const data = await validateUploadBody$1(body);
2455
+ const file2 = await uploadService.updateFileInfo(id, data.fileInfo, { user });
2456
+ ctx.body = await pm.sanitizeOutput(file2, { action: ACTIONS.read });
2457
+ },
2458
+ async replaceFile(ctx) {
2459
+ const {
2460
+ state: { userAbility, user },
2461
+ query: { id },
2462
+ request: { body, files: { files } = {} }
2463
+ } = ctx;
2464
+ if (typeof id !== "string") {
2465
+ throw new utils.errors.ValidationError("File id is required");
2466
+ }
2467
+ const uploadService = getService("upload");
2468
+ const { pm } = await findEntityAndCheckPermissions(
2469
+ userAbility,
2470
+ ACTIONS.update,
2471
+ FILE_MODEL_UID,
2472
+ id
2473
+ );
2474
+ if (Array.isArray(files)) {
2475
+ throw new utils.errors.ApplicationError("Cannot replace a file with multiple ones");
2476
+ }
2477
+ const data = await validateUploadBody$1(body);
2478
+ const replacedFile = await uploadService.replace(id, { data, file: files }, { user });
2479
+ const signedFile = await getService("file").signFileUrls(replacedFile);
2480
+ ctx.body = await pm.sanitizeOutput(signedFile, { action: ACTIONS.read });
2481
+ },
2482
+ async uploadFiles(ctx) {
2483
+ const {
2484
+ state: { userAbility, user },
2485
+ request: { body, files: { files } = {} }
2486
+ } = ctx;
2487
+ const uploadService = getService("upload");
2488
+ const pm = strapi.service("admin::permission").createPermissionsManager({
2489
+ ability: userAbility,
2490
+ action: ACTIONS.create,
2491
+ model: FILE_MODEL_UID
2492
+ });
2493
+ if (!pm.isAllowed) {
2494
+ return ctx.forbidden();
2495
+ }
2496
+ const data = await validateUploadBody$1(body);
2497
+ const uploadedFiles = await uploadService.upload({ data, files }, { user });
2498
+ const signedFiles = await utils.async.map(uploadedFiles, getService("file").signFileUrls);
2499
+ ctx.body = await pm.sanitizeOutput(signedFiles, { action: ACTIONS.read });
2500
+ ctx.status = 201;
2501
+ },
2502
+ // TODO: split into multiple endpoints
2503
+ async upload(ctx) {
2504
+ const {
2505
+ query: { id },
2506
+ request: { files: { files } = {} }
2507
+ } = ctx;
2508
+ if (___default.default.isEmpty(files) || !Array.isArray(files) && files.size === 0) {
2509
+ if (id) {
2510
+ return this.updateFileInfo(ctx);
2511
+ }
2512
+ throw new utils.errors.ApplicationError("Files are empty");
2513
+ }
2514
+ await (id ? this.replaceFile : this.uploadFiles)(ctx);
2515
+ }
2516
+ };
2517
+ const fileInfoSchema = utils.yup.object({
2518
+ name: utils.yup.string().nullable(),
2519
+ alternativeText: utils.yup.string().nullable(),
2520
+ caption: utils.yup.string().nullable()
2521
+ }).noUnknown();
2522
+ const uploadSchema = utils.yup.object({
2523
+ fileInfo: fileInfoSchema
2524
+ });
2525
+ const multiUploadSchema = utils.yup.object({
2526
+ fileInfo: utils.yup.array().of(fileInfoSchema)
2527
+ });
2528
+ const validateUploadBody = (data = {}, isMulti = false) => {
2529
+ const schema = isMulti ? multiUploadSchema : uploadSchema;
2530
+ return utils.validateYupSchema(schema, { strict: false })(data);
2531
+ };
2532
+ const { ValidationError } = utils__default.default.errors;
2533
+ const contentApi = ({ strapi: strapi2 }) => {
2534
+ const sanitizeOutput = async (data, ctx) => {
2535
+ const schema = strapi2.getModel(FILE_MODEL_UID);
2536
+ const { auth } = ctx.state;
2537
+ return strapi2.contentAPI.sanitize.output(data, schema, { auth });
2538
+ };
2539
+ const validateQuery = async (data, ctx) => {
2540
+ const schema = strapi2.getModel(FILE_MODEL_UID);
2541
+ const { auth } = ctx.state;
2542
+ return strapi2.contentAPI.validate.query(data, schema, { auth });
2543
+ };
2544
+ const sanitizeQuery = async (data, ctx) => {
2545
+ const schema = strapi2.getModel(FILE_MODEL_UID);
2546
+ const { auth } = ctx.state;
2547
+ return strapi2.contentAPI.sanitize.query(data, schema, { auth });
2548
+ };
2549
+ return {
2550
+ async find(ctx) {
2551
+ await validateQuery(ctx.query, ctx);
2552
+ const sanitizedQuery = await sanitizeQuery(ctx.query, ctx);
2553
+ const files = await getService("upload").findMany(sanitizedQuery);
2554
+ ctx.body = await sanitizeOutput(files, ctx);
2555
+ },
2556
+ async findOne(ctx) {
2557
+ const {
2558
+ params: { id }
2559
+ } = ctx;
2560
+ await validateQuery(ctx.query, ctx);
2561
+ const sanitizedQuery = await sanitizeQuery(ctx.query, ctx);
2562
+ const file2 = await getService("upload").findOne(id, sanitizedQuery.populate);
2563
+ if (!file2) {
2564
+ return ctx.notFound("file.notFound");
2565
+ }
2566
+ ctx.body = await sanitizeOutput(file2, ctx);
2567
+ },
2568
+ async destroy(ctx) {
2569
+ const {
2570
+ params: { id }
2571
+ } = ctx;
2572
+ const file2 = await getService("upload").findOne(id);
2573
+ if (!file2) {
2574
+ return ctx.notFound("file.notFound");
2575
+ }
2576
+ await getService("upload").remove(file2);
2577
+ ctx.body = await sanitizeOutput(file2, ctx);
2578
+ },
2579
+ async updateFileInfo(ctx) {
2580
+ const {
2581
+ query: { id },
2582
+ request: { body }
2583
+ } = ctx;
2584
+ const data = await validateUploadBody(body);
2585
+ if (!id || typeof id !== "string" && typeof id !== "number") {
2586
+ throw new ValidationError("File id is required and must be a single value");
2587
+ }
2588
+ const result = await getService("upload").updateFileInfo(id, data.fileInfo);
2589
+ ctx.body = await sanitizeOutput(result, ctx);
2590
+ },
2591
+ async replaceFile(ctx) {
2592
+ const {
2593
+ query: { id },
2594
+ request: { body, files: { files } = {} }
2595
+ } = ctx;
2596
+ if (Array.isArray(files)) {
2597
+ throw new ValidationError("Cannot replace a file with multiple ones");
2598
+ }
2599
+ if (!id || typeof id !== "string" && typeof id !== "number") {
2600
+ throw new ValidationError("File id is required and must be a single value");
2601
+ }
2602
+ const data = await validateUploadBody(body);
2603
+ const replacedFiles = await getService("upload").replace(id, { data, file: files });
2604
+ ctx.body = await sanitizeOutput(replacedFiles, ctx);
2605
+ },
2606
+ async uploadFiles(ctx) {
2607
+ const {
2608
+ request: { body, files: { files } = {} }
2609
+ } = ctx;
2610
+ const data = await validateUploadBody(body, Array.isArray(files));
2611
+ const apiUploadFolderService = getService("api-upload-folder");
2612
+ const apiUploadFolder2 = await apiUploadFolderService.getAPIUploadFolder();
2613
+ if (Array.isArray(files)) {
2614
+ data.fileInfo = data.fileInfo || [];
2615
+ data.fileInfo = files.map((_f, i) => ({ ...data.fileInfo[i], folder: apiUploadFolder2.id }));
2616
+ } else {
2617
+ data.fileInfo = { ...data.fileInfo, folder: apiUploadFolder2.id };
2618
+ }
2619
+ const uploadedFiles = await getService("upload").upload({
2620
+ data,
2621
+ files
2622
+ });
2623
+ ctx.body = await sanitizeOutput(uploadedFiles, ctx);
2624
+ ctx.status = 201;
2625
+ },
2626
+ // TODO: split into multiple endpoints
2627
+ async upload(ctx) {
2628
+ const {
2629
+ query: { id },
2630
+ request: { files: { files } = {} }
2631
+ } = ctx;
2632
+ if (___default.default.isEmpty(files) || !Array.isArray(files) && files.size === 0) {
2633
+ if (id) {
2634
+ return this.updateFileInfo(ctx);
2635
+ }
2636
+ throw new ValidationError("Files are empty");
2637
+ }
2638
+ await (id ? this.replaceFile : this.uploadFiles)(ctx);
2639
+ }
2640
+ };
2641
+ };
2642
+ const configSchema = utils.yup.object({
2643
+ pageSize: utils.yup.number().required(),
2644
+ sort: utils.yup.mixed().oneOf(ALLOWED_SORT_STRINGS)
2645
+ });
2646
+ const validateViewConfiguration = utils.validateYupSchema(configSchema);
2647
+ const viewConfiguration = {
2648
+ async updateViewConfiguration(ctx) {
2649
+ const {
2650
+ request: { body },
2651
+ state: { userAbility }
2652
+ } = ctx;
2653
+ if (userAbility.cannot(ACTIONS.configureView)) {
2654
+ return ctx.forbidden();
2655
+ }
2656
+ const data = await validateViewConfiguration(body);
2657
+ await getService("upload").setConfiguration(data);
2658
+ ctx.body = { data };
2659
+ },
2660
+ async findViewConfiguration(ctx) {
2661
+ const data = await getService("upload").getConfiguration();
2662
+ ctx.body = { data };
2663
+ }
2664
+ };
2665
+ const controllers = {
2666
+ "admin-file": adminFile,
2667
+ "admin-folder": adminFolder,
2668
+ "admin-folder-file": adminFolderFile,
2669
+ "admin-settings": adminSettings,
2670
+ "admin-upload": adminUpload,
2671
+ "content-api": contentApi,
2672
+ "view-configuration": viewConfiguration
2673
+ };
2674
+ const index = () => ({
2675
+ register,
2676
+ bootstrap,
2677
+ config,
2678
+ routes,
2679
+ controllers,
2680
+ contentTypes,
2681
+ services
2682
+ });
2683
+ exports.FILE_MODEL_UID = FILE_MODEL_UID;
2684
+ exports.index = index;
2685
+ //# sourceMappingURL=index-DNIvA1Nj.js.map