nextjs-cms 0.9.21 → 0.9.23

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 (190) hide show
  1. package/README.md +65 -13
  2. package/dist/api/actions/files.d.ts +30 -0
  3. package/dist/api/actions/files.d.ts.map +1 -0
  4. package/dist/api/actions/files.js +234 -0
  5. package/dist/api/actions/index.d.ts +4 -0
  6. package/dist/api/actions/index.d.ts.map +1 -0
  7. package/dist/api/actions/index.js +3 -0
  8. package/dist/api/actions/pages.d.ts +297 -0
  9. package/dist/api/actions/pages.d.ts.map +1 -0
  10. package/dist/api/actions/pages.js +1215 -0
  11. package/dist/api/actions/privileges.d.ts +25 -0
  12. package/dist/api/actions/privileges.d.ts.map +1 -0
  13. package/dist/api/actions/privileges.js +98 -0
  14. package/dist/api/client/index.d.ts +4 -0
  15. package/dist/api/client/index.d.ts.map +1 -0
  16. package/dist/api/client/index.js +3 -0
  17. package/dist/api/client.d.ts +30 -0
  18. package/dist/api/client.d.ts.map +1 -0
  19. package/dist/api/client.js +82 -0
  20. package/dist/api/index.d.ts +1 -938
  21. package/dist/api/index.d.ts.map +1 -1
  22. package/dist/api/index.js +0 -13
  23. package/dist/api/lib/serverActions.d.ts +3 -3
  24. package/dist/api/plugin/index.d.ts +7 -0
  25. package/dist/api/plugin/index.d.ts.map +1 -0
  26. package/dist/api/plugin/index.js +5 -0
  27. package/dist/api/root.d.ts +18 -1844
  28. package/dist/api/root.d.ts.map +1 -1
  29. package/dist/api/root.js +18 -83
  30. package/dist/api/routers/navigation.d.ts +3 -3
  31. package/dist/api/server/index.d.ts +8 -0
  32. package/dist/api/server/index.d.ts.map +1 -0
  33. package/dist/api/server/index.js +3 -0
  34. package/dist/api/server.d.ts +2748 -0
  35. package/dist/api/server.d.ts.map +1 -0
  36. package/dist/api/server.js +100 -0
  37. package/dist/api/trpc/client.d.ts +19 -3
  38. package/dist/api/trpc/client.d.ts.map +1 -1
  39. package/dist/api/trpc/client.js +55 -1
  40. package/dist/api/trpc/query-client.d.ts +3 -1
  41. package/dist/api/trpc/query-client.d.ts.map +1 -1
  42. package/dist/api/trpc/query-client.js +25 -20
  43. package/dist/api/trpc/root.d.ts +906 -0
  44. package/dist/api/trpc/root.d.ts.map +1 -0
  45. package/dist/api/trpc/root.js +47 -0
  46. package/dist/api/trpc/routers/accountSettings.d.ts +66 -0
  47. package/dist/api/trpc/routers/accountSettings.d.ts.map +1 -0
  48. package/dist/api/trpc/routers/accountSettings.js +200 -0
  49. package/dist/api/trpc/routers/admins.d.ts +112 -0
  50. package/dist/api/trpc/routers/admins.d.ts.map +1 -0
  51. package/dist/api/trpc/routers/admins.js +331 -0
  52. package/dist/api/trpc/routers/auth.d.ts +54 -0
  53. package/dist/api/trpc/routers/auth.d.ts.map +1 -0
  54. package/dist/api/trpc/routers/auth.js +50 -0
  55. package/dist/api/trpc/routers/categorySection.d.ts +105 -0
  56. package/dist/api/trpc/routers/categorySection.d.ts.map +1 -0
  57. package/dist/api/trpc/routers/categorySection.js +49 -0
  58. package/dist/api/trpc/routers/config.d.ts +48 -0
  59. package/dist/api/trpc/routers/config.d.ts.map +1 -0
  60. package/dist/api/trpc/routers/config.js +18 -0
  61. package/dist/api/trpc/routers/cpanel.d.ts +82 -0
  62. package/dist/api/trpc/routers/cpanel.d.ts.map +1 -0
  63. package/dist/api/trpc/routers/cpanel.js +216 -0
  64. package/dist/api/trpc/routers/fields.d.ts +35 -0
  65. package/dist/api/trpc/routers/fields.d.ts.map +1 -0
  66. package/dist/api/trpc/routers/fields.js +81 -0
  67. package/dist/api/trpc/routers/files.d.ts +34 -0
  68. package/dist/api/trpc/routers/files.d.ts.map +1 -0
  69. package/dist/api/trpc/routers/files.js +14 -0
  70. package/dist/api/trpc/routers/gallery.d.ts +35 -0
  71. package/dist/api/trpc/routers/gallery.d.ts.map +1 -0
  72. package/dist/api/trpc/routers/gallery.js +92 -0
  73. package/dist/api/trpc/routers/hasItemsSection.d.ts +194 -0
  74. package/dist/api/trpc/routers/hasItemsSection.d.ts.map +1 -0
  75. package/dist/api/trpc/routers/hasItemsSection.js +86 -0
  76. package/dist/api/trpc/routers/logs.d.ts +59 -0
  77. package/dist/api/trpc/routers/logs.d.ts.map +1 -0
  78. package/dist/api/trpc/routers/logs.js +79 -0
  79. package/dist/api/trpc/routers/navigation.d.ts +65 -0
  80. package/dist/api/trpc/routers/navigation.d.ts.map +1 -0
  81. package/dist/api/trpc/routers/navigation.js +11 -0
  82. package/dist/api/trpc/routers/simpleSection.d.ts +93 -0
  83. package/dist/api/trpc/routers/simpleSection.d.ts.map +1 -0
  84. package/dist/api/trpc/routers/simpleSection.js +54 -0
  85. package/dist/api/trpc/server.d.ts +2789 -5
  86. package/dist/api/trpc/server.d.ts.map +1 -1
  87. package/dist/api/trpc/server.js +91 -52
  88. package/dist/api/trpc/trpc.d.ts +111 -0
  89. package/dist/api/trpc/trpc.d.ts.map +1 -0
  90. package/dist/api/trpc/trpc.js +99 -0
  91. package/dist/api/trpc/utils/async-caller-proxy.d.ts +2 -0
  92. package/dist/api/trpc/utils/async-caller-proxy.d.ts.map +1 -0
  93. package/dist/api/trpc/utils/async-caller-proxy.js +38 -0
  94. package/dist/api/trpc/utils/refresh-token-link.d.ts +6 -0
  95. package/dist/api/trpc/utils/refresh-token-link.d.ts.map +1 -0
  96. package/dist/api/trpc/utils/refresh-token-link.js +81 -0
  97. package/dist/api/trpc/utils/router-types.d.ts +7 -0
  98. package/dist/api/trpc/utils/router-types.d.ts.map +1 -0
  99. package/dist/api/trpc/utils/router-types.js +0 -0
  100. package/dist/api/use-axios-private.d.ts +6 -0
  101. package/dist/api/use-axios-private.d.ts.map +1 -0
  102. package/dist/api/use-axios-private.js +57 -0
  103. package/dist/api/utils/async-caller-proxy.d.ts +2 -0
  104. package/dist/api/utils/async-caller-proxy.d.ts.map +1 -0
  105. package/dist/api/utils/async-caller-proxy.js +36 -0
  106. package/dist/api/utils/lazy-caller-proxy.d.ts +2 -0
  107. package/dist/api/utils/lazy-caller-proxy.d.ts.map +1 -0
  108. package/dist/api/utils/lazy-caller-proxy.js +36 -0
  109. package/dist/api/utils/router-types.d.ts +7 -0
  110. package/dist/api/utils/router-types.d.ts.map +1 -0
  111. package/dist/api/utils/router-types.js +0 -0
  112. package/dist/auth/hooks/index.d.ts +1 -2
  113. package/dist/auth/hooks/index.d.ts.map +1 -1
  114. package/dist/auth/hooks/index.js +1 -2
  115. package/dist/auth/react.d.ts +1 -2
  116. package/dist/auth/react.d.ts.map +1 -1
  117. package/dist/auth/react.js +1 -2
  118. package/dist/auth/trpc.d.ts +1 -1
  119. package/dist/auth/trpc.d.ts.map +1 -1
  120. package/dist/auth/trpc.js +0 -1
  121. package/dist/cli/lib/fix-master-admin.d.ts.map +1 -1
  122. package/dist/cli/lib/fix-master-admin.js +12 -25
  123. package/dist/cli/lib/update-sections.d.ts.map +1 -1
  124. package/dist/cli/lib/update-sections.js +90 -46
  125. package/dist/core/config/config-loader.d.ts +23 -7
  126. package/dist/core/config/config-loader.d.ts.map +1 -1
  127. package/dist/core/config/config-loader.js +26 -9
  128. package/dist/core/db/table-checker/MysqlTable.d.ts.map +1 -1
  129. package/dist/core/db/table-checker/MysqlTable.js +3 -1
  130. package/dist/core/fields/date-range.d.ts +4 -4
  131. package/dist/core/fields/select.d.ts +1 -1
  132. package/dist/core/sections/category.d.ts +8 -8
  133. package/dist/core/sections/hasItems.d.ts +8 -8
  134. package/dist/core/sections/section.d.ts +5 -5
  135. package/dist/core/sections/simple.d.ts +4 -4
  136. package/dist/core/types/index.d.ts +17 -0
  137. package/dist/core/types/index.d.ts.map +1 -1
  138. package/dist/index.d.ts +0 -1
  139. package/dist/index.d.ts.map +1 -1
  140. package/dist/index.js +0 -1
  141. package/dist/plugins/client.d.ts +19 -0
  142. package/dist/plugins/client.d.ts.map +1 -0
  143. package/dist/plugins/client.js +24 -0
  144. package/dist/plugins/define.d.ts +4 -0
  145. package/dist/plugins/define.d.ts.map +1 -0
  146. package/dist/plugins/define.js +3 -0
  147. package/dist/plugins/derive.d.ts +32 -0
  148. package/dist/plugins/derive.d.ts.map +1 -0
  149. package/dist/plugins/derive.js +77 -0
  150. package/dist/plugins/loader.d.ts +51 -7
  151. package/dist/plugins/loader.d.ts.map +1 -1
  152. package/dist/plugins/loader.js +111 -51
  153. package/dist/plugins/manifest.d.ts +28 -0
  154. package/dist/plugins/manifest.d.ts.map +1 -0
  155. package/dist/plugins/manifest.js +83 -0
  156. package/dist/plugins/prefetch.d.ts +16 -0
  157. package/dist/plugins/prefetch.d.ts.map +1 -0
  158. package/dist/plugins/prefetch.js +40 -0
  159. package/dist/plugins/registry.d.ts +22 -0
  160. package/dist/plugins/registry.d.ts.map +1 -0
  161. package/dist/plugins/registry.js +25 -0
  162. package/dist/plugins/server.d.ts +2 -0
  163. package/dist/plugins/server.d.ts.map +1 -1
  164. package/dist/plugins/server.js +2 -0
  165. package/dist/plugins/types.d.ts +9 -0
  166. package/dist/plugins/types.d.ts.map +1 -0
  167. package/dist/plugins/types.js +0 -0
  168. package/dist/translations/base/en.d.ts +5 -0
  169. package/dist/translations/base/en.d.ts.map +1 -1
  170. package/dist/translations/base/en.js +5 -0
  171. package/dist/translations/client.d.ts +64 -4
  172. package/dist/translations/client.d.ts.map +1 -1
  173. package/dist/translations/server.d.ts +64 -4
  174. package/dist/translations/server.d.ts.map +1 -1
  175. package/dist/utils/console-log.d.ts +18 -0
  176. package/dist/utils/console-log.d.ts.map +1 -0
  177. package/dist/utils/console-log.js +28 -0
  178. package/dist/utils/index.d.ts +1 -0
  179. package/dist/utils/index.d.ts.map +1 -1
  180. package/dist/utils/index.js +1 -0
  181. package/dist/utils/log.d.ts +18 -0
  182. package/dist/utils/log.d.ts.map +1 -0
  183. package/dist/utils/log.js +28 -0
  184. package/dist/validators/index.d.ts +1 -0
  185. package/dist/validators/index.d.ts.map +1 -1
  186. package/dist/validators/index.js +1 -0
  187. package/dist/validators/tags.d.ts +4 -0
  188. package/dist/validators/tags.d.ts.map +1 -0
  189. package/dist/validators/tags.js +8 -0
  190. package/package.json +36 -18
