@ubercode/dcmtk 0.9.1 → 0.9.3
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/{index-C9oo35ZO.d.ts → index-CWZOBvrt.d.ts} +3 -1
- package/dist/{index-Bq947ilN.d.cts → index-vXxeheHY.d.cts} +3 -1
- package/dist/index.cjs +34 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +34 -8
- package/dist/index.js.map +1 -1
- package/dist/servers.cjs +34 -8
- package/dist/servers.cjs.map +1 -1
- package/dist/servers.d.cts +1 -1
- package/dist/servers.d.ts +1 -1
- package/dist/servers.js +34 -8
- package/dist/servers.js.map +1 -1
- package/package.json +1 -1
package/dist/servers.cjs
CHANGED
|
@@ -3227,18 +3227,44 @@ var DicomReceiver = class _DicomReceiver extends events.EventEmitter {
|
|
|
3227
3227
|
/** Wires FILE_RECEIVED from dcmrecv worker to handleFileReceived. */
|
|
3228
3228
|
wireFileReceived(worker) {
|
|
3229
3229
|
worker.dcmrecv.onFileReceived((data) => {
|
|
3230
|
-
const
|
|
3230
|
+
const assocId = worker.associationId;
|
|
3231
|
+
const assocDir = worker.associationDir;
|
|
3232
|
+
if (assocDir === void 0 || assocId === void 0) {
|
|
3233
|
+
this.emit("error", {
|
|
3234
|
+
error: new Error(`DicomReceiver: FILE_RECEIVED with no active association (worker state: ${worker.state})`),
|
|
3235
|
+
filePath: data.filePath,
|
|
3236
|
+
callingAE: data.callingAE,
|
|
3237
|
+
calledAE: data.calledAE,
|
|
3238
|
+
source: data.source
|
|
3239
|
+
});
|
|
3240
|
+
return;
|
|
3241
|
+
}
|
|
3242
|
+
const promise = this.handleFileReceived(worker, data, assocId, assocDir);
|
|
3231
3243
|
worker.pendingFiles.push(promise);
|
|
3232
3244
|
void promise.finally(() => removePending(worker.pendingFiles, promise));
|
|
3233
3245
|
});
|
|
3234
3246
|
}
|
|
3235
3247
|
/** Moves a received file, opens it as DicomInstance, and emits FILE_RECEIVED. */
|
|
3236
|
-
async handleFileReceived(worker, data) {
|
|
3237
|
-
|
|
3248
|
+
async handleFileReceived(worker, data, assocId, assocDir) {
|
|
3249
|
+
try {
|
|
3250
|
+
await this.moveAndEmitFile(worker, data, assocId, assocDir);
|
|
3251
|
+
} catch (thrown) {
|
|
3252
|
+
const error = thrown instanceof Error ? thrown : new Error(String(thrown));
|
|
3253
|
+
this.emit("error", {
|
|
3254
|
+
error,
|
|
3255
|
+
filePath: data.filePath,
|
|
3256
|
+
associationId: assocId,
|
|
3257
|
+
associationDir: assocDir,
|
|
3258
|
+
callingAE: data.callingAE,
|
|
3259
|
+
calledAE: data.calledAE,
|
|
3260
|
+
source: data.source
|
|
3261
|
+
});
|
|
3262
|
+
}
|
|
3263
|
+
}
|
|
3264
|
+
/** Inner handler: move file, parse DICOM, emit FILE_RECEIVED or error. */
|
|
3265
|
+
async moveAndEmitFile(worker, data, assocId, assocDir) {
|
|
3238
3266
|
const srcPath = data.filePath;
|
|
3239
|
-
const destPath = path__namespace.join(
|
|
3240
|
-
const assocId = worker.associationId;
|
|
3241
|
-
const assocDir = worker.associationDir;
|
|
3267
|
+
const destPath = path__namespace.join(assocDir, path__namespace.basename(srcPath));
|
|
3242
3268
|
const moveResult = await moveFile(srcPath, destPath);
|
|
3243
3269
|
const finalPath = moveResult.ok ? destPath : srcPath;
|
|
3244
3270
|
const fileSize = await statFileSafe(finalPath);
|
|
@@ -3274,9 +3300,9 @@ var DicomReceiver = class _DicomReceiver extends events.EventEmitter {
|
|
|
3274
3300
|
void this.finalizeAssociation(worker, data);
|
|
3275
3301
|
});
|
|
3276
3302
|
}
|
|
3277
|
-
/** Awaits pending file operations, emits ASSOCIATION_COMPLETE, resets worker state. */
|
|
3303
|
+
/** Awaits ALL pending file operations, emits ASSOCIATION_COMPLETE, resets worker state. */
|
|
3278
3304
|
async finalizeAssociation(worker, data) {
|
|
3279
|
-
|
|
3305
|
+
while (worker.pendingFiles.length > 0) {
|
|
3280
3306
|
await Promise.all(worker.pendingFiles);
|
|
3281
3307
|
}
|
|
3282
3308
|
this.emitAssociationComplete(worker, data);
|