arkos 1.3.1-beta → 1.3.2-beta

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 (256) hide show
  1. package/dist/cjs/app.js +139 -1
  2. package/dist/cjs/exports/auth/index.js +6 -1
  3. package/dist/cjs/exports/controllers/index.js +11 -1
  4. package/dist/cjs/exports/error-handler/index.js +11 -1
  5. package/dist/cjs/exports/index.js +12 -1
  6. package/dist/cjs/exports/middlewares/index.js +7 -1
  7. package/dist/cjs/exports/prisma/index.js +13 -1
  8. package/dist/cjs/exports/services/index.js +48 -1
  9. package/dist/cjs/exports/utils/index.js +44 -1
  10. package/dist/cjs/exports/validation/index.js +11 -1
  11. package/dist/cjs/modules/auth/auth.controller.js +229 -1
  12. package/dist/cjs/modules/auth/auth.controller.js.map +1 -1
  13. package/dist/cjs/modules/auth/auth.router.js +82 -1
  14. package/dist/cjs/modules/auth/auth.router.js.map +1 -1
  15. package/dist/cjs/modules/auth/auth.service.js +226 -1
  16. package/dist/cjs/modules/auth/utils/auth-error-objects.js +10 -1
  17. package/dist/cjs/modules/auth/utils/helpers/auth.controller.helpers.js +83 -1
  18. package/dist/cjs/modules/auth/utils/services/auth-action.service.js +92 -1
  19. package/dist/cjs/modules/auth/utils/services/auth-action.service.js.map +1 -1
  20. package/dist/cjs/modules/base/base.controller.js +172 -1
  21. package/dist/cjs/modules/base/base.middlewares.js +92 -1
  22. package/dist/cjs/modules/base/base.router.js +22 -1
  23. package/dist/cjs/modules/base/base.service.js +507 -1
  24. package/dist/cjs/modules/base/base.service.js.map +1 -1
  25. package/dist/cjs/modules/base/types/base.service.types.js +3 -1
  26. package/dist/cjs/modules/base/types/base.service.types.js.map +1 -1
  27. package/dist/cjs/modules/base/utils/helpers/base.controller.helpers.js +80 -1
  28. package/dist/cjs/modules/base/utils/helpers/base.middlewares.helpers.js +50 -1
  29. package/dist/cjs/modules/base/utils/helpers/base.router.helpers.js +104 -1
  30. package/dist/cjs/modules/base/utils/helpers/base.service.helpers.js +208 -1
  31. package/dist/cjs/modules/base/utils/router-validator.js +16 -1
  32. package/dist/cjs/modules/base/utils/service-hooks-manager.js +19 -1
  33. package/dist/cjs/modules/email/email.service.js +104 -1
  34. package/dist/cjs/modules/error-handler/error-handler.controller.js +146 -4
  35. package/dist/cjs/modules/error-handler/utils/app-error.js +17 -1
  36. package/dist/cjs/modules/error-handler/utils/catch-async.js +21 -1
  37. package/dist/cjs/modules/error-handler/utils/error-handler.helpers.js +205 -3
  38. package/dist/cjs/modules/file-upload/file-upload.controller.js +233 -1
  39. package/dist/cjs/modules/file-upload/file-upload.router.js +60 -1
  40. package/dist/cjs/modules/file-upload/file-upload.service.js +322 -1
  41. package/dist/cjs/modules/file-upload/utils/helpers/file-upload.helpers.js +97 -1
  42. package/dist/cjs/modules/swagger/swagger.router.js +38 -1
  43. package/dist/cjs/modules/swagger/utils/helpers/get-authentication-json-schema-paths.js +338 -1
  44. package/dist/cjs/modules/swagger/utils/helpers/get-swagger-default-configs.js +64 -1
  45. package/dist/cjs/modules/swagger/utils/helpers/get-system-json-schema-paths.js +37 -1
  46. package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-class-validator-json-schemas.js +48 -1
  47. package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-prisma-json-schemas.js +32 -1
  48. package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-system-json-schemas.js +49 -1
  49. package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-zod-json-schemas.js +34 -1
  50. package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes-paths.js +471 -1
  51. package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-parent-routes-paths.js +572 -1
  52. package/dist/cjs/modules/swagger/utils/helpers/missing-json-schemas-generator.js +260 -1
  53. package/dist/cjs/modules/swagger/utils/helpers/swagger.router.helpers.js +112 -1
  54. package/dist/cjs/paths.js +9 -1
  55. package/dist/cjs/server.js +94 -5
  56. package/dist/cjs/types/arkos-config.js +3 -1
  57. package/dist/cjs/types/arkos-config.js.map +1 -1
  58. package/dist/cjs/types/auth.js +3 -1
  59. package/dist/cjs/types/index.js +11 -1
  60. package/dist/cjs/types/router-config.js +3 -1
  61. package/dist/cjs/utils/arkos-env.js +9 -1
  62. package/dist/cjs/utils/cli/build.js +214 -5
  63. package/dist/cjs/utils/cli/dev.js +154 -3
  64. package/dist/cjs/utils/cli/generate.js +109 -1
  65. package/dist/cjs/utils/cli/index.js +104 -1
  66. package/dist/cjs/utils/cli/index.js.map +1 -1
  67. package/dist/cjs/utils/cli/prisma-generate.js +120 -0
  68. package/dist/cjs/utils/cli/prisma-generate.js.map +1 -0
  69. package/dist/cjs/utils/cli/start.js +103 -1
  70. package/dist/cjs/utils/cli/utils/cli.helpers.js +24 -1
  71. package/dist/cjs/utils/cli/utils/smart-fs-watcher.js +73 -1
  72. package/dist/cjs/utils/cli/utils/template-generator/templates/auth-configs-template.js +36 -0
  73. package/dist/cjs/utils/cli/utils/template-generator/templates/auth-configs-template.js.map +1 -0
  74. package/dist/cjs/utils/cli/utils/template-generator/templates/controller-template.js +21 -0
  75. package/dist/cjs/utils/cli/utils/template-generator/templates/controller-template.js.map +1 -0
  76. package/dist/cjs/utils/cli/utils/template-generator/templates/hooks-template.js +201 -0
  77. package/dist/cjs/utils/cli/utils/template-generator/templates/hooks-template.js.map +1 -0
  78. package/dist/cjs/utils/cli/utils/template-generator/templates/middlewares-template.js +288 -0
  79. package/dist/cjs/utils/cli/utils/template-generator/templates/{generate-middlewares.js.map → middlewares-template.js.map} +1 -1
  80. package/dist/cjs/utils/cli/utils/template-generator/templates/query-options-template.js +64 -0
  81. package/dist/cjs/utils/cli/utils/template-generator/templates/query-options-template.js.map +1 -0
  82. package/dist/cjs/utils/cli/utils/template-generator/templates/router-template.js +45 -0
  83. package/dist/cjs/utils/cli/utils/template-generator/templates/router-template.js.map +1 -0
  84. package/dist/cjs/utils/cli/utils/template-generator/templates/service-template.js +29 -0
  85. package/dist/cjs/utils/cli/utils/template-generator/templates/service-template.js.map +1 -0
  86. package/dist/cjs/utils/cli/utils/template-generators.js +34 -2
  87. package/dist/cjs/utils/cli/utils/template-generators.js.map +1 -1
  88. package/dist/cjs/utils/cli/utils/watermark-stamper.js +17 -3
  89. package/dist/cjs/utils/dotenv.helpers.js +43 -1
  90. package/dist/cjs/utils/dynamic-loader.js +270 -9
  91. package/dist/cjs/utils/features/api.features.js +169 -1
  92. package/dist/cjs/utils/features/change-case.features.js +67 -1
  93. package/dist/cjs/utils/features/port-and-host-allocator.js +105 -1
  94. package/dist/cjs/utils/helpers/api.features.helpers.js +112 -1
  95. package/dist/cjs/utils/helpers/change-case.helpers.js +177 -1
  96. package/dist/cjs/utils/helpers/deepmerge.helper.js +115 -1
  97. package/dist/cjs/utils/helpers/dynamic-loader.helpers.js +76 -1
  98. package/dist/cjs/utils/helpers/fs.helpers.js +57 -1
  99. package/dist/cjs/utils/helpers/global.helpers.js +94 -1
  100. package/dist/cjs/utils/helpers/prisma.helpers.js +40 -1
  101. package/dist/cjs/utils/helpers/query-parser.helpers.js +45 -1
  102. package/dist/cjs/utils/helpers/routers.helpers.js +37 -1
  103. package/dist/cjs/utils/helpers/text.helpers.js +28 -1
  104. package/dist/cjs/utils/prisma/prisma-json-schema-generator.js +455 -1
  105. package/dist/cjs/utils/prisma/prisma-schema-parser.js +216 -4
  106. package/dist/cjs/utils/prisma/types.js +3 -1
  107. package/dist/cjs/utils/sheu.js +120 -1
  108. package/dist/cjs/utils/validate-dto.js +17 -1
  109. package/dist/cjs/utils/validate-schema.js +15 -1
  110. package/dist/esm/app.js +132 -1
  111. package/dist/esm/exports/auth/index.js +2 -1
  112. package/dist/esm/exports/controllers/index.js +4 -1
  113. package/dist/esm/exports/error-handler/index.js +4 -1
  114. package/dist/esm/exports/index.js +8 -1
  115. package/dist/esm/exports/middlewares/index.js +2 -1
  116. package/dist/esm/exports/prisma/index.js +6 -1
  117. package/dist/esm/exports/services/index.js +9 -1
  118. package/dist/esm/exports/utils/index.js +4 -1
  119. package/dist/esm/exports/validation/index.js +4 -1
  120. package/dist/esm/modules/auth/auth.controller.js +222 -1
  121. package/dist/esm/modules/auth/auth.controller.js.map +1 -1
  122. package/dist/esm/modules/auth/auth.router.js +76 -1
  123. package/dist/esm/modules/auth/auth.router.js.map +1 -1
  124. package/dist/esm/modules/auth/auth.service.js +219 -1
  125. package/dist/esm/modules/auth/utils/auth-error-objects.js +4 -1
  126. package/dist/esm/modules/auth/utils/helpers/auth.controller.helpers.js +73 -1
  127. package/dist/esm/modules/auth/utils/services/auth-action.service.js +90 -1
  128. package/dist/esm/modules/auth/utils/services/auth-action.service.js.map +1 -1
  129. package/dist/esm/modules/base/base.controller.js +165 -1
  130. package/dist/esm/modules/base/base.middlewares.js +81 -1
  131. package/dist/esm/modules/base/base.router.js +15 -1
  132. package/dist/esm/modules/base/base.service.js +500 -1
  133. package/dist/esm/modules/base/base.service.js.map +1 -1
  134. package/dist/esm/modules/base/types/base.service.types.js +2 -1
  135. package/dist/esm/modules/base/types/base.service.types.js.map +1 -1
  136. package/dist/esm/modules/base/utils/helpers/base.controller.helpers.js +76 -1
  137. package/dist/esm/modules/base/utils/helpers/base.middlewares.helpers.js +44 -1
  138. package/dist/esm/modules/base/utils/helpers/base.router.helpers.js +96 -1
  139. package/dist/esm/modules/base/utils/helpers/base.service.helpers.js +198 -1
  140. package/dist/esm/modules/base/utils/router-validator.js +14 -1
  141. package/dist/esm/modules/base/utils/service-hooks-manager.js +17 -1
  142. package/dist/esm/modules/email/email.service.js +97 -1
  143. package/dist/esm/modules/error-handler/error-handler.controller.js +107 -4
  144. package/dist/esm/modules/error-handler/utils/app-error.js +15 -1
  145. package/dist/esm/modules/error-handler/utils/catch-async.js +19 -1
  146. package/dist/esm/modules/error-handler/utils/error-handler.helpers.js +163 -3
  147. package/dist/esm/modules/file-upload/file-upload.controller.js +228 -1
  148. package/dist/esm/modules/file-upload/file-upload.router.js +54 -1
  149. package/dist/esm/modules/file-upload/file-upload.service.js +314 -1
  150. package/dist/esm/modules/file-upload/utils/helpers/file-upload.helpers.js +87 -1
  151. package/dist/esm/modules/swagger/swagger.router.js +32 -1
  152. package/dist/esm/modules/swagger/utils/helpers/get-authentication-json-schema-paths.js +333 -1
  153. package/dist/esm/modules/swagger/utils/helpers/get-swagger-default-configs.js +58 -1
  154. package/dist/esm/modules/swagger/utils/helpers/get-system-json-schema-paths.js +34 -1
  155. package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-class-validator-json-schemas.js +42 -1
  156. package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-prisma-json-schemas.js +26 -1
  157. package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-system-json-schemas.js +46 -1
  158. package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-zod-json-schemas.js +28 -1
  159. package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes-paths.js +465 -1
  160. package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-parent-routes-paths.js +566 -1
  161. package/dist/esm/modules/swagger/utils/helpers/missing-json-schemas-generator.js +255 -1
  162. package/dist/esm/modules/swagger/utils/helpers/swagger.router.helpers.js +101 -1
  163. package/dist/esm/paths.js +3 -1
  164. package/dist/esm/server.js +85 -5
  165. package/dist/esm/types/arkos-config.js +2 -1
  166. package/dist/esm/types/arkos-config.js.map +1 -1
  167. package/dist/esm/types/auth.js +2 -1
  168. package/dist/esm/types/index.js +8 -1
  169. package/dist/esm/types/router-config.js +2 -1
  170. package/dist/esm/utils/arkos-env.js +7 -1
  171. package/dist/esm/utils/cli/build.js +208 -5
  172. package/dist/esm/utils/cli/dev.js +147 -3
  173. package/dist/esm/utils/cli/generate.js +103 -1
  174. package/dist/esm/utils/cli/index.js +94 -1
  175. package/dist/esm/utils/cli/index.js.map +1 -1
  176. package/dist/esm/utils/cli/prisma-generate.js +114 -0
  177. package/dist/esm/utils/cli/prisma-generate.js.map +1 -0
  178. package/dist/esm/utils/cli/start.js +96 -1
  179. package/dist/esm/utils/cli/utils/cli.helpers.js +16 -1
  180. package/dist/esm/utils/cli/utils/smart-fs-watcher.js +68 -1
  181. package/dist/esm/utils/cli/utils/template-generator/templates/auth-configs-template.js +33 -0
  182. package/dist/esm/utils/cli/utils/template-generator/templates/auth-configs-template.js.map +1 -0
  183. package/dist/esm/utils/cli/utils/template-generator/templates/controller-template.js +18 -0
  184. package/dist/esm/utils/cli/utils/template-generator/templates/controller-template.js.map +1 -0
  185. package/dist/esm/utils/cli/utils/template-generator/templates/hooks-template.js +198 -0
  186. package/dist/esm/utils/cli/utils/template-generator/templates/hooks-template.js.map +1 -0
  187. package/dist/esm/utils/cli/utils/template-generator/templates/middlewares-template.js +285 -0
  188. package/dist/esm/utils/cli/utils/template-generator/templates/{generate-middlewares.js.map → middlewares-template.js.map} +1 -1
  189. package/dist/esm/utils/cli/utils/template-generator/templates/query-options-template.js +61 -0
  190. package/dist/esm/utils/cli/utils/template-generator/templates/query-options-template.js.map +1 -0
  191. package/dist/esm/utils/cli/utils/template-generator/templates/router-template.js +39 -0
  192. package/dist/esm/utils/cli/utils/template-generator/templates/router-template.js.map +1 -0
  193. package/dist/esm/utils/cli/utils/template-generator/templates/service-template.js +26 -0
  194. package/dist/esm/utils/cli/utils/template-generator/templates/service-template.js.map +1 -0
  195. package/dist/esm/utils/cli/utils/template-generators.js +28 -2
  196. package/dist/esm/utils/cli/utils/template-generators.js.map +1 -1
  197. package/dist/esm/utils/cli/utils/watermark-stamper.js +15 -3
  198. package/dist/esm/utils/dotenv.helpers.js +37 -1
  199. package/dist/esm/utils/dynamic-loader.js +254 -9
  200. package/dist/esm/utils/features/api.features.js +162 -1
  201. package/dist/esm/utils/features/change-case.features.js +31 -1
  202. package/dist/esm/utils/features/port-and-host-allocator.js +67 -1
  203. package/dist/esm/utils/helpers/api.features.helpers.js +106 -1
  204. package/dist/esm/utils/helpers/change-case.helpers.js +161 -1
  205. package/dist/esm/utils/helpers/deepmerge.helper.js +113 -1
  206. package/dist/esm/utils/helpers/dynamic-loader.helpers.js +69 -1
  207. package/dist/esm/utils/helpers/fs.helpers.js +48 -1
  208. package/dist/esm/utils/helpers/global.helpers.js +51 -1
  209. package/dist/esm/utils/helpers/prisma.helpers.js +32 -1
  210. package/dist/esm/utils/helpers/query-parser.helpers.js +40 -1
  211. package/dist/esm/utils/helpers/routers.helpers.js +29 -1
  212. package/dist/esm/utils/helpers/text.helpers.js +22 -1
  213. package/dist/esm/utils/prisma/prisma-json-schema-generator.js +448 -1
  214. package/dist/esm/utils/prisma/prisma-schema-parser.js +209 -4
  215. package/dist/esm/utils/prisma/types.js +2 -1
  216. package/dist/esm/utils/sheu.js +118 -1
  217. package/dist/esm/utils/validate-dto.js +11 -1
  218. package/dist/esm/utils/validate-schema.js +9 -1
  219. package/dist/types/modules/auth/utils/services/auth-action.service.d.ts +1 -1
  220. package/dist/types/modules/base/types/base.service.types.d.ts +12 -9
  221. package/dist/types/types/arkos-config.d.ts +3 -2
  222. package/dist/types/utils/cli/prisma-generate.d.ts +1 -0
  223. package/package.json +2 -2
  224. package/dist/cjs/utils/cli/utils/template-generator/templates/generate-auth-configs-template.js +0 -21
  225. package/dist/cjs/utils/cli/utils/template-generator/templates/generate-auth-configs-template.js.map +0 -1
  226. package/dist/cjs/utils/cli/utils/template-generator/templates/generate-controller-template.js +0 -12
  227. package/dist/cjs/utils/cli/utils/template-generator/templates/generate-controller-template.js.map +0 -1
  228. package/dist/cjs/utils/cli/utils/template-generator/templates/generate-hooks-template.js +0 -144
  229. package/dist/cjs/utils/cli/utils/template-generator/templates/generate-hooks-template.js.map +0 -1
  230. package/dist/cjs/utils/cli/utils/template-generator/templates/generate-middlewares.js +0 -256
  231. package/dist/cjs/utils/cli/utils/template-generator/templates/generate-prisma-query-options.js +0 -36
  232. package/dist/cjs/utils/cli/utils/template-generator/templates/generate-prisma-query-options.js.map +0 -1
  233. package/dist/cjs/utils/cli/utils/template-generator/templates/generate-router-template.js +0 -18
  234. package/dist/cjs/utils/cli/utils/template-generator/templates/generate-router-template.js.map +0 -1
  235. package/dist/cjs/utils/cli/utils/template-generator/templates/generate-service-template.js +0 -9
  236. package/dist/cjs/utils/cli/utils/template-generator/templates/generate-service-template.js.map +0 -1
  237. package/dist/esm/utils/cli/utils/template-generator/templates/generate-auth-configs-template.js +0 -21
  238. package/dist/esm/utils/cli/utils/template-generator/templates/generate-auth-configs-template.js.map +0 -1
  239. package/dist/esm/utils/cli/utils/template-generator/templates/generate-controller-template.js +0 -12
  240. package/dist/esm/utils/cli/utils/template-generator/templates/generate-controller-template.js.map +0 -1
  241. package/dist/esm/utils/cli/utils/template-generator/templates/generate-hooks-template.js +0 -144
  242. package/dist/esm/utils/cli/utils/template-generator/templates/generate-hooks-template.js.map +0 -1
  243. package/dist/esm/utils/cli/utils/template-generator/templates/generate-middlewares.js +0 -256
  244. package/dist/esm/utils/cli/utils/template-generator/templates/generate-prisma-query-options.js +0 -36
  245. package/dist/esm/utils/cli/utils/template-generator/templates/generate-prisma-query-options.js.map +0 -1
  246. package/dist/esm/utils/cli/utils/template-generator/templates/generate-router-template.js +0 -18
  247. package/dist/esm/utils/cli/utils/template-generator/templates/generate-router-template.js.map +0 -1
  248. package/dist/esm/utils/cli/utils/template-generator/templates/generate-service-template.js +0 -9
  249. package/dist/esm/utils/cli/utils/template-generator/templates/generate-service-template.js.map +0 -1
  250. /package/dist/types/utils/cli/utils/template-generator/templates/{generate-auth-configs-template.d.ts → auth-configs-template.d.ts} +0 -0
  251. /package/dist/types/utils/cli/utils/template-generator/templates/{generate-controller-template.d.ts → controller-template.d.ts} +0 -0
  252. /package/dist/types/utils/cli/utils/template-generator/templates/{generate-hooks-template.d.ts → hooks-template.d.ts} +0 -0
  253. /package/dist/types/utils/cli/utils/template-generator/templates/{generate-middlewares.d.ts → middlewares-template.d.ts} +0 -0
  254. /package/dist/types/utils/cli/utils/template-generator/templates/{generate-prisma-query-options.d.ts → query-options-template.d.ts} +0 -0
  255. /package/dist/types/utils/cli/utils/template-generator/templates/{generate-router-template.d.ts → router-template.d.ts} +0 -0
  256. /package/dist/types/utils/cli/utils/template-generator/templates/{generate-service-template.d.ts → service-template.d.ts} +0 -0
@@ -1 +1,314 @@
1
- "use strict";import y from"multer";import p from"path";import m from"fs";import d from"../error-handler/utils/app-error.js";import{promisify as f}from"util";import{getArkosConfig as U}from"../../server.js";import j from"../../utils/helpers/deepmerge.helper.js";import{processFile as F,processImage as k}from"./utils/helpers/file-upload.helpers.js";import{removeBothSlashes as D}from"../../utils/helpers/text.helpers.js";export class FileUploadService{constructor(e,s=1024*1024*5,t=/.*/,a=30){this.fileFilter=(o,i,l)=>{const n=this.allowedFileTypes.test(p.extname(i.originalname).toLowerCase());this.allowedFileTypes.test(i.mimetype)&&n?l(null,!0):l(new d("Invalid file type",400))},e=e.startsWith("/")?e.substring(1):e,e=e.endsWith("/")?e.slice(0,-1):e,this.uploadDir=p.resolve(process.cwd(),`${e}/`),this.fileSizeLimit=s,this.allowedFileTypes=t,this.maxCount=a,m.existsSync(this.uploadDir)||m.mkdirSync(this.uploadDir,{recursive:!0}),this.storage=y.diskStorage({destination:(o,i,l)=>{l(null,this.uploadDir)},filename:(o,i,l)=>{const n=Date.now()+"-"+Math.round(Math.random()*1e9);l(null,`${n}${p.extname(i.originalname)}`)}})}getUpload(){return y({storage:this.storage,fileFilter:this.fileFilter,limits:{fileSize:this.fileSizeLimit}})}handleSingleUpload(e){return(s,t,a)=>{this.getUpload().single(this.getFieldName())(s,t,async i=>{if(i instanceof y.MulterError)return a(i);if(i)return a(i);if(e){const{fileUpload:l}=U(),n=p.resolve(process.cwd(),D(l?.baseUploadDir),D(e));try{await f(m.stat)(n)&&await f(m.unlink)(n)}catch(r){console.error(r)}}a()})}}handleMultipleUpload(){return(e,s,t)=>{this.getUpload().array(this.getFieldName(),this.maxCount)(e,s,o=>{if(o instanceof y.MulterError)return t(o);if(o)return t(o);t()})}}handleDeleteSingleFile(e){return async(s,t,a)=>{const o=p.join(e);try{await f(m.stat)(o)&&await f(m.unlink)(o)}catch(i){console.error(i)}a()}}async deleteFileByUrl(e){try{const{fileUpload:s}=U(),t=s?.baseRoute||"/api/uploads";let a;e.startsWith("http")?a=new URL(e).pathname:a=e;const o=a.indexOf(t);if(o===-1)throw new d("Invalid file URL: base route not found",400);const i=a.substring(o+t.length),l=i.startsWith("/")?i.substring(1):i,n=["images","videos","documents","files"];let r=null,c=null;for(const x of n){const b=l.indexOf(x+"/");if(b!==-1){r=x,c=l.substring(b+x.length+1);break}}if(!r||!c)throw new d("Unable to determine file type or file name from URL",400);const{documentUploadService:g,fileUploadService:u,imageUploadService:S,videoUploadService:h}=getFileUploadServices();let w;switch(r){case"images":w=p.join(S.uploadDir,c);break;case"videos":w=p.join(h.uploadDir,c);break;case"documents":w=p.join(g.uploadDir,c);break;case"files":w=p.join(u.uploadDir,c);break;default:throw new d(`Unsupported file type: ${r}`,400)}return await f(m.stat)(w),await f(m.unlink)(w),!0}catch(s){throw s instanceof d?s:s.code==="ENOENT"?new d("File not found",404):new d(`Failed to delete file: ${s.message}`,500)}}getFieldName(){let e="files";return(this.uploadDir.endsWith("images")||this.uploadDir.endsWith("images/"))&&(e="images"),(this.uploadDir.endsWith("videos")||this.uploadDir.endsWith("videos/"))&&(e="videos"),(this.uploadDir.endsWith("documents")||this.uploadDir.endsWith("documents/"))&&(e="documents"),(this.uploadDir.endsWith("files")||this.uploadDir.endsWith("files/"))&&(e="files"),e}async upload(e,s,t={}){const{fileUpload:a}=U();return a?.baseRoute,new Promise((o,i)=>{((Array.isArray(e.query.multiple)?e.query.multiple[0]=="true":e.query.multiple=="true")?this.getUpload().array(this.getFieldName(),this.maxCount):this.getUpload().single(this.getFieldName()))(e,s,async r=>{if(r)return i(r);try{`${e.get("host")?.includes?.("localhost")?"http":"https"}${e.get("host")}`;const g=this.uploadDir.split("/");this.uploadDir.endsWith("/")?g[g.length-2]:g[g.length-1];let u;if(e.files&&Array.isArray(e.files)&&e.files.length>0)this.uploadDir?.includes?.("/images")?u=await Promise.all(e.files.map(h=>k(e,h.path,t))):u=await Promise.all(e.files.map(h=>F(e,h.path))),u=u.filter(h=>h!==null);else if(e.file)this.uploadDir?.includes?.("/images")?u=await k(e,e.file.path,t):u=await F(e,e.file.path);else return i(new d("No file uploaded",400));o(u)}catch(c){i(c)}})})}async deleteFileByName(e,s){try{if(!s)throw new d("File type parameter is required",400);const t=["images","videos","documents","files"];if(!t.includes(s))throw new d(`Invalid file type: ${s}. Must be one of: ${t.join(", ")}`,400);const{documentUploadService:a,fileUploadService:o,imageUploadService:i,videoUploadService:l}=getFileUploadServices();let n;switch(s){case"images":n=i;break;case"videos":n=l;break;case"documents":n=a;break;case"files":n=o;break;default:throw new d(`Unsupported file type: ${s}`,400)}const r=p.join(n.uploadDir,e);return await f(m.stat)(r),await f(m.unlink)(r),!0}catch(t){throw t instanceof d?t:t.code==="ENOENT"?new d("File not found",404):new d(`Failed to delete file: ${t.message}`,500)}}}export const getFileUploadServices=()=>{const{fileUpload:v}=U(),e=v?.baseUploadDir||"/uploads",s={images:{maxCount:30,maxSize:1024*1024*15,supportedFilesRegex:/jpeg|jpg|png|gif|webp|svg|bmp|tiff|heif|heic|ico|jfif|raw|cr2|nef|orf|sr2|arw|dng|pef|raf|rw2|psd|ai|eps|xcf|jxr|wdp|hdp|jp2|j2k|jpf|jpx|jpm|mj2|avif/},videos:{maxCount:10,maxSize:1024*1024*5096,supportedFilesRegex:/mp4|avi|mov|mkv|flv|wmv|webm|mpg|mpeg|3gp|m4v|ts|rm|rmvb|vob|ogv|dv|qt|asf|m2ts|mts|divx|f4v|swf|mxf|roq|nsv|mvb|svi|mpe|m2v|mp2|mpv|h264|h265|hevc/},documents:{maxCount:30,maxSize:1024*1024*50,supportedFilesRegex:/pdf|doc|docx|xls|xlsx|ppt|pptx|odt|ods|odg|odp|txt|rtf|csv|epub|md|tex|pages|numbers|key|xml|json|yaml|yml|ini|cfg|conf|log|html|htm|xhtml|djvu|mobi|azw|azw3|fb2|lit|ps|wpd|wps|dot|dotx|xlt|xltx|pot|potx|oft|one|onetoc2|opf|oxps|hwp/},files:{maxCount:10,maxSize:1024*1024*5096,supportedFilesRegex:/.*/}},t=v?.restrictions?j(s,v.restrictions):s,a=new FileUploadService(`${e}/images`,t.images.maxSize,t.images.supportedFilesRegex,t.images.maxCount),o=new FileUploadService(`${e}/videos`,t.videos.maxSize,t.videos.supportedFilesRegex,t.videos.maxCount),i=new FileUploadService(`${e}/documents`,t.documents.maxSize,t.documents.supportedFilesRegex,t.documents.maxCount),l=new FileUploadService(`${e}/files`,t.files.maxSize,t.files.supportedFilesRegex,t.files.maxCount);return{imageUploadService:a,videoUploadService:o,documentUploadService:i,fileUploadService:l}};
1
+ import multer from "multer";
2
+ import path from "path";
3
+ import fs from "fs";
4
+ import AppError from "../error-handler/utils/app-error.js";
5
+ import { promisify } from "util";
6
+ import { getArkosConfig } from "../../server.js";
7
+ import deepmerge from "../../utils/helpers/deepmerge.helper.js";
8
+ import { processFile, processImage } from "./utils/helpers/file-upload.helpers.js";
9
+ import { removeBothSlashes } from "../../utils/helpers/text.helpers.js";
10
+ export class FileUploadService {
11
+ constructor(uploadDir, fileSizeLimit = 1024 * 1024 * 5, allowedFileTypes = /.*/, maxCount = 30) {
12
+ this.fileFilter = (_, file, cb) => {
13
+ const extName = this.allowedFileTypes.test(path.extname(file.originalname).toLowerCase());
14
+ const mimeType = this.allowedFileTypes.test(file.mimetype);
15
+ if (mimeType && extName) {
16
+ cb(null, true);
17
+ }
18
+ else {
19
+ cb(new AppError("Invalid file type", 400));
20
+ }
21
+ };
22
+ uploadDir = uploadDir.startsWith("/") ? uploadDir.substring(1) : uploadDir;
23
+ uploadDir = uploadDir.endsWith("/") ? uploadDir.slice(0, -1) : uploadDir;
24
+ this.uploadDir = path.resolve(process.cwd(), `${uploadDir}/`);
25
+ this.fileSizeLimit = fileSizeLimit;
26
+ this.allowedFileTypes = allowedFileTypes;
27
+ this.maxCount = maxCount;
28
+ if (!fs.existsSync(this.uploadDir)) {
29
+ fs.mkdirSync(this.uploadDir, { recursive: true });
30
+ }
31
+ this.storage = multer.diskStorage({
32
+ destination: (_, _1, cb) => {
33
+ cb(null, this.uploadDir);
34
+ },
35
+ filename: (_, file, cb) => {
36
+ const uniqueSuffix = Date.now() + "-" + Math.round(Math.random() * 1e9);
37
+ cb(null, `${uniqueSuffix}${path.extname(file.originalname)}`);
38
+ },
39
+ });
40
+ }
41
+ getUpload() {
42
+ return multer({
43
+ storage: this.storage,
44
+ fileFilter: this.fileFilter,
45
+ limits: { fileSize: this.fileSizeLimit },
46
+ });
47
+ }
48
+ handleSingleUpload(oldFilePath) {
49
+ return (req, res, next) => {
50
+ const upload = this.getUpload().single(this.getFieldName());
51
+ upload(req, res, async (err) => {
52
+ if (err instanceof multer.MulterError) {
53
+ return next(err);
54
+ }
55
+ else if (err) {
56
+ return next(err);
57
+ }
58
+ if (oldFilePath) {
59
+ const { fileUpload: configs } = getArkosConfig();
60
+ const filePath = path.resolve(process.cwd(), removeBothSlashes(configs?.baseUploadDir), removeBothSlashes(oldFilePath));
61
+ try {
62
+ const stats = await promisify(fs.stat)(filePath);
63
+ if (stats)
64
+ await promisify(fs.unlink)(filePath);
65
+ }
66
+ catch (err) {
67
+ console.error(err);
68
+ }
69
+ }
70
+ next();
71
+ });
72
+ };
73
+ }
74
+ handleMultipleUpload() {
75
+ return (req, res, next) => {
76
+ const upload = this.getUpload().array(this.getFieldName(), this.maxCount);
77
+ upload(req, res, (err) => {
78
+ if (err instanceof multer.MulterError)
79
+ return next(err);
80
+ else if (err)
81
+ return next(err);
82
+ next();
83
+ });
84
+ };
85
+ }
86
+ handleDeleteSingleFile(oldFilePath) {
87
+ return async (_, _1, next) => {
88
+ const filePath = path.join(oldFilePath);
89
+ try {
90
+ const stats = await promisify(fs.stat)(filePath);
91
+ if (stats) {
92
+ await promisify(fs.unlink)(filePath);
93
+ }
94
+ }
95
+ catch (err) {
96
+ console.error(err);
97
+ }
98
+ next();
99
+ };
100
+ }
101
+ async deleteFileByUrl(fileUrl) {
102
+ try {
103
+ const { fileUpload } = getArkosConfig();
104
+ const baseRoute = fileUpload?.baseRoute || "/api/uploads";
105
+ let urlPath;
106
+ if (fileUrl.startsWith("http")) {
107
+ const url = new URL(fileUrl);
108
+ urlPath = url.pathname;
109
+ }
110
+ else {
111
+ urlPath = fileUrl;
112
+ }
113
+ const baseRouteIndex = urlPath.indexOf(baseRoute);
114
+ if (baseRouteIndex === -1) {
115
+ throw new AppError("Invalid file URL: base route not found", 400);
116
+ }
117
+ const pathAfterBaseRoute = urlPath.substring(baseRouteIndex + baseRoute.length);
118
+ const cleanPath = pathAfterBaseRoute.startsWith("/")
119
+ ? pathAfterBaseRoute.substring(1)
120
+ : pathAfterBaseRoute;
121
+ const fileTypes = ["images", "videos", "documents", "files"];
122
+ let fileType = null;
123
+ let fileName = null;
124
+ for (const type of fileTypes) {
125
+ const typeIndex = cleanPath.indexOf(type + "/");
126
+ if (typeIndex !== -1) {
127
+ fileType = type;
128
+ fileName = cleanPath.substring(typeIndex + type.length + 1);
129
+ break;
130
+ }
131
+ }
132
+ if (!fileType || !fileName) {
133
+ throw new AppError("Unable to determine file type or file name from URL", 400);
134
+ }
135
+ const { documentUploadService, fileUploadService, imageUploadService, videoUploadService, } = getFileUploadServices();
136
+ let filePath;
137
+ switch (fileType) {
138
+ case "images":
139
+ filePath = path.join(imageUploadService.uploadDir, fileName);
140
+ break;
141
+ case "videos":
142
+ filePath = path.join(videoUploadService.uploadDir, fileName);
143
+ break;
144
+ case "documents":
145
+ filePath = path.join(documentUploadService.uploadDir, fileName);
146
+ break;
147
+ case "files":
148
+ filePath = path.join(fileUploadService.uploadDir, fileName);
149
+ break;
150
+ default:
151
+ throw new AppError(`Unsupported file type: ${fileType}`, 400);
152
+ }
153
+ await promisify(fs.stat)(filePath);
154
+ await promisify(fs.unlink)(filePath);
155
+ return true;
156
+ }
157
+ catch (error) {
158
+ if (error instanceof AppError) {
159
+ throw error;
160
+ }
161
+ if (error.code === "ENOENT") {
162
+ throw new AppError("File not found", 404);
163
+ }
164
+ throw new AppError(`Failed to delete file: ${error.message}`, 500);
165
+ }
166
+ }
167
+ getFieldName() {
168
+ let fieldName = "files";
169
+ if (this.uploadDir.endsWith("images") || this.uploadDir.endsWith("images/"))
170
+ fieldName = "images";
171
+ if (this.uploadDir.endsWith("videos") || this.uploadDir.endsWith("videos/"))
172
+ fieldName = "videos";
173
+ if (this.uploadDir.endsWith("documents") ||
174
+ this.uploadDir.endsWith("documents/"))
175
+ fieldName = "documents";
176
+ if (this.uploadDir.endsWith("files") || this.uploadDir.endsWith("files/"))
177
+ fieldName = "files";
178
+ return fieldName;
179
+ }
180
+ async upload(req, res, options = {}) {
181
+ const { fileUpload } = getArkosConfig();
182
+ fileUpload?.baseRoute || "/api/uploads";
183
+ return new Promise((resolve, reject) => {
184
+ const isMultiple = Array.isArray(req.query.multiple)
185
+ ? req.query.multiple[0] == "true"
186
+ : req.query.multiple == "true";
187
+ const uploadHandler = isMultiple
188
+ ? this.getUpload().array(this.getFieldName(), this.maxCount)
189
+ : this.getUpload().single(this.getFieldName());
190
+ uploadHandler(req, res, async (err) => {
191
+ if (err)
192
+ return reject(err);
193
+ try {
194
+ const protocol = req.get("host")?.includes?.("localhost")
195
+ ? "http"
196
+ : "https";
197
+ `${protocol}://${req.get("host")}`;
198
+ const dirParts = this.uploadDir.split("/");
199
+ (this.uploadDir.endsWith("/")
200
+ ? dirParts[dirParts.length - 2]
201
+ : dirParts[dirParts.length - 1]) || "files";
202
+ let data;
203
+ if (req.files && Array.isArray(req.files) && req.files.length > 0) {
204
+ const isImageUpload = this.uploadDir?.includes?.("/images");
205
+ if (isImageUpload) {
206
+ data = await Promise.all(req.files.map((file) => processImage(req, file.path, options)));
207
+ }
208
+ else {
209
+ data = await Promise.all(req.files.map((file) => processFile(req, file.path)));
210
+ }
211
+ data = data.filter((url) => url !== null);
212
+ }
213
+ else if (req.file) {
214
+ const isImageUpload = this.uploadDir?.includes?.("/images");
215
+ if (isImageUpload) {
216
+ data = await processImage(req, req.file.path, options);
217
+ }
218
+ else {
219
+ data = await processFile(req, req.file.path);
220
+ }
221
+ }
222
+ else {
223
+ return reject(new AppError("No file uploaded", 400));
224
+ }
225
+ resolve(data);
226
+ }
227
+ catch (error) {
228
+ reject(error);
229
+ }
230
+ });
231
+ });
232
+ }
233
+ async deleteFileByName(fileName, fileType) {
234
+ try {
235
+ if (!fileType)
236
+ throw new AppError("File type parameter is required", 400);
237
+ const validFileTypes = ["images", "videos", "documents", "files"];
238
+ if (!validFileTypes.includes(fileType)) {
239
+ throw new AppError(`Invalid file type: ${fileType}. Must be one of: ${validFileTypes.join(", ")}`, 400);
240
+ }
241
+ const { documentUploadService, fileUploadService, imageUploadService, videoUploadService, } = getFileUploadServices();
242
+ let targetService;
243
+ switch (fileType) {
244
+ case "images":
245
+ targetService = imageUploadService;
246
+ break;
247
+ case "videos":
248
+ targetService = videoUploadService;
249
+ break;
250
+ case "documents":
251
+ targetService = documentUploadService;
252
+ break;
253
+ case "files":
254
+ targetService = fileUploadService;
255
+ break;
256
+ default:
257
+ throw new AppError(`Unsupported file type: ${fileType}`, 400);
258
+ }
259
+ const filePath = path.join(targetService.uploadDir, fileName);
260
+ await promisify(fs.stat)(filePath);
261
+ await promisify(fs.unlink)(filePath);
262
+ return true;
263
+ }
264
+ catch (error) {
265
+ if (error instanceof AppError) {
266
+ throw error;
267
+ }
268
+ if (error.code === "ENOENT") {
269
+ throw new AppError("File not found", 404);
270
+ }
271
+ throw new AppError(`Failed to delete file: ${error.message}`, 500);
272
+ }
273
+ }
274
+ }
275
+ export const getFileUploadServices = () => {
276
+ const { fileUpload } = getArkosConfig();
277
+ const baseUploadDir = fileUpload?.baseUploadDir || "/uploads";
278
+ const defaultRestrictions = {
279
+ images: {
280
+ maxCount: 30,
281
+ maxSize: 1024 * 1024 * 15,
282
+ supportedFilesRegex: /jpeg|jpg|png|gif|webp|svg|bmp|tiff|heif|heic|ico|jfif|raw|cr2|nef|orf|sr2|arw|dng|pef|raf|rw2|psd|ai|eps|xcf|jxr|wdp|hdp|jp2|j2k|jpf|jpx|jpm|mj2|avif/,
283
+ },
284
+ videos: {
285
+ maxCount: 10,
286
+ maxSize: 1024 * 1024 * 5096,
287
+ supportedFilesRegex: /mp4|avi|mov|mkv|flv|wmv|webm|mpg|mpeg|3gp|m4v|ts|rm|rmvb|vob|ogv|dv|qt|asf|m2ts|mts|divx|f4v|swf|mxf|roq|nsv|mvb|svi|mpe|m2v|mp2|mpv|h264|h265|hevc/,
288
+ },
289
+ documents: {
290
+ maxCount: 30,
291
+ maxSize: 1024 * 1024 * 50,
292
+ supportedFilesRegex: /pdf|doc|docx|xls|xlsx|ppt|pptx|odt|ods|odg|odp|txt|rtf|csv|epub|md|tex|pages|numbers|key|xml|json|yaml|yml|ini|cfg|conf|log|html|htm|xhtml|djvu|mobi|azw|azw3|fb2|lit|ps|wpd|wps|dot|dotx|xlt|xltx|pot|potx|oft|one|onetoc2|opf|oxps|hwp/,
293
+ },
294
+ files: {
295
+ maxCount: 10,
296
+ maxSize: 1024 * 1024 * 5096,
297
+ supportedFilesRegex: /.*/,
298
+ },
299
+ };
300
+ const restrictions = fileUpload?.restrictions
301
+ ? deepmerge(defaultRestrictions, fileUpload.restrictions)
302
+ : defaultRestrictions;
303
+ const imageUploadService = new FileUploadService(`${baseUploadDir}/images`, restrictions.images.maxSize, restrictions.images.supportedFilesRegex, restrictions.images.maxCount);
304
+ const videoUploadService = new FileUploadService(`${baseUploadDir}/videos`, restrictions.videos.maxSize, restrictions.videos.supportedFilesRegex, restrictions.videos.maxCount);
305
+ const documentUploadService = new FileUploadService(`${baseUploadDir}/documents`, restrictions.documents.maxSize, restrictions.documents.supportedFilesRegex, restrictions.documents.maxCount);
306
+ const fileUploadService = new FileUploadService(`${baseUploadDir}/files`, restrictions.files.maxSize, restrictions.files.supportedFilesRegex, restrictions.files.maxCount);
307
+ return {
308
+ imageUploadService,
309
+ videoUploadService,
310
+ documentUploadService,
311
+ fileUploadService,
312
+ };
313
+ };
314
+ //# sourceMappingURL=file-upload.service.js.map
@@ -1 +1,87 @@
1
- "use strict";import m from"fs";import n from"path";import y from"sharp";import{promisify as u}from"util";import{getArkosConfig as h}from"../../../../server.js";import U from"mimetype";import{fullCleanCwd as x}from"../../../../utils/helpers/fs.helpers.js";export function adjustRequestUrl(t,a,o){const{fileUpload:e}=h();t.url=t.url.replace(e?.baseRoute+"/"||"/api/uploads/","/"),t.url=t.url.replace(e?.baseRoute||"/api/uploads/","/"),o()}export function extractRequestInfo(t){const{fileUpload:a}=h(),e=`${t.headers["x-forwarded-proto"]==="https"?"https":"http"}://${t.get?.("host")}`,i=a?.baseRoute||"/api/uploads";return{baseURL:e,baseRoute:i}}const d=(t,a)=>{const{fileUpload:o}=h(),e=o?.baseUploadDir||"/uploads";return e.startsWith("..")?n.join(a,n.basename(t)):x(t.replace(`${e}/`,"").replace(`/${e}/`,"").replace(`/${e}`,"").replace(`${e}`,""))};export const processFile=async(t,a)=>{const{baseURL:o,baseRoute:e}=extractRequestInfo(t),i=d(a,t.params.fileType);return`${o}${e==="/"?"":e}/${i}`},processImage=async(t,a,o)=>{const{baseURL:e,baseRoute:i}=extractRequestInfo(t),p=n.extname(a).toLowerCase(),w=p.replace(".",""),l=o.format||w;if(!U.lookup(p)?.includes?.("image")){const r=d(a,t.params.fileType);return`${e}${i}/${r}`}const g=`${n.basename(a,p)}_${Date.now()}${p}`,c=n.join(n.dirname(a),g);try{let r=y(a);const s=await r.metadata();if(o.resizeTo&&s.width&&s.height){const f=o.resizeTo/Math.min(s.width,s.height),b=Math.round(s.width*f),R=Math.round(s.height*f);r=r.resize(b,R)}else(o.width||o.height)&&(r=r.resize(o.width||null,o.height||null,{fit:"inside"}));l==="webp"?r=r.toFormat("webp"):(l==="jpeg"||l==="jpg")&&(r=r.toFormat("jpeg")),await r.toFile(c),await u(m.rename)(c,a);const $=d(a,t?.params.fileType);return`${e}${i}/${$}`}catch(r){try{await u(m.stat)(c),await u(m.unlink)(c)}catch{}throw r}};
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import sharp from "sharp";
4
+ import { promisify } from "util";
5
+ import { getArkosConfig } from "../../../../server.js";
6
+ import mimetype from "mimetype";
7
+ import { fullCleanCwd } from "../../../../utils/helpers/fs.helpers.js";
8
+ export function adjustRequestUrl(req, _, next) {
9
+ const { fileUpload } = getArkosConfig();
10
+ req.url = req.url.replace(fileUpload?.baseRoute + "/" || "/api/uploads/", "/");
11
+ req.url = req.url.replace(fileUpload?.baseRoute || "/api/uploads/", "/");
12
+ next();
13
+ }
14
+ export function extractRequestInfo(req) {
15
+ const { fileUpload } = getArkosConfig();
16
+ const protocol = req.headers["x-forwarded-proto"] === "https" ? "https" : "http";
17
+ const baseURL = `${protocol}://${req.get?.("host")}`;
18
+ const baseRoute = fileUpload?.baseRoute || "/api/uploads";
19
+ return { baseURL, baseRoute };
20
+ }
21
+ const generateRelativePath = (filePath, fileType) => {
22
+ const { fileUpload } = getArkosConfig();
23
+ const baseUploadDir = fileUpload?.baseUploadDir || "/uploads";
24
+ if (baseUploadDir.startsWith("..")) {
25
+ return path.join(fileType, path.basename(filePath));
26
+ }
27
+ else {
28
+ return fullCleanCwd(filePath
29
+ .replace(`${baseUploadDir}/`, "")
30
+ .replace(`/${baseUploadDir}/`, "")
31
+ .replace(`/${baseUploadDir}`, "")
32
+ .replace(`${baseUploadDir}`, ""));
33
+ }
34
+ };
35
+ export const processFile = async (req, filePath) => {
36
+ const { baseURL, baseRoute } = extractRequestInfo(req);
37
+ const relativePath = generateRelativePath(filePath, req.params.fileType);
38
+ return `${baseURL}${baseRoute === "/" ? "" : baseRoute}/${relativePath}`;
39
+ };
40
+ export const processImage = async (req, filePath, options) => {
41
+ const { baseURL, baseRoute } = extractRequestInfo(req);
42
+ const ext = path.extname(filePath).toLowerCase();
43
+ const originalFormat = ext.replace(".", "");
44
+ const outputFormat = options.format || originalFormat;
45
+ if (!mimetype.lookup(ext)?.includes?.("image")) {
46
+ const relativePath = generateRelativePath(filePath, req.params.fileType);
47
+ return `${baseURL}${baseRoute}/${relativePath}`;
48
+ }
49
+ const tempName = `${path.basename(filePath, ext)}_${Date.now()}${ext}`;
50
+ const tempPath = path.join(path.dirname(filePath), tempName);
51
+ try {
52
+ let transformer = sharp(filePath);
53
+ const metadata = await transformer.metadata();
54
+ if (options.resizeTo && metadata.width && metadata.height) {
55
+ const targetSize = options.resizeTo;
56
+ const scaleFactor = targetSize / Math.min(metadata.width, metadata.height);
57
+ const newWidth = Math.round(metadata.width * scaleFactor);
58
+ const newHeight = Math.round(metadata.height * scaleFactor);
59
+ transformer = transformer.resize(newWidth, newHeight);
60
+ }
61
+ else if (options.width || options.height) {
62
+ transformer = transformer.resize(options.width || null, options.height || null, {
63
+ fit: "inside",
64
+ });
65
+ }
66
+ if (outputFormat === "webp") {
67
+ transformer = transformer.toFormat("webp");
68
+ }
69
+ else if (outputFormat === "jpeg" || outputFormat === "jpg") {
70
+ transformer = transformer.toFormat("jpeg");
71
+ }
72
+ await transformer.toFile(tempPath);
73
+ await promisify(fs.rename)(tempPath, filePath);
74
+ const relativePath = generateRelativePath(filePath, req?.params.fileType);
75
+ return `${baseURL}${baseRoute}/${relativePath}`;
76
+ }
77
+ catch (error) {
78
+ try {
79
+ await promisify(fs.stat)(tempPath);
80
+ await promisify(fs.unlink)(tempPath);
81
+ }
82
+ catch (err) {
83
+ }
84
+ throw error;
85
+ }
86
+ };
87
+ //# sourceMappingURL=file-upload.helpers.js.map
@@ -1 +1,32 @@
1
- "use strict";import{Router as g}from"express";import c from"swagger-jsdoc";import p from"../../utils/helpers/deepmerge.helper.js";import{generatePathsForModels as f,getOpenAPIJsonSchemasByConfigMode as w}from"./utils/helpers/swagger.router.helpers.js";import d from"./utils/helpers/missing-json-schemas-generator.js";import u from"./utils/helpers/get-swagger-default-configs.js";import{importEsmPreventingTsTransformation as l}from"../../utils/helpers/global.helpers.js";import S from"./utils/helpers/json-schema-generators/generate-system-json-schemas.js";const n=g();export async function getSwaggerRouter(e){let t=await w(e);const r=await f(e);t={...t,...await d.generateMissingJsonSchemas(r,t,e),...S(e)};const o=p(await u(r,t)||{},e.swagger||{}),{definition:a,...s}=o?.options,i=c({definition:a,...s}),m=await l("@scalar/express-api-reference");return n.use(o.endpoint,m.apiReference({content:i,...o?.scalarApiReferenceConfiguration})),n}
1
+ import { Router } from "express";
2
+ import swaggerJsdoc from "swagger-jsdoc";
3
+ import deepmerge from "../../utils/helpers/deepmerge.helper.js";
4
+ import { generatePathsForModels, getOpenAPIJsonSchemasByConfigMode, } from "./utils/helpers/swagger.router.helpers.js";
5
+ import missingJsonSchemaGenerator from "./utils/helpers/missing-json-schemas-generator.js";
6
+ import getSwaggerDefaultConfig from "./utils/helpers/get-swagger-default-configs.js";
7
+ import { importEsmPreventingTsTransformation } from "../../utils/helpers/global.helpers.js";
8
+ import generateSystemJsonSchemas from "./utils/helpers/json-schema-generators/generate-system-json-schemas.js";
9
+ const swaggerRouter = Router();
10
+ export async function getSwaggerRouter(arkosConfig) {
11
+ let defaultJsonSchemas = await getOpenAPIJsonSchemasByConfigMode(arkosConfig);
12
+ const defaultModelsPaths = await generatePathsForModels(arkosConfig);
13
+ defaultJsonSchemas = {
14
+ ...defaultJsonSchemas,
15
+ ...(await missingJsonSchemaGenerator.generateMissingJsonSchemas(defaultModelsPaths, defaultJsonSchemas, arkosConfig)),
16
+ ...generateSystemJsonSchemas(arkosConfig),
17
+ };
18
+ const swaggerConfigs = deepmerge((await getSwaggerDefaultConfig(defaultModelsPaths, defaultJsonSchemas)) ||
19
+ {}, arkosConfig.swagger || {});
20
+ const { definition, ...options } = swaggerConfigs?.options;
21
+ const swaggerSpecification = swaggerJsdoc({
22
+ definition: definition,
23
+ ...options,
24
+ });
25
+ const scalar = await importEsmPreventingTsTransformation("@scalar/express-api-reference");
26
+ swaggerRouter.use(swaggerConfigs.endpoint, scalar.apiReference({
27
+ content: swaggerSpecification,
28
+ ...swaggerConfigs?.scalarApiReferenceConfiguration,
29
+ }));
30
+ return swaggerRouter;
31
+ }
32
+ //# sourceMappingURL=swagger.router.js.map