Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Port Blob fixes to Orionode's filePlugin

  • Loading branch information...
commit 9879cd41b5bc9cafb69eb682088b6ab2c90482e6 1 parent 2583a86
@mamacdon authored
Showing with 52 additions and 72 deletions.
  1. +52 −72 lib/orionode.client/plugins/filePlugin/fileImpl.js
View
124 lib/orionode.client/plugins/filePlugin/fileImpl.js
@@ -447,102 +447,82 @@ define(["orion/Deferred", "orion/xhr", "orion/es5shim"], function(Deferred, xhr)
return result;
}.bind(this));
}
- // mamacdon -- we don't implement /filesearch so remove the 'search' service -- we'll use crawler instead
- /*,
-
- /__
- * Performs a search with the given query.
- * @param {String} query The search query
- _/
- search: function(location, query) {
- var locationIndex = query.indexOf("+Location:");
- if (locationIndex !== -1) {
- var loc = query.substring(locationIndex + "+Location:".length);
- if (loc.indexOf("://") !== -1) {
- var hostIndex = loc.indexOf("://") + 3;
- var pathIndex = loc.indexOf("/", hostIndex);
- loc = (pathIndex === -1 ) ? "" : loc.substring(pathIndex);
- }
- query = query.substring(0, locationIndex + "+Location:".length) + loc;
- }
-
- return xhr("GET", "/filesearch" + query, {
- headers: {
- "Accept": "application/json",
- "Orion-Version": "1"
- },
- timeout: 15000
- }).then(function(result) {
- return result.response ? JSON.parse(result.response) : {};
- }).then(function(result) {
- if (this.makeAbsolute) {
- _normalizeLocations(result);
- }
- return result;
- }.bind(this));
- }*/
+// ,
+// // mamacdon -- we don't implement /filesearch so remove the 'search' service -- we'll use crawler instead
+//
+// /**
+// * Performs a search with the given query.
+// * @param {String} query The search query
+// */
+// search: function(location, query) {
+// var locationIndex = query.indexOf("+Location:");
+// if (locationIndex !== -1) {
+// var loc = query.substring(locationIndex + "+Location:".length);
+// if (loc.indexOf("://") !== -1) {
+// var hostIndex = loc.indexOf("://") + 3;
+// var pathIndex = loc.indexOf("/", hostIndex);
+// loc = (pathIndex === -1 ) ? "" : loc.substring(pathIndex);
+// }
+// query = query.substring(0, locationIndex + "+Location:".length) + loc;
+// }
+//
+// return xhr("GET", "/filesearch" + query, {
+// headers: {
+// "Accept": "application/json",
+// "Orion-Version": "1"
+// },
+// timeout: 15000
+// }).then(function(result) {
+// return result.response ? JSON.parse(result.response) : {};
+// }).then(function(result) {
+// if (this.makeAbsolute) {
+// _normalizeLocations(result);
+// }
+// return result;
+// }.bind(this));
+// }
};
function _call2(method, url, headers, body) {
var d = new Deferred(); // create a promise
var xhr = new XMLHttpRequest();
- var header;
try {
xhr.open(method, url);
- if (headers !== null) {
- for (header in headers) {
- if (headers.hasOwnProperty(header)) {
- xhr.setRequestHeader(header, headers[header]);
- }
- }
+ if (headers) {
+ Object.keys(headers).forEach(function(header){
+ xhr.setRequestHeader(header, headers[header]);
+ });
}
xhr.responseType = "arraybuffer";
xhr.send(body);
- xhr.onreadystatechange = function() {
- if (xhr.readyState === 4) {
- d.resolve({
- status: xhr.status,
- statusText: xhr.statusText,
- headers: xhr.getAllResponseHeaders(),
- response: xhr.response //builder.getBlob()
- });
- }
+ xhr.onload = function() {
+ d.resolve({
+ status: xhr.status,
+ statusText: xhr.statusText,
+ headers: xhr.getAllResponseHeaders(),
+ response: xhr.response //builder.getBlob()
+ });
};
} catch (e) {
d.reject(e);
}
return d; // return the promise immediately
- }
-
- window.BlobBuilder = window.MozBlobBuilder || window.WebKitBlobBuilder || window.BlobBuilder;
- if (window.BlobBuilder) {
+ }
+
+ if (window.Blob) {
FileServiceImpl.prototype.readBlob = function(location) {
- return _call2("GET", location).then(function(response) {
- if (window.WebKitBlobBuilder) { // webkit works better with blobs, FF with ArrayBuffers
- var builder = new BlobBuilder();
- builder.append(response.response);
- return builder.getBlob();
- }
- return response.response;
- });
+ return _call2("GET", location).then(function(result) {
+ return result.response;
+ });
};
-
+
FileServiceImpl.prototype.writeBlob = function(location, contents, args) {
var headerData = {};
if (args && args.ETag) {
headerData["If-Match"] = args.ETag;
}
-
- if (!contents.type) { // webkit works better with blobs, FF with ArrayBuffers
- var builder = new BlobBuilder();
- if (contents) {
- builder.append(contents);
- }
- contents = builder.getBlob();
- }
return _call2("PUT", location, headerData, contents);
};
-
}
return FileServiceImpl;
Please sign in to comment.
Something went wrong with that request. Please try again.