@rglabs/butterfly 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +25 -0
- package/dist/commands/add.d.ts +21 -0
- package/dist/commands/add.d.ts.map +1 -0
- package/dist/commands/add.js +301 -0
- package/dist/commands/add.js.map +1 -0
- package/dist/commands/download.d.ts +4 -0
- package/dist/commands/download.d.ts.map +1 -0
- package/dist/commands/download.js +309 -0
- package/dist/commands/download.js.map +1 -0
- package/dist/commands/setup.d.ts +3 -0
- package/dist/commands/setup.d.ts.map +1 -0
- package/dist/commands/setup.js +41 -0
- package/dist/commands/setup.js.map +1 -0
- package/dist/commands/start/handlers/aiTasks.d.ts +4 -0
- package/dist/commands/start/handlers/aiTasks.d.ts.map +1 -0
- package/dist/commands/start/handlers/aiTasks.js +95 -0
- package/dist/commands/start/handlers/aiTasks.js.map +1 -0
- package/dist/commands/start/handlers/cronjobs.d.ts +4 -0
- package/dist/commands/start/handlers/cronjobs.d.ts.map +1 -0
- package/dist/commands/start/handlers/cronjobs.js +80 -0
- package/dist/commands/start/handlers/cronjobs.js.map +1 -0
- package/dist/commands/start/handlers/emailLayouts.d.ts +4 -0
- package/dist/commands/start/handlers/emailLayouts.d.ts.map +1 -0
- package/dist/commands/start/handlers/emailLayouts.js +83 -0
- package/dist/commands/start/handlers/emailLayouts.js.map +1 -0
- package/dist/commands/start/handlers/emailTemplates.d.ts +4 -0
- package/dist/commands/start/handlers/emailTemplates.d.ts.map +1 -0
- package/dist/commands/start/handlers/emailTemplates.js +83 -0
- package/dist/commands/start/handlers/emailTemplates.js.map +1 -0
- package/dist/commands/start/handlers/index.d.ts +11 -0
- package/dist/commands/start/handlers/index.d.ts.map +1 -0
- package/dist/commands/start/handlers/index.js +11 -0
- package/dist/commands/start/handlers/index.js.map +1 -0
- package/dist/commands/start/handlers/objects.d.ts +8 -0
- package/dist/commands/start/handlers/objects.d.ts.map +1 -0
- package/dist/commands/start/handlers/objects.js +205 -0
- package/dist/commands/start/handlers/objects.js.map +1 -0
- package/dist/commands/start/handlers/pages.d.ts +4 -0
- package/dist/commands/start/handlers/pages.d.ts.map +1 -0
- package/dist/commands/start/handlers/pages.js +86 -0
- package/dist/commands/start/handlers/pages.js.map +1 -0
- package/dist/commands/start/handlers/pdfTemplates.d.ts +4 -0
- package/dist/commands/start/handlers/pdfTemplates.d.ts.map +1 -0
- package/dist/commands/start/handlers/pdfTemplates.js +81 -0
- package/dist/commands/start/handlers/pdfTemplates.js.map +1 -0
- package/dist/commands/start/handlers/reports.d.ts +4 -0
- package/dist/commands/start/handlers/reports.d.ts.map +1 -0
- package/dist/commands/start/handlers/reports.js +159 -0
- package/dist/commands/start/handlers/reports.js.map +1 -0
- package/dist/commands/start/handlers/stateMachines.d.ts +4 -0
- package/dist/commands/start/handlers/stateMachines.d.ts.map +1 -0
- package/dist/commands/start/handlers/stateMachines.js +549 -0
- package/dist/commands/start/handlers/stateMachines.js.map +1 -0
- package/dist/commands/start/handlers/workflows.d.ts +5 -0
- package/dist/commands/start/handlers/workflows.d.ts.map +1 -0
- package/dist/commands/start/handlers/workflows.js +277 -0
- package/dist/commands/start/handlers/workflows.js.map +1 -0
- package/dist/commands/start/index.d.ts +5 -0
- package/dist/commands/start/index.d.ts.map +1 -0
- package/dist/commands/start/index.js +304 -0
- package/dist/commands/start/index.js.map +1 -0
- package/dist/commands/start/types.d.ts +25 -0
- package/dist/commands/start/types.d.ts.map +1 -0
- package/dist/commands/start/types.js +2 -0
- package/dist/commands/start/types.js.map +1 -0
- package/dist/commands/start/utils.d.ts +10 -0
- package/dist/commands/start/utils.d.ts.map +1 -0
- package/dist/commands/start/utils.js +191 -0
- package/dist/commands/start/utils.js.map +1 -0
- package/dist/commands/start.d.ts +2 -0
- package/dist/commands/start.d.ts.map +1 -0
- package/dist/commands/start.js +2 -0
- package/dist/commands/start.js.map +1 -0
- package/dist/commands/upload.d.ts +3 -0
- package/dist/commands/upload.d.ts.map +1 -0
- package/dist/commands/upload.js +115 -0
- package/dist/commands/upload.js.map +1 -0
- package/dist/commands/workflow-info.d.ts +11 -0
- package/dist/commands/workflow-info.d.ts.map +1 -0
- package/dist/commands/workflow-info.js +159 -0
- package/dist/commands/workflow-info.js.map +1 -0
- package/dist/components/DownloadProgress.d.ts +11 -0
- package/dist/components/DownloadProgress.d.ts.map +1 -0
- package/dist/components/DownloadProgress.js +29 -0
- package/dist/components/DownloadProgress.js.map +1 -0
- package/dist/components/SetupForm.d.ts +8 -0
- package/dist/components/SetupForm.d.ts.map +1 -0
- package/dist/components/SetupForm.js +56 -0
- package/dist/components/SetupForm.js.map +1 -0
- package/dist/components/UploadProgress.d.ts +11 -0
- package/dist/components/UploadProgress.d.ts.map +1 -0
- package/dist/components/UploadProgress.js +29 -0
- package/dist/components/UploadProgress.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +63 -0
- package/dist/index.js.map +1 -0
- package/dist/types/index.d.ts +18 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/api.d.ts +47 -0
- package/dist/utils/api.d.ts.map +1 -0
- package/dist/utils/api.js +676 -0
- package/dist/utils/api.js.map +1 -0
- package/dist/utils/auth.d.ts +4 -0
- package/dist/utils/auth.d.ts.map +1 -0
- package/dist/utils/auth.js +22 -0
- package/dist/utils/auth.js.map +1 -0
- package/dist/utils/docs.d.ts +2 -0
- package/dist/utils/docs.d.ts.map +1 -0
- package/dist/utils/docs.js +41 -0
- package/dist/utils/docs.js.map +1 -0
- package/dist/utils/errorLogger.d.ts +6 -0
- package/dist/utils/errorLogger.d.ts.map +1 -0
- package/dist/utils/errorLogger.js +29 -0
- package/dist/utils/errorLogger.js.map +1 -0
- package/dist/utils/files.d.ts +14 -0
- package/dist/utils/files.d.ts.map +1 -0
- package/dist/utils/files.js +732 -0
- package/dist/utils/files.js.map +1 -0
- package/dist/utils/lockManager.d.ts +15 -0
- package/dist/utils/lockManager.d.ts.map +1 -0
- package/dist/utils/lockManager.js +126 -0
- package/dist/utils/lockManager.js.map +1 -0
- package/dist/utils/summaryGenerator.d.ts +2 -0
- package/dist/utils/summaryGenerator.d.ts.map +1 -0
- package/dist/utils/summaryGenerator.js +183 -0
- package/dist/utils/summaryGenerator.js.map +1 -0
- package/dist/utils/uploadHandler.d.ts +35 -0
- package/dist/utils/uploadHandler.d.ts.map +1 -0
- package/dist/utils/uploadHandler.js +706 -0
- package/dist/utils/uploadHandler.js.map +1 -0
- package/object_response.png +0 -0
- package/object_specs_response.png +0 -0
- package/package.json +56 -0
|
@@ -0,0 +1,706 @@
|
|
|
1
|
+
import { restoreFieldsFromFiles, restoreAiTaskFromFiles, restoreTableRecordFromFiles } from './files.js';
|
|
2
|
+
import { promises as fs } from 'fs';
|
|
3
|
+
import { basename, dirname, join } from 'path';
|
|
4
|
+
export class UploadHandler {
|
|
5
|
+
api;
|
|
6
|
+
options;
|
|
7
|
+
constructor(api, options = {}) {
|
|
8
|
+
this.api = api;
|
|
9
|
+
this.options = options;
|
|
10
|
+
}
|
|
11
|
+
log(message, type = 'info') {
|
|
12
|
+
if (this.options.onProgress) {
|
|
13
|
+
this.options.onProgress(message, type);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
async uploadFile(filePath) {
|
|
17
|
+
try {
|
|
18
|
+
const parts = filePath.split('/');
|
|
19
|
+
const resourcesIndex = parts.findIndex(part => part === 'butterfly-resources');
|
|
20
|
+
if (resourcesIndex === -1 || parts.length < resourcesIndex + 2) {
|
|
21
|
+
return { success: false, message: 'Invalid file path structure' };
|
|
22
|
+
}
|
|
23
|
+
const resourceType = parts[resourcesIndex + 1];
|
|
24
|
+
if (resourceType === 'reports') {
|
|
25
|
+
return await this.handleReportFile(filePath);
|
|
26
|
+
}
|
|
27
|
+
else if (resourceType === 'bfy_ai_tasks') {
|
|
28
|
+
return await this.handleAiTaskFile(filePath);
|
|
29
|
+
}
|
|
30
|
+
else if (resourceType === 'bfy_state_machines') {
|
|
31
|
+
return await this.handleStateMachineFile(filePath);
|
|
32
|
+
}
|
|
33
|
+
else if (resourceType === 'pages') {
|
|
34
|
+
return await this.handlePageFile(filePath);
|
|
35
|
+
}
|
|
36
|
+
else if (resourceType === 'bfy_cronjobs') {
|
|
37
|
+
return await this.handleCronjobFile(filePath);
|
|
38
|
+
}
|
|
39
|
+
else if (resourceType === 'cms_email_templates') {
|
|
40
|
+
return await this.handleEmailTemplateFile(filePath);
|
|
41
|
+
}
|
|
42
|
+
else if (resourceType === 'cms_email_layouts') {
|
|
43
|
+
return await this.handleEmailLayoutFile(filePath);
|
|
44
|
+
}
|
|
45
|
+
else if (resourceType === 'objects') {
|
|
46
|
+
return await this.handleObjectFile(filePath);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
return { success: false, message: `Unsupported resource type: ${resourceType}` };
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
54
|
+
this.log(`Error uploading file: ${message}`, 'error');
|
|
55
|
+
return { success: false, message };
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async handleReportFile(filePath) {
|
|
59
|
+
const fileName = basename(filePath);
|
|
60
|
+
try {
|
|
61
|
+
if (fileName === 'report.json') {
|
|
62
|
+
const reportData = JSON.parse(await fs.readFile(filePath, 'utf-8'));
|
|
63
|
+
const fileDir = dirname(filePath);
|
|
64
|
+
const restoredData = await restoreFieldsFromFiles(fileDir, reportData);
|
|
65
|
+
const response = await this.api.updateReport(restoredData.id, restoredData);
|
|
66
|
+
if (response && response.success) {
|
|
67
|
+
this.log(`✓ Updated report (ID: ${restoredData.id})`, 'success');
|
|
68
|
+
return { success: true, message: `Updated report (ID: ${restoredData.id})`, resourceId: restoredData.id };
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
const errorMsg = response?.error || response?.message || 'Unknown response format';
|
|
72
|
+
this.log(`✗ Failed to update report: ${errorMsg}`, 'error');
|
|
73
|
+
return { success: false, message: `Failed to update report: ${errorMsg}` };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
else if (filePath.includes('/specs/') && fileName === 'spec.json') {
|
|
77
|
+
const specData = JSON.parse(await fs.readFile(filePath, 'utf-8'));
|
|
78
|
+
const fileDir = dirname(filePath);
|
|
79
|
+
const restoredData = await restoreFieldsFromFiles(fileDir, specData);
|
|
80
|
+
const response = await this.api.updateReportSpec(restoredData.id, restoredData);
|
|
81
|
+
if (response && response.success) {
|
|
82
|
+
this.log(`✓ Updated report spec (ID: ${restoredData.id})`, 'success');
|
|
83
|
+
return { success: true, message: `Updated report spec (ID: ${restoredData.id})`, resourceId: restoredData.id };
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
const errorMsg = response?.error || response?.message || 'Unknown response format';
|
|
87
|
+
this.log(`✗ Failed to update report spec: ${errorMsg}`, 'error');
|
|
88
|
+
return { success: false, message: `Failed to update report spec: ${errorMsg}` };
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
else if (filePath.includes('/queries/') && fileName === 'query.json') {
|
|
92
|
+
const queryData = JSON.parse(await fs.readFile(filePath, 'utf-8'));
|
|
93
|
+
const fileDir = dirname(filePath);
|
|
94
|
+
const restoredData = await restoreFieldsFromFiles(fileDir, queryData);
|
|
95
|
+
const response = await this.api.updateReportQuery(restoredData.id, restoredData);
|
|
96
|
+
if (response && response.success) {
|
|
97
|
+
this.log(`✓ Updated report query (ID: ${restoredData.id})`, 'success');
|
|
98
|
+
return { success: true, message: `Updated report query (ID: ${restoredData.id})`, resourceId: restoredData.id };
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
const errorMsg = response?.error || response?.message || 'Unknown response format';
|
|
102
|
+
this.log(`✗ Failed to update report query: ${errorMsg}`, 'error');
|
|
103
|
+
return { success: false, message: `Failed to update report query: ${errorMsg}` };
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
else if (filePath.includes('/specs/') && fileName === 'code.js') {
|
|
107
|
+
return await this.handleReportSpecCodeUpdate(filePath);
|
|
108
|
+
}
|
|
109
|
+
else if (filePath.includes('/queries/') && fileName === 'query_code.bfy') {
|
|
110
|
+
return await this.handleReportQueryCodeUpdate(filePath, 'query');
|
|
111
|
+
}
|
|
112
|
+
else if (filePath.includes('/queries/') && fileName === 'script.js') {
|
|
113
|
+
return await this.handleReportQueryCodeUpdate(filePath, 'js_code');
|
|
114
|
+
}
|
|
115
|
+
else if (fileName === 'main_query.bfy') {
|
|
116
|
+
return await this.handleReportMainQueryUpdate(filePath);
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
return { success: false, message: `Unsupported report file type: ${fileName}` };
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
124
|
+
return { success: false, message: `Failed to handle report file: ${message}` };
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
async handleAiTaskFile(filePath) {
|
|
128
|
+
const fileName = basename(filePath);
|
|
129
|
+
try {
|
|
130
|
+
if (fileName === 'task.json') {
|
|
131
|
+
const aiTaskData = JSON.parse(await fs.readFile(filePath, 'utf-8'));
|
|
132
|
+
const taskDir = dirname(filePath);
|
|
133
|
+
const restoredData = await restoreAiTaskFromFiles(taskDir, aiTaskData);
|
|
134
|
+
const formData = new URLSearchParams();
|
|
135
|
+
formData.append('id', restoredData.id.toString());
|
|
136
|
+
Object.entries(restoredData).forEach(([key, value]) => {
|
|
137
|
+
if (key !== 'id' && value !== null && value !== undefined) {
|
|
138
|
+
formData.append(key, typeof value === 'string' ? value : JSON.stringify(value));
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
const response = await this.api.httpClient.post('/admin/ajax/cms_object/operation?do=bfy_ai_tasks__edit', formData, {
|
|
142
|
+
headers: {
|
|
143
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
if (response.data && response.data.success) {
|
|
147
|
+
this.log(`✓ Updated AI task (ID: ${restoredData.id})`, 'success');
|
|
148
|
+
return { success: true, message: `Updated AI task (ID: ${restoredData.id})`, resourceId: restoredData.id };
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
const errorMsg = response.data?.error || response.data?.message || 'Unknown response format';
|
|
152
|
+
this.log(`✗ Failed to update AI task: ${errorMsg}`, 'error');
|
|
153
|
+
return { success: false, message: `Failed to update AI task: ${errorMsg}` };
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
const fieldMappings = {
|
|
158
|
+
'prompt.bfy': 'prompt',
|
|
159
|
+
'output_format.json': 'output_format',
|
|
160
|
+
'system_message.bfy': 'system_message',
|
|
161
|
+
'action_code.bfy': 'action_code',
|
|
162
|
+
'action_preview_code.bfy': 'action_preview_code',
|
|
163
|
+
'initial_code.bfy': 'initial_code'
|
|
164
|
+
};
|
|
165
|
+
const fieldName = fieldMappings[fileName];
|
|
166
|
+
if (fieldName) {
|
|
167
|
+
return await this.handleAiTaskCodeUpdate(filePath, fieldName);
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
return { success: false, message: `Unsupported AI task file type: ${fileName}` };
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
catch (error) {
|
|
175
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
176
|
+
return { success: false, message: `Failed to handle AI task file: ${message}` };
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
async handleStateMachineFile(filePath) {
|
|
180
|
+
const fileName = basename(filePath);
|
|
181
|
+
try {
|
|
182
|
+
if (fileName === 'state_machine.json') {
|
|
183
|
+
const stateMachineData = JSON.parse(await fs.readFile(filePath, 'utf-8'));
|
|
184
|
+
const formData = new URLSearchParams();
|
|
185
|
+
formData.append('id', stateMachineData.id.toString());
|
|
186
|
+
Object.entries(stateMachineData).forEach(([key, value]) => {
|
|
187
|
+
if (key !== 'id' && value !== null && value !== undefined) {
|
|
188
|
+
formData.append(key, String(value));
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
const response = await this.api.httpClient.post('/admin/ajax/cms_object/operation?do=bfy_state_machines__edit', formData, {
|
|
192
|
+
headers: {
|
|
193
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
if (response.data && response.data.success) {
|
|
197
|
+
this.log(`✓ Updated state machine (ID: ${stateMachineData.id})`, 'success');
|
|
198
|
+
return { success: true, message: `Updated state machine (ID: ${stateMachineData.id})`, resourceId: stateMachineData.id };
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
const errorMsg = response.data?.error || response.data?.message || 'Unknown response format';
|
|
202
|
+
this.log(`✗ Failed to update state machine: ${errorMsg}`, 'error');
|
|
203
|
+
return { success: false, message: `Failed to update state machine: ${errorMsg}` };
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
else if (filePath.includes('/states/') && fileName === 'state.json') {
|
|
207
|
+
return await this.handleStateMachineState(filePath);
|
|
208
|
+
}
|
|
209
|
+
else if (filePath.includes('/roles/') && fileName === 'role.json') {
|
|
210
|
+
return await this.handleStateMachineRole(filePath);
|
|
211
|
+
}
|
|
212
|
+
else if (filePath.includes('/transitions/') && fileName === 'transition.json') {
|
|
213
|
+
return await this.handleStateMachineTransition(filePath);
|
|
214
|
+
}
|
|
215
|
+
else if (filePath.includes('/actions/') && fileName === 'action.json') {
|
|
216
|
+
return await this.handleStateMachineAction(filePath);
|
|
217
|
+
}
|
|
218
|
+
else if (filePath.includes('/transition_actions/') && fileName.includes('.json')) {
|
|
219
|
+
return await this.handleTransitionAction(filePath);
|
|
220
|
+
}
|
|
221
|
+
else if (filePath.includes('/specs/') && fileName === 'spec.json') {
|
|
222
|
+
return await this.handleStateMachineSpec(filePath);
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
return { success: false, message: `Unsupported state machine file type: ${fileName}` };
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
catch (error) {
|
|
229
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
230
|
+
return { success: false, message: `Failed to handle state machine file: ${message}` };
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
async handleStateMachineState(filePath) {
|
|
234
|
+
const stateData = JSON.parse(await fs.readFile(filePath, 'utf-8'));
|
|
235
|
+
const formData = new URLSearchParams();
|
|
236
|
+
formData.append('id', stateData.id.toString());
|
|
237
|
+
Object.entries(stateData).forEach(([key, value]) => {
|
|
238
|
+
if (key !== 'id' && value !== null && value !== undefined) {
|
|
239
|
+
formData.append(key, String(value));
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
const response = await this.api.httpClient.post('/admin/ajax/cms_object/operation?do=bfy_state_machine_states__edit', formData, {
|
|
243
|
+
headers: {
|
|
244
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
if (response.data && response.data.success) {
|
|
248
|
+
this.log(`✓ Updated state machine state (ID: ${stateData.id})`, 'success');
|
|
249
|
+
return { success: true, message: `Updated state machine state (ID: ${stateData.id})`, resourceId: stateData.id };
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
const errorMsg = response.data?.error || response.data?.message || 'Unknown response format';
|
|
253
|
+
this.log(`✗ Failed to update state: ${errorMsg}`, 'error');
|
|
254
|
+
return { success: false, message: `Failed to update state: ${errorMsg}` };
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
async handleStateMachineRole(filePath) {
|
|
258
|
+
const roleData = JSON.parse(await fs.readFile(filePath, 'utf-8'));
|
|
259
|
+
const fileDir = dirname(filePath);
|
|
260
|
+
const restoredData = await restoreTableRecordFromFiles(fileDir, 'bfy_state_machine_roles', roleData);
|
|
261
|
+
const formData = new URLSearchParams();
|
|
262
|
+
formData.append('id', restoredData.id.toString());
|
|
263
|
+
Object.entries(restoredData).forEach(([key, value]) => {
|
|
264
|
+
if (key !== 'id' && value !== null && value !== undefined) {
|
|
265
|
+
formData.append(key, String(value));
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
const response = await this.api.httpClient.post('/admin/ajax/cms_object/operation?do=bfy_state_machine_roles__edit', formData, {
|
|
269
|
+
headers: {
|
|
270
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
if (response.data && response.data.success) {
|
|
274
|
+
this.log(`✓ Updated state machine role (ID: ${restoredData.id})`, 'success');
|
|
275
|
+
return { success: true, message: `Updated state machine role (ID: ${restoredData.id})`, resourceId: restoredData.id };
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
const errorMsg = response.data?.error || response.data?.message || 'Unknown response format';
|
|
279
|
+
this.log(`✗ Failed to update role: ${errorMsg}`, 'error');
|
|
280
|
+
return { success: false, message: `Failed to update role: ${errorMsg}` };
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
async handleStateMachineTransition(filePath) {
|
|
284
|
+
const transitionData = JSON.parse(await fs.readFile(filePath, 'utf-8'));
|
|
285
|
+
const fileDir = dirname(filePath);
|
|
286
|
+
const restoredData = await restoreTableRecordFromFiles(fileDir, 'bfy_state_machine_transitions', transitionData);
|
|
287
|
+
const formData = new URLSearchParams();
|
|
288
|
+
formData.append('id', restoredData.id.toString());
|
|
289
|
+
Object.entries(restoredData).forEach(([key, value]) => {
|
|
290
|
+
if (key !== 'id' && value !== null && value !== undefined) {
|
|
291
|
+
formData.append(key, String(value));
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
const response = await this.api.httpClient.post('/admin/ajax/cms_object/operation?do=bfy_state_machine_transitions__edit', formData, {
|
|
295
|
+
headers: {
|
|
296
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
if (response.data && response.data.success) {
|
|
300
|
+
this.log(`✓ Updated state machine transition (ID: ${restoredData.id})`, 'success');
|
|
301
|
+
return { success: true, message: `Updated state machine transition (ID: ${restoredData.id})`, resourceId: restoredData.id };
|
|
302
|
+
}
|
|
303
|
+
else {
|
|
304
|
+
const errorMsg = response.data?.error || response.data?.message || 'Unknown response format';
|
|
305
|
+
this.log(`✗ Failed to update transition: ${errorMsg}`, 'error');
|
|
306
|
+
return { success: false, message: `Failed to update transition: ${errorMsg}` };
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
async handleStateMachineAction(filePath) {
|
|
310
|
+
const actionData = JSON.parse(await fs.readFile(filePath, 'utf-8'));
|
|
311
|
+
const fileDir = dirname(filePath);
|
|
312
|
+
const restoredData = await restoreTableRecordFromFiles(fileDir, 'bfy_sm_actions', actionData);
|
|
313
|
+
const formData = new URLSearchParams();
|
|
314
|
+
formData.append('id', restoredData.id.toString());
|
|
315
|
+
Object.entries(restoredData).forEach(([key, value]) => {
|
|
316
|
+
if (key !== 'id' && value !== null && value !== undefined) {
|
|
317
|
+
formData.append(key, String(value));
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
const response = await this.api.httpClient.post('/admin/ajax/cms_object/operation?do=bfy_sm_actions__edit', formData, {
|
|
321
|
+
headers: {
|
|
322
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
if (response.data && response.data.success) {
|
|
326
|
+
this.log(`✓ Updated state machine action (ID: ${restoredData.id})`, 'success');
|
|
327
|
+
return { success: true, message: `Updated state machine action (ID: ${restoredData.id})`, resourceId: restoredData.id };
|
|
328
|
+
}
|
|
329
|
+
else {
|
|
330
|
+
const errorMsg = response.data?.error || response.data?.message || 'Unknown response format';
|
|
331
|
+
this.log(`✗ Failed to update action: ${errorMsg}`, 'error');
|
|
332
|
+
return { success: false, message: `Failed to update action: ${errorMsg}` };
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
async handleTransitionAction(filePath) {
|
|
336
|
+
const mappingData = JSON.parse(await fs.readFile(filePath, 'utf-8'));
|
|
337
|
+
const formData = new URLSearchParams();
|
|
338
|
+
formData.append('id', mappingData.id.toString());
|
|
339
|
+
Object.entries(mappingData).forEach(([key, value]) => {
|
|
340
|
+
if (key !== 'id' && value !== null && value !== undefined) {
|
|
341
|
+
formData.append(key, String(value));
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
const response = await this.api.httpClient.post('/admin/ajax/cms_object/operation?do=bfy_sm_transition_actions__edit', formData, {
|
|
345
|
+
headers: {
|
|
346
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
if (response.data && response.data.success) {
|
|
350
|
+
this.log(`✓ Updated transition-action mapping (ID: ${mappingData.id})`, 'success');
|
|
351
|
+
return { success: true, message: `Updated transition-action mapping (ID: ${mappingData.id})`, resourceId: mappingData.id };
|
|
352
|
+
}
|
|
353
|
+
else {
|
|
354
|
+
const errorMsg = response.data?.error || response.data?.message || 'Unknown response format';
|
|
355
|
+
this.log(`✗ Failed to update transition-action mapping: ${errorMsg}`, 'error');
|
|
356
|
+
return { success: false, message: `Failed to update transition-action mapping: ${errorMsg}` };
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
async handleStateMachineSpec(filePath) {
|
|
360
|
+
const specData = JSON.parse(await fs.readFile(filePath, 'utf-8'));
|
|
361
|
+
const fileDir = dirname(filePath);
|
|
362
|
+
const restoredData = await restoreFieldsFromFiles(fileDir, specData);
|
|
363
|
+
let tableName = '';
|
|
364
|
+
if (filePath.includes('/transitions/')) {
|
|
365
|
+
tableName = 'bfy_state_machine_transition_specs';
|
|
366
|
+
}
|
|
367
|
+
else if (filePath.includes('/actions/')) {
|
|
368
|
+
tableName = 'bfy_sm_action_specs';
|
|
369
|
+
}
|
|
370
|
+
else {
|
|
371
|
+
return { success: false, message: 'Unknown spec type' };
|
|
372
|
+
}
|
|
373
|
+
const formData = new URLSearchParams();
|
|
374
|
+
formData.append('id', restoredData.id.toString());
|
|
375
|
+
Object.entries(restoredData).forEach(([key, value]) => {
|
|
376
|
+
if (key !== 'id' && value !== null && value !== undefined) {
|
|
377
|
+
formData.append(key, String(value));
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
const response = await this.api.httpClient.post(`/admin/ajax/cms_object/operation?do=${tableName}__edit`, formData, {
|
|
381
|
+
headers: {
|
|
382
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
383
|
+
}
|
|
384
|
+
});
|
|
385
|
+
if (response.data && response.data.success) {
|
|
386
|
+
this.log(`✓ Updated ${tableName.split('_').slice(-1)[0]} spec (ID: ${restoredData.id})`, 'success');
|
|
387
|
+
return { success: true, message: `Updated ${tableName.split('_').slice(-1)[0]} spec (ID: ${restoredData.id})`, resourceId: restoredData.id };
|
|
388
|
+
}
|
|
389
|
+
else {
|
|
390
|
+
const errorMsg = response.data?.error || response.data?.message || 'Unknown response format';
|
|
391
|
+
this.log(`✗ Failed to update ${tableName.split('_').slice(-1)[0]} spec: ${errorMsg}`, 'error');
|
|
392
|
+
return { success: false, message: `Failed to update ${tableName.split('_').slice(-1)[0]} spec: ${errorMsg}` };
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
async handlePageFile(filePath) {
|
|
396
|
+
const fileName = basename(filePath);
|
|
397
|
+
try {
|
|
398
|
+
if (fileName === 'page.json') {
|
|
399
|
+
const pageData = JSON.parse(await fs.readFile(filePath, 'utf-8'));
|
|
400
|
+
const fileDir = dirname(filePath);
|
|
401
|
+
const restoredData = await restoreTableRecordFromFiles(fileDir, 'pages', pageData);
|
|
402
|
+
const formData = new URLSearchParams();
|
|
403
|
+
formData.append('id', restoredData.id.toString());
|
|
404
|
+
Object.entries(restoredData).forEach(([key, value]) => {
|
|
405
|
+
if (key !== 'id' && value !== null && value !== undefined) {
|
|
406
|
+
formData.append(key, String(value));
|
|
407
|
+
}
|
|
408
|
+
});
|
|
409
|
+
const response = await this.api.httpClient.post('/admin/ajax/cms_object/operation?do=pages__edit', formData, {
|
|
410
|
+
headers: {
|
|
411
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
if (response.data && response.data.success) {
|
|
415
|
+
this.log(`✓ Updated page (ID: ${restoredData.id})`, 'success');
|
|
416
|
+
return { success: true, message: `Updated page (ID: ${restoredData.id})`, resourceId: restoredData.id };
|
|
417
|
+
}
|
|
418
|
+
else {
|
|
419
|
+
const errorMsg = response.data?.error || response.data?.message || 'Unknown response format';
|
|
420
|
+
this.log(`✗ Failed to update page: ${errorMsg}`, 'error');
|
|
421
|
+
return { success: false, message: `Failed to update page: ${errorMsg}` };
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
else {
|
|
425
|
+
return { success: false, message: `Unsupported page file type: ${fileName}` };
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
catch (error) {
|
|
429
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
430
|
+
return { success: false, message: `Failed to handle page file: ${message}` };
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
async handleCronjobFile(filePath) {
|
|
434
|
+
const fileName = basename(filePath);
|
|
435
|
+
try {
|
|
436
|
+
if (fileName === 'cronjob.json') {
|
|
437
|
+
const cronjobData = JSON.parse(await fs.readFile(filePath, 'utf-8'));
|
|
438
|
+
const fileDir = dirname(filePath);
|
|
439
|
+
const restoredData = await restoreTableRecordFromFiles(fileDir, 'bfy_cronjobs', cronjobData);
|
|
440
|
+
const formData = new URLSearchParams();
|
|
441
|
+
formData.append('id', restoredData.id.toString());
|
|
442
|
+
Object.entries(restoredData).forEach(([key, value]) => {
|
|
443
|
+
if (key !== 'id' && value !== null && value !== undefined) {
|
|
444
|
+
formData.append(key, String(value));
|
|
445
|
+
}
|
|
446
|
+
});
|
|
447
|
+
const response = await this.api.httpClient.post('/admin/ajax/cms_object/operation?do=bfy_cronjobs__edit', formData, {
|
|
448
|
+
headers: {
|
|
449
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
if (response.data && response.data.success) {
|
|
453
|
+
this.log(`✓ Updated cronjob (ID: ${restoredData.id})`, 'success');
|
|
454
|
+
return { success: true, message: `Updated cronjob (ID: ${restoredData.id})`, resourceId: restoredData.id };
|
|
455
|
+
}
|
|
456
|
+
else {
|
|
457
|
+
const errorMsg = response.data?.error || response.data?.message || 'Unknown response format';
|
|
458
|
+
this.log(`✗ Failed to update cronjob: ${errorMsg}`, 'error');
|
|
459
|
+
return { success: false, message: `Failed to update cronjob: ${errorMsg}` };
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
else {
|
|
463
|
+
return { success: false, message: `Unsupported cronjob file type: ${fileName}` };
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
catch (error) {
|
|
467
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
468
|
+
return { success: false, message: `Failed to handle cronjob file: ${message}` };
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
async handleEmailTemplateFile(filePath) {
|
|
472
|
+
const fileName = basename(filePath);
|
|
473
|
+
try {
|
|
474
|
+
if (fileName === 'template.json') {
|
|
475
|
+
const templateData = JSON.parse(await fs.readFile(filePath, 'utf-8'));
|
|
476
|
+
const fileDir = dirname(filePath);
|
|
477
|
+
const restoredData = await restoreTableRecordFromFiles(fileDir, 'cms_email_templates', templateData);
|
|
478
|
+
const formData = new URLSearchParams();
|
|
479
|
+
formData.append('id', restoredData.id.toString());
|
|
480
|
+
Object.entries(restoredData).forEach(([key, value]) => {
|
|
481
|
+
if (key !== 'id' && value !== null && value !== undefined) {
|
|
482
|
+
formData.append(key, String(value));
|
|
483
|
+
}
|
|
484
|
+
});
|
|
485
|
+
const response = await this.api.httpClient.post('/admin/ajax/cms_object/operation?do=cms_email_templates__edit', formData, {
|
|
486
|
+
headers: {
|
|
487
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
488
|
+
}
|
|
489
|
+
});
|
|
490
|
+
if (response.data && response.data.success) {
|
|
491
|
+
this.log(`✓ Updated email template (ID: ${restoredData.id})`, 'success');
|
|
492
|
+
return { success: true, message: `Updated email template (ID: ${restoredData.id})`, resourceId: restoredData.id };
|
|
493
|
+
}
|
|
494
|
+
else {
|
|
495
|
+
const errorMsg = response.data?.error || response.data?.message || 'Unknown response format';
|
|
496
|
+
this.log(`✗ Failed to update email template: ${errorMsg}`, 'error');
|
|
497
|
+
return { success: false, message: `Failed to update email template: ${errorMsg}` };
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
else {
|
|
501
|
+
return { success: false, message: `Unsupported email template file type: ${fileName}` };
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
catch (error) {
|
|
505
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
506
|
+
return { success: false, message: `Failed to handle email template file: ${message}` };
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
async handleEmailLayoutFile(filePath) {
|
|
510
|
+
const fileName = basename(filePath);
|
|
511
|
+
try {
|
|
512
|
+
if (fileName === 'layout.json') {
|
|
513
|
+
const layoutData = JSON.parse(await fs.readFile(filePath, 'utf-8'));
|
|
514
|
+
const fileDir = dirname(filePath);
|
|
515
|
+
const restoredData = await restoreTableRecordFromFiles(fileDir, 'cms_email_layouts', layoutData);
|
|
516
|
+
const formData = new URLSearchParams();
|
|
517
|
+
formData.append('id', restoredData.id.toString());
|
|
518
|
+
Object.entries(restoredData).forEach(([key, value]) => {
|
|
519
|
+
if (key !== 'id' && value !== null && value !== undefined) {
|
|
520
|
+
formData.append(key, String(value));
|
|
521
|
+
}
|
|
522
|
+
});
|
|
523
|
+
const response = await this.api.httpClient.post('/admin/ajax/cms_object/operation?do=cms_email_layouts__edit', formData, {
|
|
524
|
+
headers: {
|
|
525
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
526
|
+
}
|
|
527
|
+
});
|
|
528
|
+
if (response.data && response.data.success) {
|
|
529
|
+
this.log(`✓ Updated email layout (ID: ${restoredData.id})`, 'success');
|
|
530
|
+
return { success: true, message: `Updated email layout (ID: ${restoredData.id})`, resourceId: restoredData.id };
|
|
531
|
+
}
|
|
532
|
+
else {
|
|
533
|
+
const errorMsg = response.data?.error || response.data?.message || 'Unknown response format';
|
|
534
|
+
this.log(`✗ Failed to update email layout: ${errorMsg}`, 'error');
|
|
535
|
+
return { success: false, message: `Failed to update email layout: ${errorMsg}` };
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
else {
|
|
539
|
+
return { success: false, message: `Unsupported email layout file type: ${fileName}` };
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
catch (error) {
|
|
543
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
544
|
+
return { success: false, message: `Failed to handle email layout file: ${message}` };
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
async handleObjectFile(filePath) {
|
|
548
|
+
const fileName = basename(filePath);
|
|
549
|
+
try {
|
|
550
|
+
if (fileName === 'object.json') {
|
|
551
|
+
const objectData = JSON.parse(await fs.readFile(filePath, 'utf-8'));
|
|
552
|
+
const formData = new URLSearchParams();
|
|
553
|
+
formData.append('id', objectData.id.toString());
|
|
554
|
+
Object.entries(objectData).forEach(([key, value]) => {
|
|
555
|
+
if (key !== 'id' && value !== null && value !== undefined) {
|
|
556
|
+
formData.append(key, String(value));
|
|
557
|
+
}
|
|
558
|
+
});
|
|
559
|
+
const response = await this.api.httpClient.post('/admin/ajax/cms_object/operation?do=objects__edit', formData, {
|
|
560
|
+
headers: {
|
|
561
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
562
|
+
}
|
|
563
|
+
});
|
|
564
|
+
if (response.data && response.data.success) {
|
|
565
|
+
this.log(`✓ Updated object (ID: ${objectData.id})`, 'success');
|
|
566
|
+
return { success: true, message: `Updated object (ID: ${objectData.id})`, resourceId: objectData.id };
|
|
567
|
+
}
|
|
568
|
+
else {
|
|
569
|
+
const errorMsg = response.data?.error || response.data?.message || 'Unknown response format';
|
|
570
|
+
this.log(`✗ Failed to update object: ${errorMsg}`, 'error');
|
|
571
|
+
return { success: false, message: `Failed to update object: ${errorMsg}` };
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
else if (fileName === 'spec.json') {
|
|
575
|
+
const specData = JSON.parse(await fs.readFile(filePath, 'utf-8'));
|
|
576
|
+
const fileDir = dirname(filePath);
|
|
577
|
+
const restoredData = await restoreFieldsFromFiles(fileDir, specData);
|
|
578
|
+
const formData = new URLSearchParams();
|
|
579
|
+
formData.append('id', restoredData.id.toString());
|
|
580
|
+
Object.entries(restoredData).forEach(([key, value]) => {
|
|
581
|
+
if (key !== 'id' && value !== null && value !== undefined) {
|
|
582
|
+
formData.append(key, String(value));
|
|
583
|
+
}
|
|
584
|
+
});
|
|
585
|
+
const response = await this.api.httpClient.post('/admin/ajax/cms_object/operation?do=object_specs__edit', formData, {
|
|
586
|
+
headers: {
|
|
587
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
588
|
+
}
|
|
589
|
+
});
|
|
590
|
+
if (response.data && response.data.success) {
|
|
591
|
+
this.log(`✓ Updated object spec (ID: ${restoredData.id})`, 'success');
|
|
592
|
+
return { success: true, message: `Updated object spec (ID: ${restoredData.id})`, resourceId: restoredData.id };
|
|
593
|
+
}
|
|
594
|
+
else {
|
|
595
|
+
const errorMsg = response.data?.error || response.data?.message || 'Unknown response format';
|
|
596
|
+
this.log(`✗ Failed to update object spec: ${errorMsg}`, 'error');
|
|
597
|
+
return { success: false, message: `Failed to update object spec: ${errorMsg}` };
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
else {
|
|
601
|
+
return { success: false, message: `Unsupported object file type: ${fileName}` };
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
catch (error) {
|
|
605
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
606
|
+
return { success: false, message: `Failed to handle object file: ${message}` };
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
async handleReportSpecCodeUpdate(filePath) {
|
|
610
|
+
try {
|
|
611
|
+
const codeContent = await fs.readFile(filePath, 'utf-8');
|
|
612
|
+
const specJsonPath = join(dirname(filePath), 'spec.json');
|
|
613
|
+
const specData = JSON.parse(await fs.readFile(specJsonPath, 'utf-8'));
|
|
614
|
+
const response = await this.api.updateReportSpec(specData.id, { js_code: codeContent });
|
|
615
|
+
if (response && response.success) {
|
|
616
|
+
this.log(`✓ Updated report spec js_code (ID: ${specData.id})`, 'success');
|
|
617
|
+
return { success: true, message: `Updated report spec js_code (ID: ${specData.id})`, resourceId: specData.id };
|
|
618
|
+
}
|
|
619
|
+
else {
|
|
620
|
+
const errorMsg = response?.error || response?.message || 'Unknown response format';
|
|
621
|
+
this.log(`✗ Failed to update report spec js_code: ${errorMsg}`, 'error');
|
|
622
|
+
return { success: false, message: `Failed to update report spec js_code: ${errorMsg}` };
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
catch (error) {
|
|
626
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
627
|
+
return { success: false, message: `Failed to handle report spec code update: ${message}` };
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
async handleReportQueryCodeUpdate(filePath, field) {
|
|
631
|
+
try {
|
|
632
|
+
const codeContent = await fs.readFile(filePath, 'utf-8');
|
|
633
|
+
const queryJsonPath = join(dirname(filePath), 'query.json');
|
|
634
|
+
const queryData = JSON.parse(await fs.readFile(queryJsonPath, 'utf-8'));
|
|
635
|
+
const updateData = { [field]: codeContent };
|
|
636
|
+
const response = await this.api.updateReportQuery(queryData.id, updateData);
|
|
637
|
+
if (response && response.success) {
|
|
638
|
+
this.log(`✓ Updated report query ${field} (ID: ${queryData.id})`, 'success');
|
|
639
|
+
return { success: true, message: `Updated report query ${field} (ID: ${queryData.id})`, resourceId: queryData.id };
|
|
640
|
+
}
|
|
641
|
+
else {
|
|
642
|
+
const errorMsg = response?.error || response?.message || 'Unknown response format';
|
|
643
|
+
this.log(`✗ Failed to update report query ${field}: ${errorMsg}`, 'error');
|
|
644
|
+
return { success: false, message: `Failed to update report query ${field}: ${errorMsg}` };
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
catch (error) {
|
|
648
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
649
|
+
return { success: false, message: `Failed to handle report query code update: ${message}` };
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
async handleReportMainQueryUpdate(filePath) {
|
|
653
|
+
try {
|
|
654
|
+
const queryContent = await fs.readFile(filePath, 'utf-8');
|
|
655
|
+
const reportJsonPath = join(dirname(filePath), 'report.json');
|
|
656
|
+
const reportData = JSON.parse(await fs.readFile(reportJsonPath, 'utf-8'));
|
|
657
|
+
const fileDir = dirname(reportJsonPath);
|
|
658
|
+
const restoredReportData = await restoreFieldsFromFiles(fileDir, reportData);
|
|
659
|
+
const response = await this.api.updateReport(restoredReportData.id, { query: queryContent });
|
|
660
|
+
if (response && response.success) {
|
|
661
|
+
this.log(`✓ Updated report main query (ID: ${restoredReportData.id})`, 'success');
|
|
662
|
+
return { success: true, message: `Updated report main query (ID: ${restoredReportData.id})`, resourceId: restoredReportData.id };
|
|
663
|
+
}
|
|
664
|
+
else {
|
|
665
|
+
const errorMsg = response?.error || response?.message || 'Unknown response format';
|
|
666
|
+
this.log(`✗ Failed to update report main query: ${errorMsg}`, 'error');
|
|
667
|
+
return { success: false, message: `Failed to update report main query: ${errorMsg}` };
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
catch (error) {
|
|
671
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
672
|
+
return { success: false, message: `Failed to handle report main query update: ${message}` };
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
async handleAiTaskCodeUpdate(filePath, fieldName) {
|
|
676
|
+
try {
|
|
677
|
+
const taskDir = dirname(filePath);
|
|
678
|
+
const taskJsonPath = join(taskDir, 'task.json');
|
|
679
|
+
const aiTaskData = JSON.parse(await fs.readFile(taskJsonPath, 'utf-8'));
|
|
680
|
+
const content = await fs.readFile(filePath, 'utf-8');
|
|
681
|
+
const fieldValue = basename(filePath).endsWith('.json') ? JSON.stringify(JSON.parse(content)) : content;
|
|
682
|
+
const formData = new URLSearchParams();
|
|
683
|
+
formData.append('id', aiTaskData.id.toString());
|
|
684
|
+
formData.append(fieldName, fieldValue);
|
|
685
|
+
const response = await this.api.httpClient.post('/admin/ajax/cms_object/operation?do=bfy_ai_tasks__edit', formData, {
|
|
686
|
+
headers: {
|
|
687
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
688
|
+
}
|
|
689
|
+
});
|
|
690
|
+
if (response.data && response.data.success) {
|
|
691
|
+
this.log(`✓ Updated AI task ${fieldName} (ID: ${aiTaskData.id})`, 'success');
|
|
692
|
+
return { success: true, message: `Updated AI task ${fieldName} (ID: ${aiTaskData.id})`, resourceId: aiTaskData.id };
|
|
693
|
+
}
|
|
694
|
+
else {
|
|
695
|
+
const errorMsg = response.data?.error || response.data?.message || 'Unknown response format';
|
|
696
|
+
this.log(`✗ Failed to update AI task ${fieldName}: ${errorMsg}`, 'error');
|
|
697
|
+
return { success: false, message: `Failed to update AI task ${fieldName}: ${errorMsg}` };
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
catch (error) {
|
|
701
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
702
|
+
return { success: false, message: `Failed to handle AI task code update: ${message}` };
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
//# sourceMappingURL=uploadHandler.js.map
|