Applied JSCS and added JSCS/jsHint config files

This commit is contained in:
Erik Ziegler committed 2016-01-11 11:32:20 +01:00
1 parent a9266608d2
commit 90a16a8059
68 files changed
+24956 -6399

No files matched your search

+16 -13
View File
@@ -4,46 +4,49 @@
* @returns {Uint8Array} Uint8 Array of character codes
*/
function stringToUint8Array(str) {
var uint=new Uint8Array(str.length);
for(var i=0,j=str.length;i<j;i++){
uint[i]=str.charCodeAt(i);
var uint = new Uint8Array(str.length);
for (var i = 0,j = str.length;i< j;i++){
uint[i] = str.charCodeAt(i);
}
return uint;
}
function checkToken(token, data, dataOffset) {
if(dataOffset + token.length > data.length) {
if (dataOffset + token.length > data.length) {
//console.log('dataOffset >> ', dataOffset);
return false;
}
for(var i = 0; i < token.length; i++) {
if(token[i] !== data[endIndex++]) {
if(endIndex > 520000) {
for (var i = 0; i < token.length; i++) {
if (token[i] !== data[endIndex++]) {
if (endIndex > 520000) {
console.log('token=',uint8ArrayToString(token));
console.log('data=', uint8ArrayToString(data, dataOffset, endIndex-dataOffset));
console.log('data=', uint8ArrayToString(data, dataOffset, endIndex - dataOffset));
console.log('miss at %d %s dataOffset=%d', i, String.fromCharCode(data[endIndex]), endIndex);
console.log('miss at %d %s dataOffset=%d', i, String.fromCharCode(token[endIndex]), endIndex);
}
return false;
}
}
return true;
}
findIndexOfString = function(data, str, offset) {
offset = offset || 0;
var token = stringToUint8Array(str);
for(var i=offset; i < data.length; i++) {
if(data[i] === token[0]) {
for (var i = offset; i < data.length; i++) {
if (data[i] === token[0]) {
//console.log('match @', i);
if(checkToken(token, data, i)) {
if (checkToken(token, data, i)) {
return i;
}
}
}
return -1;
};
};
+3 -2
View File
@@ -8,10 +8,11 @@
uint8ArrayToString = function(data, offset, length) {
offset = offset || 0;
length = length || data.length - offset;
var str = "";
var str = '';
for(var i=offset; i < offset + length; i++) {
for (var i = offset; i < offset + length; i++) {
str += String.fromCharCode(data[i]);
}
return str;
};
+5 -5
View File
@@ -1,10 +1,10 @@
Package.describe({
name: "dicomweb",
summary: "DICOM Web Helper Functions",
version: '0.0.1'
name: 'dicomweb',
summary: 'DICOM Web Helper Functions',
version: '0.0.1'
});
Package.onUse(function (api) {
Package.onUse(function(api) {
api.use('http');
// DICOMWeb API functions
@@ -19,6 +19,6 @@ Package.onUse(function (api) {
api.addFiles('lib/findIndexOfString.js', 'server');
api.addFiles('lib/uint8ArrayToString.js', 'server');
api.export("DICOMWeb", 'server');
api.export('DICOMWeb', 'server');
});
+63 -59
View File
@@ -1,70 +1,74 @@
function findBoundary(header) {
for(var i=0; i < header.length; i++) {
if(header[i].substr(0,2) === '--') {
return header[i];
for (var i = 0; i < header.length; i++) {
if (header[i].substr(0,2) === '--') {
return header[i];
}
}
}
return undefined;
return undefined;
}
function findContentType(header) {
for(var i=0; i < header.length; i++) {
if(header[i].substr(0,13) === 'Content-Type:') {
return header[i].substr(13).trim();
for (var i = 0; i < header.length; i++) {
if (header[i].substr(0,13) === 'Content-Type:') {
return header[i].substr(13).trim();
}
}
}
return undefined;
return undefined;
}
DICOMWeb.getImageFrame = function(uri, mediaType) {
mediaType = mediaType || 'application/octet-stream';
mediaType = mediaType || 'application/octet-stream';
return new Promise(function(resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.responseType = "arraybuffer";
xhr.open("get", uri, true);
xhr.setRequestHeader('Accept', 'multipart/related;type=' + mediaType);
xhr.onreadystatechange = function (oEvent) {
// TODO: consider sending out progress messages here as we receive the pixel data
if (xhr.readyState === 4) {
if (xhr.status === 200) {
// request succeeded, Parse the multi-part mime response
var imageFrameAsArrayBuffer = xhr.response;
var response = new Uint8Array(xhr.response);
// First look for the multipart mime header
var tokenIndex = findIndexOfString(response, '\n\r\n');
if(tokenIndex === -1) {
reject('invalid response - no multipart mime header');
}
var header = uint8ArrayToString(response, 0, tokenIndex);
// Now find the boundary marker
var split = header.split('\r\n');
var boundary = findBoundary(split);
if(!boundary) {
reject('invalid response - no boundary marker');
}
var offset = tokenIndex + 4; // skip over the \n\r\n
return new Promise(function(resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.responseType = 'arraybuffer';
xhr.open('get', uri, true);
xhr.setRequestHeader('Accept', 'multipart/related;type=' + mediaType);
xhr.onreadystatechange = function(oEvent) {
// TODO: consider sending out progress messages here as we receive the pixel data
if (xhr.readyState === 4) {
if (xhr.status === 200) {
// request succeeded, Parse the multi-part mime response
var imageFrameAsArrayBuffer = xhr.response;
var response = new Uint8Array(xhr.response);
// First look for the multipart mime header
var tokenIndex = findIndexOfString(response, '\n\r\n');
if (tokenIndex === -1) {
reject('invalid response - no multipart mime header');
}
// find the terminal boundary marker
var endIndex = findIndexOfString(response, boundary, offset);
if(endIndex === -1) {
reject('invalid response - terminating boundary not found');
}
// return the info for this pixel data
var length = endIndex - offset - 1;
resolve({
contentType: findContentType(split),
arrayBuffer: imageFrameAsArrayBuffer,
offset: offset,
length: length
});
}
else {
// request failed, reject the deferred
reject(xhr.response);
}
}
};
xhr.send();
});
};
var header = uint8ArrayToString(response, 0, tokenIndex);
// Now find the boundary marker
var split = header.split('\r\n');
var boundary = findBoundary(split);
if (!boundary) {
reject('invalid response - no boundary marker');
}
var offset = tokenIndex + 4; // skip over the \n\r\n
// find the terminal boundary marker
var endIndex = findIndexOfString(response, boundary, offset);
if (endIndex === -1) {
reject('invalid response - terminating boundary not found');
}
// return the info for this pixel data
var length = endIndex - offset - 1;
resolve({
contentType: findContentType(split),
arrayBuffer: imageFrameAsArrayBuffer,
offset: offset,
length: length
});
} else {
// request failed, reject the deferred
reject(xhr.response);
}
}
};
xhr.send();
});
};
+22 -22
View File
@@ -1,31 +1,31 @@
DICOMWeb.getJSON = function(url, options) {
var getOptions = {
headers: {
'Accept' : 'application/json'
var getOptions = {
headers: {
Accept: 'application/json'
},
};
};
if (options.auth) {
getOptions.auth = options.auth;
}
if (options.auth) {
getOptions.auth = options.auth;
}
if (options.logRequests) {
console.log(url);
}
if (options.logRequests) {
console.log(url);
}
if (options.logTiming) {
console.time(url);
}
if (options.logTiming) {
console.time(url);
}
var result = HTTP.get(url, getOptions);
var result = HTTP.get(url, getOptions);
if (options.logTiming) {
console.timeEnd(url);
}
if (options.logTiming) {
console.timeEnd(url);
}
if (options.logResponses) {
console.log(result.data);
}
if (options.logResponses) {
console.log(result.data);
}
return result;
};
return result;
};
+18 -18
View File
@@ -6,21 +6,21 @@
* @returns {*}
*/
DICOMWeb.getName = function(element, defaultValue) {
if(!element) {
return defaultValue;
}
// Value is not present if the attribute has a zero length value
if(!element.Value) {
return defaultValue;
}
// Sanity check to make sure we have at least one entry in the array.
if(!element.Value.length) {
return defaultValue;
}
// Return the Alphabetic component group
if(element.Value[0].Alphabetic) {
return element.Value[0].Alphabetic;
}
// Orthanc does not return PN properly so this is a temporary workaround
return element.Value[0];
};
if (!element) {
return defaultValue;
}
// Value is not present if the attribute has a zero length value
if (!element.Value) {
return defaultValue;
}
// Sanity check to make sure we have at least one entry in the array.
if (!element.Value.length) {
return defaultValue;
}
// Return the Alphabetic component group
if (element.Value[0].Alphabetic) {
return element.Value[0].Alphabetic;
}
// Orthanc does not return PN properly so this is a temporary workaround
return element.Value[0];
};
+14 -13
View File
@@ -5,16 +5,17 @@
* @returns {*}
*/
DICOMWeb.getNumber = function(element, defaultValue) {
if(!element) {
return defaultValue;
}
// Value is not present if the attribute has a zero length value
if(!element.Value) {
return defaultValue;
}
// Sanity check to make sure we have at least one entry in the array.
if(!element.Value.length) {
return defaultValue;
}
return parseFloat(element.Value[0]);
};
if (!element) {
return defaultValue;
}
// Value is not present if the attribute has a zero length value
if (!element.Value) {
return defaultValue;
}
// Sanity check to make sure we have at least one entry in the array.
if (!element.Value.length) {
return defaultValue;
}
return parseFloat(element.Value[0]);
};
+15 -15
View File
@@ -6,18 +6,18 @@
* @returns {*}
*/
DICOMWeb.getString = function(element, defaultValue) {
if(!element) {
return defaultValue;
}
// Value is not present if the attribute has a zero length value
if(!element.Value) {
return defaultValue;
}
// Sanity check to make sure we have at least one entry in the array.
if(!element.Value.length) {
return defaultValue;
}
// Join the array together separated by backslash
// NOTE: Orthanc does not correctly split values into an array so the join is a no-op
return element.Value.join('\\');
};
if (!element) {
return defaultValue;
}
// Value is not present if the attribute has a zero length value
if (!element.Value) {
return defaultValue;
}
// Sanity check to make sure we have at least one entry in the array.
if (!element.Value.length) {
return defaultValue;
}
// Join the array together separated by backslash
// NOTE: Orthanc does not correctly split values into an array so the join is a no-op
return element.Value.join('\\');
};