@@ -0,0 +1,82 @@
1
+ import * as z from 'zod';
2
+ export declare const cpanelRouter: import("@trpc/server").TRPCBuiltRouter<{
3
+ ctx: {
4
+ headers: Headers;
5
+ db: import("drizzle-orm/mysql2").MySql2Database<typeof import("../../../db/schema.js")> & {
6
+ $client: import("mysql2/promise").Pool;
7
+ };
8
+ session: import("../../../index.js").Session | null;
9
+ };
10
+ meta: object;
11
+ errorShape: {
12
+ data: {
13
+ zodError: z.core.$ZodFlattenedError<unknown, string> | null;
14
+ code: import("@trpc/server").TRPC_ERROR_CODE_KEY;
15
+ httpStatus: number;
16
+ path?: string;
17
+ stack?: string;
18
+ };
19
+ message: string;
20
+ code: import("@trpc/server").TRPC_ERROR_CODE_NUMBER;
21
+ };
22
+ transformer: true;
23
+ }, import("@trpc/server").TRPCDecorateCreateRouterOptions<{
24
+ getData: import("@trpc/server").TRPCQueryProcedure<{
25
+ input: void;
26
+ output: {
27
+ dbsLimit: number;
28
+ dbsCount: number;
29
+ bandwidthUsage: number;
30
+ bandwidthLimit: number;
31
+ diskSpaceUsage: number;
32
+ diskSpaceLimit: number;
33
+ emailsUsage: number;
34
+ emailsLimit: number;
35
+ dbInfo: any;
36
+ dbsList: any;
37
+ phpVersion: any;
38
+ passengerAppList: never[];
39
+ documentRoot: any;
40
+ };
41
+ meta: object;
42
+ }>;
43
+ getEmails: import("@trpc/server").TRPCQueryProcedure<{
44
+ input: void;
45
+ output: {
46
+ emails: any;
47
+ };
48
+ meta: object;
49
+ }>;
50
+ createEmail: import("@trpc/server").TRPCMutationProcedure<{
51
+ input: {
52
+ email: string;
53
+ password: string;
54
+ quota: string;
55
+ };
56
+ output: any;
57
+ meta: object;
58
+ }>;
59
+ quotaChange: import("@trpc/server").TRPCMutationProcedure<{
60
+ input: {
61
+ email: string;
62
+ quota: string;
63
+ };
64
+ output: any;
65
+ meta: object;
66
+ }>;
67
+ passwordChange: import("@trpc/server").TRPCMutationProcedure<{
68
+ input: {
69
+ email: string;
70
+ password: string;
71
+ passwordConfirm: string;
72
+ };
73
+ output: any;
74
+ meta: object;
75
+ }>;
76
+ deleteEmail: import("@trpc/server").TRPCMutationProcedure<{
77
+ input: string;
78
+ output: any;
79
+ meta: object;
80
+ }>;
81
+ }>>;
82
+ //# sourceMappingURL=cpanel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cpanel.d.ts","sourceRoot":"","sources":["../../../../src/api/trpc/routers/cpanel.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAKxB,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0QvB,CAAA"}
@@ -0,0 +1,216 @@
1
+ import { privateProcedure, router } from '../trpc.js';
2
+ import { CpanelAPI } from '../../../utils/index.js';
3
+ import * as z from 'zod';
4
+ import { TRPCError } from '@trpc/server';
5
+ import getString from '../../../translations/index.js';
6
+ // import '@/envConfig'
7
+ export const cpanelRouter = router({
8
+ getData: privateProcedure.query(async ({ ctx, input }) => {
9
+ if (!process.env.CPANEL_USER || !process.env.CPANEL_PASSWORD || !process.env.CPANEL_DOMAIN) {
10
+ throw new TRPCError({
11
+ code: 'BAD_REQUEST',
12
+ message: getString('cpanelCredentialsNotSet', ctx.session.user.language),
13
+ });
14
+ }
15
+ const cPanel = new CpanelAPI(process.env.CPANEL_USER, process.env.CPANEL_PASSWORD, `cpanel.${process.env.CPANEL_DOMAIN}`);
16
+ const data = await Promise.all([
17
+ cPanel.callApi('DomainInfo', 'single_domain_data', {
18
+ domain: process.env.CPANEL_DOMAIN,
19
+ }),
20
+ cPanel.callApi('ResourceUsage', 'get_usages'),
21
+ cPanel.callApi('Mysql', 'get_server_information'),
22
+ cPanel.callApi('Mysql', 'list_databases'),
23
+ // cPanel.callApi('PassengerApps', 'list_applications'),
24
+ ]);
25
+ // console.log(data)
26
+ if (cPanel.isError) {
27
+ throw new TRPCError({
28
+ code: 'BAD_REQUEST',
29
+ message: cPanel.getError(),
30
+ });
31
+ }
32
+ const dbInfo = data[2];
33
+ const dbsList = data[3];
34
+ // const passengerAppList = data[4]
35
+ let bandwidthLimit = 0, bandwidthUsage = 0;
36
+ let diskSpaceLimit = 0, usedDiskSpace = 0;
37
+ let emailsLimit = 0, emailsCount = 0;
38
+ let dbsLimit = 0, dbsCount = 0;
39
+ const domainInfoData = data[0].data;
40
+ const cpanelUsagesArray = data[1].data;
41
+ cpanelUsagesArray.forEach((singleItemUsage) => {
42
+ switch (singleItemUsage.id) {
43
+ case 'bandwidth':
44
+ bandwidthLimit = singleItemUsage.maximum || 1000000000000;
45
+ bandwidthUsage = singleItemUsage.usage;
46
+ break;
47
+ case 'disk_usage':
48
+ diskSpaceLimit = singleItemUsage.maximum || 1000000000000;
49
+ usedDiskSpace = singleItemUsage.usage;
50
+ break;
51
+ case 'email_accounts':
52
+ emailsLimit = singleItemUsage.maximum || 1000000000000;
53
+ emailsCount = singleItemUsage.usage;
54
+ break;
55
+ case 'mysql_databases':
56
+ dbsLimit = singleItemUsage.maximum || 1000000000000;
57
+ dbsCount = singleItemUsage.usage;
58
+ break;
59
+ }
60
+ });
61
+ /*data[4].data = Object.keys(data[4].data).map((key) => {
62
+ const app = data[4].data[key]
63
+ return {
64
+ name: app.name,
65
+ path: app.path,
66
+ domain: app.domain,
67
+ enabled: app.enabled,
68
+ url: app.base_uri,
69
+ nodejs: app.nodejs,
70
+ deploymentMode: app.deployment_mode,
71
+ }
72
+ })*/
73
+ return {
74
+ dbsLimit,
75
+ dbsCount,
76
+ bandwidthUsage,
77
+ bandwidthLimit,
78
+ diskSpaceUsage: usedDiskSpace,
79
+ diskSpaceLimit,
80
+ emailsUsage: emailsCount,
81
+ emailsLimit,
82
+ dbInfo: dbInfo.data,
83
+ dbsList: dbsList.data,
84
+ phpVersion: domainInfoData?.phpversion,
85
+ passengerAppList: [],
86
+ documentRoot: domainInfoData?.documentroot,
87
+ };
88
+ }),
89
+ getEmails: privateProcedure.query(async ({ ctx, input }) => {
90
+ if (!process.env.CPANEL_USER || !process.env.CPANEL_PASSWORD || !process.env.CPANEL_DOMAIN) {
91
+ throw new TRPCError({
92
+ code: 'BAD_REQUEST',
93
+ message: getString('cpanelCredentialsNotSet', ctx.session.user.language),
94
+ });
95
+ }
96
+ const cPanel = new CpanelAPI(process.env.CPANEL_USER, process.env.CPANEL_PASSWORD, `cpanel.${process.env.CPANEL_DOMAIN}`);
97
+ const data = await cPanel.callApi('Email', 'list_pops_with_disk', {
98
+ domain: process.env.CPANEL_DOMAIN,
99
+ maxaccounts: 100,
100
+ no_validate: 1,
101
+ infinitylang: 1,
102
+ 'api.sort': '1',
103
+ 'api.sort_column': 'mtime',
104
+ });
105
+ return {
106
+ emails: data.data,
107
+ };
108
+ }),
109
+ createEmail: privateProcedure
110
+ .input(z.object({
111
+ email: z.string(),
112
+ password: z.string(),
113
+ quota: z.string(),
114
+ }))
115
+ .mutation(async ({ ctx, input }) => {
116
+ if (!process.env.CPANEL_USER || !process.env.CPANEL_PASSWORD || !process.env.CPANEL_DOMAIN) {
117
+ throw new TRPCError({
118
+ code: 'BAD_REQUEST',
119
+ message: getString('cpanelCredentialsNotSet', ctx.session.user.language),
120
+ });
121
+ }
122
+ const cPanel = new CpanelAPI(process.env.CPANEL_USER, process.env.CPANEL_PASSWORD, `cpanel.${process.env.CPANEL_DOMAIN}`);
123
+ const data = await cPanel.callApi('Email', 'add_pop', {
124
+ domain: process.env.CPANEL_DOMAIN,
125
+ email: input.email,
126
+ password: input.password,
127
+ quota: input.quota,
128
+ });
129
+ if (cPanel.isError) {
130
+ throw new TRPCError({
131
+ code: 'BAD_REQUEST',
132
+ message: cPanel.getError(),
133
+ });
134
+ }
135
+ return data;
136
+ }),
137
+ quotaChange: privateProcedure
138
+ .input(z.object({
139
+ email: z.string(),
140
+ quota: z.string(),
141
+ }))
142
+ .mutation(async ({ ctx, input }) => {
143
+ if (!process.env.CPANEL_USER || !process.env.CPANEL_PASSWORD || !process.env.CPANEL_DOMAIN) {
144
+ throw new TRPCError({
145
+ code: 'BAD_REQUEST',
146
+ message: getString('cpanelCredentialsNotSet', ctx.session.user.language),
147
+ });
148
+ }
149
+ const cPanel = new CpanelAPI(process.env.CPANEL_USER, process.env.CPANEL_PASSWORD, `cpanel.${process.env.CPANEL_DOMAIN}`);
150
+ const data = await cPanel.callApi('Email', 'edit_pop_quota', {
151
+ domain: process.env.CPANEL_DOMAIN,
152
+ email: input.email,
153
+ quota: input.quota,
154
+ });
155
+ if (cPanel.isError) {
156
+ throw new TRPCError({
157
+ code: 'BAD_REQUEST',
158
+ message: cPanel.getError(),
159
+ });
160
+ }
161
+ return data;
162
+ }),
163
+ passwordChange: privateProcedure
164
+ .input(z.object({
165
+ email: z.string(),
166
+ password: z.string(),
167
+ passwordConfirm: z.string(),
168
+ }))
169
+ .mutation(async ({ ctx, input }) => {
170
+ if (!process.env.CPANEL_USER || !process.env.CPANEL_PASSWORD || !process.env.CPANEL_DOMAIN) {
171
+ throw new TRPCError({
172
+ code: 'BAD_REQUEST',
173
+ message: getString('cpanelCredentialsNotSet', ctx.session.user.language),
174
+ });
175
+ }
176
+ if (input.password !== input.passwordConfirm) {
177
+ throw new TRPCError({
178
+ code: 'BAD_REQUEST',
179
+ message: getString('passwordsDoNotMatch', ctx.session.user.language),
180
+ });
181
+ }
182
+ const cPanel = new CpanelAPI(process.env.CPANEL_USER, process.env.CPANEL_PASSWORD, `cpanel.${process.env.CPANEL_DOMAIN}`);
183
+ const data = await cPanel.callApi('Email', 'passwd_pop', {
184
+ domain: process.env.CPANEL_DOMAIN,
185
+ email: input.email,
186
+ password: input.password,
187
+ });
188
+ if (cPanel.isError) {
189
+ throw new TRPCError({
190
+ code: 'BAD_REQUEST',
191
+ message: cPanel.getError(),
192
+ });
193
+ }
194
+ return data;
195
+ }),
196
+ deleteEmail: privateProcedure.input(z.string()).mutation(async ({ ctx, input }) => {
197
+ if (!process.env.CPANEL_USER || !process.env.CPANEL_PASSWORD || !process.env.CPANEL_DOMAIN) {
198
+ throw new TRPCError({
199
+ code: 'BAD_REQUEST',
200
+ message: getString('cpanelCredentialsNotSet', ctx.session.user.language),
201
+ });
202
+ }
203
+ const cPanel = new CpanelAPI(process.env.CPANEL_USER, process.env.CPANEL_PASSWORD, `cpanel.${process.env.CPANEL_DOMAIN}`);
204
+ const data = await cPanel.callApi('Email', 'delete_pop', {
205
+ domain: process.env.CPANEL_DOMAIN,
206
+ email: input,
207
+ });
208
+ if (cPanel.isError) {
209
+ throw new TRPCError({
210
+ code: 'BAD_REQUEST',
211
+ message: cPanel.getError(),
212
+ });
213
+ }
214
+ return data;
215
+ }),
216
+ });
@@ -0,0 +1,35 @@
1
+ import * as z from 'zod';
2
+ export declare const fieldsRouter: import("@trpc/server").TRPCBuiltRouter<{
3
+ ctx: {
4
+ headers: Headers;
5
+ db: import("drizzle-orm/mysql2").MySql2Database<typeof import("../../../db/schema.js")> & {
6
+ $client: import("mysql2/promise").Pool;
7
+ };
8
+ session: import("../../../index.js").Session | null;
9
+ };
10
+ meta: object;
11
+ errorShape: {
12
+ data: {
13
+ zodError: z.core.$ZodFlattenedError<unknown, string> | null;
14
+ code: import("@trpc/server").TRPC_ERROR_CODE_KEY;
15
+ httpStatus: number;
16
+ path?: string;
17
+ stack?: string;
18
+ };
19
+ message: string;
20
+ code: import("@trpc/server").TRPC_ERROR_CODE_NUMBER;
21
+ };
22
+ transformer: true;
23
+ }, import("@trpc/server").TRPCDecorateCreateRouterOptions<{
24
+ tagsAutoComplete: import("@trpc/server").TRPCQueryProcedure<{
25
+ input: {
26
+ sectionName: string;
27
+ fieldName: string;
28
+ query: string;
29
+ locale?: string | undefined;
30
+ };
31
+ output: string[];
32
+ meta: object;
33
+ }>;
34
+ }>>;
35
+ //# sourceMappingURL=fields.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../../../../src/api/trpc/routers/fields.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAWxB,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoFvB,CAAA"}
@@ -0,0 +1,81 @@
1
+ import { privateProcedure, router } from '../trpc.js';
2
+ import * as z from 'zod';
3
+ import { SectionFactory } from '../../../core/factories/index.js';
4
+ import { TRPCError } from '@trpc/server';
5
+ import getString from '../../../translations/index.js';
6
+ import { db } from '../../../db/client.js';
7
+ import { sql } from 'drizzle-orm';
8
+ import { is } from '../../../core/helpers/index.js';
9
+ import { TagsField } from '../../../core/fields/index.js';
10
+ import { getCMSConfig } from '../../../core/config/index.js';
11
+ import { resolveLocale } from '../../../core/localization/index.js';
12
+ export const fieldsRouter = router({
13
+ tagsAutoComplete: privateProcedure
14
+ .input(z.object({
15
+ sectionName: z.string(),
16
+ fieldName: z.string(),
17
+ query: z.string().max(100),
18
+ locale: z.string().optional(),
19
+ }))
20
+ .query(async ({ ctx, input }) => {
21
+ const sectionConfig = await SectionFactory.getSectionForAdmin({
22
+ name: input.sectionName,
23
+ admin: {
24
+ id: ctx.session.user.id,
25
+ },
26
+ });
27
+ if (!sectionConfig?.name) {
28
+ throw new TRPCError({
29
+ code: 'NOT_FOUND',
30
+ message: getString('sectionNotFound', ctx.session.user.language),
31
+ });
32
+ }
33
+ const section = sectionConfig.build();
34
+ section.buildFields();
35
+ const field = section.fields.find((f) => f.name === input.fieldName);
36
+ if (!field || !is(field, TagsField) || !field.autoCompletion || !field.destinationDb) {
37
+ throw new TRPCError({
38
+ code: 'BAD_REQUEST',
39
+ message: `Field "${input.fieldName}" does not support auto-completion`,
40
+ });
41
+ }
42
+ const { table, selectIdentifier } = field.destinationDb;
43
+ const searchPattern = `%${input.query}%`;
44
+ const query = sql `SELECT DISTINCT \`${sql.raw(selectIdentifier)}\` as value
45
+ FROM \`${sql.raw(table)}\`
46
+ WHERE \`${sql.raw(selectIdentifier)}\` LIKE ${searchPattern}`;
47
+ if (field.localized) {
48
+ const cmsConfig = await getCMSConfig();
49
+ const localeResult = resolveLocale({
50
+ localization: cmsConfig.localization,
51
+ locale: input.locale,
52
+ });
53
+ if (input.locale !== undefined && !localeResult.localizationEnabled) {
54
+ throw new TRPCError({
55
+ code: 'BAD_REQUEST',
56
+ message: getString('localizationNotEnabledForSection', ctx.session.user.language),
57
+ });
58
+ }
59
+ if (input.locale !== undefined && !localeResult.resolvedLocale) {
60
+ throw new TRPCError({
61
+ code: 'BAD_REQUEST',
62
+ message: getString('invalidLocale', ctx.session.user.language, {
63
+ locale: input.locale,
64
+ locales: localeResult.availableLocales.map((l) => l.code).join(', '),
65
+ }),
66
+ });
67
+ }
68
+ if (localeResult.localizationEnabled) {
69
+ const localeForQuery = localeResult.isDefault
70
+ ? cmsConfig.localization.defaultLocale
71
+ : (localeResult.resolvedLocale?.code ?? undefined);
72
+ if (localeForQuery !== undefined) {
73
+ query.append(sql ` AND \`locale\` = ${localeForQuery}`);
74
+ }
75
+ }
76
+ }
77
+ query.append(sql ` ORDER BY \`${sql.raw(selectIdentifier)}\` ASC LIMIT 20`);
78
+ const [rows] = await db.execute(query);
79
+ return rows.map((row) => row.value);
80
+ }),
81
+ });
@@ -0,0 +1,34 @@
1
+ import * as z from 'zod';
2
+ export declare const filesRouter: import("@trpc/server").TRPCBuiltRouter<{
3
+ ctx: {
4
+ headers: Headers;
5
+ db: import("drizzle-orm/mysql2").MySql2Database<typeof import("../../../db/schema.js")> & {
6
+ $client: import("mysql2/promise").Pool;
7
+ };
8
+ session: import("../../../index.js").Session | null;
9
+ };
10
+ meta: object;
11
+ errorShape: {
12
+ data: {
13
+ zodError: z.core.$ZodFlattenedError<unknown, string> | null;
14
+ code: import("@trpc/server").TRPC_ERROR_CODE_KEY;
15
+ httpStatus: number;
16
+ path?: string;
17
+ stack?: string;
18
+ };
19
+ message: string;
20
+ code: import("@trpc/server").TRPC_ERROR_CODE_NUMBER;
21
+ };
22
+ transformer: true;
23
+ }, import("@trpc/server").TRPCDecorateCreateRouterOptions<{
24
+ getPhoto: import("@trpc/server").TRPCQueryProcedure<{
25
+ input: {
26
+ name: string;
27
+ folder: string;
28
+ isThumb?: boolean | undefined;
29
+ };
30
+ output: string;
31
+ meta: object;
32
+ }>;
33
+ }>>;
34
+ //# sourceMappingURL=files.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../../../src/api/trpc/routers/files.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAGxB,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAYtB,CAAA"}
@@ -0,0 +1,14 @@
1
+ import { privateProcedure, router } from '../trpc.js';
2
+ import * as z from 'zod';
3
+ import { getPhoto } from '../../actions/files.js';
4
+ export const filesRouter = router({
5
+ getPhoto: privateProcedure
6
+ .input(z.object({
7
+ name: z.string(),
8
+ folder: z.string(),
9
+ isThumb: z.boolean().optional(),
10
+ }))
11
+ .query(async ({ ctx, input }) => {
12
+ return await getPhoto(input);
13
+ }),
14
+ });
@@ -0,0 +1,35 @@
1
+ import * as z from 'zod';
2
+ export declare const galleryRouter: import("@trpc/server").TRPCBuiltRouter<{
3
+ ctx: {
4
+ headers: Headers;
5
+ db: import("drizzle-orm/mysql2").MySql2Database<typeof import("../../../db/schema.js")> & {
6
+ $client: import("mysql2/promise").Pool;
7
+ };
8
+ session: import("../../../index.js").Session | null;
9
+ };
10
+ meta: object;
11
+ errorShape: {
12
+ data: {
13
+ zodError: z.core.$ZodFlattenedError<unknown, string> | null;
14
+ code: import("@trpc/server").TRPC_ERROR_CODE_KEY;
15
+ httpStatus: number;
16
+ path?: string;
17
+ stack?: string;
18
+ };
19
+ message: string;
20
+ code: import("@trpc/server").TRPC_ERROR_CODE_NUMBER;
21
+ };
22
+ transformer: true;
23
+ }, import("@trpc/server").TRPCDecorateCreateRouterOptions<{
24
+ deletePhoto: import("@trpc/server").TRPCMutationProcedure<{
25
+ input: {
26
+ sectionName: string;
27
+ photoName: string;
28
+ referenceId: string;
29
+ locale?: string | undefined;
30
+ };
31
+ output: boolean;
32
+ meta: object;
33
+ }>;
34
+ }>>;
35
+ //# sourceMappingURL=gallery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gallery.d.ts","sourceRoot":"","sources":["../../../../src/api/trpc/routers/gallery.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAUxB,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0FxB,CAAA"}
@@ -0,0 +1,92 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import { TRPCError } from '@trpc/server';
4
+ import { sql } from 'drizzle-orm';
5
+ import * as z from 'zod';
6
+ import { getCMSConfig } from '../../../core/config/index.js';
7
+ import { MysqlTableChecker } from '../../../core/db/index.js';
8
+ import { SectionFactory } from '../../../core/factories/index.js';
9
+ import { resolveLocale } from '../../../core/localization/index.js';
10
+ import { db } from '../../../db/client.js';
11
+ import getString from '../../../translations/index.js';
12
+ import { privateProcedure, router } from '../trpc.js';
13
+ export const galleryRouter = router({
14
+ deletePhoto: privateProcedure
15
+ .input(z.object({
16
+ sectionName: z.string(),
17
+ photoName: z.string(),
18
+ referenceId: z.string(),
19
+ locale: z.string().optional(),
20
+ }))
21
+ .mutation(async ({ ctx, input }) => {
22
+ const cmsConfig = await getCMSConfig();
23
+ const uploadsFolder = cmsConfig.media.upload.path;
24
+ /**
25
+ * Get the section information
26
+ */
27
+ const sectionConfig = await SectionFactory.getSectionForAdmin({
28
+ name: input.sectionName,
29
+ admin: {
30
+ id: ctx.session.user.id,
31
+ requiredRole: 'D',
32
+ },
33
+ });
34
+ if (sectionConfig?.name !== input.sectionName) {
35
+ throw new TRPCError({
36
+ code: 'BAD_REQUEST',
37
+ message: getString('sectionNotFound', ctx.session.user.language),
38
+ });
39
+ }
40
+ const section = sectionConfig?.build();
41
+ /**
42
+ * Delete the photo from the database
43
+ */
44
+ const gallery = await section.getGallery();
45
+ if (gallery?.db.tableName) {
46
+ const columns = await MysqlTableChecker.getColumns(gallery.db.tableName);
47
+ if (columns.includes(gallery.db.photoNameField) &&
48
+ columns.includes(gallery.db.referenceIdentifierField)) {
49
+ const galleryIsLocalized = gallery.localized === true && cmsConfig.localization?.enabled === true;
50
+ if (galleryIsLocalized) {
51
+ const localeResult = resolveLocale({
52
+ localization: cmsConfig.localization,
53
+ locale: input.locale,
54
+ });
55
+ if (!input.locale || !localeResult.resolvedLocale) {
56
+ throw new TRPCError({
57
+ code: 'BAD_REQUEST',
58
+ message: getString('invalidLocale', ctx.session.user.language, {
59
+ locale: input.locale ?? '',
60
+ locales: localeResult.availableLocales.map((l) => l.code).join(', '),
61
+ }),
62
+ });
63
+ }
64
+ if (!columns.includes('locale')) {
65
+ throw new TRPCError({
66
+ code: 'BAD_REQUEST',
67
+ message: getString('galleryTableNotSetUp', ctx.session.user.language),
68
+ });
69
+ }
70
+ await db.execute(sql `DELETE FROM ${sql.raw(gallery.db.tableName)} WHERE ${sql.raw(gallery.db.photoNameField)} = ${input.photoName} AND ${sql.raw(gallery.db.referenceIdentifierField)} = ${input.referenceId} AND \`locale\` = ${localeResult.resolvedLocale.code}`);
71
+ }
72
+ else {
73
+ await db.execute(sql `DELETE FROM ${sql.raw(gallery.db.tableName)} WHERE ${sql.raw(gallery.db.photoNameField)} = ${input.photoName} AND ${sql.raw(gallery.db.referenceIdentifierField)} = ${input.referenceId}`);
74
+ }
75
+ }
76
+ }
77
+ /**
78
+ * Delete the photo from disk
79
+ */
80
+ try {
81
+ await fs.promises.unlink(path.join(uploadsFolder, '.photos', section.name, input.photoName));
82
+ /**
83
+ * TODO: Thumbs are not being deleted, it throws an error that they are being used by nodejs. Fix this
84
+ */
85
+ await fs.promises.unlink(path.join(uploadsFolder, '.thumbs', section.name, input.photoName));
86
+ }
87
+ catch (error) {
88
+ console.error(error);
89
+ }
90
+ return true;
91
+ }),
92
+ });