Коммит
2433146394
|
@ -204,6 +204,17 @@ WebResource.prototype.withHeader = function (name, value) {
|
|||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds an optional body.
|
||||
*
|
||||
* @param {Object} body The request body.
|
||||
* @return {Object} The web resource.
|
||||
*/
|
||||
WebResource.prototype.withBody = function (body) {
|
||||
this.body = body;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds optional query string parameters.
|
||||
*
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -14,6 +14,8 @@
|
|||
*/
|
||||
|
||||
// Module dependencies.
|
||||
var azureutil = require('../../../util/util');
|
||||
|
||||
var Constants = require('../../../util/constants');
|
||||
var HeaderConstants = Constants.HeaderConstants;
|
||||
|
||||
|
@ -85,4 +87,83 @@ BlobResult.prototype.getPropertiesFromHeaders = function (headers) {
|
|||
setBlobPropertyFromHeaders('copyStatus', HeaderConstants.COPY_STATUS);
|
||||
};
|
||||
|
||||
BlobResult.setHeadersFromBlob = function (webResource, blob) {
|
||||
var setHeaderPropertyFromBlob = function (headerProperty, blobProperty) {
|
||||
if (blob[blobProperty]) {
|
||||
webResource.withHeader(headerProperty, blob[blobProperty]);
|
||||
}
|
||||
};
|
||||
|
||||
if (blob) {
|
||||
// Content-Type
|
||||
setHeaderPropertyFromBlob(HeaderConstants.CONTENT_TYPE_HEADER, 'contentTypeHeader');
|
||||
setHeaderPropertyFromBlob(HeaderConstants.CONTENT_TYPE_HEADER, 'contentType');
|
||||
setHeaderPropertyFromBlob(HeaderConstants.CONTENT_TYPE, 'contentType');
|
||||
|
||||
// Content-Encoding
|
||||
setHeaderPropertyFromBlob(HeaderConstants.CONTENT_ENCODING_HEADER, 'contentEncodingHeader');
|
||||
setHeaderPropertyFromBlob(HeaderConstants.CONTENT_ENCODING_HEADER, 'contentEncoding');
|
||||
setHeaderPropertyFromBlob(HeaderConstants.CONTENT_ENCODING, 'contentEncoding');
|
||||
|
||||
// Content-MD5
|
||||
setHeaderPropertyFromBlob(HeaderConstants.BLOB_CONTENT_MD5_HEADER, 'contentMD5Header');
|
||||
setHeaderPropertyFromBlob(HeaderConstants.BLOB_CONTENT_MD5_HEADER, 'contentMD5');
|
||||
setHeaderPropertyFromBlob(HeaderConstants.CONTENT_MD5, 'contentMD5');
|
||||
|
||||
// Content-Language
|
||||
setHeaderPropertyFromBlob(HeaderConstants.CONTENT_LANGUAGE_HEADER, 'contentLanguageHeader');
|
||||
setHeaderPropertyFromBlob(HeaderConstants.CONTENT_LANGUAGE_HEADER, 'contentLanguage');
|
||||
setHeaderPropertyFromBlob(HeaderConstants.CONTENT_LANGUAGE, 'contentLanguage');
|
||||
|
||||
// Cache-Control
|
||||
setHeaderPropertyFromBlob(HeaderConstants.CACHE_CONTROL_HEADER, 'cacheControlHeader');
|
||||
setHeaderPropertyFromBlob(HeaderConstants.CACHE_CONTROL_HEADER, 'cacheControl');
|
||||
setHeaderPropertyFromBlob(HeaderConstants.CACHE_CONTROL, 'cacheControl');
|
||||
|
||||
// Content-Length
|
||||
setHeaderPropertyFromBlob(HeaderConstants.CONTENT_LENGTH_HEADER, 'contentLengthHeader');
|
||||
setHeaderPropertyFromBlob(HeaderConstants.CONTENT_LENGTH_HEADER, 'contentLength');
|
||||
setHeaderPropertyFromBlob(HeaderConstants.CONTENT_LENGTH, 'contentLength');
|
||||
|
||||
// Range
|
||||
if (!azureutil.objectIsNull(blob.rangeStart)) {
|
||||
var range = 'bytes=' + blob.rangeStart + '-';
|
||||
|
||||
if (!azureutil.objectIsNull(blob.rangeEnd)) {
|
||||
range += blob.rangeEnd;
|
||||
}
|
||||
|
||||
webResource.withHeader(HeaderConstants.RANGE, range);
|
||||
}
|
||||
|
||||
if (!azureutil.objectIsNull(blob.rangeStartHeader)) {
|
||||
var rangeHeader = 'bytes=' + blob.rangeStartHeader + '-';
|
||||
|
||||
if (!azureutil.objectIsNull(blob.rangeEndHeader)) {
|
||||
rangeHeader += blob.rangeEndHeader;
|
||||
}
|
||||
|
||||
webResource.withHeader(HeaderConstants.STORAGE_RANGE_HEADER, rangeHeader);
|
||||
}
|
||||
|
||||
// Range get content-md5
|
||||
setHeaderPropertyFromBlob(HeaderConstants.RANGE_GET_CONTENT_MD5, 'rangeGetContentMd5');
|
||||
|
||||
// Blob Type
|
||||
setHeaderPropertyFromBlob(HeaderConstants.BLOB_TYPE_HEADER, 'blobTypeHeader');
|
||||
setHeaderPropertyFromBlob(HeaderConstants.BLOB_TYPE_HEADER, 'blobType');
|
||||
|
||||
// Lease id
|
||||
setHeaderPropertyFromBlob(HeaderConstants.LEASE_ID_HEADER, 'leaseId');
|
||||
|
||||
// Sequence number
|
||||
setHeaderPropertyFromBlob(HeaderConstants.SEQUENCE_NUMBER, 'sequenceNumberHeader');
|
||||
setHeaderPropertyFromBlob('x-ms-sequence-number-action', 'sequenceNumberActionHeader');
|
||||
|
||||
if (blob.metadata) {
|
||||
webResource.addOptionalMetadataHeaders(blob.metadata);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = BlobResult;
|
|
@ -18,6 +18,7 @@ var util = require('util');
|
|||
var _ = require('underscore');
|
||||
|
||||
var azureutil = require('../../util/util');
|
||||
var validate = require('../../util/validate');
|
||||
|
||||
var StorageServiceClient = require('../core/storageserviceclient');
|
||||
var SharedKey = require('../blob/internal/sharedkey');
|
||||
|
@ -63,53 +64,6 @@ function QueueService(storageAccountOrConnectionString, storageAccessKey, host,
|
|||
|
||||
util.inherits(QueueService, StorageServiceClient);
|
||||
|
||||
// Non-module methods
|
||||
|
||||
/**
|
||||
* Validates a queue name.
|
||||
*
|
||||
* @param {string} queue The queue name.
|
||||
* @return {undefined}
|
||||
*/
|
||||
function validateQueueName(queue) {
|
||||
if (!azureutil.objectIsString(queue) || azureutil.stringIsEmpty(queue)) {
|
||||
throw new Error('Queue name must be a non empty string.');
|
||||
}
|
||||
|
||||
if (queue === '$root') {
|
||||
return;
|
||||
}
|
||||
|
||||
// Caps aren't allowed by the REST API
|
||||
if (queue.match('^[a-z0-9][a-z0-9-]*$') === null) {
|
||||
throw new Error('Incorrect queue name format.');
|
||||
}
|
||||
|
||||
if (queue.indexOf('--') !== -1) {
|
||||
throw new Error('Incorrect queue name format.');
|
||||
}
|
||||
|
||||
if (queue.length < 3 || queue.length > 63) {
|
||||
throw new Error('Incorrect queue name format.');
|
||||
}
|
||||
|
||||
if (queue.substr(queue.length - 1, 1) === '-') {
|
||||
throw new Error('Incorrect queue name format.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates a callback function.
|
||||
*
|
||||
* @param (function) callback The callback function.
|
||||
* @return {undefined}
|
||||
*/
|
||||
function validateCallback(callback) {
|
||||
if (!callback) {
|
||||
throw new Error('Callback must be specified.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the properties of a storage account’s Queue service, including Windows Azure Storage Analytics.
|
||||
*
|
||||
|
@ -120,18 +74,16 @@ function validateCallback(callback) {
|
|||
* @return {undefined}
|
||||
*/
|
||||
QueueService.prototype.getServiceProperties = function (optionsOrCallback, callback) {
|
||||
var options = null;
|
||||
if (typeof optionsOrCallback === 'function' && !callback) {
|
||||
callback = optionsOrCallback;
|
||||
} else {
|
||||
options = optionsOrCallback;
|
||||
}
|
||||
var options;
|
||||
azureutil.normalizeArgs(optionsOrCallback, callback, function (o, c) { options = o; callback = c; });
|
||||
|
||||
validateCallback(callback);
|
||||
validate.validateArgs('getServiceProperties', function (v) {
|
||||
v.callback(callback);
|
||||
});
|
||||
|
||||
var webResource = WebResource.get();
|
||||
webResource.withQueryOption(QueryStringConstants.COMP, 'properties');
|
||||
webResource.withQueryOption(QueryStringConstants.RESTYPE, 'service');
|
||||
var webResource = WebResource.get()
|
||||
.withQueryOption(QueryStringConstants.COMP, 'properties')
|
||||
.withQueryOption(QueryStringConstants.RESTYPE, 'service');
|
||||
|
||||
var processResponseCallback = function (responseObject, next) {
|
||||
responseObject.servicePropertiesResult = null;
|
||||
|
@ -161,14 +113,12 @@ QueueService.prototype.getServiceProperties = function (optionsOrCallback, callb
|
|||
* @return {undefined}
|
||||
*/
|
||||
QueueService.prototype.setServiceProperties = function (serviceProperties, optionsOrCallback, callback) {
|
||||
var options = null;
|
||||
if (typeof optionsOrCallback === 'function' && !callback) {
|
||||
callback = optionsOrCallback;
|
||||
} else {
|
||||
options = optionsOrCallback;
|
||||
}
|
||||
var options;
|
||||
azureutil.normalizeArgs(optionsOrCallback, callback, function (o, c) { options = o; callback = c; });
|
||||
|
||||
validateCallback(callback);
|
||||
validate.validateArgs('setServiceProperties', function (v) {
|
||||
v.callback(callback);
|
||||
});
|
||||
|
||||
var servicePropertiesXml = servicePropertiesResult.serialize(serviceProperties);
|
||||
|
||||
|
@ -176,7 +126,8 @@ QueueService.prototype.setServiceProperties = function (serviceProperties, optio
|
|||
.withQueryOption(QueryStringConstants.COMP, 'properties')
|
||||
.withQueryOption(QueryStringConstants.RESTYPE, 'service')
|
||||
.withHeader(HeaderConstants.CONTENT_TYPE, 'application/xml;charset="utf-8"')
|
||||
.withHeader(HeaderConstants.CONTENT_LENGTH, Buffer.byteLength(servicePropertiesXml));
|
||||
.withHeader(HeaderConstants.CONTENT_LENGTH, Buffer.byteLength(servicePropertiesXml))
|
||||
.withBody(servicePropertiesXml);
|
||||
|
||||
var processResponseCallback = function (responseObject, next) {
|
||||
var finalCallback = function (returnObject) {
|
||||
|
@ -186,7 +137,7 @@ QueueService.prototype.setServiceProperties = function (serviceProperties, optio
|
|||
next(responseObject, finalCallback);
|
||||
};
|
||||
|
||||
this.performRequest(webResource, servicePropertiesXml, options, processResponseCallback);
|
||||
this.performRequest(webResource, webResource.body, options, processResponseCallback);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -203,14 +154,12 @@ QueueService.prototype.setServiceProperties = function (serviceProperties, optio
|
|||
* @return {undefined}
|
||||
*/
|
||||
QueueService.prototype.listQueues = function (optionsOrCallback, callback) {
|
||||
var options = null;
|
||||
if (typeof optionsOrCallback === 'function' && !callback) {
|
||||
callback = optionsOrCallback;
|
||||
} else {
|
||||
options = optionsOrCallback;
|
||||
}
|
||||
var options;
|
||||
azureutil.normalizeArgs(optionsOrCallback, callback, function (o, c) { options = o; callback = c; });
|
||||
|
||||
validateCallback(callback);
|
||||
validate.validateArgs('listQueues', function (v) {
|
||||
v.callback(callback);
|
||||
});
|
||||
|
||||
var webResource = WebResource.get();
|
||||
webResource.withQueryOption(QueryStringConstants.COMP, 'list');
|
||||
|
@ -266,15 +215,14 @@ QueueService.prototype.listQueues = function (optionsOrCallback, callback) {
|
|||
* @return {undefined}
|
||||
*/
|
||||
QueueService.prototype.createQueue = function (queue, optionsOrCallback, callback) {
|
||||
var options = null;
|
||||
if (typeof optionsOrCallback === 'function' && !callback) {
|
||||
callback = optionsOrCallback;
|
||||
} else {
|
||||
options = optionsOrCallback;
|
||||
}
|
||||
var options;
|
||||
azureutil.normalizeArgs(optionsOrCallback, callback, function (o, c) { options = o; callback = c; });
|
||||
|
||||
validateQueueName(queue);
|
||||
validateCallback(callback);
|
||||
validate.validateArgs('createQueue', function (v) {
|
||||
v.string(queue, 'queue');
|
||||
v.queueNameIsValid(queue);
|
||||
v.callback(callback);
|
||||
});
|
||||
|
||||
var webResource = WebResource.put(queue);
|
||||
if (options) {
|
||||
|
@ -312,15 +260,14 @@ QueueService.prototype.createQueue = function (queue, optionsOrCallback, callbac
|
|||
* @return {undefined}
|
||||
*/
|
||||
QueueService.prototype.createQueueIfNotExists = function (queue, optionsOrCallback, callback) {
|
||||
var options = null;
|
||||
if (typeof optionsOrCallback === 'function' && !callback) {
|
||||
callback = optionsOrCallback;
|
||||
} else {
|
||||
options = optionsOrCallback;
|
||||
}
|
||||
var options;
|
||||
azureutil.normalizeArgs(optionsOrCallback, callback, function (o, c) { options = o; callback = c; });
|
||||
|
||||
validateQueueName(queue);
|
||||
validateCallback(callback);
|
||||
validate.validateArgs('createQueueIfNotExists', function (v) {
|
||||
v.string(queue, 'queue');
|
||||
v.queueNameIsValid(queue);
|
||||
v.callback(callback);
|
||||
});
|
||||
|
||||
// Create WebResource specifying an additional ok code for the already created scenario.
|
||||
var webResource = WebResource.put(queue);
|
||||
|
@ -359,15 +306,14 @@ QueueService.prototype.createQueueIfNotExists = function (queue, optionsOrCallba
|
|||
* @return {undefined}
|
||||
*/
|
||||
QueueService.prototype.deleteQueue = function (queue, optionsOrCallback, callback) {
|
||||
var options = null;
|
||||
if (typeof optionsOrCallback === 'function' && !callback) {
|
||||
callback = optionsOrCallback;
|
||||
} else {
|
||||
options = optionsOrCallback;
|
||||
}
|
||||
var options;
|
||||
azureutil.normalizeArgs(optionsOrCallback, callback, function (o, c) { options = o; callback = c; });
|
||||
|
||||
validateQueueName(queue);
|
||||
validateCallback(callback);
|
||||
validate.validateArgs('deleteQueue', function (v) {
|
||||
v.string(queue, 'queue');
|
||||
v.queueNameIsValid(queue);
|
||||
v.callback(callback);
|
||||
});
|
||||
|
||||
var webResource = WebResource.del(queue);
|
||||
var processResponseCallback = function (responseObject, next) {
|
||||
|
@ -392,18 +338,17 @@ QueueService.prototype.deleteQueue = function (queue, optionsOrCallback, callbac
|
|||
* @return {undefined}
|
||||
*/
|
||||
QueueService.prototype.getQueueMetadata = function (queue, optionsOrCallback, callback) {
|
||||
var options = null;
|
||||
if (typeof optionsOrCallback === 'function' && !callback) {
|
||||
callback = optionsOrCallback;
|
||||
} else {
|
||||
options = optionsOrCallback;
|
||||
}
|
||||
var options;
|
||||
azureutil.normalizeArgs(optionsOrCallback, callback, function (o, c) { options = o; callback = c; });
|
||||
|
||||
validateQueueName(queue);
|
||||
validateCallback(callback);
|
||||
validate.validateArgs('getQueueMetadata', function (v) {
|
||||
v.string(queue, 'queue');
|
||||
v.queueNameIsValid(queue);
|
||||
v.callback(callback);
|
||||
});
|
||||
|
||||
var webResource = WebResource.get(queue);
|
||||
webResource.withQueryOption(QueryStringConstants.COMP, 'metadata');
|
||||
var webResource = WebResource.get(queue)
|
||||
.withQueryOption(QueryStringConstants.COMP, 'metadata');
|
||||
|
||||
var self = this;
|
||||
var processResponseCallback = function (responseObject, next) {
|
||||
|
@ -436,15 +381,14 @@ QueueService.prototype.getQueueMetadata = function (queue, optionsOrCallback, ca
|
|||
* @return {undefined}
|
||||
*/
|
||||
QueueService.prototype.setQueueMetadata = function (queue, metadata, optionsOrCallback, callback) {
|
||||
var options = null;
|
||||
if (typeof optionsOrCallback === 'function' && !callback) {
|
||||
callback = optionsOrCallback;
|
||||
} else {
|
||||
options = optionsOrCallback;
|
||||
}
|
||||
var options;
|
||||
azureutil.normalizeArgs(optionsOrCallback, callback, function (o, c) { options = o; callback = c; });
|
||||
|
||||
validateQueueName(queue);
|
||||
validateCallback(callback);
|
||||
validate.validateArgs('setQueueMetadata', function (v) {
|
||||
v.string(queue, 'queue');
|
||||
v.queueNameIsValid(queue);
|
||||
v.callback(callback);
|
||||
});
|
||||
|
||||
var webResource = WebResource.put(queue)
|
||||
.withQueryOption(QueryStringConstants.COMP, 'metadata')
|
||||
|
@ -484,24 +428,22 @@ QueueService.prototype.setQueueMetadata = function (queue, metadata, optionsOrCa
|
|||
* @return {undefined}
|
||||
*/
|
||||
QueueService.prototype.createMessage = function (queue, messageText, optionsOrCallback, callback) {
|
||||
var options = null;
|
||||
if (typeof optionsOrCallback === 'function' && !callback) {
|
||||
callback = optionsOrCallback;
|
||||
} else {
|
||||
options = optionsOrCallback;
|
||||
}
|
||||
var options;
|
||||
azureutil.normalizeArgs(optionsOrCallback, callback, function (o, c) { options = o; callback = c; });
|
||||
|
||||
validateQueueName(queue);
|
||||
validateCallback(callback);
|
||||
validate.validateArgs('createMessage', function (v) {
|
||||
v.string(queue, 'queue');
|
||||
v.queueNameIsValid(queue);
|
||||
v.callback(callback);
|
||||
});
|
||||
|
||||
var xmlMessageDescriptor = QueueMessageResult.serialize(messageText);
|
||||
|
||||
var webResource = WebResource.post(queue + '/messages');
|
||||
|
||||
webResource.withHeader(HeaderConstants.CONTENT_TYPE, 'application/atom+xml;charset="utf-8"');
|
||||
webResource.withHeader(HeaderConstants.CONTENT_LENGTH, Buffer.byteLength(xmlMessageDescriptor, 'utf8'));
|
||||
|
||||
webResource.withQueryOptions(options, QueryStringConstants.MESSAGE_TTL, QueryStringConstants.VISIBILITY_TIMEOUT);
|
||||
var webResource = WebResource.post(queue + '/messages')
|
||||
.withHeader(HeaderConstants.CONTENT_TYPE, 'application/atom+xml;charset="utf-8"')
|
||||
.withHeader(HeaderConstants.CONTENT_LENGTH, Buffer.byteLength(xmlMessageDescriptor, 'utf8'))
|
||||
.withQueryOptions(options, QueryStringConstants.MESSAGE_TTL, QueryStringConstants.VISIBILITY_TIMEOUT)
|
||||
.withBody(xmlMessageDescriptor);
|
||||
|
||||
var processResponseCallback = function (responseObject, next) {
|
||||
responseObject.queueMessageResult = null;
|
||||
|
@ -517,7 +459,7 @@ QueueService.prototype.createMessage = function (queue, messageText, optionsOrCa
|
|||
next(responseObject, finalCallback);
|
||||
};
|
||||
|
||||
this.performRequest(webResource, xmlMessageDescriptor, options, processResponseCallback);
|
||||
this.performRequest(webResource, webResource.body, options, processResponseCallback);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -534,14 +476,14 @@ QueueService.prototype.createMessage = function (queue, messageText, optionsOrCa
|
|||
* @return {undefined}
|
||||
*/
|
||||
QueueService.prototype.getMessages = function (queue, optionsOrCallback, callback) {
|
||||
var options = null;
|
||||
if (typeof optionsOrCallback === 'function' && !callback) {
|
||||
callback = optionsOrCallback;
|
||||
} else {
|
||||
options = optionsOrCallback;
|
||||
}
|
||||
var options;
|
||||
azureutil.normalizeArgs(optionsOrCallback, callback, function (o, c) { options = o; callback = c; });
|
||||
|
||||
validateCallback(callback);
|
||||
validate.validateArgs('getMessages', function (v) {
|
||||
v.string(queue, 'queue');
|
||||
v.queueNameIsValid(queue);
|
||||
v.callback(callback);
|
||||
});
|
||||
|
||||
var webResource = WebResource.get(queue + '/messages');
|
||||
webResource.withQueryOptions(options, QueryStringConstants.NUM_OF_MESSAGES, QueryStringConstants.VISIBILITY_TIMEOUT);
|
||||
|
@ -591,12 +533,8 @@ QueueService.prototype.getMessages = function (queue, optionsOrCallback, callbac
|
|||
* @return {undefined}
|
||||
*/
|
||||
QueueService.prototype.peekMessages = function (queue, optionsOrCallback, callback) {
|
||||
var options = null;
|
||||
if (typeof optionsOrCallback === 'function' && !callback) {
|
||||
callback = optionsOrCallback;
|
||||
} else {
|
||||
options = optionsOrCallback;
|
||||
}
|
||||
var options;
|
||||
azureutil.normalizeArgs(optionsOrCallback, callback, function (o, c) { options = o; callback = c; });
|
||||
|
||||
if (!options) {
|
||||
options = {};
|
||||
|
@ -623,22 +561,21 @@ QueueService.prototype.peekMessages = function (queue, optionsOrCallback, callba
|
|||
* @return {undefined}
|
||||
*/
|
||||
QueueService.prototype.deleteMessage = function (queue, messageid, popreceipt, optionsOrCallback, callback) {
|
||||
var options = null;
|
||||
if (typeof optionsOrCallback === 'function' && !callback) {
|
||||
callback = optionsOrCallback;
|
||||
} else {
|
||||
options = optionsOrCallback;
|
||||
}
|
||||
var options;
|
||||
azureutil.normalizeArgs(optionsOrCallback, callback, function (o, c) { options = o; callback = c; });
|
||||
|
||||
validateQueueName(queue);
|
||||
validateCallback(callback);
|
||||
validate.validateArgs('deleteMessage', function (v) {
|
||||
v.string(queue, 'queue');
|
||||
v.queueNameIsValid(queue);
|
||||
v.callback(callback);
|
||||
});
|
||||
|
||||
if (!popreceipt) {
|
||||
throw new Error('A message retrieved using \'peekMessages\' can not be deleted! Use \'getMessages\' instead.');
|
||||
}
|
||||
|
||||
var webResource = WebResource.del(queue + '/messages/' + messageid);
|
||||
webResource.withQueryOption(QueryStringConstants.POP_RECEIPT, popreceipt, null, true);
|
||||
var webResource = WebResource.del(queue + '/messages/' + messageid)
|
||||
.withQueryOption(QueryStringConstants.POP_RECEIPT, popreceipt, null, true);
|
||||
|
||||
var processResponseCallback = function (responseObject, next) {
|
||||
var finalCallback = function (returnObject) {
|
||||
|
@ -662,15 +599,14 @@ QueueService.prototype.deleteMessage = function (queue, messageid, popreceipt, o
|
|||
* @return {undefined}
|
||||
*/
|
||||
QueueService.prototype.clearMessages = function (queue, optionsOrCallback, callback) {
|
||||
var options = null;
|
||||
if (typeof optionsOrCallback === 'function' && !callback) {
|
||||
callback = optionsOrCallback;
|
||||
} else {
|
||||
options = optionsOrCallback;
|
||||
}
|
||||
var options;
|
||||
azureutil.normalizeArgs(optionsOrCallback, callback, function (o, c) { options = o; callback = c; });
|
||||
|
||||
validateQueueName(queue);
|
||||
validateCallback(callback);
|
||||
validate.validateArgs('clearMessages', function (v) {
|
||||
v.string(queue, 'queue');
|
||||
v.queueNameIsValid(queue);
|
||||
v.callback(callback);
|
||||
});
|
||||
|
||||
var webResource = WebResource.del(queue + '/messages');
|
||||
|
||||
|
@ -701,28 +637,26 @@ QueueService.prototype.clearMessages = function (queue, optionsOrCallback, callb
|
|||
* @return {undefined}
|
||||
*/
|
||||
QueueService.prototype.updateMessage = function (queue, messageid, popreceipt, visibilitytimeout, optionsOrCallback, callback) {
|
||||
var options = null;
|
||||
if (typeof optionsOrCallback === 'function' && !callback) {
|
||||
callback = optionsOrCallback;
|
||||
} else {
|
||||
options = optionsOrCallback;
|
||||
}
|
||||
var options;
|
||||
azureutil.normalizeArgs(optionsOrCallback, callback, function (o, c) { options = o; callback = c; });
|
||||
|
||||
validateQueueName(queue);
|
||||
validateCallback(callback);
|
||||
validate.validateArgs('updateMessage', function (v) {
|
||||
v.string(queue, 'queue');
|
||||
v.queueNameIsValid(queue);
|
||||
v.callback(callback);
|
||||
});
|
||||
|
||||
var content = null;
|
||||
if (options && options.messagetext) {
|
||||
content = QueueMessageResult.serialize(options.messagetext);
|
||||
}
|
||||
|
||||
var webResource = WebResource.put(queue + '/messages/' + messageid);
|
||||
|
||||
webResource.withHeader(HeaderConstants.CONTENT_TYPE, 'application/atom+xml;charset="utf-8"');
|
||||
webResource.withHeader(HeaderConstants.CONTENT_LENGTH, Buffer.byteLength(content, 'utf8'));
|
||||
|
||||
webResource.withQueryOption(QueryStringConstants.POP_RECEIPT, popreceipt, null, true);
|
||||
webResource.withQueryOption(QueryStringConstants.VISIBILITY_TIMEOUT, visibilitytimeout);
|
||||
var webResource = WebResource.put(queue + '/messages/' + messageid)
|
||||
.withHeader(HeaderConstants.CONTENT_TYPE, 'application/atom+xml;charset="utf-8"')
|
||||
.withHeader(HeaderConstants.CONTENT_LENGTH, Buffer.byteLength(content, 'utf8'))
|
||||
.withQueryOption(QueryStringConstants.POP_RECEIPT, popreceipt, null, true)
|
||||
.withQueryOption(QueryStringConstants.VISIBILITY_TIMEOUT, visibilitytimeout)
|
||||
.withBody(content);
|
||||
|
||||
var processResponseCallback = function (responseObject, next) {
|
||||
responseObject.queueMessageResult = null;
|
||||
|
@ -738,7 +672,7 @@ QueueService.prototype.updateMessage = function (queue, messageid, popreceipt, v
|
|||
next(responseObject, finalCallback);
|
||||
};
|
||||
|
||||
this.performRequest(webResource, content, options, processResponseCallback);
|
||||
this.performRequest(webResource, webResource.body, options, processResponseCallback);
|
||||
};
|
||||
|
||||
module.exports = QueueService;
|
|
@ -151,7 +151,8 @@ TableService.prototype.setServiceProperties = function (serviceProperties, optio
|
|||
.withQueryOption(QueryStringConstants.COMP, 'properties')
|
||||
.withQueryOption(QueryStringConstants.RESTYPE, 'service')
|
||||
.withHeader(HeaderConstants.CONTENT_TYPE, 'application/xml;charset="utf-8"')
|
||||
.withHeader(HeaderConstants.CONTENT_LENGTH, Buffer.byteLength(servicePropertiesXml, 'utf8'));
|
||||
.withHeader(HeaderConstants.CONTENT_LENGTH, Buffer.byteLength(servicePropertiesXml, 'utf8'))
|
||||
.withBody(servicePropertiesXml);
|
||||
|
||||
var processResponseCallback = function (responseObject, next) {
|
||||
var finalCallback = function (returnObject) {
|
||||
|
@ -161,7 +162,7 @@ TableService.prototype.setServiceProperties = function (serviceProperties, optio
|
|||
next(responseObject, finalCallback);
|
||||
};
|
||||
|
||||
this._performRequestExtended(webResource, servicePropertiesXml, options, processResponseCallback);
|
||||
this._performRequestExtended(webResource, webResource.body, options, processResponseCallback);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -228,7 +229,8 @@ TableService.prototype.createTable = function (table, optionsOrCallback, callbac
|
|||
|
||||
var webResource = WebResource.post('Tables')
|
||||
.withHeader(HeaderConstants.CONTENT_TYPE, 'application/atom+xml;charset="utf-8"')
|
||||
.withHeader(HeaderConstants.CONTENT_LENGTH, Buffer.byteLength(xmlTableDescriptor, 'utf8'));
|
||||
.withHeader(HeaderConstants.CONTENT_LENGTH, Buffer.byteLength(xmlTableDescriptor, 'utf8'))
|
||||
.withBody(xmlTableDescriptor);
|
||||
|
||||
var processResponseCallback = function (responseObject, next) {
|
||||
responseObject.tableResponse = null;
|
||||
|
@ -243,7 +245,7 @@ TableService.prototype.createTable = function (table, optionsOrCallback, callbac
|
|||
next(responseObject, finalCallback);
|
||||
};
|
||||
|
||||
this._performRequestExtended(webResource, xmlTableDescriptor, options, processResponseCallback);
|
||||
this._performRequestExtended(webResource, webResource.body, options, processResponseCallback);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -488,7 +490,8 @@ TableService.prototype.insertEntity = function (table, entityDescriptor, options
|
|||
|
||||
var webResource = WebResource.post(table)
|
||||
.withHeader(HeaderConstants.CONTENT_TYPE, 'application/atom+xml;charset="utf-8"')
|
||||
.withHeader(HeaderConstants.CONTENT_LENGTH, Buffer.byteLength(entityXmlDescriptor, 'utf8'));
|
||||
.withHeader(HeaderConstants.CONTENT_LENGTH, Buffer.byteLength(entityXmlDescriptor, 'utf8'))
|
||||
.withBody(entityXmlDescriptor);
|
||||
|
||||
if (this.isInBatch()) {
|
||||
this.addOperation(webResource, entityXmlDescriptor, options);
|
||||
|
@ -509,7 +512,7 @@ TableService.prototype.insertEntity = function (table, entityDescriptor, options
|
|||
next(responseObject, finalCallback);
|
||||
};
|
||||
|
||||
this._performRequestExtended(webResource, entityXmlDescriptor, options, processResponseCallback);
|
||||
this._performRequestExtended(webResource, webResource.body, options, processResponseCallback);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -544,7 +547,8 @@ TableService.prototype.insertOrReplaceEntity = function (table, entityDescriptor
|
|||
var path = getEntityPath(table, entityDescriptor.PartitionKey, entityDescriptor.RowKey);
|
||||
var webResource = WebResource.put(path)
|
||||
.withHeader(HeaderConstants.CONTENT_TYPE, 'application/atom+xml;charset="utf-8"')
|
||||
.withHeader(HeaderConstants.CONTENT_LENGTH, Buffer.byteLength(entityXmlDescriptor, 'utf8'));
|
||||
.withHeader(HeaderConstants.CONTENT_LENGTH, Buffer.byteLength(entityXmlDescriptor, 'utf8'))
|
||||
.withBody(entityXmlDescriptor);
|
||||
|
||||
if (this.isInBatch()) {
|
||||
this.addOperation(webResource, entityXmlDescriptor, options);
|
||||
|
@ -565,7 +569,7 @@ TableService.prototype.insertOrReplaceEntity = function (table, entityDescriptor
|
|||
next(responseObject, finalCallback);
|
||||
};
|
||||
|
||||
this._performRequestExtended(webResource, entityXmlDescriptor, options, processResponseCallback);
|
||||
this._performRequestExtended(webResource, webResource.body, options, processResponseCallback);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -602,7 +606,8 @@ TableService.prototype.updateEntity = function (table, entityDescriptor, options
|
|||
var webResource = WebResource.put(path)
|
||||
.withHeader(HeaderConstants.CONTENT_TYPE, 'application/atom+xml;charset="utf-8"')
|
||||
.withHeader(HeaderConstants.CONTENT_LENGTH, Buffer.byteLength(entityXmlDescriptor, 'utf8'))
|
||||
.withHeader(HeaderConstants.IF_MATCH, (options && options.checkEtag === true ? entityResult.getEtag(entityDescriptor) : '*'));
|
||||
.withHeader(HeaderConstants.IF_MATCH, (options && options.checkEtag === true ? entityResult.getEtag(entityDescriptor) : '*'))
|
||||
.withBody(entityXmlDescriptor);
|
||||
|
||||
if (this.isInBatch()) {
|
||||
this.addOperation(webResource, entityXmlDescriptor, options);
|
||||
|
@ -623,7 +628,7 @@ TableService.prototype.updateEntity = function (table, entityDescriptor, options
|
|||
next(responseObject, finalCallback);
|
||||
};
|
||||
|
||||
this._performRequestExtended(webResource, entityXmlDescriptor, options, processResponseCallback);
|
||||
this._performRequestExtended(webResource, webResource.body, options, processResponseCallback);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -660,7 +665,8 @@ TableService.prototype.mergeEntity = function (table, entityDescriptor, optionsO
|
|||
var webResource = WebResource.merge(path)
|
||||
.withHeader(HeaderConstants.CONTENT_TYPE, 'application/atom+xml;charset="utf-8"')
|
||||
.withHeader(HeaderConstants.CONTENT_LENGTH, Buffer.byteLength(entityXmlDescriptor, 'utf8'))
|
||||
.withHeader(HeaderConstants.IF_MATCH, (options && options.checkEtag === true ? entityResult.getEtag(entityDescriptor) : '*'));
|
||||
.withHeader(HeaderConstants.IF_MATCH, (options && options.checkEtag === true ? entityResult.getEtag(entityDescriptor) : '*'))
|
||||
.withBody(entityXmlDescriptor);
|
||||
|
||||
if (this.isInBatch()) {
|
||||
this.addOperation(webResource, entityXmlDescriptor, options);
|
||||
|
@ -681,7 +687,7 @@ TableService.prototype.mergeEntity = function (table, entityDescriptor, optionsO
|
|||
next(responseObject, finalCallback);
|
||||
};
|
||||
|
||||
this._performRequestExtended(webResource, entityXmlDescriptor, options, processResponseCallback);
|
||||
this._performRequestExtended(webResource, webResource.body, options, processResponseCallback);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -716,7 +722,8 @@ TableService.prototype.insertOrMergeEntity = function (table, entityDescriptor,
|
|||
|
||||
var webResource = WebResource.merge(path)
|
||||
.withHeader(HeaderConstants.CONTENT_TYPE, 'application/atom+xml;charset="utf-8"')
|
||||
.withHeader(HeaderConstants.CONTENT_LENGTH, Buffer.byteLength(entityXmlDescriptor, 'utf8'));
|
||||
.withHeader(HeaderConstants.CONTENT_LENGTH, Buffer.byteLength(entityXmlDescriptor, 'utf8'))
|
||||
.withBody(entityXmlDescriptor);
|
||||
|
||||
if (this.isInBatch()) {
|
||||
this.addOperation(webResource, entityXmlDescriptor, options);
|
||||
|
@ -737,7 +744,7 @@ TableService.prototype.insertOrMergeEntity = function (table, entityDescriptor,
|
|||
next(responseObject, finalCallback);
|
||||
};
|
||||
|
||||
this._performRequestExtended(webResource, entityXmlDescriptor, options, processResponseCallback);
|
||||
this._performRequestExtended(webResource, webResource.body, options, processResponseCallback);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var crypto = require('crypto');
|
||||
var _ = require('underscore');
|
||||
|
||||
/**
|
||||
|
@ -319,4 +320,29 @@ exports.getNodeVersion = function () {
|
|||
};
|
||||
};
|
||||
|
||||
exports.analyzeStream = function (stream, calculateMD5, callback) {
|
||||
var digest = null;
|
||||
var length = 0;
|
||||
if (calculateMD5) {
|
||||
digest = crypto.createHash('md5');
|
||||
}
|
||||
|
||||
stream.on('data', function (chunk) {
|
||||
if (calculateMD5) {
|
||||
digest.update(chunk);
|
||||
}
|
||||
|
||||
length += chunk.length;
|
||||
});
|
||||
|
||||
stream.on('end', function () {
|
||||
var md5 = null;
|
||||
if (calculateMD5) {
|
||||
md5 = digest.digest('base64');
|
||||
}
|
||||
|
||||
callback(length, md5);
|
||||
});
|
||||
};
|
||||
|
||||
exports.pathExistsSync = fs.existsSync ? fs.existsSync : path.existsSync;
|
|
@ -106,6 +106,89 @@ exports.namespaceNameIsValid = function (name, callback) {
|
|||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Validates a container name.
|
||||
*
|
||||
* @param {string} containerName The container name.
|
||||
* @return {undefined}
|
||||
*/
|
||||
exports.containerNameIsValid = function (containerName, callback) {
|
||||
var fail;
|
||||
|
||||
if (callback) {
|
||||
fail = function (err) {
|
||||
callback(new Error(err));
|
||||
return false;
|
||||
};
|
||||
} else {
|
||||
fail = function (err) {
|
||||
throw new Error(err);
|
||||
};
|
||||
callback = function () {};
|
||||
}
|
||||
|
||||
if (!azureutil.objectIsString(containerName) || azureutil.stringIsEmpty(containerName)) {
|
||||
return fail('Container name must be a non empty string.');
|
||||
}
|
||||
|
||||
if (containerName === '$root') {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (containerName.match('^[a-z0-9][a-z0-9-]*$') === null) {
|
||||
return fail('Container name format is incorrect.');
|
||||
}
|
||||
|
||||
if (containerName.indexOf('--') !== -1) {
|
||||
return fail('Container name format is incorrect.');
|
||||
}
|
||||
|
||||
if (containerName.length < 3 || containerName.length > 63) {
|
||||
return fail('Container name format is incorrect.');
|
||||
}
|
||||
|
||||
if (containerName.substr(containerName.length - 1, 1) === '-') {
|
||||
return fail('Container name format is incorrect.');
|
||||
}
|
||||
|
||||
callback();
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Validates a blob name.
|
||||
*
|
||||
* @param {string} containerName The container name.
|
||||
* @param {string} blobname The blob name.
|
||||
* @return {undefined}
|
||||
*/
|
||||
exports.blobNameIsValid = function (containerName, blobName, callback) {
|
||||
var fail;
|
||||
|
||||
if (callback) {
|
||||
fail = function (err) {
|
||||
callback(new Error(err));
|
||||
return false;
|
||||
};
|
||||
} else {
|
||||
fail = function (err) {
|
||||
throw new Error(err);
|
||||
};
|
||||
callback = function () {};
|
||||
}
|
||||
|
||||
if (!blobName) {
|
||||
return fail( 'Blob name is not specified.');
|
||||
}
|
||||
|
||||
if (containerName === '$root' && blobName.indexOf('/') !== -1) {
|
||||
return fail('Blob name format is incorrect.');
|
||||
}
|
||||
|
||||
callback();
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Validates a table name.
|
||||
*
|
||||
|
@ -135,6 +218,91 @@ exports.tableNameIsValid = function (name, callback) {
|
|||
return true;
|
||||
};
|
||||
|
||||
exports.pageRangesAreValid = function (rangeStart, rangeEnd, writeBlockSizeInBytes, callback) {
|
||||
var fail;
|
||||
|
||||
if (callback) {
|
||||
fail = function (err) {
|
||||
callback(new Error(err));
|
||||
return false;
|
||||
};
|
||||
} else {
|
||||
fail = function (err) {
|
||||
throw new Error(err);
|
||||
};
|
||||
callback = function () {};
|
||||
}
|
||||
|
||||
if (rangeStart % 512 !== 0) {
|
||||
return fail('Start byte offset must be a modulus of 512.');
|
||||
}
|
||||
|
||||
var size = null;
|
||||
if (!azureutil.objectIsNull(rangeEnd)) {
|
||||
if ((rangeEnd + 1) % 512 !== 0) {
|
||||
return fail('End byte offset must be a modulus of 512 minus 1.');
|
||||
}
|
||||
|
||||
size = (rangeEnd - rangeStart) + 1;
|
||||
if (size > this.writeBlockSizeInBytes) {
|
||||
return fail('Page blob size cant be larger than ' + writeBlockSizeInBytes + ' bytes.');
|
||||
}
|
||||
}
|
||||
|
||||
callback();
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Validates a queue name.
|
||||
*
|
||||
* @param {string} queue The queue name.
|
||||
* @return {undefined}
|
||||
*/
|
||||
exports.queueNameIsValid = function (queue, callback) {
|
||||
var fail;
|
||||
|
||||
if (callback) {
|
||||
fail = function (err) {
|
||||
callback(new Error(err));
|
||||
return false;
|
||||
};
|
||||
} else {
|
||||
fail = function (err) {
|
||||
throw new Error(err);
|
||||
};
|
||||
callback = function () {};
|
||||
}
|
||||
|
||||
if (!azureutil.objectIsString(queue) || azureutil.stringIsEmpty(queue)) {
|
||||
return fail('Queue name must be a non empty string.');
|
||||
}
|
||||
|
||||
if (queue === '$root') {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Caps aren't allowed by the REST API
|
||||
if (queue.match('^[a-z0-9][a-z0-9-]*$') === null) {
|
||||
return fail('Incorrect queue name format.');
|
||||
}
|
||||
|
||||
if (queue.indexOf('--') !== -1) {
|
||||
return fail('Incorrect queue name format.');
|
||||
}
|
||||
|
||||
if (queue.length < 3 || queue.length > 63) {
|
||||
return fail('Incorrect queue name format.');
|
||||
}
|
||||
|
||||
if (queue.substr(queue.length - 1, 1) === '-') {
|
||||
return fail('Incorrect queue name format.');
|
||||
}
|
||||
|
||||
callback();
|
||||
return true;
|
||||
};
|
||||
|
||||
// common functions for validating arguments
|
||||
|
||||
function throwMissingArgument(name, func) {
|
||||
|
@ -164,7 +332,11 @@ _.extend(ArgumentValidator.prototype, {
|
|||
callback: function (val) {
|
||||
this.object(val, 'callback');
|
||||
},
|
||||
tableNameIsValid: exports.tableNameIsValid
|
||||
tableNameIsValid: exports.tableNameIsValid,
|
||||
containerNameIsValid: exports.containerNameIsValid,
|
||||
blobNameIsValid: exports.blobNameIsValid,
|
||||
pageRangesAreValid: exports.pageRangesAreValid,
|
||||
queueNameIsValid: exports.queueNameIsValid
|
||||
});
|
||||
|
||||
function validateArgs(functionName, validationRules) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче