@xuda.io/drive_module 1.1.1397 → 1.1.1399
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 +102 -0
- package/package.json +2 -1
package/index_ms.mjs
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// =====================================================
|
|
2
|
+
// Queue wrapper – generated from index.mjs
|
|
3
|
+
// Queue target : drive_module
|
|
4
|
+
// =====================================================
|
|
5
|
+
|
|
6
|
+
import amqplib from 'amqplib';
|
|
7
|
+
import { randomUUID } from 'crypto';
|
|
8
|
+
|
|
9
|
+
let queue={}
|
|
10
|
+
|
|
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
|
+
|
|
16
|
+
channel.consume(`_drive_module-${global.module_in}_ch`, async (msg) => {
|
|
17
|
+
try{
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
if (msg === null) {
|
|
21
|
+
console.log('Consumer cancelled by server');
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const content = JSON.parse(msg.content.toString());
|
|
26
|
+
|
|
27
|
+
queue[content.queue_id].resolve(content.ret)
|
|
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
|
+
});
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
const send_to_queue =async function(ms_method, ...args) {
|
|
39
|
+
|
|
40
|
+
const queue_id = randomUUID();
|
|
41
|
+
return new Promise((resolve,reject)=>{
|
|
42
|
+
|
|
43
|
+
queue[queue_id] = { resolve, reject };
|
|
44
|
+
|
|
45
|
+
// Set timeout to prevent hanging
|
|
46
|
+
const timeout = setTimeout(() => {
|
|
47
|
+
delete queue[queue_id];
|
|
48
|
+
reject(new Error(`Queue timeout for ${ms_method}`));
|
|
49
|
+
}, 30000); // 30 second timeout
|
|
50
|
+
|
|
51
|
+
// Wrap resolve to clean up
|
|
52
|
+
queue[queue_id].resolve = (value) => {
|
|
53
|
+
clearTimeout(timeout);
|
|
54
|
+
delete queue[queue_id];
|
|
55
|
+
resolve(value);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// Wrap reject to clean up
|
|
59
|
+
queue[queue_id].reject = (error) => {
|
|
60
|
+
clearTimeout(timeout);
|
|
61
|
+
delete queue[queue_id];
|
|
62
|
+
reject(error);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
global[`_${global.module_in}_ch`].sendToQueue(
|
|
66
|
+
'drive_module',
|
|
67
|
+
Buffer.from(
|
|
68
|
+
JSON.stringify({
|
|
69
|
+
ms_method,
|
|
70
|
+
data: args,
|
|
71
|
+
cb:`_drive_module-${global.module_in}_ch`,
|
|
72
|
+
queue_id
|
|
73
|
+
})
|
|
74
|
+
)
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// You must define this somewhere before using these wrappers:
|
|
82
|
+
const module_name = 'drive_module';
|
|
83
|
+
|
|
84
|
+
export const getExtensionFromUrl = async function (...args) {
|
|
85
|
+
return await send_to_queue("getExtensionFromUrl", ...args);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export const get_user_drive_file = async function (...args) {
|
|
89
|
+
return await send_to_queue("get_user_drive_file", ...args);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export const save_user_drive_file = async function (...args) {
|
|
93
|
+
return await send_to_queue("save_user_drive_file", ...args);
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export const find_contact_query = async function (...args) {
|
|
97
|
+
return await send_to_queue("find_contact_query", ...args);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
export const file_upload_validator = async function (...args) {
|
|
101
|
+
return await send_to_queue("file_upload_validator", ...args);
|
|
102
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xuda.io/drive_module",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1399",
|
|
4
4
|
"description": "Xuda Drive Server Module",
|
|
5
5
|
"main": "index.mjs",
|
|
6
6
|
"dependencies": {
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"node-xlsx": "^0.23.0",
|
|
17
17
|
"@aws-sdk/client-s3": "^3.935.0",
|
|
18
18
|
"@aws-sdk/lib-storage": "^3.935.0",
|
|
19
|
+
"amqplib": "^0.10.9",
|
|
19
20
|
"query-registry": "^4.2.0"
|
|
20
21
|
},
|
|
21
22
|
"devDependencies": {},
|