@ubercode/dcmtk 0.9.0 → 0.9.2

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/servers.cjs CHANGED
@@ -3126,7 +3126,7 @@ var DicomReceiver = class _DicomReceiver extends events.EventEmitter {
3126
3126
  acseTimeout: this.options.acseTimeout,
3127
3127
  dimseTimeout: this.options.dimseTimeout,
3128
3128
  maxPdu: this.options.maxPdu,
3129
- filenameMode: this.options.filenameMode,
3129
+ filenameMode: this.options.filenameMode ?? "unique",
3130
3130
  filenameExtension: this.options.filenameExtension,
3131
3131
  storageMode: this.options.storageMode
3132
3132
  });
@@ -3235,14 +3235,32 @@ var DicomReceiver = class _DicomReceiver extends events.EventEmitter {
3235
3235
  /** Moves a received file, opens it as DicomInstance, and emits FILE_RECEIVED. */
3236
3236
  async handleFileReceived(worker, data) {
3237
3237
  if (worker.associationDir === void 0 || worker.associationId === void 0) return;
3238
- const srcPath = data.filePath;
3239
- const destPath = path__namespace.join(worker.associationDir, path__namespace.basename(srcPath));
3240
3238
  const assocId = worker.associationId;
3241
3239
  const assocDir = worker.associationDir;
3240
+ try {
3241
+ await this.moveAndEmitFile(worker, data, assocId, assocDir);
3242
+ } catch (thrown) {
3243
+ const error = thrown instanceof Error ? thrown : new Error(String(thrown));
3244
+ this.emit("error", {
3245
+ error,
3246
+ filePath: data.filePath,
3247
+ associationId: assocId,
3248
+ associationDir: assocDir,
3249
+ callingAE: data.callingAE,
3250
+ calledAE: data.calledAE,
3251
+ source: data.source
3252
+ });
3253
+ }
3254
+ }
3255
+ /** Inner handler: move file, parse DICOM, emit FILE_RECEIVED or error. */
3256
+ async moveAndEmitFile(worker, data, assocId, assocDir) {
3257
+ const srcPath = data.filePath;
3258
+ const destPath = path__namespace.join(assocDir, path__namespace.basename(srcPath));
3242
3259
  const moveResult = await moveFile(srcPath, destPath);
3243
3260
  const finalPath = moveResult.ok ? destPath : srcPath;
3261
+ const fileSize = await statFileSafe(finalPath);
3244
3262
  worker.files.push(finalPath);
3245
- worker.fileSizes.push(await statFileSafe(finalPath));
3263
+ worker.fileSizes.push(fileSize);
3246
3264
  const openResult = await DicomInstance.open(finalPath);
3247
3265
  if (!openResult.ok) {
3248
3266
  this.emit("error", {
@@ -3258,6 +3276,7 @@ var DicomReceiver = class _DicomReceiver extends events.EventEmitter {
3258
3276
  }
3259
3277
  this.emit("FILE_RECEIVED", {
3260
3278
  filePath: finalPath,
3279
+ fileSize,
3261
3280
  associationId: assocId,
3262
3281
  associationDir: assocDir,
3263
3282
  callingAE: data.callingAE,