@rimori/client 2.5.32 → 2.5.33
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/dist/cli/scripts/init/dev-registration.js +118 -136
- package/dist/cli/scripts/init/main.js +116 -127
- package/dist/cli/scripts/init/package-setup.js +15 -2
- package/dist/cli/scripts/release/detect-translation-languages.js +24 -35
- package/dist/cli/scripts/release/release-config-upload.js +87 -100
- package/dist/cli/scripts/release/release-db-update.js +70 -81
- package/dist/cli/scripts/release/release-file-upload.js +75 -91
- package/dist/cli/scripts/release/release-prompts-upload.js +60 -72
- package/dist/cli/scripts/release/release.js +20 -31
- package/dist/controller/AccomplishmentController.js +12 -12
- package/dist/controller/AudioController.js +15 -33
- package/dist/controller/TranslationController.js +108 -118
- package/dist/fromRimori/EventBus.js +20 -31
- package/dist/plugin/CommunicationHandler.js +73 -81
- package/dist/plugin/Logger.js +71 -83
- package/dist/plugin/RimoriClient.js +31 -31
- package/dist/plugin/StandaloneClient.js +81 -98
- package/dist/plugin/TTS/ChunkedAudioPlayer.js +31 -41
- package/dist/plugin/TTS/MessageSender.js +28 -37
- package/dist/plugin/module/AIModule.js +215 -237
- package/dist/plugin/module/DbModule.js +22 -31
- package/dist/plugin/module/EventModule.js +23 -32
- package/dist/plugin/module/ExerciseModule.js +42 -56
- package/dist/plugin/module/PluginModule.js +97 -106
- package/dist/plugin/module/SharedContentController.js +170 -207
- package/dist/plugin/module/StorageModule.js +18 -29
- package/dist/worker/WorkerSetup.js +23 -34
- package/package.json +1 -1
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
export class SharedContentController {
|
|
2
|
+
supabase;
|
|
3
|
+
rimoriClient;
|
|
11
4
|
constructor(supabase, rimoriClient) {
|
|
12
5
|
this.supabase = supabase;
|
|
13
6
|
this.rimoriClient = rimoriClient;
|
|
@@ -29,30 +22,28 @@ export class SharedContentController {
|
|
|
29
22
|
* @param params.ignoreSkillLevel - If true, don't filter by skill level or add skill level guidance to AI instructions
|
|
30
23
|
* @returns Existing or newly generated shared content item
|
|
31
24
|
*/
|
|
32
|
-
getNew(params) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}),
|
|
50
|
-
});
|
|
51
|
-
if (!response.ok) {
|
|
52
|
-
throw new Error(`Failed to generate shared content: ${response.statusText}`);
|
|
53
|
-
}
|
|
54
|
-
return yield response.json();
|
|
25
|
+
async getNew(params) {
|
|
26
|
+
// Generate new content via backend endpoint
|
|
27
|
+
const response = await this.rimoriClient.runtime.fetchBackend('/shared-content/generate', {
|
|
28
|
+
method: 'POST',
|
|
29
|
+
body: JSON.stringify({
|
|
30
|
+
tableName: params.table,
|
|
31
|
+
skillType: params.skillType,
|
|
32
|
+
placeholders: params.placeholders,
|
|
33
|
+
filter: params.filter,
|
|
34
|
+
customFields: params.customFields,
|
|
35
|
+
tool: params.tool,
|
|
36
|
+
options: {
|
|
37
|
+
skipDbSave: params.skipDbSave,
|
|
38
|
+
isPrivate: params.isPrivate,
|
|
39
|
+
ignoreSkillLevel: params.ignoreSkillLevel,
|
|
40
|
+
},
|
|
41
|
+
}),
|
|
55
42
|
});
|
|
43
|
+
if (!response.ok) {
|
|
44
|
+
throw new Error(`Failed to generate shared content: ${response.statusText}`);
|
|
45
|
+
}
|
|
46
|
+
return await response.json();
|
|
56
47
|
}
|
|
57
48
|
/**
|
|
58
49
|
* Search for shared content by topic using RAG (semantic similarity).
|
|
@@ -62,21 +53,19 @@ export class SharedContentController {
|
|
|
62
53
|
* @param limit - Maximum number of results to return (default: 10)
|
|
63
54
|
* @returns Matching shared content
|
|
64
55
|
*/
|
|
65
|
-
searchByTopic(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}),
|
|
74
|
-
});
|
|
75
|
-
if (!response.ok) {
|
|
76
|
-
throw new Error(`Failed to search shared content: ${response.statusText}`);
|
|
77
|
-
}
|
|
78
|
-
return (yield response.json());
|
|
56
|
+
async searchByTopic(tableName, topic, limit = 10) {
|
|
57
|
+
const response = await this.rimoriClient.runtime.fetchBackend('/shared-content/get-by-topic', {
|
|
58
|
+
method: 'POST',
|
|
59
|
+
body: JSON.stringify({
|
|
60
|
+
tableName,
|
|
61
|
+
limit,
|
|
62
|
+
filter: { title: { filterType: 'rag', value: topic } },
|
|
63
|
+
}),
|
|
79
64
|
});
|
|
65
|
+
if (!response.ok) {
|
|
66
|
+
throw new Error(`Failed to search shared content: ${response.statusText}`);
|
|
67
|
+
}
|
|
68
|
+
return (await response.json());
|
|
80
69
|
}
|
|
81
70
|
/**
|
|
82
71
|
* Get bookmarked shared content.
|
|
@@ -84,21 +73,19 @@ export class SharedContentController {
|
|
|
84
73
|
* @param limit - Maximum number of results
|
|
85
74
|
* @returns Array of bookmarked content
|
|
86
75
|
*/
|
|
87
|
-
getBookmarked(
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
return (data || []);
|
|
101
|
-
});
|
|
76
|
+
async getBookmarked(tableName, limit = 30) {
|
|
77
|
+
const fullTableName = this.getTableName(tableName);
|
|
78
|
+
const completedTableName = this.getCompletedTableName(tableName);
|
|
79
|
+
const { data, error } = await this.supabase
|
|
80
|
+
.from(fullTableName)
|
|
81
|
+
.select(`*, completed:${completedTableName}!inner(*)`)
|
|
82
|
+
.eq(`completed.bookmarked`, true)
|
|
83
|
+
.limit(limit);
|
|
84
|
+
if (error) {
|
|
85
|
+
console.error('Error fetching bookmarked content:', error);
|
|
86
|
+
throw new Error('Error fetching bookmarked content');
|
|
87
|
+
}
|
|
88
|
+
return (data || []);
|
|
102
89
|
}
|
|
103
90
|
/**
|
|
104
91
|
* Get ongoing shared content.
|
|
@@ -106,21 +93,19 @@ export class SharedContentController {
|
|
|
106
93
|
* @param limit - Maximum number of results
|
|
107
94
|
* @returns Array of ongoing content
|
|
108
95
|
*/
|
|
109
|
-
getOngoing(
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
return (data || []);
|
|
123
|
-
});
|
|
96
|
+
async getOngoing(tableName, limit = 30) {
|
|
97
|
+
const fullTableName = this.getTableName(tableName);
|
|
98
|
+
const completedTableName = this.getCompletedTableName(tableName);
|
|
99
|
+
const { data, error } = await this.supabase
|
|
100
|
+
.from(fullTableName)
|
|
101
|
+
.select(`*, completed:${completedTableName}!inner(*)`)
|
|
102
|
+
.eq(`completed.state`, 'ongoing')
|
|
103
|
+
.limit(limit);
|
|
104
|
+
if (error) {
|
|
105
|
+
console.error('Error fetching ongoing content:', error);
|
|
106
|
+
throw new Error('Error fetching ongoing content');
|
|
107
|
+
}
|
|
108
|
+
return (data || []);
|
|
124
109
|
}
|
|
125
110
|
/**
|
|
126
111
|
* Get completed shared content.
|
|
@@ -128,39 +113,35 @@ export class SharedContentController {
|
|
|
128
113
|
* @param limit - Maximum number of results
|
|
129
114
|
* @returns Array of completed content
|
|
130
115
|
*/
|
|
131
|
-
getCompleted(
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
return (data || []);
|
|
145
|
-
});
|
|
116
|
+
async getCompleted(tableName, limit = 30) {
|
|
117
|
+
const fullTableName = this.getTableName(tableName);
|
|
118
|
+
const completedTableName = this.getCompletedTableName(tableName);
|
|
119
|
+
const { data, error } = await this.supabase
|
|
120
|
+
.from(fullTableName)
|
|
121
|
+
.select(`*, completed:${completedTableName}!inner(*)`)
|
|
122
|
+
.eq(`completed.state`, 'completed')
|
|
123
|
+
.limit(limit);
|
|
124
|
+
if (error) {
|
|
125
|
+
console.error('Error fetching completed content:', error);
|
|
126
|
+
throw new Error('Error fetching completed content');
|
|
127
|
+
}
|
|
128
|
+
return (data || []);
|
|
146
129
|
}
|
|
147
130
|
/**
|
|
148
131
|
* Mark shared content as completed.
|
|
149
132
|
* @param tableName - Name of the shared content table
|
|
150
133
|
* @param contentId - ID of the content to mark as completed
|
|
151
134
|
*/
|
|
152
|
-
complete(tableName, contentId) {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
}
|
|
163
|
-
});
|
|
135
|
+
async complete(tableName, contentId) {
|
|
136
|
+
const completedTableName = this.getCompletedTableName(tableName);
|
|
137
|
+
const { error } = await this.supabase.from(completedTableName).upsert({
|
|
138
|
+
content_id: contentId,
|
|
139
|
+
state: 'completed',
|
|
140
|
+
}, { onConflict: 'content_id,user_id' });
|
|
141
|
+
if (error) {
|
|
142
|
+
console.error('Error completing shared content:', error);
|
|
143
|
+
throw new Error('Error completing shared content');
|
|
144
|
+
}
|
|
164
145
|
}
|
|
165
146
|
/**
|
|
166
147
|
* Update the state of shared content.
|
|
@@ -168,18 +149,16 @@ export class SharedContentController {
|
|
|
168
149
|
* @param contentId - ID of the content
|
|
169
150
|
* @param state - New state
|
|
170
151
|
*/
|
|
171
|
-
updateState(tableName, contentId, state) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
});
|
|
152
|
+
async updateState(tableName, contentId, state) {
|
|
153
|
+
const completedTableName = this.getCompletedTableName(tableName);
|
|
154
|
+
const { error } = await this.supabase.from(completedTableName).upsert({
|
|
155
|
+
content_id: contentId,
|
|
156
|
+
state,
|
|
157
|
+
}, { onConflict: 'content_id,user_id' });
|
|
158
|
+
if (error) {
|
|
159
|
+
console.error('Error updating content state:', error);
|
|
160
|
+
throw new Error('Error updating content state');
|
|
161
|
+
}
|
|
183
162
|
}
|
|
184
163
|
/**
|
|
185
164
|
* Bookmark or unbookmark shared content.
|
|
@@ -187,18 +166,16 @@ export class SharedContentController {
|
|
|
187
166
|
* @param contentId - ID of the content
|
|
188
167
|
* @param bookmarked - Whether to bookmark or unbookmark
|
|
189
168
|
*/
|
|
190
|
-
bookmark(tableName, contentId, bookmarked) {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
}
|
|
201
|
-
});
|
|
169
|
+
async bookmark(tableName, contentId, bookmarked) {
|
|
170
|
+
const completedTableName = this.getCompletedTableName(tableName);
|
|
171
|
+
const { error } = await this.supabase.from(completedTableName).upsert({
|
|
172
|
+
content_id: contentId,
|
|
173
|
+
bookmarked,
|
|
174
|
+
}, { onConflict: 'content_id,user_id' });
|
|
175
|
+
if (error) {
|
|
176
|
+
console.error('Error bookmarking content:', error);
|
|
177
|
+
throw new Error('Error bookmarking content');
|
|
178
|
+
}
|
|
202
179
|
}
|
|
203
180
|
/**
|
|
204
181
|
* React to shared content with like/dislike.
|
|
@@ -206,18 +183,16 @@ export class SharedContentController {
|
|
|
206
183
|
* @param contentId - ID of the content
|
|
207
184
|
* @param reaction - Reaction type or null to remove reaction
|
|
208
185
|
*/
|
|
209
|
-
react(tableName, contentId, reaction) {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
}
|
|
220
|
-
});
|
|
186
|
+
async react(tableName, contentId, reaction) {
|
|
187
|
+
const completedTableName = this.getCompletedTableName(tableName);
|
|
188
|
+
const { error } = await this.supabase.from(completedTableName).upsert({
|
|
189
|
+
content_id: contentId,
|
|
190
|
+
reaction,
|
|
191
|
+
}, { onConflict: 'content_id,user_id' });
|
|
192
|
+
if (error) {
|
|
193
|
+
console.error('Error reacting to content:', error);
|
|
194
|
+
throw new Error('Error reacting to content');
|
|
195
|
+
}
|
|
221
196
|
}
|
|
222
197
|
/**
|
|
223
198
|
* Get a specific shared content item by ID.
|
|
@@ -225,16 +200,14 @@ export class SharedContentController {
|
|
|
225
200
|
* @param contentId - ID of the content
|
|
226
201
|
* @returns The shared content item
|
|
227
202
|
*/
|
|
228
|
-
get(tableName, contentId) {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
return data;
|
|
237
|
-
});
|
|
203
|
+
async get(tableName, contentId) {
|
|
204
|
+
const fullTableName = this.getTableName(tableName);
|
|
205
|
+
const { data, error } = await this.supabase.from(fullTableName).select('*').eq('id', contentId).single();
|
|
206
|
+
if (error) {
|
|
207
|
+
console.error('Error fetching shared content:', error);
|
|
208
|
+
throw new Error('Error fetching shared content');
|
|
209
|
+
}
|
|
210
|
+
return data;
|
|
238
211
|
}
|
|
239
212
|
/**
|
|
240
213
|
* Fetch all shared content items.
|
|
@@ -242,16 +215,14 @@ export class SharedContentController {
|
|
|
242
215
|
* @param limit - Maximum number of results (default: 100)
|
|
243
216
|
* @returns Array of all shared content items
|
|
244
217
|
*/
|
|
245
|
-
getAll(
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
return (data || []);
|
|
254
|
-
});
|
|
218
|
+
async getAll(tableName, limit = 100) {
|
|
219
|
+
const fullTableName = this.getTableName(tableName);
|
|
220
|
+
const { data, error } = await this.supabase.from(fullTableName).select('*').limit(limit);
|
|
221
|
+
if (error) {
|
|
222
|
+
console.error('Error fetching all shared content:', error);
|
|
223
|
+
throw new Error('Error fetching all shared content');
|
|
224
|
+
}
|
|
225
|
+
return (data || []);
|
|
255
226
|
}
|
|
256
227
|
/**
|
|
257
228
|
* Create new shared content manually.
|
|
@@ -259,16 +230,14 @@ export class SharedContentController {
|
|
|
259
230
|
* @param content - Content to create
|
|
260
231
|
* @returns Created content
|
|
261
232
|
*/
|
|
262
|
-
create(tableName, content) {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
return data;
|
|
271
|
-
});
|
|
233
|
+
async create(tableName, content) {
|
|
234
|
+
const fullTableName = this.getTableName(tableName);
|
|
235
|
+
const { data, error } = await this.supabase.from(fullTableName).insert(content).select().single();
|
|
236
|
+
if (error) {
|
|
237
|
+
console.error('Error creating shared content:', error);
|
|
238
|
+
throw new Error('Error creating shared content');
|
|
239
|
+
}
|
|
240
|
+
return data;
|
|
272
241
|
}
|
|
273
242
|
/**
|
|
274
243
|
* Update existing shared content via backend.
|
|
@@ -279,22 +248,20 @@ export class SharedContentController {
|
|
|
279
248
|
* @param updates - Updates to apply
|
|
280
249
|
* @returns Updated content
|
|
281
250
|
*/
|
|
282
|
-
update(tableName, contentId, updates) {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
}),
|
|
291
|
-
});
|
|
292
|
-
if (!response.ok) {
|
|
293
|
-
console.error('Error updating shared content:', response.statusText);
|
|
294
|
-
throw new Error(`Failed to update shared content: ${response.statusText}`);
|
|
295
|
-
}
|
|
296
|
-
return (yield response.json());
|
|
251
|
+
async update(tableName, contentId, updates) {
|
|
252
|
+
const response = await this.rimoriClient.runtime.fetchBackend('/shared-content/update', {
|
|
253
|
+
method: 'POST',
|
|
254
|
+
body: JSON.stringify({
|
|
255
|
+
tableName,
|
|
256
|
+
contentId,
|
|
257
|
+
updates,
|
|
258
|
+
}),
|
|
297
259
|
});
|
|
260
|
+
if (!response.ok) {
|
|
261
|
+
console.error('Error updating shared content:', response.statusText);
|
|
262
|
+
throw new Error(`Failed to update shared content: ${response.statusText}`);
|
|
263
|
+
}
|
|
264
|
+
return (await response.json());
|
|
298
265
|
}
|
|
299
266
|
/**
|
|
300
267
|
* Request validation for shared content.
|
|
@@ -304,36 +271,32 @@ export class SharedContentController {
|
|
|
304
271
|
* @param contentId - ID of the content to validate
|
|
305
272
|
* @returns Validation result with new content_status
|
|
306
273
|
*/
|
|
307
|
-
validate(tableName, contentId) {
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
}),
|
|
315
|
-
});
|
|
316
|
-
if (!response.ok) {
|
|
317
|
-
console.error('Error validating shared content:', response.statusText);
|
|
318
|
-
throw new Error(`Failed to validate shared content: ${response.statusText}`);
|
|
319
|
-
}
|
|
320
|
-
return yield response.json();
|
|
274
|
+
async validate(tableName, contentId) {
|
|
275
|
+
const response = await this.rimoriClient.runtime.fetchBackend('/shared-content/validate', {
|
|
276
|
+
method: 'POST',
|
|
277
|
+
body: JSON.stringify({
|
|
278
|
+
tableName,
|
|
279
|
+
contentId,
|
|
280
|
+
}),
|
|
321
281
|
});
|
|
282
|
+
if (!response.ok) {
|
|
283
|
+
console.error('Error validating shared content:', response.statusText);
|
|
284
|
+
throw new Error(`Failed to validate shared content: ${response.statusText}`);
|
|
285
|
+
}
|
|
286
|
+
return await response.json();
|
|
322
287
|
}
|
|
323
288
|
/**
|
|
324
289
|
* Delete shared content.
|
|
325
290
|
* @param tableName - Name of the shared content table
|
|
326
291
|
* @param contentId - ID of the content to delete
|
|
327
292
|
*/
|
|
328
|
-
remove(tableName, contentId) {
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
}
|
|
336
|
-
});
|
|
293
|
+
async remove(tableName, contentId) {
|
|
294
|
+
const fullTableName = this.getTableName(tableName);
|
|
295
|
+
const { error } = await this.supabase.from(fullTableName).delete().eq('id', contentId);
|
|
296
|
+
if (error) {
|
|
297
|
+
console.error('Error deleting shared content:', error);
|
|
298
|
+
throw new Error('Error deleting shared content');
|
|
299
|
+
}
|
|
337
300
|
}
|
|
338
301
|
getCompletedTableName(tableName) {
|
|
339
302
|
return this.getTableName(tableName) + '_completed';
|
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
export class StorageModule {
|
|
2
|
+
controller;
|
|
11
3
|
constructor(controller) {
|
|
12
4
|
this.controller = controller;
|
|
13
5
|
}
|
|
@@ -20,26 +12,23 @@ export class StorageModule {
|
|
|
20
12
|
*
|
|
21
13
|
* @returns `{ data: { url, path } }` on success, `{ error }` on failure.
|
|
22
14
|
*/
|
|
23
|
-
uploadImage(pngBlob) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
const body = (yield response.json().catch(() => ({})));
|
|
35
|
-
return { error: new Error((_a = body.message) !== null && _a !== void 0 ? _a : `Upload failed (${response.status})`) };
|
|
36
|
-
}
|
|
37
|
-
const result = (yield response.json());
|
|
38
|
-
return { data: result };
|
|
15
|
+
async uploadImage(pngBlob) {
|
|
16
|
+
const formData = new FormData();
|
|
17
|
+
formData.append('file', pngBlob, 'image.png');
|
|
18
|
+
try {
|
|
19
|
+
const response = await this.controller.fetchBackend('/plugin-images/upload', {
|
|
20
|
+
method: 'POST',
|
|
21
|
+
body: formData,
|
|
22
|
+
});
|
|
23
|
+
if (!response.ok) {
|
|
24
|
+
const body = (await response.json().catch(() => ({})));
|
|
25
|
+
return { error: new Error(body.message ?? `Upload failed (${response.status})`) };
|
|
39
26
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
27
|
+
const result = (await response.json());
|
|
28
|
+
return { data: result };
|
|
29
|
+
}
|
|
30
|
+
catch (err) {
|
|
31
|
+
return { error: err instanceof Error ? err : new Error(String(err)) };
|
|
32
|
+
}
|
|
44
33
|
}
|
|
45
34
|
}
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { RimoriClient } from '../plugin/RimoriClient';
|
|
11
2
|
import { EventBusHandler } from '../fromRimori/EventBus';
|
|
12
3
|
/**
|
|
@@ -15,29 +6,27 @@ import { EventBusHandler } from '../fromRimori/EventBus';
|
|
|
15
6
|
* @param init - The function containing the initialization logic. The init must be completed within 5s. For long running tasks use the init event (e.g. onboarding.triggerInitPlugin) or run the work async.
|
|
16
7
|
* @returns A promise that resolves when the worker is setup.
|
|
17
8
|
*/
|
|
18
|
-
export function setupWorker(pluginId, init) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
rimoriClient.event.emit('self.rimori.triggerInitFinished');
|
|
42
|
-
});
|
|
9
|
+
export async function setupWorker(pluginId, init) {
|
|
10
|
+
// Mock of the window object for the worker context to be able to use the PluginController.
|
|
11
|
+
const mockWindow = {
|
|
12
|
+
isWorker: true,
|
|
13
|
+
location: {},
|
|
14
|
+
parent: {
|
|
15
|
+
postMessage: () => { },
|
|
16
|
+
},
|
|
17
|
+
addEventListener: () => { },
|
|
18
|
+
};
|
|
19
|
+
// Assign the mock to globalThis.
|
|
20
|
+
Object.assign(globalThis, { window: mockWindow });
|
|
21
|
+
EventBusHandler.getInstance('Worker ' + pluginId + ' EventBus');
|
|
22
|
+
const rimoriClient = await RimoriClient.getInstance(pluginId);
|
|
23
|
+
console.debug('[Worker] RimoriClient initialized.');
|
|
24
|
+
const timoutError = new Error('[Worker ' +
|
|
25
|
+
pluginId +
|
|
26
|
+
'] Worker setup must complete within 5s. Use init event (e.g. onboarding.triggerInitPlugin) or run work async.');
|
|
27
|
+
const initPromise = Promise.resolve(init(rimoriClient));
|
|
28
|
+
const timeout = new Promise((_, reject) => setTimeout(() => reject(timoutError), 5000));
|
|
29
|
+
await Promise.race([initPromise, timeout]);
|
|
30
|
+
console.debug('[Worker] Worker initialized.');
|
|
31
|
+
rimoriClient.event.emit('self.rimori.triggerInitFinished');
|
|
43
32
|
}
|