Commit 2fddffaf authored by Romain Courteaud's avatar Romain Courteaud

Release Version 3.23.0

Add facebook storage.
Keyless queries are case insensitive (like a fulltext search could be).
parent a00c7056
...@@ -6684,7 +6684,7 @@ return new Parser; ...@@ -6684,7 +6684,7 @@ return new Parser;
} }
return new RegExp("^" + stringEscapeRegexpCharacters(string) return new RegExp("^" + stringEscapeRegexpCharacters(string)
.replace(regexp_percent, '[\\s\\S]*') .replace(regexp_percent, '[\\s\\S]*')
.replace(regexp_underscore, '.') + "$"); .replace(regexp_underscore, '.') + "$", "i");
} }
/** /**
...@@ -13794,95 +13794,117 @@ return new Parser; ...@@ -13794,95 +13794,117 @@ return new Parser;
jIO.addStorage('websql', WebSQLStorage); jIO.addStorage('websql', WebSQLStorage);
}(jIO, RSVP, Blob, openDatabase)); }(jIO, RSVP, Blob, openDatabase));
;/*jslint indent:2,maxlen:80,nomen:true*/ ;/*jslint nomen: true */
/*global jIO, RSVP*/ /*global RSVP, UriTemplate*/
(function (jIO, RSVP) { (function (jIO, RSVP, UriTemplate) {
"use strict"; "use strict";
/** var GET_POST_URL = "https://graph.facebook.com/v2.9/{+post_id}" +
* The jIO SafeRepairStorage extension "?fields={+fields}&access_token={+access_token}",
* get_post_template = UriTemplate.parse(GET_POST_URL),
* @class SafeRepairStorage GET_FEED_URL = "https://graph.facebook.com/v2.9/{+user_id}/feed" +
* @constructor "?fields={+fields}&limit={+limit}&since={+since}&access_token=" +
*/ "{+access_token}",
get_feed_template = UriTemplate.parse(GET_FEED_URL);
function SafeRepairStorage(spec) { function FBStorage(spec) {
this._sub_storage = jIO.createJIO(spec.sub_storage); if (typeof spec.access_token !== 'string' || !spec.access_token) {
this._id_dict = {}; throw new TypeError("Access Token must be a string " +
"which contains more than one character.");
} }
if (typeof spec.user_id !== 'string' || !spec.user_id) {
SafeRepairStorage.prototype.get = function () { throw new TypeError("User ID must be a string " +
return this._sub_storage.get.apply(this._sub_storage, arguments); "which contains more than one character.");
};
SafeRepairStorage.prototype.allAttachments = function () {
return this._sub_storage.allAttachments.apply(this._sub_storage, arguments);
};
SafeRepairStorage.prototype.post = function () {
return this._sub_storage.post.apply(this._sub_storage, arguments);
};
SafeRepairStorage.prototype.put = function (id, doc) {
var storage = this;
return this._sub_storage.put.apply(this._sub_storage, arguments)
.push(undefined, function (error) {
if (error instanceof jIO.util.jIOError &&
error.status_code === 403) {
if (storage._id_dict[id]) {
return storage._sub_storage.put(storage._id_dict[id], doc);
} }
return storage._sub_storage.post(doc) this._access_token = spec.access_token;
.push(function (sub_id) { this._user_id = spec.user_id;
storage._id_dict[id] = sub_id; this._default_field_list = spec.default_field_list || [];
return sub_id; this._default_limit = spec.default_limit || 500;
});
} }
FBStorage.prototype.get = function (id) {
var that = this;
return new RSVP.Queue()
.push(function () {
return jIO.util.ajax({
type: "GET",
url: get_post_template.expand({post_id: id,
fields: that._default_field_list, access_token: that._access_token})
});
})
.push(function (result) {
return JSON.parse(result.target.responseText);
}); });
}; };
SafeRepairStorage.prototype.remove = function () {
return; function paginateResult(url, result, select_list) {
};
SafeRepairStorage.prototype.getAttachment = function () {
return this._sub_storage.getAttachment.apply(this._sub_storage, arguments);
};
SafeRepairStorage.prototype.putAttachment = function (id, attachment_id,
attachment) {
var storage = this;
return this._sub_storage.putAttachment.apply(this._sub_storage, arguments)
.push(undefined, function (error) {
if (error instanceof jIO.util.jIOError &&
error.status_code === 403) {
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
if (storage._id_dict[id]) { return jIO.util.ajax({
return storage._id_dict[id]; type: "GET",
} url: url
return storage._sub_storage.get(id)
.push(function (doc) {
return storage._sub_storage.post(doc);
}); });
}) })
.push(function (sub_id) { .push(function (response) {
storage._id_dict[id] = sub_id; return JSON.parse(response.target.responseText);
return storage._sub_storage.putAttachment(sub_id, attachment_id, },
attachment); function (err) {
}); throw new jIO.util.jIOError("Getting feed failed " + err.toString(),
err.target.status);
})
.push(function (response) {
if (response.data.length === 0) {
return result;
}
var i, j, obj = {};
for (i = 0; i < response.data.length; i += 1) {
obj.id = response.data[i].id;
obj.value = {};
for (j = 0; j < select_list.length; j += 1) {
obj.value[select_list[j]] = response.data[i][select_list[j]];
}
result.push(obj);
obj = {};
} }
return paginateResult(response.paging.next, result, select_list);
}); });
}
FBStorage.prototype.buildQuery = function (query) {
var that = this, fields = [], limit = this._default_limit,
template_argument = {
user_id: this._user_id,
limit: limit,
access_token: this._access_token
}; };
SafeRepairStorage.prototype.removeAttachment = function () { if (query.include_docs) {
return; fields = fields.concat(that._default_field_list);
}; }
SafeRepairStorage.prototype.repair = function () { if (query.select_list) {
return this._sub_storage.repair.apply(this._sub_storage, arguments); fields = fields.concat(query.select_list);
}; }
SafeRepairStorage.prototype.hasCapacity = function (name) { if (query.limit) {
return this._sub_storage.hasCapacity(name); limit = query.limit[1];
}
template_argument.fields = fields;
template_argument.limit = limit;
return paginateResult(get_feed_template.expand(template_argument), [],
fields)
.push(function (result) {
if (!query.limit) {
return result;
}
return result.slice(query.limit[0], query.limit[1]);
});
}; };
SafeRepairStorage.prototype.buildQuery = function () {
return this._sub_storage.buildQuery.apply(this._sub_storage, FBStorage.prototype.hasCapacity = function (name) {
arguments); var this_storage_capacity_list = ["list", "select", "include", "limit"];
if (this_storage_capacity_list.indexOf(name) !== -1) {
return true;
}
}; };
jIO.addStorage('saferepair', SafeRepairStorage); jIO.addStorage('facebook', FBStorage);
}(jIO, RSVP)); }(jIO, RSVP, UriTemplate));
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
{ {
"name": "jio", "name": "jio",
"version": "v3.22.0", "version": "v3.23.0",
"license": "LGPLv3", "license": "LGPLv3",
"author": "Nexedi SA", "author": "Nexedi SA",
"contributors": [ "contributors": [
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment