underpost 2.6.3 → 2.7.2

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 (216) hide show
  1. package/.dockerignore +13 -13
  2. package/.env.development +7 -7
  3. package/.env.production +7 -7
  4. package/.env.test +7 -7
  5. package/.github/workflows/publish.yml +26 -0
  6. package/.nycrc +9 -9
  7. package/.prettierignore +12 -12
  8. package/.prettierrc +9 -9
  9. package/.vscode/extensions.json +72 -72
  10. package/.vscode/settings.json +100 -99
  11. package/AUTHORS.md +10 -0
  12. package/CHANGELOG.md +91 -0
  13. package/Dockerfile +89 -89
  14. package/LICENSE +21 -21
  15. package/README.md +96 -96
  16. package/bin/db.js +172 -119
  17. package/bin/deploy.js +582 -626
  18. package/bin/dns.js +1 -1
  19. package/bin/file.js +92 -92
  20. package/bin/index.js +53 -34
  21. package/bin/install.js +398 -357
  22. package/bin/shortcut.js +44 -44
  23. package/bin/ssl.js +65 -61
  24. package/bin/util.js +182 -182
  25. package/bin/vs.js +35 -35
  26. package/conf.js +251 -249
  27. package/docker-compose.yml +67 -67
  28. package/jsconfig.json +7 -7
  29. package/jsdoc.json +32 -32
  30. package/nodemon.json +6 -6
  31. package/package.json +137 -128
  32. package/prometheus.yml +36 -36
  33. package/setup.sh +24 -24
  34. package/src/api/core/core.controller.js +69 -69
  35. package/src/api/core/core.model.js +11 -11
  36. package/src/api/core/core.router.js +23 -23
  37. package/src/api/core/core.service.js +29 -29
  38. package/src/api/crypto/crypto.controller.js +51 -51
  39. package/src/api/crypto/crypto.model.js +23 -23
  40. package/src/api/crypto/crypto.router.js +20 -20
  41. package/src/api/crypto/crypto.service.js +64 -64
  42. package/src/api/default/default.controller.js +69 -69
  43. package/src/api/default/default.model.js +20 -20
  44. package/src/api/default/default.router.js +23 -23
  45. package/src/api/default/default.service.js +31 -31
  46. package/src/api/file/file.controller.js +53 -51
  47. package/src/api/file/file.model.js +19 -19
  48. package/src/api/file/file.router.js +21 -20
  49. package/src/api/file/file.service.js +76 -70
  50. package/src/api/instance/instance.controller.js +69 -69
  51. package/src/api/instance/instance.model.js +36 -36
  52. package/src/api/instance/instance.router.js +33 -33
  53. package/src/api/instance/instance.service.js +48 -48
  54. package/src/api/test/test.controller.js +59 -59
  55. package/src/api/test/test.model.js +14 -14
  56. package/src/api/test/test.router.js +21 -21
  57. package/src/api/test/test.service.js +35 -35
  58. package/src/api/user/user.build.js +16 -0
  59. package/src/api/user/user.controller.js +70 -70
  60. package/src/api/user/user.model.js +65 -65
  61. package/src/api/user/user.router.js +345 -345
  62. package/src/api/user/user.service.js +479 -479
  63. package/src/api.js +23 -23
  64. package/src/client/Default.index.js +40 -40
  65. package/src/client/components/core/Account.js +290 -290
  66. package/src/client/components/core/AgGrid.js +160 -160
  67. package/src/client/components/core/Auth.js +19 -19
  68. package/src/client/components/core/Badge.js +32 -32
  69. package/src/client/components/core/BlockChain.js +41 -41
  70. package/src/client/components/core/Blog.js +9 -9
  71. package/src/client/components/core/BtnIcon.js +101 -94
  72. package/src/client/components/core/CalendarCore.js +458 -319
  73. package/src/client/components/core/Chat.js +64 -64
  74. package/src/client/components/core/ColorPalette.js +5267 -5267
  75. package/src/client/components/core/CommonJs.js +735 -732
  76. package/src/client/components/core/Content.js +193 -49
  77. package/src/client/components/core/Css.js +1064 -1027
  78. package/src/client/components/core/CssCore.js +817 -796
  79. package/src/client/components/core/D3Chart.js +44 -44
  80. package/src/client/components/core/Docs.js +229 -229
  81. package/src/client/components/core/DropDown.js +164 -164
  82. package/src/client/components/core/EventsUI.js +46 -54
  83. package/src/client/components/core/FileExplorer.js +699 -624
  84. package/src/client/components/core/FullScreen.js +45 -45
  85. package/src/client/components/core/Input.js +346 -259
  86. package/src/client/components/core/JoyStick.js +77 -77
  87. package/src/client/components/core/Keyboard.js +73 -73
  88. package/src/client/components/core/LoadingAnimation.js +179 -157
  89. package/src/client/components/core/LogIn.js +187 -181
  90. package/src/client/components/core/LogOut.js +58 -52
  91. package/src/client/components/core/Logger.js +26 -26
  92. package/src/client/components/core/Modal.js +1612 -1596
  93. package/src/client/components/core/NotificationManager.js +84 -84
  94. package/src/client/components/core/Panel.js +613 -413
  95. package/src/client/components/core/PanelForm.js +468 -0
  96. package/src/client/components/core/Polyhedron.js +162 -162
  97. package/src/client/components/core/Recover.js +204 -204
  98. package/src/client/components/core/Responsive.js +53 -53
  99. package/src/client/components/core/RichText.js +51 -27
  100. package/src/client/components/core/Router.js +76 -77
  101. package/src/client/components/core/Scroll.js +34 -0
  102. package/src/client/components/core/SignUp.js +125 -125
  103. package/src/client/components/core/SocketIo.js +72 -72
  104. package/src/client/components/core/Stream.js +113 -113
  105. package/src/client/components/core/ToggleSwitch.js +87 -87
  106. package/src/client/components/core/ToolTip.js +26 -26
  107. package/src/client/components/core/Translate.js +437 -408
  108. package/src/client/components/core/Validator.js +100 -100
  109. package/src/client/components/core/VanillaJs.js +460 -457
  110. package/src/client/components/core/Wallet.js +106 -106
  111. package/src/client/components/core/Webhook.js +25 -25
  112. package/src/client/components/core/Worker.js +272 -272
  113. package/src/client/components/default/CommonDefault.js +29 -29
  114. package/src/client/components/default/CssDefault.js +13 -13
  115. package/src/client/components/default/ElementsDefault.js +38 -38
  116. package/src/client/components/default/LogInDefault.js +41 -41
  117. package/src/client/components/default/LogOutDefault.js +28 -28
  118. package/src/client/components/default/MenuDefault.js +389 -389
  119. package/src/client/components/default/RoutesDefault.js +48 -48
  120. package/src/client/components/default/SettingsDefault.js +16 -16
  121. package/src/client/components/default/SignUpDefault.js +9 -9
  122. package/src/client/components/default/SocketIoDefault.js +54 -54
  123. package/src/client/components/default/TranslateDefault.js +7 -7
  124. package/src/client/public/default/assets/mailer/api-user-check.png +0 -0
  125. package/src/client/public/default/assets/mailer/api-user-invalid-token.png +0 -0
  126. package/src/client/public/default/assets/mailer/api-user-recover.png +0 -0
  127. package/src/client/public/default/browserconfig.xml +11 -11
  128. package/src/client/public/default/manifest.webmanifest +68 -68
  129. package/src/client/public/default/plantuml/client-conf.svg +1 -0
  130. package/src/client/public/default/plantuml/client-schema.svg +1 -0
  131. package/src/client/public/default/plantuml/cron-conf.svg +1 -0
  132. package/src/client/public/default/plantuml/cron-schema.svg +1 -0
  133. package/src/client/public/default/plantuml/server-conf.svg +1 -0
  134. package/src/client/public/default/plantuml/server-schema.svg +1 -0
  135. package/src/client/public/default/plantuml/ssr-conf.svg +1 -0
  136. package/src/client/public/default/plantuml/ssr-schema.svg +1 -0
  137. package/src/client/public/default/sitemap +147 -147
  138. package/src/client/public/default/yandex-browser-manifest.json +8 -8
  139. package/src/client/public/doc/sitemap +147 -147
  140. package/src/client/public/test/sitemap +147 -147
  141. package/src/client/services/core/core.service.js +170 -152
  142. package/src/client/services/crypto/crypto.service.js +70 -70
  143. package/src/client/services/default/default.management.js +345 -345
  144. package/src/client/services/default/default.service.js +89 -89
  145. package/src/client/services/file/file.service.js +70 -70
  146. package/src/client/services/instance/instance.management.js +74 -74
  147. package/src/client/services/instance/instance.service.js +89 -89
  148. package/src/client/services/test/test.service.js +70 -70
  149. package/src/client/services/user/user.management.js +50 -50
  150. package/src/client/services/user/user.service.js +89 -89
  151. package/src/client/ssr/Render.js +16 -16
  152. package/src/client/ssr/body-components/CacheControl.js +114 -113
  153. package/src/client/ssr/body-components/DefaultSplashScreen.js +79 -79
  154. package/src/client/ssr/email-components/DefaultRecoverEmail.js +21 -21
  155. package/src/client/ssr/email-components/DefaultVerifyEmail.js +17 -17
  156. package/src/client/ssr/head-components/Css.js +241 -241
  157. package/src/client/ssr/head-components/DefaultScripts.js +3 -3
  158. package/src/client/ssr/head-components/Microdata.js +11 -11
  159. package/src/client/ssr/head-components/Production.js +1 -1
  160. package/src/client/ssr/head-components/PwaDefault.js +59 -59
  161. package/src/client/ssr/head-components/Seo.js +14 -14
  162. package/src/client/sw/default.sw.js +201 -201
  163. package/src/client/sw/template.sw.js +84 -84
  164. package/src/client.build.js +22 -22
  165. package/src/client.dev.js +21 -21
  166. package/src/cron.js +25 -25
  167. package/src/db/DataBaseProvider.js +34 -34
  168. package/src/db/mariadb/MariaDB.js +33 -33
  169. package/src/db/mongo/MongooseDB.js +46 -46
  170. package/src/dns.js +22 -22
  171. package/src/index.js +42 -0
  172. package/src/mailer/EmailRender.js +69 -69
  173. package/src/mailer/MailerProvider.js +96 -96
  174. package/src/proxy.js +22 -22
  175. package/src/runtime/lampp/Lampp.js +69 -44
  176. package/src/runtime/nginx/Nginx.js +3 -3
  177. package/src/runtime/xampp/Xampp.js +49 -49
  178. package/src/server/auth.js +235 -204
  179. package/src/server/backup.js +101 -84
  180. package/src/server/client-build-live.js +72 -72
  181. package/src/server/client-build.js +705 -699
  182. package/src/server/client-dev-server.js +60 -58
  183. package/src/server/client-formatted.js +48 -48
  184. package/src/server/client-icons.js +149 -150
  185. package/src/server/conf.js +860 -611
  186. package/src/server/dns.js +98 -87
  187. package/src/server/downloader.js +42 -42
  188. package/src/server/logger.js +180 -135
  189. package/src/server/network.js +122 -122
  190. package/src/server/peer.js +33 -33
  191. package/src/server/process.js +66 -66
  192. package/src/server/prompt-optimizer.js +28 -0
  193. package/src/server/proxy.js +118 -118
  194. package/src/server/runtime.js +444 -393
  195. package/src/server/ssl.js +109 -107
  196. package/src/server.js +25 -25
  197. package/src/ws/IoInterface.js +45 -45
  198. package/src/ws/IoServer.js +39 -39
  199. package/src/ws/core/channels/core.ws.chat.js +23 -23
  200. package/src/ws/core/channels/core.ws.mailer.js +35 -35
  201. package/src/ws/core/channels/core.ws.stream.js +31 -31
  202. package/src/ws/core/core.ws.connection.js +28 -28
  203. package/src/ws/core/core.ws.emit.js +14 -14
  204. package/src/ws/core/core.ws.server.js +24 -24
  205. package/src/ws/core/management/core.ws.chat.js +8 -8
  206. package/src/ws/core/management/core.ws.mailer.js +16 -16
  207. package/src/ws/core/management/core.ws.stream.js +8 -8
  208. package/src/ws/default/channels/default.ws.main.js +16 -16
  209. package/src/ws/default/default.ws.connection.js +22 -22
  210. package/src/ws/default/default.ws.emit.js +14 -14
  211. package/src/ws/default/default.ws.server.js +20 -20
  212. package/src/ws/default/management/default.ws.main.js +8 -8
  213. package/startup.js +11 -11
  214. package/supervisord-openssh-server.conf +4 -4
  215. package/test/api.test.js +60 -60
  216. package/bin/help.js +0 -110
@@ -1,148 +1,148 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <xsl:stylesheet version="2.0"
3
- xmlns:html="http://www.w3.org/TR/REC-html40"
4
- xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
5
- xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9"
6
- xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
7
- <xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes" />
8
- <xsl:template match="/">
9
- <html xmlns="http://www.w3.org/1999/xhtml">
10
- <head>
11
- <title>XML Sitemap</title>
12
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
13
- <style type="text/css">
14
- body {
15
- font-family: sans-serif;
16
- font-size: 16px;
17
- color: #242628;
18
- }
19
- a {
20
- color: #000;
21
- text-decoration: none;
22
- }
23
- a:hover {
24
- text-decoration: underline;
25
- }
26
- table {
27
- border: none;
28
- border-collapse: collapse;
29
- width: 100%
30
- }
31
- th {
32
- text-align: left;
33
- padding-right: 30px;
34
- font-size: 11px;
35
- }
36
- thead th {
37
- border-bottom: 1px solid #7d878a;
38
- cursor: pointer;
39
- }
40
- td {
41
- font-size:11px;
42
- padding: 5px;
43
- }
44
- tr:nth-child(odd) td {
45
- background-color: rgba(0,0,0,0.04);
46
- }
47
- tr:hover td {
48
- background-color: #e2edf2;
49
- }
50
-
51
- #content {
52
- margin: 0 auto;
53
- padding: 2% 5%;
54
- max-width: 800px;
55
- }
56
-
57
- .desc {
58
- margin: 18px 3px;
59
- line-height: 1.2em;
60
- }
61
- .desc a {
62
- color: #5ba4e5;
63
- }
64
- </style>
65
- </head>
66
- <body>
67
- <div id="content">
68
- <h1>XML Sitemap</h1>
69
- <p class="desc"> This is a sitemap generated by <a
70
- href="https://www.nexodev.org">nexodev.org</a>
71
- </p>
72
- <xsl:if test="count(sitemap:sitemapindex/sitemap:sitemap) &gt; 0">
73
- <table id="sitemap" cellpadding="3">
74
- <thead>
75
- <tr>
76
- <th width="75%">Sitemap</th>
77
- <th width="25%">Last Modified</th>
78
- </tr>
79
- </thead>
80
- <tbody>
81
- <xsl:for-each select="sitemap:sitemapindex/sitemap:sitemap">
82
- <xsl:variable name="sitemapURL">
83
- <xsl:value-of select="sitemap:loc" />
84
- </xsl:variable>
85
- <tr>
86
- <td>
87
- <a href="{$sitemapURL}">
88
- <xsl:value-of select="sitemap:loc" />
89
- </a>
90
- </td>
91
- <td>
92
- <xsl:value-of
93
- select="concat(substring(sitemap:lastmod,0,11),concat(' ', substring(sitemap:lastmod,12,5)))" />
94
- </td>
95
- </tr>
96
- </xsl:for-each>
97
- </tbody>
98
- </table>
99
- </xsl:if>
100
- <xsl:if test="count(sitemap:sitemapindex/sitemap:sitemap) &lt; 1">
101
- <p class="desc">
102
- <a href="{{web-url}}sitemap.xml" class="back-link">&#8592; Back to index</a>
103
- </p>
104
- <table
105
- id="sitemap" cellpadding="3">
106
- <thead>
107
- <tr>
108
- <th width="70%">URL (<xsl:value-of
109
- select="count(sitemap:urlset/sitemap:url)" /> total)</th>
110
- <th width="15%">Images</th>
111
- <th title="Last Modification Time" width="15%">Last Modified</th>
112
- </tr>
113
- </thead>
114
- <tbody>
115
- <xsl:variable name="lower" select="'abcdefghijklmnopqrstuvwxyz'" />
116
- <xsl:variable name="upper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />
117
- <xsl:for-each select="sitemap:urlset/sitemap:url">
118
- <tr>
119
- <td>
120
- <xsl:variable name="itemURL">
121
- <xsl:value-of select="sitemap:loc" />
122
- </xsl:variable>
123
- <a href="{$itemURL}">
124
- <xsl:value-of select="sitemap:loc" />
125
- </a>
126
- </td>
127
- <td>
128
- <xsl:value-of select="count(image:image)" />
129
- </td>
130
- <td>
131
- <xsl:value-of
132
- select="concat(substring(sitemap:lastmod,0,11),concat(' ', substring(sitemap:lastmod,12,5)))" />
133
- </td>
134
- </tr>
135
- </xsl:for-each>
136
- </tbody>
137
- </table>
138
- <p
139
- class="desc">
140
- <a href="{{web-url}}sitemap.xml" class="back-link">&#8592; Back to index</a>
141
- </p>
142
- </xsl:if>
143
- </div>
144
- </body>
145
- </html>
146
-
147
- </xsl:template>
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <xsl:stylesheet version="2.0"
3
+ xmlns:html="http://www.w3.org/TR/REC-html40"
4
+ xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
5
+ xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9"
6
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
7
+ <xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes" />
8
+ <xsl:template match="/">
9
+ <html xmlns="http://www.w3.org/1999/xhtml">
10
+ <head>
11
+ <title>XML Sitemap</title>
12
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
13
+ <style type="text/css">
14
+ body {
15
+ font-family: sans-serif;
16
+ font-size: 16px;
17
+ color: #242628;
18
+ }
19
+ a {
20
+ color: #000;
21
+ text-decoration: none;
22
+ }
23
+ a:hover {
24
+ text-decoration: underline;
25
+ }
26
+ table {
27
+ border: none;
28
+ border-collapse: collapse;
29
+ width: 100%
30
+ }
31
+ th {
32
+ text-align: left;
33
+ padding-right: 30px;
34
+ font-size: 11px;
35
+ }
36
+ thead th {
37
+ border-bottom: 1px solid #7d878a;
38
+ cursor: pointer;
39
+ }
40
+ td {
41
+ font-size:11px;
42
+ padding: 5px;
43
+ }
44
+ tr:nth-child(odd) td {
45
+ background-color: rgba(0,0,0,0.04);
46
+ }
47
+ tr:hover td {
48
+ background-color: #e2edf2;
49
+ }
50
+
51
+ #content {
52
+ margin: 0 auto;
53
+ padding: 2% 5%;
54
+ max-width: 800px;
55
+ }
56
+
57
+ .desc {
58
+ margin: 18px 3px;
59
+ line-height: 1.2em;
60
+ }
61
+ .desc a {
62
+ color: #5ba4e5;
63
+ }
64
+ </style>
65
+ </head>
66
+ <body>
67
+ <div id="content">
68
+ <h1>XML Sitemap</h1>
69
+ <p class="desc"> This is a sitemap generated by <a
70
+ href="https://www.nexodev.org">nexodev.org</a>
71
+ </p>
72
+ <xsl:if test="count(sitemap:sitemapindex/sitemap:sitemap) &gt; 0">
73
+ <table id="sitemap" cellpadding="3">
74
+ <thead>
75
+ <tr>
76
+ <th width="75%">Sitemap</th>
77
+ <th width="25%">Last Modified</th>
78
+ </tr>
79
+ </thead>
80
+ <tbody>
81
+ <xsl:for-each select="sitemap:sitemapindex/sitemap:sitemap">
82
+ <xsl:variable name="sitemapURL">
83
+ <xsl:value-of select="sitemap:loc" />
84
+ </xsl:variable>
85
+ <tr>
86
+ <td>
87
+ <a href="{$sitemapURL}">
88
+ <xsl:value-of select="sitemap:loc" />
89
+ </a>
90
+ </td>
91
+ <td>
92
+ <xsl:value-of
93
+ select="concat(substring(sitemap:lastmod,0,11),concat(' ', substring(sitemap:lastmod,12,5)))" />
94
+ </td>
95
+ </tr>
96
+ </xsl:for-each>
97
+ </tbody>
98
+ </table>
99
+ </xsl:if>
100
+ <xsl:if test="count(sitemap:sitemapindex/sitemap:sitemap) &lt; 1">
101
+ <p class="desc">
102
+ <a href="{{web-url}}sitemap.xml" class="back-link">&#8592; Back to index</a>
103
+ </p>
104
+ <table
105
+ id="sitemap" cellpadding="3">
106
+ <thead>
107
+ <tr>
108
+ <th width="70%">URL (<xsl:value-of
109
+ select="count(sitemap:urlset/sitemap:url)" /> total)</th>
110
+ <th width="15%">Images</th>
111
+ <th title="Last Modification Time" width="15%">Last Modified</th>
112
+ </tr>
113
+ </thead>
114
+ <tbody>
115
+ <xsl:variable name="lower" select="'abcdefghijklmnopqrstuvwxyz'" />
116
+ <xsl:variable name="upper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />
117
+ <xsl:for-each select="sitemap:urlset/sitemap:url">
118
+ <tr>
119
+ <td>
120
+ <xsl:variable name="itemURL">
121
+ <xsl:value-of select="sitemap:loc" />
122
+ </xsl:variable>
123
+ <a href="{$itemURL}">
124
+ <xsl:value-of select="sitemap:loc" />
125
+ </a>
126
+ </td>
127
+ <td>
128
+ <xsl:value-of select="count(image:image)" />
129
+ </td>
130
+ <td>
131
+ <xsl:value-of
132
+ select="concat(substring(sitemap:lastmod,0,11),concat(' ', substring(sitemap:lastmod,12,5)))" />
133
+ </td>
134
+ </tr>
135
+ </xsl:for-each>
136
+ </tbody>
137
+ </table>
138
+ <p
139
+ class="desc">
140
+ <a href="{{web-url}}sitemap.xml" class="back-link">&#8592; Back to index</a>
141
+ </p>
142
+ </xsl:if>
143
+ </div>
144
+ </body>
145
+ </html>
146
+
147
+ </xsl:template>
148
148
  </xsl:stylesheet>
@@ -1,152 +1,170 @@
1
- import { Auth } from '../../components/core/Auth.js';
2
- import { loggerFactory } from '../../components/core/Logger.js';
3
- import { getProxyPath } from '../../components/core/VanillaJs.js';
4
-
5
- const logger = loggerFactory(import.meta);
6
-
7
- // https://developer.mozilla.org/en-US/docs/Web/API/AbortController
8
- const getBaseHost = () => location.host;
9
-
10
- const getApiBasePath = () => `${getProxyPath()}api/`;
11
-
12
- const getApiBaseUrl = (options = { id: '', endpoint: '' }) =>
13
- `${location.protocol}//${getBaseHost()}${getApiBasePath()}${options?.endpoint ? options.endpoint : ''}${
14
- options?.id ? `/${options.id}` : ''
15
- }`;
16
-
17
- const getWsBasePath = () => (getProxyPath() !== '/' ? `${getProxyPath()}socket.io/` : undefined);
18
-
19
- const getWsBaseUrl = (options = { id: '', endpoint: '', wsBasePath: '' }) =>
20
- `${window.location.protocol === 'https:' ? 'wss:' : 'ws:'}//${getBaseHost()}${
21
- options?.wsBasePath !== undefined ? options.wsBasePath : getWsBasePath()
22
- }${options?.endpoint ? options.endpoint : ''}${options?.id ? `/${options.id}` : ''}`;
23
-
24
- const headersFactory = (headerId = '') => {
25
- const headers = { Authorization: Auth.getJWT() };
26
- switch (headerId) {
27
- case 'file':
28
- return headers;
29
-
30
- default:
31
- headers['Content-Type'] = 'application/json';
32
- return headers;
33
- }
34
- };
35
-
36
- const payloadFactory = (body) => {
37
- if (body instanceof FormData) return body;
38
- return JSON.stringify(body);
39
- };
40
-
41
- logger.info('Load service');
42
-
43
- const endpoint = 'core';
44
-
45
- const CoreService = {
46
- getRaw: (options = { url: '' }) =>
47
- new Promise((resolve, reject) =>
48
- fetch(options.url, {
49
- method: 'GET',
50
- })
51
- .then(async (res) => {
52
- return await res.text();
53
- })
54
- .then((res) => {
55
- // logger.info(res);
56
- return resolve(res);
57
- })
58
- .catch((error) => {
59
- logger.error(error);
60
- return reject(error);
61
- }),
62
- ),
63
- post: (options = { id: '', body: {} }) =>
64
- new Promise((resolve, reject) =>
65
- fetch(getApiBaseUrl({ id: options.id, endpoint }), {
66
- method: 'POST',
67
- headers: headersFactory(),
68
- body: payloadFactory(options.body),
69
- })
70
- .then(async (res) => {
71
- return await res.json();
72
- })
73
- .then((res) => {
74
- logger.info(res);
75
- return resolve(res);
76
- })
77
- .catch((error) => {
78
- logger.error(error);
79
- return reject(error);
80
- }),
81
- ),
82
- put: (options = { id: '', body: {} }) =>
83
- new Promise((resolve, reject) =>
84
- fetch(getApiBaseUrl({ id: options.id, endpoint }), {
85
- method: 'PUT',
86
- headers: headersFactory(),
87
- body: payloadFactory(options.body),
88
- })
89
- .then(async (res) => {
90
- return await res.json();
91
- })
92
- .then((res) => {
93
- logger.info(res);
94
- return resolve(res);
95
- })
96
- .catch((error) => {
97
- logger.error(error);
98
- return reject(error);
99
- }),
100
- ),
101
- get: (options = { id: '', body: {} }) =>
102
- new Promise((resolve, reject) =>
103
- fetch(getApiBaseUrl({ id: options.id, endpoint }), {
104
- method: 'GET',
105
- headers: headersFactory(),
106
- })
107
- .then(async (res) => {
108
- return await res.json();
109
- })
110
- .then((res) => {
111
- logger.info(res);
112
- return resolve(res);
113
- })
114
- .catch((error) => {
115
- logger.error(error);
116
- return reject(error);
117
- }),
118
- ),
119
- delete: (options = { id: '', body: {} }) =>
120
- new Promise((resolve, reject) =>
121
- fetch(getApiBaseUrl({ id: options.id, endpoint }), {
122
- method: 'DELETE',
123
- headers: headersFactory(),
124
- body: payloadFactory(options.body),
125
- })
126
- .then(async (res) => {
127
- return await res.json();
128
- })
129
- .then((res) => {
130
- logger.info(res);
131
- return resolve(res);
132
- })
133
- .catch((error) => {
134
- logger.error(error);
135
- return reject(error);
136
- }),
137
- ),
138
- };
139
-
140
- const ApiBase = getApiBaseUrl;
141
-
142
- export {
143
- CoreService,
144
- headersFactory,
145
- payloadFactory,
146
- getBaseHost,
147
- getApiBasePath,
148
- getApiBaseUrl,
149
- getWsBasePath,
150
- getWsBaseUrl,
151
- ApiBase,
152
- };
1
+ import { Auth } from '../../components/core/Auth.js';
2
+ import { loggerFactory } from '../../components/core/Logger.js';
3
+ import { getProxyPath } from '../../components/core/VanillaJs.js';
4
+
5
+ const logger = loggerFactory(import.meta);
6
+
7
+ // https://developer.mozilla.org/en-US/docs/Web/API/AbortController
8
+ const getBaseHost = () => location.host;
9
+
10
+ const getApiBasePath = () => `${getProxyPath()}api/`;
11
+
12
+ const getApiBaseUrl = (options = { id: '', endpoint: '' }) =>
13
+ `${location.protocol}//${getBaseHost()}${getApiBasePath()}${options?.endpoint ? options.endpoint : ''}${
14
+ options?.id ? `/${options.id}` : ''
15
+ }`;
16
+
17
+ const getWsBasePath = () => (getProxyPath() !== '/' ? `${getProxyPath()}socket.io/` : undefined);
18
+
19
+ const getWsBaseUrl = (options = { id: '', endpoint: '', wsBasePath: '' }) =>
20
+ `${window.location.protocol === 'https:' ? 'wss:' : 'ws:'}//${getBaseHost()}${
21
+ options?.wsBasePath !== undefined ? options.wsBasePath : getWsBasePath()
22
+ }${options?.endpoint ? options.endpoint : ''}${options?.id ? `/${options.id}` : ''}`;
23
+
24
+ const headersFactory = (headerId = '') => {
25
+ const headers = { Authorization: Auth.getJWT() }; // , mode: 'no-cors'
26
+ switch (headerId) {
27
+ case 'file':
28
+ return headers;
29
+
30
+ default:
31
+ headers['Content-Type'] = 'application/json';
32
+ return headers;
33
+ }
34
+ };
35
+
36
+ const payloadFactory = (body) => {
37
+ if (body instanceof FormData) return body;
38
+ return JSON.stringify(body);
39
+ };
40
+
41
+ logger.info('Load service');
42
+
43
+ const endpoint = 'core';
44
+
45
+ const CoreService = {
46
+ getRaw: (options = { url: '' }) =>
47
+ new Promise((resolve, reject) =>
48
+ fetch(options.url, {
49
+ method: 'GET',
50
+ })
51
+ .then(async (res) => {
52
+ return await res.text();
53
+ })
54
+ .then((res) => {
55
+ // logger.info(res);
56
+ return resolve(res);
57
+ })
58
+ .catch((error) => {
59
+ logger.error(error);
60
+ return reject(error);
61
+ }),
62
+ ),
63
+ getRandomImage: (options = { category: ['city'], mimetype: 'image/jpg' }) => {
64
+ const src = `https://api.api-ninjas.com/v1/randomimage?category=${options.category[0]}`;
65
+ return new Promise((resolve) => {
66
+ fetch(src, {
67
+ headers: { 'X-Api-Key': 'FyITmcxRXkCaUehbX6K0/g==uxZcFKL0dZUUg48G', Accept: options.mimetype },
68
+ })
69
+ .then((res) => res.blob())
70
+ .then(async (blob) => {
71
+ return resolve({
72
+ file: {
73
+ mimetype: 'image/jpg',
74
+ name: 'image.jpg',
75
+ },
76
+ url: URL.createObjectURL(blob),
77
+ });
78
+ });
79
+ });
80
+ },
81
+ post: (options = { id: '', body: {} }) =>
82
+ new Promise((resolve, reject) =>
83
+ fetch(getApiBaseUrl({ id: options.id, endpoint }), {
84
+ method: 'POST',
85
+ headers: headersFactory(),
86
+ body: payloadFactory(options.body),
87
+ })
88
+ .then(async (res) => {
89
+ return await res.json();
90
+ })
91
+ .then((res) => {
92
+ logger.info(res);
93
+ return resolve(res);
94
+ })
95
+ .catch((error) => {
96
+ logger.error(error);
97
+ return reject(error);
98
+ }),
99
+ ),
100
+ put: (options = { id: '', body: {} }) =>
101
+ new Promise((resolve, reject) =>
102
+ fetch(getApiBaseUrl({ id: options.id, endpoint }), {
103
+ method: 'PUT',
104
+ headers: headersFactory(),
105
+ body: payloadFactory(options.body),
106
+ })
107
+ .then(async (res) => {
108
+ return await res.json();
109
+ })
110
+ .then((res) => {
111
+ logger.info(res);
112
+ return resolve(res);
113
+ })
114
+ .catch((error) => {
115
+ logger.error(error);
116
+ return reject(error);
117
+ }),
118
+ ),
119
+ get: (options = { id: '', body: {} }) =>
120
+ new Promise((resolve, reject) =>
121
+ fetch(getApiBaseUrl({ id: options.id, endpoint }), {
122
+ method: 'GET',
123
+ headers: headersFactory(),
124
+ })
125
+ .then(async (res) => {
126
+ return await res.json();
127
+ })
128
+ .then((res) => {
129
+ logger.info(res);
130
+ return resolve(res);
131
+ })
132
+ .catch((error) => {
133
+ logger.error(error);
134
+ return reject(error);
135
+ }),
136
+ ),
137
+ delete: (options = { id: '', body: {} }) =>
138
+ new Promise((resolve, reject) =>
139
+ fetch(getApiBaseUrl({ id: options.id, endpoint }), {
140
+ method: 'DELETE',
141
+ headers: headersFactory(),
142
+ body: payloadFactory(options.body),
143
+ })
144
+ .then(async (res) => {
145
+ return await res.json();
146
+ })
147
+ .then((res) => {
148
+ logger.info(res);
149
+ return resolve(res);
150
+ })
151
+ .catch((error) => {
152
+ logger.error(error);
153
+ return reject(error);
154
+ }),
155
+ ),
156
+ };
157
+
158
+ const ApiBase = getApiBaseUrl;
159
+
160
+ export {
161
+ CoreService,
162
+ headersFactory,
163
+ payloadFactory,
164
+ getBaseHost,
165
+ getApiBasePath,
166
+ getApiBaseUrl,
167
+ getWsBasePath,
168
+ getWsBaseUrl,
169
+ ApiBase,
170
+ };