@xuda.io/drive_module 1.1.1402 → 1.1.1403
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/index_ms.mjs +95 -102
- package/package.json +1 -1
package/index_ms.mjs
CHANGED
|
@@ -6,17 +6,15 @@
|
|
|
6
6
|
import amqplib from 'amqplib';
|
|
7
7
|
import { randomUUID } from 'crypto';
|
|
8
8
|
|
|
9
|
-
let queue={}
|
|
9
|
+
let queue = {};
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
// --- AMQP Connection & Channel ---
|
|
12
|
+
const conn = await amqplib.connect('amqp://localhost');
|
|
13
|
+
const channel = await conn.createChannel();
|
|
14
|
+
await channel.assertQueue(`_drive_module-${global.module_in}_ch`, { durable: false });
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
try{
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
channel.consume(`_drive_module-${global.module_in}_ch`, async (msg) => {
|
|
17
|
+
try {
|
|
20
18
|
if (msg === null) {
|
|
21
19
|
console.log('Consumer cancelled by server');
|
|
22
20
|
return;
|
|
@@ -24,327 +22,322 @@ let queue={}
|
|
|
24
22
|
|
|
25
23
|
const content = JSON.parse(msg.content.toString());
|
|
26
24
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
channel.ack(msg);
|
|
30
|
-
} catch (err) {
|
|
31
|
-
channel.ack(msg); // Acknowledge to prevent requeue loops on error
|
|
32
|
-
console.error(module_in, content.method, err.message, err);
|
|
33
|
-
// debugger;
|
|
34
|
-
}
|
|
35
|
-
});
|
|
25
|
+
queue[content.queue_id].resolve(content.ret);
|
|
36
26
|
|
|
27
|
+
channel.ack(msg);
|
|
28
|
+
} catch (err) {
|
|
29
|
+
channel.ack(msg); // Acknowledge to prevent requeue loops on error
|
|
30
|
+
console.error(module_in, content.method, err.message, err);
|
|
31
|
+
// debugger;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
37
34
|
|
|
38
|
-
const send_to_queue =async function(ms_method, ...args) {
|
|
39
|
-
|
|
35
|
+
const send_to_queue = async function (ms_method, ...args) {
|
|
40
36
|
const queue_id = randomUUID();
|
|
41
|
-
return new Promise((resolve,reject)=>{
|
|
42
|
-
|
|
37
|
+
return new Promise((resolve, reject) => {
|
|
43
38
|
queue[queue_id] = { resolve, reject };
|
|
44
|
-
|
|
39
|
+
|
|
45
40
|
// Set timeout to prevent hanging
|
|
46
41
|
const timeout = setTimeout(() => {
|
|
47
42
|
delete queue[queue_id];
|
|
48
43
|
reject(new Error(`Queue timeout for ${ms_method}`));
|
|
49
44
|
}, 300000); // 300 second timeout
|
|
50
|
-
|
|
45
|
+
|
|
51
46
|
// Wrap resolve to clean up
|
|
52
47
|
queue[queue_id].resolve = (value) => {
|
|
53
48
|
clearTimeout(timeout);
|
|
54
49
|
delete queue[queue_id];
|
|
55
50
|
resolve(value);
|
|
56
51
|
};
|
|
57
|
-
|
|
52
|
+
|
|
58
53
|
// Wrap reject to clean up
|
|
59
54
|
queue[queue_id].reject = (error) => {
|
|
60
55
|
clearTimeout(timeout);
|
|
61
56
|
delete queue[queue_id];
|
|
62
57
|
reject(error);
|
|
63
58
|
};
|
|
64
|
-
|
|
65
|
-
try{
|
|
59
|
+
|
|
60
|
+
try {
|
|
66
61
|
global[`_${global.module_in}_ch`].sendToQueue(
|
|
67
62
|
'drive_module',
|
|
68
63
|
Buffer.from(
|
|
69
64
|
JSON.stringify({
|
|
70
65
|
ms_method,
|
|
71
66
|
data: args,
|
|
72
|
-
cb
|
|
73
|
-
queue_id
|
|
74
|
-
})
|
|
75
|
-
)
|
|
67
|
+
cb: `_drive_module-${global.module_in}_ch`,
|
|
68
|
+
queue_id,
|
|
69
|
+
}),
|
|
70
|
+
),
|
|
76
71
|
);
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
debugger
|
|
72
|
+
} catch (err) {
|
|
73
|
+
debugger;
|
|
80
74
|
}
|
|
81
|
-
})
|
|
82
|
-
|
|
75
|
+
});
|
|
83
76
|
};
|
|
84
77
|
|
|
85
78
|
// You must define this somewhere before using these wrappers:
|
|
86
79
|
const module_name = 'drive_module';
|
|
87
80
|
|
|
88
81
|
export const get_drive_files = async function (...args) {
|
|
89
|
-
return await send_to_queue(
|
|
82
|
+
return await send_to_queue('get_drive_files', ...args);
|
|
90
83
|
};
|
|
91
84
|
|
|
92
85
|
export const get_drive_file_info = async function (...args) {
|
|
93
|
-
return await send_to_queue(
|
|
86
|
+
return await send_to_queue('get_drive_file_info', ...args);
|
|
94
87
|
};
|
|
95
88
|
|
|
96
89
|
export const delete_drive_files = async function (...args) {
|
|
97
|
-
return await send_to_queue(
|
|
90
|
+
return await send_to_queue('delete_drive_files', ...args);
|
|
98
91
|
};
|
|
99
92
|
|
|
100
93
|
export const update_drive_file = async function (...args) {
|
|
101
|
-
return await send_to_queue(
|
|
94
|
+
return await send_to_queue('update_drive_file', ...args);
|
|
102
95
|
};
|
|
103
96
|
|
|
104
97
|
export const create_drive_folder = async function (...args) {
|
|
105
|
-
return await send_to_queue(
|
|
98
|
+
return await send_to_queue('create_drive_folder', ...args);
|
|
106
99
|
};
|
|
107
100
|
|
|
108
101
|
export const rename_drive_file = async function (...args) {
|
|
109
|
-
return await send_to_queue(
|
|
102
|
+
return await send_to_queue('rename_drive_file', ...args);
|
|
110
103
|
};
|
|
111
104
|
|
|
112
105
|
export const rename_drive_folder = async function (...args) {
|
|
113
|
-
return await send_to_queue(
|
|
106
|
+
return await send_to_queue('rename_drive_folder', ...args);
|
|
114
107
|
};
|
|
115
108
|
|
|
116
109
|
export const update_drive_file_sharing_mode = async function (...args) {
|
|
117
|
-
return await send_to_queue(
|
|
110
|
+
return await send_to_queue('update_drive_file_sharing_mode', ...args);
|
|
118
111
|
};
|
|
119
112
|
|
|
120
113
|
export const extract_drive_file = async function (...args) {
|
|
121
|
-
return await send_to_queue(
|
|
114
|
+
return await send_to_queue('extract_drive_file', ...args);
|
|
122
115
|
};
|
|
123
116
|
|
|
124
117
|
export const delete_file_bulk = async function (...args) {
|
|
125
|
-
return await send_to_queue(
|
|
118
|
+
return await send_to_queue('delete_file_bulk', ...args);
|
|
126
119
|
};
|
|
127
120
|
|
|
128
121
|
export const upload_drive_file = async function (...args) {
|
|
129
|
-
return await send_to_queue(
|
|
122
|
+
return await send_to_queue('upload_drive_file', ...args);
|
|
130
123
|
};
|
|
131
124
|
|
|
132
125
|
export const check_drive_file = async function (...args) {
|
|
133
|
-
return await send_to_queue(
|
|
126
|
+
return await send_to_queue('check_drive_file', ...args);
|
|
134
127
|
};
|
|
135
128
|
|
|
136
129
|
export const run_drive_pending_ocr = async function (...args) {
|
|
137
|
-
return await send_to_queue(
|
|
130
|
+
return await send_to_queue('run_drive_pending_ocr', ...args);
|
|
138
131
|
};
|
|
139
132
|
|
|
140
133
|
export const get_drive_size = async function (...args) {
|
|
141
|
-
return await send_to_queue(
|
|
134
|
+
return await send_to_queue('get_drive_size', ...args);
|
|
142
135
|
};
|
|
143
136
|
|
|
144
137
|
export const copy_file_to_another_bucket = async function (...args) {
|
|
145
|
-
return await send_to_queue(
|
|
138
|
+
return await send_to_queue('copy_file_to_another_bucket', ...args);
|
|
146
139
|
};
|
|
147
140
|
|
|
148
141
|
export const delete_file_from_bucket = async function (...args) {
|
|
149
|
-
return await send_to_queue(
|
|
142
|
+
return await send_to_queue('delete_file_from_bucket', ...args);
|
|
150
143
|
};
|
|
151
144
|
|
|
152
145
|
export const update_drive_file_tags = async function (...args) {
|
|
153
|
-
return await send_to_queue(
|
|
146
|
+
return await send_to_queue('update_drive_file_tags', ...args);
|
|
154
147
|
};
|
|
155
148
|
|
|
156
149
|
export const compile_javascript_program_in_studio_drive = async function (...args) {
|
|
157
|
-
return await send_to_queue(
|
|
150
|
+
return await send_to_queue('compile_javascript_program_in_studio_drive', ...args);
|
|
158
151
|
};
|
|
159
152
|
|
|
160
153
|
export const update_drive_addons = async function (...args) {
|
|
161
|
-
return await send_to_queue(
|
|
154
|
+
return await send_to_queue('update_drive_addons', ...args);
|
|
162
155
|
};
|
|
163
156
|
|
|
164
157
|
export const get_drive_files_workspace = async function (...args) {
|
|
165
|
-
return await send_to_queue(
|
|
158
|
+
return await send_to_queue('get_drive_files_workspace', ...args);
|
|
166
159
|
};
|
|
167
160
|
|
|
168
161
|
export const get_drive_files_studio = async function (...args) {
|
|
169
|
-
return await send_to_queue(
|
|
162
|
+
return await send_to_queue('get_drive_files_studio', ...args);
|
|
170
163
|
};
|
|
171
164
|
|
|
172
165
|
export const get_drive_files_user = async function (...args) {
|
|
173
|
-
return await send_to_queue(
|
|
166
|
+
return await send_to_queue('get_drive_files_user', ...args);
|
|
174
167
|
};
|
|
175
168
|
|
|
176
169
|
export const get_drive_file_info_workspace = async function (...args) {
|
|
177
|
-
return await send_to_queue(
|
|
170
|
+
return await send_to_queue('get_drive_file_info_workspace', ...args);
|
|
178
171
|
};
|
|
179
172
|
|
|
180
173
|
export const get_drive_file_info_studio = async function (...args) {
|
|
181
|
-
return await send_to_queue(
|
|
174
|
+
return await send_to_queue('get_drive_file_info_studio', ...args);
|
|
182
175
|
};
|
|
183
176
|
|
|
184
177
|
export const get_drive_file_info_user = async function (...args) {
|
|
185
|
-
return await send_to_queue(
|
|
178
|
+
return await send_to_queue('get_drive_file_info_user', ...args);
|
|
186
179
|
};
|
|
187
180
|
|
|
188
181
|
export const delete_drive_files_workspace = async function (...args) {
|
|
189
|
-
return await send_to_queue(
|
|
182
|
+
return await send_to_queue('delete_drive_files_workspace', ...args);
|
|
190
183
|
};
|
|
191
184
|
|
|
192
185
|
export const delete_drive_files_studio = async function (...args) {
|
|
193
|
-
return await send_to_queue(
|
|
186
|
+
return await send_to_queue('delete_drive_files_studio', ...args);
|
|
194
187
|
};
|
|
195
188
|
|
|
196
189
|
export const delete_drive_files_user = async function (...args) {
|
|
197
|
-
return await send_to_queue(
|
|
190
|
+
return await send_to_queue('delete_drive_files_user', ...args);
|
|
198
191
|
};
|
|
199
192
|
|
|
200
193
|
export const extract_drive_file_workspace = async function (...args) {
|
|
201
|
-
return await send_to_queue(
|
|
194
|
+
return await send_to_queue('extract_drive_file_workspace', ...args);
|
|
202
195
|
};
|
|
203
196
|
|
|
204
197
|
export const extract_drive_file_studio = async function (...args) {
|
|
205
|
-
return await send_to_queue(
|
|
198
|
+
return await send_to_queue('extract_drive_file_studio', ...args);
|
|
206
199
|
};
|
|
207
200
|
|
|
208
201
|
export const extract_drive_file_user = async function (...args) {
|
|
209
|
-
return await send_to_queue(
|
|
202
|
+
return await send_to_queue('extract_drive_file_user', ...args);
|
|
210
203
|
};
|
|
211
204
|
|
|
212
205
|
export const upload_drive_file_workspace = async function (...args) {
|
|
213
|
-
return await send_to_queue(
|
|
206
|
+
return await send_to_queue('upload_drive_file_workspace', ...args);
|
|
214
207
|
};
|
|
215
208
|
|
|
216
209
|
export const upload_drive_file_studio = async function (...args) {
|
|
217
|
-
return await send_to_queue(
|
|
210
|
+
return await send_to_queue('upload_drive_file_studio', ...args);
|
|
218
211
|
};
|
|
219
212
|
|
|
220
213
|
export const upload_drive_file_user = async function (...args) {
|
|
221
|
-
return await send_to_queue(
|
|
214
|
+
return await send_to_queue('upload_drive_file_user', ...args);
|
|
222
215
|
};
|
|
223
216
|
|
|
224
217
|
export const update_drive_file_workspace = async function (...args) {
|
|
225
|
-
return await send_to_queue(
|
|
218
|
+
return await send_to_queue('update_drive_file_workspace', ...args);
|
|
226
219
|
};
|
|
227
220
|
|
|
228
221
|
export const update_drive_file_studio = async function (...args) {
|
|
229
|
-
return await send_to_queue(
|
|
222
|
+
return await send_to_queue('update_drive_file_studio', ...args);
|
|
230
223
|
};
|
|
231
224
|
|
|
232
225
|
export const update_drive_file_user = async function (...args) {
|
|
233
|
-
return await send_to_queue(
|
|
226
|
+
return await send_to_queue('update_drive_file_user', ...args);
|
|
234
227
|
};
|
|
235
228
|
|
|
236
229
|
export const create_drive_folder_workspace = async function (...args) {
|
|
237
|
-
return await send_to_queue(
|
|
230
|
+
return await send_to_queue('create_drive_folder_workspace', ...args);
|
|
238
231
|
};
|
|
239
232
|
|
|
240
233
|
export const create_drive_folder_studio = async function (...args) {
|
|
241
|
-
return await send_to_queue(
|
|
234
|
+
return await send_to_queue('create_drive_folder_studio', ...args);
|
|
242
235
|
};
|
|
243
236
|
|
|
244
237
|
export const create_drive_folder_user = async function (...args) {
|
|
245
|
-
return await send_to_queue(
|
|
238
|
+
return await send_to_queue('create_drive_folder_user', ...args);
|
|
246
239
|
};
|
|
247
240
|
|
|
248
241
|
export const rename_drive_file_workspace = async function (...args) {
|
|
249
|
-
return await send_to_queue(
|
|
242
|
+
return await send_to_queue('rename_drive_file_workspace', ...args);
|
|
250
243
|
};
|
|
251
244
|
|
|
252
245
|
export const rename_drive_file_studio = async function (...args) {
|
|
253
|
-
return await send_to_queue(
|
|
246
|
+
return await send_to_queue('rename_drive_file_studio', ...args);
|
|
254
247
|
};
|
|
255
248
|
|
|
256
249
|
export const rename_drive_file_user = async function (...args) {
|
|
257
|
-
return await send_to_queue(
|
|
250
|
+
return await send_to_queue('rename_drive_file_user', ...args);
|
|
258
251
|
};
|
|
259
252
|
|
|
260
253
|
export const rename_drive_folder_workspace = async function (...args) {
|
|
261
|
-
return await send_to_queue(
|
|
254
|
+
return await send_to_queue('rename_drive_folder_workspace', ...args);
|
|
262
255
|
};
|
|
263
256
|
|
|
264
257
|
export const rename_drive_folder_studio = async function (...args) {
|
|
265
|
-
return await send_to_queue(
|
|
258
|
+
return await send_to_queue('rename_drive_folder_studio', ...args);
|
|
266
259
|
};
|
|
267
260
|
|
|
268
261
|
export const rename_drive_folder_user = async function (...args) {
|
|
269
|
-
return await send_to_queue(
|
|
262
|
+
return await send_to_queue('rename_drive_folder_user', ...args);
|
|
270
263
|
};
|
|
271
264
|
|
|
272
265
|
export const update_drive_file_sharing_mode_workspace = async function (...args) {
|
|
273
|
-
return await send_to_queue(
|
|
266
|
+
return await send_to_queue('update_drive_file_sharing_mode_workspace', ...args);
|
|
274
267
|
};
|
|
275
268
|
|
|
276
269
|
export const update_drive_file_sharing_mode_studio = async function (...args) {
|
|
277
|
-
return await send_to_queue(
|
|
270
|
+
return await send_to_queue('update_drive_file_sharing_mode_studio', ...args);
|
|
278
271
|
};
|
|
279
272
|
|
|
280
273
|
export const update_drive_file_sharing_mode_user = async function (...args) {
|
|
281
|
-
return await send_to_queue(
|
|
274
|
+
return await send_to_queue('update_drive_file_sharing_mode_user', ...args);
|
|
282
275
|
};
|
|
283
276
|
|
|
284
277
|
export const delete_file_bulk_workspace = async function (...args) {
|
|
285
|
-
return await send_to_queue(
|
|
278
|
+
return await send_to_queue('delete_file_bulk_workspace', ...args);
|
|
286
279
|
};
|
|
287
280
|
|
|
288
281
|
export const delete_file_bulk_studio = async function (...args) {
|
|
289
|
-
return await send_to_queue(
|
|
282
|
+
return await send_to_queue('delete_file_bulk_studio', ...args);
|
|
290
283
|
};
|
|
291
284
|
|
|
292
285
|
export const delete_file_bulk_user = async function (...args) {
|
|
293
|
-
return await send_to_queue(
|
|
286
|
+
return await send_to_queue('delete_file_bulk_user', ...args);
|
|
294
287
|
};
|
|
295
288
|
|
|
296
289
|
export const check_drive_file_workspace = async function (...args) {
|
|
297
|
-
return await send_to_queue(
|
|
290
|
+
return await send_to_queue('check_drive_file_workspace', ...args);
|
|
298
291
|
};
|
|
299
292
|
|
|
300
293
|
export const check_drive_file_studio = async function (...args) {
|
|
301
|
-
return await send_to_queue(
|
|
294
|
+
return await send_to_queue('check_drive_file_studio', ...args);
|
|
302
295
|
};
|
|
303
296
|
|
|
304
297
|
export const check_drive_file_user = async function (...args) {
|
|
305
|
-
return await send_to_queue(
|
|
298
|
+
return await send_to_queue('check_drive_file_user', ...args);
|
|
306
299
|
};
|
|
307
300
|
|
|
308
301
|
export const update_drive_file_tags_workspace = async function (...args) {
|
|
309
|
-
return await send_to_queue(
|
|
302
|
+
return await send_to_queue('update_drive_file_tags_workspace', ...args);
|
|
310
303
|
};
|
|
311
304
|
|
|
312
305
|
export const update_drive_file_tags_studio = async function (...args) {
|
|
313
|
-
return await send_to_queue(
|
|
306
|
+
return await send_to_queue('update_drive_file_tags_studio', ...args);
|
|
314
307
|
};
|
|
315
308
|
|
|
316
309
|
export const update_drive_file_tags_user = async function (...args) {
|
|
317
|
-
return await send_to_queue(
|
|
310
|
+
return await send_to_queue('update_drive_file_tags_user', ...args);
|
|
318
311
|
};
|
|
319
312
|
|
|
320
313
|
export const update_drive_addons_workspace = async function (...args) {
|
|
321
|
-
return await send_to_queue(
|
|
314
|
+
return await send_to_queue('update_drive_addons_workspace', ...args);
|
|
322
315
|
};
|
|
323
316
|
|
|
324
317
|
export const update_drive_addons_studio = async function (...args) {
|
|
325
|
-
return await send_to_queue(
|
|
318
|
+
return await send_to_queue('update_drive_addons_studio', ...args);
|
|
326
319
|
};
|
|
327
320
|
|
|
328
321
|
export const update_drive_addons_user = async function (...args) {
|
|
329
|
-
return await send_to_queue(
|
|
322
|
+
return await send_to_queue('update_drive_addons_user', ...args);
|
|
330
323
|
};
|
|
331
324
|
|
|
332
325
|
export const getExtensionFromUrl = async function (...args) {
|
|
333
|
-
return await send_to_queue(
|
|
326
|
+
return await send_to_queue('getExtensionFromUrl', ...args);
|
|
334
327
|
};
|
|
335
328
|
|
|
336
329
|
export const get_user_drive_file = async function (...args) {
|
|
337
|
-
return await send_to_queue(
|
|
330
|
+
return await send_to_queue('get_user_drive_file', ...args);
|
|
338
331
|
};
|
|
339
332
|
|
|
340
333
|
export const save_user_drive_file = async function (...args) {
|
|
341
|
-
return await send_to_queue(
|
|
334
|
+
return await send_to_queue('save_user_drive_file', ...args);
|
|
342
335
|
};
|
|
343
336
|
|
|
344
337
|
export const find_contact_query = async function (...args) {
|
|
345
|
-
return await send_to_queue(
|
|
338
|
+
return await send_to_queue('find_contact_query', ...args);
|
|
346
339
|
};
|
|
347
340
|
|
|
348
341
|
export const file_upload_validator = async function (...args) {
|
|
349
|
-
return await send_to_queue(
|
|
342
|
+
return await send_to_queue('file_upload_validator', ...args);
|
|
350
343
|
};
|