Skip to content

Commit

Permalink
fix: set header after they are sent in STOW-RS
Browse files Browse the repository at this point in the history
- If STOW-RS do not have any plugins, the next will sent 404 status code
because there is no any next function can call
> Check is any STOW-RS' plugins is enable, if true call next
> do nothing otherwise
  • Loading branch information
Chinlinlee committed Dec 16, 2022
1 parent fa53f2f commit b663747
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions api/dicom-web/stow/controller/postSTOW.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ const {
sendServerWrongMessage
} = require("../../../../models/DICOMWeb/httpMessage");
const uuid = require("uuid");
const jp = require("jsonpath");
const { logger } = require("../../../../utils/log");
const { stow } = require("../service/stow");
const { pluginsConfig } = require("../../../../plugins/config.js");

//browserify
//https://github.com/node-formidable/formidable/blob/6baefeec3df6f38e34c018c9e978329ae68b4c78/src/Formidable.js#L496
Expand Down Expand Up @@ -195,8 +197,24 @@ module.exports = async (req, res, next) => {
`[STOW-RS] [Finished STOW-RS, elapsed time: ${elapsedTime} ms]`
);
res.locals.storeInstanceResultList = storeInstanceResultList;
next();
return res.status(retCode).send(resMessage);

let stowPluginsNodes = jp.nodes(pluginsConfig, `$..routers[?(@.path=="/${process.env.DICOMWEB_API}/studies" || @.path=="/${process.env.DICOMWEB_API}/studies/:studyID")]`).map( v => v.path.slice(1, v.path.length - 2).join(".") );
stowPluginsNodes = _.uniq(stowPluginsNodes);

let enableStowPluginsName = _.compact(
stowPluginsNodes.map( v => {
if(pluginsConfig[v].enable) {
return v;
}
})
);

// call next if any STOW-RS plugins are available
if (enableStowPluginsName.length > 0) {
next();
}

res.status(retCode).send(resMessage);
} catch (err) {
let errMsg = err.message || err;
console.error('/dicom-web/studies "STOW Api" err, ', errMsg);
Expand Down

0 comments on commit b663747

Please sign in to comment.