Skip to content

Commit

Permalink
feat: support switch to mongodb mode with module alias
Browse files Browse the repository at this point in the history
  • Loading branch information
Chinlinlee committed Nov 19, 2023
1 parent 20bf8df commit dcfe3aa
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 12 deletions.
5 changes: 3 additions & 2 deletions config-class.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class SqlDbConfig {
this.username = env.get("SQL_USERNAME").default("postgres").asString();
this.password = env.get("SQL_PASSWORD").default("postgres").asString();
this.logging = env.get("SQL_LOGGING").default("false").asBool();
this.dbName = this.database;
}
}

Expand Down Expand Up @@ -92,11 +93,11 @@ class RaccoonConfig {

/** @type {string} */
this.mediaStorageUID = generateUidFromGuid(
uuid.v5(this.dbConfig.database, NAME_SPACE)
uuid.v5(this.dbConfig.dbName, NAME_SPACE)
);

/** @type {string} */
this.mediaStorageID = this.dbConfig.database;
this.mediaStorageID = this.dbConfig.dbName;

this.aeTitle = this.dicomWebConfig.aeTitle;
// this.aeTitle = this.dicomDimseConfig.enableDimse ? this.dicomDimseConfig.getAeTitle() : this.dicomWebConfig.aeTitle;
Expand Down
17 changes: 16 additions & 1 deletion config/jsconfig.mongodb.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,22 @@
"@root/*": ["./*"],
"@chinlinlee/*": ["./models/DICOM/dcm4che/wrapper/org/github/chinlinlee/*"],
"@dbModels/*": ["./models/mongodb/models/*"],
"@dicom-json-model": ["./models/DICOM/dicom-json-model.js"]
"@dicom-json-model": ["./models/DICOM/dicom-json-model.js"],
"@query-dicom-json-factory": ["./api/dicom-web/controller/QIDO-RS/service/query-dicom-json-factory.js"],
"@stow-rs-service": ["./api/dicom-web/controller/STOW-RS/service/stow-rs.service.js"],
"@qido-rs-service": ["./api/dicom-web/controller/QIDO-RS/service/QIDO-RS.service.js"],
"@wado-rs-service": ["./api/dicom-web/controller/WADO-RS/service/WADO-RS.service.js"],
"@wado-uri-service": ["./api/WADO-URI/service/WADO-URI.service.js"],
"@bulkdata-service": ["./api/dicom-web/controller/WADO-RS/bulkdata/service/bulkdata.js"],
"@delete-service": ["./api/dicom-web/controller/WADO-RS/deletion/service/delete.js"],
"@rendered-service": ["./api/dicom-web/controller/WADO-RS/service/rendered.service.js"],
"@thumbnail-service": ["./api/dicom-web/controller/WADO-RS/service/thumbnail.service.js"],
"@dimse-query-builder": ["./dimse/queryBuilder.js"],
"@dimse-patient-query-task": ["./dimse/patientQueryTask.js"],
"@dimse-study-query-task": ["./dimse/studyQueryTask.js"],
"@dimse-series-query-task": ["./dimse/seriesQueryTask.js"],
"@dimse-instance-query-task": ["./dimse/instanceQueryTask.js"],
"@dimse-utils": ["./dimse/utils.js"]
}
},
"exclude": [
Expand Down
4 changes: 3 additions & 1 deletion config/modula-alias/mongodb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@stow-rs-service": "../../../api/dicom-web/controller/STOW-RS/service/stow-rs.service.js",
"@qido-rs-service": "../../../api/dicom-web/controller/QIDO-RS/service/QIDO-RS.service.js",
"@wado-rs-service": "../../../api/dicom-web/controller/WADO-RS/service/WADO-RS.service.js",
"@wado-uri-service": "../../../api/WADO-URI/service/WADO-URI.service.js",
"@bulkdata-service": "../../../api/dicom-web/controller/WADO-RS/bulkdata/service/bulkdata.js",
"@delete-service": "../../../api/dicom-web/controller/WADO-RS/deletion/service/delete.js",
"@rendered-service": "../../../api/dicom-web/controller/WADO-RS/service/rendered.service.js",
Expand All @@ -22,6 +23,7 @@
"@dimse-study-query-task": "../../../dimse/studyQueryTask.js",
"@dimse-series-query-task": "../../../dimse/seriesQueryTask.js",
"@dimse-instance-query-task": "../../../dimse/instanceQueryTask.js",
"@dimse-utils": "../../../dimse/utils.js"
"@dimse-utils": "../../../dimse/utils.js",
"@dimse": "../../../dimse"
}
}
2 changes: 1 addition & 1 deletion models/mongodb/connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const {
authSource,
isShardingMode,
urlOptions
} = raccoonConfig.mongoDbConfig;
} = raccoonConfig.dbConfig;
module.exports = exports = function () {

const collection = {};
Expand Down
31 changes: 24 additions & 7 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,37 @@ if (raccoonConfig.serverConfig.dbType === "mongodb") {
require('module-alias')(__dirname + "/config/modula-alias/sql");
}


const { app, server } = require("./app");
const bodyParser = require("body-parser");
const session = require("express-session");
const cookieParser = require("cookie-parser");
const compress = require("compression");
const cors = require("cors");
const os = require("os");
const SequelizeStore = require("connect-session-sequelize")(session.Store);
const sequelizeInstance = require("./models/sql/instance");

let sessionStore;
let dbInstance;
let sessionStoreOption;
if (raccoonConfig.serverConfig.dbType === "mongodb") {
sessionStore = require("connect-mongo");
dbInstance = require("mongoose");

sessionStoreOption = sessionStore.create({
client: dbInstance.connection.getClient(),
dbName: raccoonConfig.dbConfig.dbName
});

} else if (raccoonConfig.serverConfig.dbType === "sql") {
sessionStore = require("connect-session-sequelize")(session.Store);
dbInstance = require("./models/sql/instance");

sessionStoreOption = new sessionStore({
db: dbInstance
});
}

const passport = require("passport");
const { DcmQrScp } = require('./dimse-sql');
const { DcmQrScp } = require('@dimse');
require("dotenv");
require("./websocket");

Expand Down Expand Up @@ -48,6 +66,7 @@ app.use(

//#region session


app.use(
session({
secret: raccoonConfig.serverConfig.secretKey || "secretKey",
Expand All @@ -57,9 +76,7 @@ app.use(
httpOnly: true,
maxAge: 60 * 60 * 1000
},
store: new SequelizeStore({
db: sequelizeInstance
})
store: sessionStoreOption
})
);

Expand Down

0 comments on commit dcfe3aa

Please sign in to comment.