in tools/dicom-web-electron/main.js [23:137]
async function createWindow() {
// Create the browser window.
win = new BrowserWindow({
width: 1200,
height: 800,
webPreferences: {
nodeIntegration: false, // is default value after Electron v5
contextIsolation: true, // protect against prototype pollution
enableRemoteModule: true, // turn off remote
preload: path.join(__dirname, "preload.js") // use a preload script
}
});
// Load app
win.loadFile(path.join(__dirname, "index.html"));
// Used to allow self signed certificates
const httpsAgent = new https.Agent({ rejectUnauthorized: false });
// Set the maximum content length size in bytes and megabytes
const maxSizeMegabytes = 2048;
const maxSizeBytes = maxSizeMegabytes * 1024 * 1024;
ipcMain.on("postFile", (event, args) => {
let form = new FormData();
let fullContentLength = 0;
for (let file of args.files) {
const { size } = fs.statSync(file);
// Check to see if this particular file is too large
if (size > maxSizeBytes) {
win.webContents.send("errorEncountered", "The file '" + file + "' exceeds the maximum content size of " + maxSizeMegabytes + " MB.");
return;
}
fullContentLength += size;
form.append('file', fs.createReadStream(file), {
contentType: "application/dicom"
});
}
// See if the sum of all the files is too large
if (fullContentLength > maxSizeBytes) {
win.webContents.send("errorEncountered", "The total size of the request exceeds the maximum content size of " + maxSizeMegabytes + " MB.");
return;
}
let authorizationHeader = ''
if (args.bearerToken !== '') {
authorizationHeader = 'Bearer ' + args.bearerToken
}
axios.post(args.url, form, {
headers: {
'Content-Type': 'multipart/related; ' + 'boundary=' + form._boundary,
'Accept': 'application/dicom+json',
'Authorization': authorizationHeader
},
maxContentLength: maxSizeBytes,
maxBodyLength: maxSizeBytes,
httpsAgent: httpsAgent
})
.then(function(response) {
win.webContents.send("success", response.data);
})
.catch(function(error) {
if (error.response === undefined) {
win.webContents.send("httpErrorEncountered", error.code);
} else {
win.webContents.send("httpErrorEncountered", error.response.status);
}
})
});
ipcMain.on("getChangeFeed", (event, args) => {
let form = new FormData();
let authorizationHeader = ''
if (args.bearerToken !== '') {
authorizationHeader = 'Bearer ' + args.bearerToken
}
axios.get(args.url, {
headers: {
'Accept': 'application/json',
'Authorization': authorizationHeader
},
httpsAgent: httpsAgent
})
.then(function(response) {
win.webContents.send("changeFeedRetrieved", response.data);
})
.catch(function(error) {
if (error.response === undefined) {
win.webContents.send("httpErrorEncountered", error.code);
} else {
win.webContents.send("httpErrorEncountered", error.response.status);
}
})
});
ipcMain.on("selectFile", (event, args) => {
dialog.showOpenDialog({
filters: [
{ name: 'DICOM Files', extensions: ['dcm'] },
],
properties: ['openFile', 'multiSelections']
}).then(result => {
win.webContents.send("fileSelected", result.filePaths);
});
})
}