1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | 1 1 1 1 1 1 278 255 278 255 1 23 23 41 16 16 188 188 25 23 1 1 255 255 9180 1538 255 9180 9180 9180 1 344 3784 54 344 344 344 344 344 344 344 344 344 38 38 35 38 344 344 344 344 344 10 1 39 273 46 39 39 39 39 39 39 39 39 39 2 1 | // // Copyright (c) Microsoft and contributors. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // // See the License for the specific language governing permissions and // limitations under the License. // // Module dependencies. var _ = require('underscore'); var azureCommon = require('./../../../common/common'); var azureutil = azureCommon.util; var Constants = azureCommon.Constants; var HeaderConstants = Constants.HeaderConstants; function BlobResult(container, blob) { if (container) { this.container = container; } if (blob) { this.blob = blob; } } BlobResult.parse = function (blobXml) { var blobResult = new BlobResult(); for (var propertyName in blobXml) { if (propertyName === 'Properties' || propertyName === 'Metadata') { blobResult[propertyName.toLowerCase()] = { }; for (var subPropertyName in blobXml[propertyName]) { Eif (blobXml[propertyName].hasOwnProperty(subPropertyName)) { blobResult[propertyName.toLowerCase()][subPropertyName.toLowerCase()] = blobXml[propertyName][subPropertyName]; } } } else { blobResult[propertyName.toLowerCase()] = blobXml[propertyName]; } } return blobResult; }; var headersForProperties = { 'etag': 'ETAG', 'lastModified': 'LAST_MODIFIED', 'contentType': 'CONTENT_TYPE', 'contentEncoding': 'CONTENT_ENCODING', 'contentLanguage': 'CONTENT_LANGUAGE', 'contentMD5': 'CONTENT_MD5', 'cacheControl': 'CACHE_CONTROL', 'contentRange': 'CONTENT_RANGE', 'blobContentType': 'BLOB_CONTENT_TYPE', 'blobContentEncoding': 'BLOB_CONTENT_ENCODING', 'blobContentLanguage': 'BLOB_CONTENT_LANGUAGE', 'blobcontentMD5': 'BLOB_CONTENT_MD5', 'blobCacheControl': 'BLOB_CACHE_CONTROL', 'contentLength': 'CONTENT_LENGTH', 'blobContentLength': 'BLOB_CONTENT_LENGTH', 'contentDisposition': 'CONTENT_DISPOSITION', 'blobContentDisposition': 'BLOB_CONTENT_DISPOSITION', 'range': 'RANGE', 'blobRange': 'STORAGE_RANGE', 'getContentMd5': 'RANGE_GET_CONTENT_MD5', 'acceptRanges': 'ACCEPT_RANGES', 'blobType': 'BLOB_TYPE', 'leaseStatus': 'LEASE_STATUS', 'leaseId': 'LEASE_ID', 'leaseDuration': 'LEASE_DURATION', 'leaseState': 'LEASE_STATE', 'sequenceNumber': 'SEQUENCE_NUMBER', 'copySource': 'COPY_SOURCE', 'copyStatus': 'COPY_STATUS', 'copyCompletionTime': 'COPY_COMPLETION_TIME', 'copyStatusDescription': 'COPY_STATUS_DESCRIPTION', 'copyId': 'COPY_ID', 'copyProgress': 'COPY_PROGRESS', 'requestId': 'REQUEST_ID', 'appendOffset': 'BLOB_APPEND_OFFSET', 'committedBlockCount': 'BLOB_COMMITTED_BLOCK_COUNT' }; BlobResult.prototype.getPropertiesFromHeaders = function (headers) { var self = this; var setBlobPropertyFromHeaders = function (blobProperty, headerProperty) { if (!self[blobProperty] && headers[headerProperty.toLowerCase()]) { self[blobProperty] = headers[headerProperty.toLowerCase()]; } }; _.chain(headersForProperties).pairs().each(function (pair) { var property = pair[0]; var header = HeaderConstants[pair[1]]; setBlobPropertyFromHeaders(property, header); }); }; /** * This method sets the HTTP headers and is used by all methods except setBlobProperties and commitBlocks. Those 2 methods will set the x-ms-* headers using setPropertiesFromBlob. */ BlobResult.setHeadersFromBlob = function (webResource, blob) { var setHeaderPropertyFromBlob = function (headerProperty, blobProperty) { if (blob[blobProperty]) { webResource.withHeader(headerProperty, blob[blobProperty]); } }; Eif (blob) { // Content-Type setHeaderPropertyFromBlob(HeaderConstants.CONTENT_TYPE, 'contentType'); // Content-Encoding setHeaderPropertyFromBlob(HeaderConstants.CONTENT_ENCODING, 'contentEncoding'); // Content-MD5 setHeaderPropertyFromBlob(HeaderConstants.CONTENT_MD5, 'contentMD5'); // Content-Language setHeaderPropertyFromBlob(HeaderConstants.CONTENT_LANGUAGE, 'contentLanguage'); // Content-Disposition setHeaderPropertyFromBlob(HeaderConstants.CONTENT_DISPOSITION, 'contentDisposition'); // Cache-Control setHeaderPropertyFromBlob(HeaderConstants.CACHE_CONTROL, 'cacheControl'); // Content-Length 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); } // Blob Type setHeaderPropertyFromBlob(HeaderConstants.BLOB_TYPE, 'blobType'); // Lease id setHeaderPropertyFromBlob(HeaderConstants.LEASE_ID, 'leaseId'); // Sequence number setHeaderPropertyFromBlob(HeaderConstants.SEQUENCE_NUMBER, 'sequenceNumber'); setHeaderPropertyFromBlob(HeaderConstants.SEQUENCE_NUMBER_ACTION, 'sequenceNumberAction'); if (blob.metadata) { webResource.addOptionalMetadataHeaders(blob.metadata); } } }; /** * This method sets the x-ms-* headers and is used by setBlobProperties and commitBlocks. All other methods will set the regular HTTP headers using setHeadersFromBlob. */ BlobResult.setPropertiesFromBlob = function (webResource, blob) { var setHeaderPropertyFromBlob = function (headerProperty, blobProperty) { if (blob[blobProperty]) { webResource.withHeader(headerProperty, blob[blobProperty]); } }; Eif (blob) { // Content-Type setHeaderPropertyFromBlob(HeaderConstants.BLOB_CONTENT_TYPE, 'contentType'); // Content-Encoding setHeaderPropertyFromBlob(HeaderConstants.BLOB_CONTENT_ENCODING, 'contentEncoding'); // Content-MD5 setHeaderPropertyFromBlob(HeaderConstants.BLOB_CONTENT_MD5, 'contentMD5'); // Content-Language setHeaderPropertyFromBlob(HeaderConstants.BLOB_CONTENT_LANGUAGE, 'contentLanguage'); // Content-Disposition setHeaderPropertyFromBlob(HeaderConstants.BLOB_CONTENT_DISPOSITION, 'contentDisposition'); // Cache-Control setHeaderPropertyFromBlob(HeaderConstants.BLOB_CACHE_CONTROL, 'cacheControl'); // Lease id setHeaderPropertyFromBlob(HeaderConstants.LEASE_ID, 'leaseId'); if (blob.metadata) { webResource.addOptionalMetadataHeaders(blob.metadata); } } }; module.exports = BlobResult; |