Commit cfea757e authored by Romain Courteaud's avatar Romain Courteaud

Release version 3.3.0

parent 30571aa6
...@@ -1025,6 +1025,507 @@ var UriTemplate = (function () { ...@@ -1025,6 +1025,507 @@ var UriTemplate = (function () {
} }
} }
)); ));
;// Copyright (c) 2013 Pieroxy <pieroxy@pieroxy.net>
// This work is free. You can redistribute it and/or modify it
// under the terms of the WTFPL, Version 2
// For more information see LICENSE.txt or http://www.wtfpl.net/
//
// For more information, the home page:
// http://pieroxy.net/blog/pages/lz-string/testing.html
//
// LZ-based compression algorithm, version 1.4.4
var LZString = (function() {
// private property
var f = String.fromCharCode;
var keyStrBase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
var keyStrUriSafe = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$";
var baseReverseDic = {};
function getBaseValue(alphabet, character) {
if (!baseReverseDic[alphabet]) {
baseReverseDic[alphabet] = {};
for (var i=0 ; i<alphabet.length ; i++) {
baseReverseDic[alphabet][alphabet.charAt(i)] = i;
}
}
return baseReverseDic[alphabet][character];
}
var LZString = {
compressToBase64 : function (input) {
if (input == null) return "";
var res = LZString._compress(input, 6, function(a){return keyStrBase64.charAt(a);});
switch (res.length % 4) { // To produce valid Base64
default: // When could this happen ?
case 0 : return res;
case 1 : return res+"===";
case 2 : return res+"==";
case 3 : return res+"=";
}
},
decompressFromBase64 : function (input) {
if (input == null) return "";
if (input == "") return null;
return LZString._decompress(input.length, 32, function(index) { return getBaseValue(keyStrBase64, input.charAt(index)); });
},
compressToUTF16 : function (input) {
if (input == null) return "";
return LZString._compress(input, 15, function(a){return f(a+32);}) + " ";
},
decompressFromUTF16: function (compressed) {
if (compressed == null) return "";
if (compressed == "") return null;
return LZString._decompress(compressed.length, 16384, function(index) { return compressed.charCodeAt(index) - 32; });
},
//compress into uint8array (UCS-2 big endian format)
compressToUint8Array: function (uncompressed) {
var compressed = LZString.compress(uncompressed);
var buf=new Uint8Array(compressed.length*2); // 2 bytes per character
for (var i=0, TotalLen=compressed.length; i<TotalLen; i++) {
var current_value = compressed.charCodeAt(i);
buf[i*2] = current_value >>> 8;
buf[i*2+1] = current_value % 256;
}
return buf;
},
//decompress from uint8array (UCS-2 big endian format)
decompressFromUint8Array:function (compressed) {
if (compressed===null || compressed===undefined){
return LZString.decompress(compressed);
} else {
var buf=new Array(compressed.length/2); // 2 bytes per character
for (var i=0, TotalLen=buf.length; i<TotalLen; i++) {
buf[i]=compressed[i*2]*256+compressed[i*2+1];
}
var result = [];
buf.forEach(function (c) {
result.push(f(c));
});
return LZString.decompress(result.join(''));
}
},
//compress into a string that is already URI encoded
compressToEncodedURIComponent: function (input) {
if (input == null) return "";
return LZString._compress(input, 6, function(a){return keyStrUriSafe.charAt(a);});
},
//decompress from an output of compressToEncodedURIComponent
decompressFromEncodedURIComponent:function (input) {
if (input == null) return "";
if (input == "") return null;
input = input.replace(/ /g, "+");
return LZString._decompress(input.length, 32, function(index) { return getBaseValue(keyStrUriSafe, input.charAt(index)); });
},
compress: function (uncompressed) {
return LZString._compress(uncompressed, 16, function(a){return f(a);});
},
_compress: function (uncompressed, bitsPerChar, getCharFromInt) {
if (uncompressed == null) return "";
var i, value,
context_dictionary= {},
context_dictionaryToCreate= {},
context_c="",
context_wc="",
context_w="",
context_enlargeIn= 2, // Compensate for the first entry which should not count
context_dictSize= 3,
context_numBits= 2,
context_data=[],
context_data_val=0,
context_data_position=0,
ii;
for (ii = 0; ii < uncompressed.length; ii += 1) {
context_c = uncompressed.charAt(ii);
if (!Object.prototype.hasOwnProperty.call(context_dictionary,context_c)) {
context_dictionary[context_c] = context_dictSize++;
context_dictionaryToCreate[context_c] = true;
}
context_wc = context_w + context_c;
if (Object.prototype.hasOwnProperty.call(context_dictionary,context_wc)) {
context_w = context_wc;
} else {
if (Object.prototype.hasOwnProperty.call(context_dictionaryToCreate,context_w)) {
if (context_w.charCodeAt(0)<256) {
for (i=0 ; i<context_numBits ; i++) {
context_data_val = (context_data_val << 1);
if (context_data_position == bitsPerChar-1) {
context_data_position = 0;
context_data.push(getCharFromInt(context_data_val));
context_data_val = 0;
} else {
context_data_position++;
}
}
value = context_w.charCodeAt(0);
for (i=0 ; i<8 ; i++) {
context_data_val = (context_data_val << 1) | (value&1);
if (context_data_position == bitsPerChar-1) {
context_data_position = 0;
context_data.push(getCharFromInt(context_data_val));
context_data_val = 0;
} else {
context_data_position++;
}
value = value >> 1;
}
} else {
value = 1;
for (i=0 ; i<context_numBits ; i++) {
context_data_val = (context_data_val << 1) | value;
if (context_data_position ==bitsPerChar-1) {
context_data_position = 0;
context_data.push(getCharFromInt(context_data_val));
context_data_val = 0;
} else {
context_data_position++;
}
value = 0;
}
value = context_w.charCodeAt(0);
for (i=0 ; i<16 ; i++) {
context_data_val = (context_data_val << 1) | (value&1);
if (context_data_position == bitsPerChar-1) {
context_data_position = 0;
context_data.push(getCharFromInt(context_data_val));
context_data_val = 0;
} else {
context_data_position++;
}
value = value >> 1;
}
}
context_enlargeIn--;
if (context_enlargeIn == 0) {
context_enlargeIn = Math.pow(2, context_numBits);
context_numBits++;
}
delete context_dictionaryToCreate[context_w];
} else {
value = context_dictionary[context_w];
for (i=0 ; i<context_numBits ; i++) {
context_data_val = (context_data_val << 1) | (value&1);
if (context_data_position == bitsPerChar-1) {
context_data_position = 0;
context_data.push(getCharFromInt(context_data_val));
context_data_val = 0;
} else {
context_data_position++;
}
value = value >> 1;
}
}
context_enlargeIn--;
if (context_enlargeIn == 0) {
context_enlargeIn = Math.pow(2, context_numBits);
context_numBits++;
}
// Add wc to the dictionary.
context_dictionary[context_wc] = context_dictSize++;
context_w = String(context_c);
}
}
// Output the code for w.
if (context_w !== "") {
if (Object.prototype.hasOwnProperty.call(context_dictionaryToCreate,context_w)) {
if (context_w.charCodeAt(0)<256) {
for (i=0 ; i<context_numBits ; i++) {
context_data_val = (context_data_val << 1);
if (context_data_position == bitsPerChar-1) {
context_data_position = 0;
context_data.push(getCharFromInt(context_data_val));
context_data_val = 0;
} else {
context_data_position++;
}
}
value = context_w.charCodeAt(0);
for (i=0 ; i<8 ; i++) {
context_data_val = (context_data_val << 1) | (value&1);
if (context_data_position == bitsPerChar-1) {
context_data_position = 0;
context_data.push(getCharFromInt(context_data_val));
context_data_val = 0;
} else {
context_data_position++;
}
value = value >> 1;
}
} else {
value = 1;
for (i=0 ; i<context_numBits ; i++) {
context_data_val = (context_data_val << 1) | value;
if (context_data_position == bitsPerChar-1) {
context_data_position = 0;
context_data.push(getCharFromInt(context_data_val));
context_data_val = 0;
} else {
context_data_position++;
}
value = 0;
}
value = context_w.charCodeAt(0);
for (i=0 ; i<16 ; i++) {
context_data_val = (context_data_val << 1) | (value&1);
if (context_data_position == bitsPerChar-1) {
context_data_position = 0;
context_data.push(getCharFromInt(context_data_val));
context_data_val = 0;
} else {
context_data_position++;
}
value = value >> 1;
}
}
context_enlargeIn--;
if (context_enlargeIn == 0) {
context_enlargeIn = Math.pow(2, context_numBits);
context_numBits++;
}
delete context_dictionaryToCreate[context_w];
} else {
value = context_dictionary[context_w];
for (i=0 ; i<context_numBits ; i++) {
context_data_val = (context_data_val << 1) | (value&1);
if (context_data_position == bitsPerChar-1) {
context_data_position = 0;
context_data.push(getCharFromInt(context_data_val));
context_data_val = 0;
} else {
context_data_position++;
}
value = value >> 1;
}
}
context_enlargeIn--;
if (context_enlargeIn == 0) {
context_enlargeIn = Math.pow(2, context_numBits);
context_numBits++;
}
}
// Mark the end of the stream
value = 2;
for (i=0 ; i<context_numBits ; i++) {
context_data_val = (context_data_val << 1) | (value&1);
if (context_data_position == bitsPerChar-1) {
context_data_position = 0;
context_data.push(getCharFromInt(context_data_val));
context_data_val = 0;
} else {
context_data_position++;
}
value = value >> 1;
}
// Flush the last char
while (true) {
context_data_val = (context_data_val << 1);
if (context_data_position == bitsPerChar-1) {
context_data.push(getCharFromInt(context_data_val));
break;
}
else context_data_position++;
}
return context_data.join('');
},
decompress: function (compressed) {
if (compressed == null) return "";
if (compressed == "") return null;
return LZString._decompress(compressed.length, 32768, function(index) { return compressed.charCodeAt(index); });
},
_decompress: function (length, resetValue, getNextValue) {
var dictionary = [],
next,
enlargeIn = 4,
dictSize = 4,
numBits = 3,
entry = "",
result = [],
i,
w,
bits, resb, maxpower, power,
c,
data = {val:getNextValue(0), position:resetValue, index:1};
for (i = 0; i < 3; i += 1) {
dictionary[i] = i;
}
bits = 0;
maxpower = Math.pow(2,2);
power=1;
while (power!=maxpower) {
resb = data.val & data.position;
data.position >>= 1;
if (data.position == 0) {
data.position = resetValue;
data.val = getNextValue(data.index++);
}
bits |= (resb>0 ? 1 : 0) * power;
power <<= 1;
}
switch (next = bits) {
case 0:
bits = 0;
maxpower = Math.pow(2,8);
power=1;
while (power!=maxpower) {
resb = data.val & data.position;
data.position >>= 1;
if (data.position == 0) {
data.position = resetValue;
data.val = getNextValue(data.index++);
}
bits |= (resb>0 ? 1 : 0) * power;
power <<= 1;
}
c = f(bits);
break;
case 1:
bits = 0;
maxpower = Math.pow(2,16);
power=1;
while (power!=maxpower) {
resb = data.val & data.position;
data.position >>= 1;
if (data.position == 0) {
data.position = resetValue;
data.val = getNextValue(data.index++);
}
bits |= (resb>0 ? 1 : 0) * power;
power <<= 1;
}
c = f(bits);
break;
case 2:
return "";
}
dictionary[3] = c;
w = c;
result.push(c);
while (true) {
if (data.index > length) {
return "";
}
bits = 0;
maxpower = Math.pow(2,numBits);
power=1;
while (power!=maxpower) {
resb = data.val & data.position;
data.position >>= 1;
if (data.position == 0) {
data.position = resetValue;
data.val = getNextValue(data.index++);
}
bits |= (resb>0 ? 1 : 0) * power;
power <<= 1;
}
switch (c = bits) {
case 0:
bits = 0;
maxpower = Math.pow(2,8);
power=1;
while (power!=maxpower) {
resb = data.val & data.position;
data.position >>= 1;
if (data.position == 0) {
data.position = resetValue;
data.val = getNextValue(data.index++);
}
bits |= (resb>0 ? 1 : 0) * power;
power <<= 1;
}
dictionary[dictSize++] = f(bits);
c = dictSize-1;
enlargeIn--;
break;
case 1:
bits = 0;
maxpower = Math.pow(2,16);
power=1;
while (power!=maxpower) {
resb = data.val & data.position;
data.position >>= 1;
if (data.position == 0) {
data.position = resetValue;
data.val = getNextValue(data.index++);
}
bits |= (resb>0 ? 1 : 0) * power;
power <<= 1;
}
dictionary[dictSize++] = f(bits);
c = dictSize-1;
enlargeIn--;
break;
case 2:
return result.join('');
}
if (enlargeIn == 0) {
enlargeIn = Math.pow(2, numBits);
numBits++;
}
if (dictionary[c]) {
entry = dictionary[c];
} else {
if (c === dictSize) {
entry = w + w.charAt(0);
} else {
return null;
}
}
result.push(entry);
// Add w+entry[0] to the dictionary.
dictionary[dictSize++] = w + entry.charAt(0);
enlargeIn--;
w = entry;
if (enlargeIn == 0) {
enlargeIn = Math.pow(2, numBits);
numBits++;
}
}
}
};
return LZString;
})();
if (typeof define === 'function' && define.amd) {
define(function () { return LZString; });
} else if( typeof module !== 'undefined' && module != null ) {
module.exports = LZString
}
;//! moment.js ;//! moment.js
//! version : 2.5.0 //! version : 2.5.0
//! authors : Tim Wood, Iskren Chernev, Moment.js contributors //! authors : Tim Wood, Iskren Chernev, Moment.js contributors
...@@ -5376,9 +5877,10 @@ Query.searchTextToRegExp = searchTextToRegExp; ...@@ -5376,9 +5877,10 @@ Query.searchTextToRegExp = searchTextToRegExp;
MSEC: MSEC MSEC: MSEC
}; };
}(window, moment)); }(window, moment));
;/*global window, RSVP, Blob, XMLHttpRequest, QueryFactory, Query, FileReader */ ;/*global window, RSVP, Blob, XMLHttpRequest, QueryFactory, Query, atob,
(function (window, RSVP, Blob, QueryFactory, Query, FileReader, ArrayBuffer, Uint8Array */
FileReader) { (function (window, RSVP, Blob, QueryFactory, Query, atob,
FileReader, ArrayBuffer, Uint8Array) {
"use strict"; "use strict";
var util = {}, var util = {},
...@@ -5551,6 +6053,25 @@ Query.searchTextToRegExp = searchTextToRegExp; ...@@ -5551,6 +6053,25 @@ Query.searchTextToRegExp = searchTextToRegExp;
} }
util.readBlobAsDataURL = readBlobAsDataURL; util.readBlobAsDataURL = readBlobAsDataURL;
// https://gist.github.com/davoclavo/4424731
function dataURItoBlob(dataURI) {
// convert base64 to raw binary data held in a string
var byteString = atob(dataURI.split(',')[1]),
// separate out the mime component
mimeString = dataURI.split(',')[0].split(':')[1],
// write the bytes of the string to an ArrayBuffer
arrayBuffer = new ArrayBuffer(byteString.length),
_ia = new Uint8Array(arrayBuffer),
i;
mimeString = mimeString.slice(0, mimeString.length - ";base64".length);
for (i = 0; i < byteString.length; i += 1) {
_ia[i] = byteString.charCodeAt(i);
}
return new Blob([arrayBuffer], {type: mimeString});
}
util.dataURItoBlob = dataURItoBlob;
// tools // tools
function checkId(argument_list, storage, method_name) { function checkId(argument_list, storage, method_name) {
if (typeof argument_list[0] !== 'string' || argument_list[0] === '') { if (typeof argument_list[0] !== 'string' || argument_list[0] === '') {
...@@ -5893,7 +6414,8 @@ Query.searchTextToRegExp = searchTextToRegExp; ...@@ -5893,7 +6414,8 @@ Query.searchTextToRegExp = searchTextToRegExp;
jIO = new JioBuilder(); jIO = new JioBuilder();
window.jIO = jIO; window.jIO = jIO;
}(window, RSVP, Blob, QueryFactory, Query, FileReader)); }(window, RSVP, Blob, QueryFactory, Query, atob,
FileReader, ArrayBuffer, Uint8Array));
;/* ;/*
* Rusha, a JavaScript implementation of the Secure Hash Algorithm, SHA-1, * Rusha, a JavaScript implementation of the Secure Hash Algorithm, SHA-1,
* as defined in FIPS PUB 180-1, tuned for high performance with large inputs. * as defined in FIPS PUB 180-1, tuned for high performance with large inputs.
...@@ -7125,8 +7647,7 @@ Query.searchTextToRegExp = searchTextToRegExp; ...@@ -7125,8 +7647,7 @@ Query.searchTextToRegExp = searchTextToRegExp;
*/ */
/*jslint nomen: true*/ /*jslint nomen: true*/
/*global jIO, sessionStorage, localStorage, Blob, RSVP, atob, /*global jIO, sessionStorage, localStorage, RSVP */
ArrayBuffer, Uint8Array*/
/** /**
* JIO Local Storage. Type = 'local'. * JIO Local Storage. Type = 'local'.
...@@ -7142,8 +7663,7 @@ Query.searchTextToRegExp = searchTextToRegExp; ...@@ -7142,8 +7663,7 @@ Query.searchTextToRegExp = searchTextToRegExp;
* @class LocalStorage * @class LocalStorage
*/ */
(function (jIO, sessionStorage, localStorage, Blob, RSVP, (function (jIO, sessionStorage, localStorage, RSVP) {
atob, ArrayBuffer, Uint8Array) {
"use strict"; "use strict";
function LocalStorage(spec) { function LocalStorage(spec) {
...@@ -7180,23 +7700,6 @@ Query.searchTextToRegExp = searchTextToRegExp; ...@@ -7180,23 +7700,6 @@ Query.searchTextToRegExp = searchTextToRegExp;
return attachments; return attachments;
}; };
// https://gist.github.com/davoclavo/4424731
function dataURItoBlob(dataURI) {
// convert base64 to raw binary data held in a string
var byteString = atob(dataURI.split(',')[1]),
// separate out the mime component
mimeString = dataURI.split(',')[0].split(':')[1],
// write the bytes of the string to an ArrayBuffer
arrayBuffer = new ArrayBuffer(byteString.length),
_ia = new Uint8Array(arrayBuffer),
i;
mimeString = mimeString.slice(0, mimeString.length - ";base64".length);
for (i = 0; i < byteString.length; i += 1) {
_ia[i] = byteString.charCodeAt(i);
}
return new Blob([arrayBuffer], {type: mimeString});
}
LocalStorage.prototype.getAttachment = function (id, name) { LocalStorage.prototype.getAttachment = function (id, name) {
restrictDocumentId(id); restrictDocumentId(id);
...@@ -7208,7 +7711,7 @@ Query.searchTextToRegExp = searchTextToRegExp; ...@@ -7208,7 +7711,7 @@ Query.searchTextToRegExp = searchTextToRegExp;
404 404
); );
} }
return dataURItoBlob(textstring); return jIO.util.dataURItoBlob(textstring);
}; };
LocalStorage.prototype.putAttachment = function (id, name, blob) { LocalStorage.prototype.putAttachment = function (id, name, blob) {
...@@ -7245,8 +7748,121 @@ Query.searchTextToRegExp = searchTextToRegExp; ...@@ -7245,8 +7748,121 @@ Query.searchTextToRegExp = searchTextToRegExp;
jIO.addStorage('local', LocalStorage); jIO.addStorage('local', LocalStorage);
}(jIO, sessionStorage, localStorage, Blob, RSVP, }(jIO, sessionStorage, localStorage, RSVP));
atob, ArrayBuffer, Uint8Array)); ;/*jslint nomen: true*/
/*global RSVP, Blob, LZString, DOMException*/
(function (RSVP, Blob, LZString, DOMException) {
"use strict";
/**
* The jIO ZipStorage extension
*
* @class ZipStorage
* @constructor
*/
var MIME_TYPE = "application/x-jio-utf16_lz_string";
function ZipStorage(spec) {
this._sub_storage = jIO.createJIO(spec.sub_storage);
}
ZipStorage.prototype.get = function () {
return this._sub_storage.get.apply(this._sub_storage,
arguments);
};
ZipStorage.prototype.post = function () {
return this._sub_storage.post.apply(this._sub_storage,
arguments);
};
ZipStorage.prototype.put = function () {
return this._sub_storage.put.apply(this._sub_storage,
arguments);
};
ZipStorage.prototype.remove = function () {
return this._sub_storage.remove.apply(this._sub_storage,
arguments);
};
ZipStorage.prototype.hasCapacity = function () {
return this._sub_storage.hasCapacity.apply(this._sub_storage,
arguments);
};
ZipStorage.prototype.buildQuery = function () {
return this._sub_storage.buildQuery.apply(this._sub_storage,
arguments);
};
ZipStorage.prototype.getAttachment = function (id, name) {
var that = this;
return that._sub_storage.getAttachment(id, name)
.push(function (blob) {
if (blob.type !== MIME_TYPE) {
return blob;
}
return new RSVP.Queue()
.push(function () {
return jIO.util.readBlobAsText(blob, 'utf16');
})
.push(function (evt) {
var result =
LZString.decompressFromUTF16(evt.target.result);
if (result === '') {
return blob;
}
try {
return jIO.util.dataURItoBlob(
result
);
} catch (error) {
if (error instanceof DOMException) {
return blob;
}
throw error;
}
});
});
};
function myEndsWith(str, query) {
return (str.indexOf(query) === str.length - query.length);
}
ZipStorage.prototype.putAttachment = function (id, name, blob) {
var that = this;
if ((blob.type.indexOf("text/") === 0) || myEndsWith(blob.type, "xml") ||
myEndsWith(blob.type, "json")) {
return new RSVP.Queue()
.push(function () {
return jIO.util.readBlobAsDataURL(blob);
})
.push(function (data) {
var result = LZString.compressToUTF16(data.target.result);
blob = new Blob([result],
{type: MIME_TYPE});
return that._sub_storage.putAttachment(id, name, blob);
});
}
return this._sub_storage.putAttachment.apply(this._sub_storage,
arguments);
};
ZipStorage.prototype.removeAttachment = function () {
return this._sub_storage.removeAttachment.apply(this._sub_storage,
arguments);
};
ZipStorage.prototype.allAttachments = function () {
return this._sub_storage.allAttachments.apply(this._sub_storage,
arguments);
};
jIO.addStorage('zip', ZipStorage);
}(RSVP, Blob, LZString, DOMException));
;/* ;/*
* Copyright 2013, Nexedi SA * Copyright 2013, Nexedi SA
* Released under the LGPL license. * Released under the LGPL license.
...@@ -7331,15 +7947,26 @@ Query.searchTextToRegExp = searchTextToRegExp; ...@@ -7331,15 +7947,26 @@ Query.searchTextToRegExp = searchTextToRegExp;
} }
DavStorage.prototype.put = function (id, param) { DavStorage.prototype.put = function (id, param) {
var that = this;
id = restrictDocumentId(id); id = restrictDocumentId(id);
if (Object.getOwnPropertyNames(param).length > 0) { if (Object.getOwnPropertyNames(param).length > 0) {
// Reject if param has some properties // Reject if param has some properties
throw new jIO.util.jIOError("Can not store properties: " + throw new jIO.util.jIOError("Can not store properties: " +
Object.getOwnPropertyNames(param), 400); Object.getOwnPropertyNames(param), 400);
} }
return ajax(this, { return new RSVP.Queue()
.push(function () {
return ajax(that, {
type: "MKCOL", type: "MKCOL",
url: this._url + id url: that._url + id
});
})
.push(undefined, function (err) {
if ((err.target !== undefined) &&
(err.target.status === 405)) {
return;
}
throw err;
}); });
}; };
...@@ -7434,13 +8061,24 @@ Query.searchTextToRegExp = searchTextToRegExp; ...@@ -7434,13 +8061,24 @@ Query.searchTextToRegExp = searchTextToRegExp;
DavStorage.prototype.putAttachment = function (id, name, blob) { DavStorage.prototype.putAttachment = function (id, name, blob) {
var that = this;
id = restrictDocumentId(id); id = restrictDocumentId(id);
restrictAttachmentId(name); restrictAttachmentId(name);
return ajax(this, {
return new RSVP.Queue()
.push(function () {
return ajax(that, {
type: "PUT", type: "PUT",
url: this._url + id + name, url: that._url + id + name,
data: blob data: blob
}); });
})
.push(undefined, function (error) {
if (error.target.status === 403) {
throw new jIO.util.jIOError("Cannot access subdocument", 404);
}
throw error;
});
}; };
DavStorage.prototype.getAttachment = function (id, name) { DavStorage.prototype.getAttachment = function (id, name) {
...@@ -8677,8 +9315,8 @@ Query.searchTextToRegExp = searchTextToRegExp; ...@@ -8677,8 +9315,8 @@ Query.searchTextToRegExp = searchTextToRegExp;
}(jIO, RSVP, Blob)); }(jIO, RSVP, Blob));
;/*jslint nomen: true*/ ;/*jslint nomen: true*/
/*global Blob, atob, btoa*/ /*global Blob, atob, btoa, RSVP*/
(function (jIO, Blob, atob, btoa) { (function (jIO, Blob, atob, btoa, RSVP) {
"use strict"; "use strict";
/** /**
...@@ -8690,6 +9328,7 @@ Query.searchTextToRegExp = searchTextToRegExp; ...@@ -8690,6 +9328,7 @@ Query.searchTextToRegExp = searchTextToRegExp;
function DocumentStorage(spec) { function DocumentStorage(spec) {
this._sub_storage = jIO.createJIO(spec.sub_storage); this._sub_storage = jIO.createJIO(spec.sub_storage);
this._document_id = spec.document_id; this._document_id = spec.document_id;
this._repair_attachment = spec.repair_attachment || false;
} }
var DOCUMENT_EXTENSION = ".json", var DOCUMENT_EXTENSION = ".json",
...@@ -8752,17 +9391,100 @@ Query.searchTextToRegExp = searchTextToRegExp; ...@@ -8752,17 +9391,100 @@ Query.searchTextToRegExp = searchTextToRegExp;
}; };
DocumentStorage.prototype.remove = function (id) { DocumentStorage.prototype.remove = function (id) {
return this._sub_storage.removeAttachment( var context = this;
this._document_id, return this.allAttachments(id)
.push(function (result) {
var key,
promise_list = [];
for (key in result) {
if (result.hasOwnProperty(key)) {
promise_list.push(context.removeAttachment(id, key));
}
}
return RSVP.all(promise_list);
})
.push(function () {
return context._sub_storage.removeAttachment(
context._document_id,
getSubAttachmentIdFromParam(id) getSubAttachmentIdFromParam(id)
) );
})
.push(function () { .push(function () {
return id; return id;
}); });
}; };
DocumentStorage.prototype.repair = function () { DocumentStorage.prototype.repair = function () {
return this._sub_storage.repair.apply(this._sub_storage, arguments); var context = this;
return this._sub_storage.repair.apply(this._sub_storage, arguments)
.push(function (result) {
if (context._repair_attachment) {
return context._sub_storage.allAttachments(context._document_id)
.push(function (result_dict) {
var promise_list = [],
id_dict = {},
attachment_dict = {},
id,
attachment,
exec,
key;
for (key in result_dict) {
if (result_dict.hasOwnProperty(key)) {
id = undefined;
attachment = undefined;
if (DOCUMENT_REGEXP.test(key)) {
try {
id = atob(DOCUMENT_REGEXP.exec(key)[1]);
} catch (error) {
// Check if unable to decode base64 data
if (!error instanceof ReferenceError) {
throw error;
}
}
if (id !== undefined) {
id_dict[id] = null;
}
} else if (ATTACHMENT_REGEXP.test(key)) {
exec = ATTACHMENT_REGEXP.exec(key);
try {
id = atob(exec[1]);
attachment = atob(exec[2]);
} catch (error) {
// Check if unable to decode base64 data
if (!error instanceof ReferenceError) {
throw error;
}
}
if (attachment !== undefined) {
if (!id_dict.hasOwnProperty(id)) {
if (!attachment_dict.hasOwnProperty(id)) {
attachment_dict[id] = {};
}
attachment_dict[id][attachment] = null;
}
}
}
}
}
for (id in attachment_dict) {
if (attachment_dict.hasOwnProperty(id)) {
if (!id_dict.hasOwnProperty(id)) {
for (attachment in attachment_dict[id]) {
if (attachment_dict[id].hasOwnProperty(attachment)) {
promise_list.push(context.removeAttachment(
id,
attachment
));
}
}
}
}
}
return RSVP.all(promise_list);
});
}
return result;
});
}; };
DocumentStorage.prototype.hasCapacity = function (capacity) { DocumentStorage.prototype.hasCapacity = function (capacity) {
...@@ -8819,7 +9541,7 @@ Query.searchTextToRegExp = searchTextToRegExp; ...@@ -8819,7 +9541,7 @@ Query.searchTextToRegExp = searchTextToRegExp;
jIO.addStorage('document', DocumentStorage); jIO.addStorage('document', DocumentStorage);
}(jIO, Blob, atob, btoa)); }(jIO, Blob, atob, btoa, RSVP));
;/* ;/*
* Copyright 2014, Nexedi SA * Copyright 2014, Nexedi SA
* Released under the LGPL license. * Released under the LGPL license.
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
{ {
"name": "jio", "name": "jio",
"version": "v3.2.1", "version": "v3.3.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