@ejfdelgado/ejflab-back 1.12.0 → 1.14.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/package.json +1 -1
- package/srv/MilvusSrv.mjs +83 -0
- package/srv/SocketIOCall.mjs +18 -1
package/package.json
CHANGED
package/srv/MilvusSrv.mjs
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import { MilvusClient, DataType } from "@zilliz/milvus2-sdk-node";
|
2
|
+
import { encode, decode } from "@msgpack/msgpack";
|
2
3
|
|
3
4
|
export class MilvusSrv {
|
4
5
|
// MilvusSrv.checkErrors(res);
|
@@ -149,4 +150,86 @@ export class MilvusSrv {
|
|
149
150
|
};
|
150
151
|
res.status(200).send(response);
|
151
152
|
}
|
153
|
+
static async insert(req, res, next) {
|
154
|
+
console.log("Milvus insert...");
|
155
|
+
const { client } = MilvusSrv.connect();
|
156
|
+
let code = 200;
|
157
|
+
const response = {
|
158
|
+
status: "ok"
|
159
|
+
};
|
160
|
+
try {
|
161
|
+
// get the request
|
162
|
+
const buffer = req.body;
|
163
|
+
const decoded = decode(buffer);
|
164
|
+
const {
|
165
|
+
db_name,
|
166
|
+
collection_name,
|
167
|
+
data
|
168
|
+
} = decoded;
|
169
|
+
await MilvusSrv.useDatabase(client, db_name, false);
|
170
|
+
await client.insert({
|
171
|
+
collection_name: collection_name,
|
172
|
+
data: data
|
173
|
+
});
|
174
|
+
console.log("Milvus insert... OK");
|
175
|
+
} catch (err) {
|
176
|
+
console.log(err);
|
177
|
+
code = 500;
|
178
|
+
response.status = "error";
|
179
|
+
response.message = err.message;
|
180
|
+
} finally {
|
181
|
+
await client.closeConnection();
|
182
|
+
res.status(code).send(response);
|
183
|
+
}
|
184
|
+
}
|
185
|
+
static async search(req, res, next) {
|
186
|
+
const { client } = MilvusSrv.connect();
|
187
|
+
let code = 200;
|
188
|
+
const response = {
|
189
|
+
status: "ok"
|
190
|
+
};
|
191
|
+
try {
|
192
|
+
// get the request
|
193
|
+
const buffer = req.body;
|
194
|
+
const decoded = decode(buffer);
|
195
|
+
// Connect to database
|
196
|
+
const {
|
197
|
+
db_name,
|
198
|
+
collection_name,
|
199
|
+
embeed,
|
200
|
+
paging
|
201
|
+
} = decoded;
|
202
|
+
console.log(`Using database ${db_name}`);
|
203
|
+
await MilvusSrv.useDatabase(client, db_name, false);
|
204
|
+
const search_params = {
|
205
|
+
"metric_type": "IP",
|
206
|
+
"topk": paging['limit'],
|
207
|
+
"params": JSON.stringify({ nprobe: 1024 }),
|
208
|
+
};
|
209
|
+
const results = await client.search({
|
210
|
+
collection_name: collection_name,
|
211
|
+
data: [embeed],
|
212
|
+
limit: paging['limit'],
|
213
|
+
offset: paging['offset'],
|
214
|
+
consistency_level: "Strong",
|
215
|
+
search_params: search_params,
|
216
|
+
output_fields: ['id', 'document_id', 'face_path', 'millis', 'x1', 'y1', 'x2', 'y2', 'ref_id']
|
217
|
+
});
|
218
|
+
response.results = results.results.map((entity) => {
|
219
|
+
return {
|
220
|
+
id: entity.id,
|
221
|
+
distance: 0,
|
222
|
+
entity
|
223
|
+
};
|
224
|
+
});
|
225
|
+
} catch (err) {
|
226
|
+
console.log(err);
|
227
|
+
code = 500;
|
228
|
+
response.status = "error";
|
229
|
+
response.message = err.message;
|
230
|
+
} finally {
|
231
|
+
await client.closeConnection();
|
232
|
+
res.status(code).send(response);
|
233
|
+
}
|
234
|
+
}
|
152
235
|
}
|
package/srv/SocketIOCall.mjs
CHANGED
@@ -203,7 +203,7 @@ export class SocketIOCall {
|
|
203
203
|
}
|
204
204
|
|
205
205
|
static getCustomHeaders(socket) {
|
206
|
-
const headersKey = ["room", "uuid"];
|
206
|
+
const headersKey = ["room", "uuid", "model"];
|
207
207
|
const headers = socket.handshake.headers;
|
208
208
|
const response = {};
|
209
209
|
headersKey.forEach((key) => {
|
@@ -216,6 +216,23 @@ export class SocketIOCall {
|
|
216
216
|
await SocketIOCall.registerSocket(socket);
|
217
217
|
// Le digo a los que están en el room quién llegó
|
218
218
|
const headers = SocketIOCall.getCustomHeaders(socket);
|
219
|
+
// Update model if provided
|
220
|
+
let defaultModel;
|
221
|
+
try {
|
222
|
+
defaultModel = headers.model;
|
223
|
+
const room = headers.room;
|
224
|
+
if (defaultModel && room) {
|
225
|
+
const defaultModelJson = JSON.parse(defaultModel);
|
226
|
+
const dataRoom = SocketIOCall.getRoomLiveTupleModel(room);
|
227
|
+
if (dataRoom) {
|
228
|
+
SimpleObj.recreate(dataRoom, `model.data.people.${socket.id}`, defaultModelJson);
|
229
|
+
dataRoom.builder.trackDifferences(dataRoom.model, [], null, ["data", "data.people", `data.people.${socket.id}`]);
|
230
|
+
}
|
231
|
+
}
|
232
|
+
} catch (err) {
|
233
|
+
console.log(err);
|
234
|
+
console.log(`Can't create default model. Provided ${defaultModel}`);
|
235
|
+
}
|
219
236
|
SocketIOCall.io.to(headers.room).emit("updateUserList", {
|
220
237
|
socketIds: SocketIOCall.mapSockets[headers.room]
|
221
238
|
});
|