diff --git a/www/assert/index.html b/www/assert/index.html index f4867629f..eb0bd659f 100644 --- a/www/assert/index.html +++ b/www/assert/index.html @@ -19,6 +19,11 @@ .error { border: 1px solid red; } + .thumb { + max-height: 150px; + width: auto; + border: 3px solid black; + } @@ -36,6 +41,7 @@

"pewpewpew"

+

Test 2

@@ -45,3 +51,6 @@

Here is a macro


+ + + diff --git a/www/assert/main.js b/www/assert/main.js index 7124f58d9..6f924f1b0 100644 --- a/www/assert/main.js +++ b/www/assert/main.js @@ -5,8 +5,9 @@ define([ 'json.sortify', '/common/cryptpad-common.js', '/drive/tests.js', - '/common/test.js' -], function ($, Hyperjson, TextPatcher, Sortify, Cryptpad, Drive, Test) { + '/common/test.js', + '/common/common-thumbnail.js', +], function ($, Hyperjson, TextPatcher, Sortify, Cryptpad, Drive, Test, Thumb) { window.Hyperjson = Hyperjson; window.TextPatcher = TextPatcher; window.Sortify = Sortify; @@ -207,6 +208,31 @@ define([ return cb(true); }, "version 2 hash failed to parse correctly"); + assert(function (cb) { + var getBlob = function (url, cb) { + var xhr = new XMLHttpRequest(); + xhr.open("GET", url, true); + xhr.responseType = "blob"; + xhr.onload = function () { + cb(void 0, this.response); + }; + xhr.send(); + }; + + var $img = $('img#thumb-orig'); + getBlob($img.attr('src'), function (e, blob) { + console.log(e, blob); + Thumb.fromImageBlob(blob, function (e, thumb) { + console.log(thumb); + var th = new Image(); + th.src = URL.createObjectURL(thumb); + th.onload = function () { + $(document.body).append($(th).addClass('thumb')); + cb(th.width === Thumb.dimension && th.height === Thumb.dimension); + }; + }); + }); + }); Drive.test(assert); diff --git a/www/common/common-file.js b/www/common/common-file.js index f22ebdf34..0c3eadd36 100644 --- a/www/common/common-file.js +++ b/www/common/common-file.js @@ -1,12 +1,13 @@ define([ 'jquery', '/file/file-crypto.js', + '/common/common-thumbnail.js', '/bower_components/tweetnacl/nacl-fast.min.js', -], function ($, FileCrypto) { +], function ($, FileCrypto, Thumb) { var Nacl = window.nacl; var module = {}; - var blobToArrayBuffer = function (blob, cb) { + var blobToArrayBuffer = module.blobToArrayBuffer = function (blob, cb) { var reader = new FileReader(); reader.onloadend = function () { cb(void 0, this.result); @@ -263,30 +264,46 @@ define([ var handleFile = File.handleFile = function (file, e, thumbnail) { var thumb; - var finish = function (arrayBuffer) { + var file_arraybuffer; + var finish = function () { var metadata = { name: file.name, type: file.type, }; if (thumb) { metadata.thumbnail = thumb; } queue.push({ - blob: arrayBuffer, + blob: file_arraybuffer, metadata: metadata, dropEvent: e }); }; - var processFile = function () { - blobToArrayBuffer(file, function (e, buffer) { - finish(buffer); - }); - }; - - if (!thumbnail) { return void processFile(); } - blobToArrayBuffer(thumbnail, function (e, buffer) { + blobToArrayBuffer(file, function (e, buffer) { if (e) { console.error(e); } - thumb = arrayBufferToString(buffer); - processFile(); + file_arraybuffer = buffer; + if (thumbnail) { // there is already a thumbnail + return blobToArrayBuffer(thumbnail, function (e, buffer) { + if (e) { console.error(e); } + thumb = arrayBufferToString(buffer); + finish(); + }); + } + + if (!Thumb.isSupportedType(file.type)) { return finish(); } + // make a resized thumbnail from the image.. + Thumb.fromImageBlob(file, function (e, thumb_blob) { + if (e) { console.error(e); } + if (!thumb_blob) { return finish(); } + + blobToArrayBuffer(thumb_blob, function (e, buffer) { + if (e) { + console.error(e); + return finish(); + } + thumb = arrayBufferToString(buffer); + finish(); + }); + }); }); }; diff --git a/www/common/common-thumbnail.js b/www/common/common-thumbnail.js index 0e739699b..5559d8065 100644 --- a/www/common/common-thumbnail.js +++ b/www/common/common-thumbnail.js @@ -3,7 +3,18 @@ define([ ], function () { var Nacl = window.nacl; var Thumb = { - dimension: 150, // thumbnails are all 150px + dimension: 100, + }; + + var supportedTypes = [ + 'image/png', + 'image/jpeg', + 'image/jpg', + 'image/gif', // TODO confirm this is true + ]; + + Thumb.isSupportedType = function (type) { + return supportedTypes.indexOf(type) !== -1; }; // create thumbnail image from metadata @@ -27,22 +38,67 @@ define([ } }; + var getResizedDimensions = function (img) { + var h = img.height; + var w = img.width; + + var dim = Thumb.dimension; + // if the image is too small, don't bother making a thumbnail + if (h <= dim || w <= dim) { return null; } + + // the image is taller than it is wide, so scale to that. + var r = dim / (h > w? h: w); // ratio + + var d; + if (h > w) { + d = Math.floor(((h * r) - dim) / 2); + return { + x1: 0, + x2: dim, + y1: d, + y2: dim + d, + }; + } else { + d = Math.floor(((w * r) - dim) / 2); + return { + x1: d, + x2: dim + d, + y1: 0, + y2: dim, + }; + } + }; + // assumes that your canvas is square // nodeback returning blob - Thumb.fromCanvas = function (canvas, cb) { - canvas = canvas; + Thumb.fromCanvas = Thumb.fromImage = function (canvas, cb) { var c2 = document.createElement('canvas'); - var d = Thumb.dimension; - c2.width = d; - c2.height = 2; + var D = getResizedDimensions(canvas); + if (!D) { return void cb('TOO_SMALL'); } + + c2.width = Thumb.dimension; + c2.height = Thumb.dimension; var ctx = c2.getContext('2d'); - ctx.drawImage(canvas, 0, 0, d, d); + ctx.drawImage(canvas, D.x1, D.y1, D.x2, D.y2); c2.toBlob(function (blob) { cb(void 0, blob); }); }; + Thumb.fromImageBlob = function (blob, cb) { + var url = URL.createObjectURL(blob); + var img = new Image(); + + img.onload = function () { + Thumb.fromImage(img, cb); + }; + img.onerror = function () { + cb('ERROR'); + }; + img.src = url; + }; + Thumb.fromVideo = function (video, cb) { cb = cb; // WIP }; diff --git a/www/common/media-tag.js b/www/common/media-tag.js index 042cb5200..d49ec0557 100644 --- a/www/common/media-tag.js +++ b/www/common/media-tag.js @@ -1 +1 @@ -(function webpackUniversalModuleDefinition(root,factory){if(typeof exports==="object"&&typeof module==="object")module.exports=factory();else if(typeof define==="function"&&define.amd)define([],factory);else if(typeof exports==="object")exports["MediaTag"]=factory();else root["MediaTag"]=factory()})(this,function(){return function(modules){var installedModules={};function __webpack_require__(moduleId){if(installedModules[moduleId]){return installedModules[moduleId].exports}var module=installedModules[moduleId]={i:moduleId,l:false,exports:{}};modules[moduleId].call(module.exports,module,module.exports,__webpack_require__);module.l=true;return module.exports}__webpack_require__.m=modules;__webpack_require__.c=installedModules;__webpack_require__.d=function(exports,name,getter){if(!__webpack_require__.o(exports,name)){Object.defineProperty(exports,name,{configurable:false,enumerable:true,get:getter})}};__webpack_require__.n=function(module){var getter=module&&module.__esModule?function getDefault(){return module["default"]}:function getModuleExports(){return module};__webpack_require__.d(getter,"a",getter);return getter};__webpack_require__.o=function(object,property){return Object.prototype.hasOwnProperty.call(object,property)};__webpack_require__.p="";return __webpack_require__(__webpack_require__.s=63)}([function(module,exports,__webpack_require__){"use strict";var Identifier={IMAGE:"image",AUDIO:"audio",VIDEO:"video",PDF:"pdf",DASH:"dash",DOWNLOAD:"download",CRYPTO:"crypto",CLEAR_KEY:"clear-key",MEDIA_OBJECT:"media-object"};module.exports=Identifier},function(module,exports,__webpack_require__){"use strict";var Type={MATCHER:"matcher",RENDERER:"renderer",FILTER:"filter",SANITIZER:"sanitizer"};module.exports=Type},function(module,exports,__webpack_require__){"use strict";var ProcessingEngine=__webpack_require__(31);var MatchingEngine=__webpack_require__(33);var PluginStore=__webpack_require__(34);var UriStore=__webpack_require__(35);var MediaTag=__webpack_require__(36);function MediaTagAPI(elements){if(elements instanceof Array){var mediaObjects=[];elements.forEach(function(element){if(element.mediaObject){mediaObjects.push(element.mediaObject)}else{var _mediaTag=new MediaTag(element,MediaTagAPI.processingEngine);_mediaTag.mediaObjects.forEach(function(mediaObject){mediaObjects.push(MediaTagAPI.processingEngine.start(mediaObject))})}});return mediaObjects}var element=elements;var mediaTag=new MediaTag(element,MediaTagAPI.processingEngine);mediaTag.mediaObjects.forEach(function(mediaObject){MediaTagAPI.processingEngine.start(mediaObject)})}MediaTagAPI.pluginStore=MediaTagAPI.pluginStore||new PluginStore;MediaTagAPI.uriStore=MediaTagAPI.uriStore||new UriStore("../plugins");MediaTagAPI.processingEngine=MediaTagAPI.processingEngine||new ProcessingEngine(MediaTagAPI.pluginStore);MediaTagAPI.matchingEngine=MediaTagAPI.matchingEngine||new MatchingEngine(MediaTagAPI.pluginStore,MediaTagAPI.uriStore);MediaTagAPI.loadingEngine=null;module.exports=MediaTagAPI},function(module,exports,__webpack_require__){"use strict";var _createClass=function(){function defineProperties(target,props){for(var i=0;i=0){CryptoFilter.mediaTypes.splice(index,1)}};CryptoFilter.removeAllAllowedMediaTypes=function(mediaTypes){mediaTypes.forEach(function(mediaType){CryptoFilter.removeAllowedMediaType(mediaType)})};CryptoFilter.isAllowedMediaType=function(mediaType){return CryptoFilter.mediaTypes.some(function(type){return type===mediaType})};module.exports=CryptoFilter},function(module,exports,__webpack_require__){"use strict";var _createClass=function(){function defineProperties(target,props){for(var i=0;i0}}]);return AttributesObject}();module.exports=AttributesObject},function(module,exports,__webpack_require__){"use strict";function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function")}}function _possibleConstructorReturn(self,call){if(!self){throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}return call&&(typeof call==="object"||typeof call==="function")?call:self}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function, not "+typeof superClass)}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__=superClass}var Errors={PluginExists:function(_Error){_inherits(PluginExists,_Error);function PluginExists(objPlugin){_classCallCheck(this,PluginExists);return _possibleConstructorReturn(this,(PluginExists.__proto__||Object.getPrototypeOf(PluginExists)).call(this,'Plugin with same "'+objPlugin.identifier+'" identifier found.'))}return PluginExists}(Error),TypeNotFound:function(_Error2){_inherits(TypeNotFound,_Error2);function TypeNotFound(){_classCallCheck(this,TypeNotFound);return _possibleConstructorReturn(this,(TypeNotFound.__proto__||Object.getPrototypeOf(TypeNotFound)).call(this,"Media Tag could not find the content type of an instance.}."))}return TypeNotFound}(Error),FilterExists:function(_Error3){_inherits(FilterExists,_Error3);function FilterExists(filter){_classCallCheck(this,FilterExists);return _possibleConstructorReturn(this,(FilterExists.__proto__||Object.getPrototypeOf(FilterExists)).call(this,'Filter with same "'+filter.identifier+' identifier found."'))}return FilterExists}(Error),FetchFail:function(_Error4){_inherits(FetchFail,_Error4);function FetchFail(response){_classCallCheck(this,FetchFail);return _possibleConstructorReturn(this,(FetchFail.__proto__||Object.getPrototypeOf(FetchFail)).call(this,'Could not fetch "'+response.url+'", received "'+response.status+": "+response.statusText+'".'))}return FetchFail}(Error),InvalidCryptoKey:function(_Error5){_inherits(InvalidCryptoKey,_Error5);function InvalidCryptoKey(){_classCallCheck(this,InvalidCryptoKey);return _possibleConstructorReturn(this,(InvalidCryptoKey.__proto__||Object.getPrototypeOf(InvalidCryptoKey)).call(this,"Invalid cryptographic key."))}return InvalidCryptoKey}(Error),InvalidCryptoLib:function(_Error6){_inherits(InvalidCryptoLib,_Error6);function InvalidCryptoLib(){_classCallCheck(this,InvalidCryptoLib);return _possibleConstructorReturn(this,(InvalidCryptoLib.__proto__||Object.getPrototypeOf(InvalidCryptoLib)).call(this,"Invalid cryptographic algorithm name."))}return InvalidCryptoLib}(Error),FailedCrypto:function(_Error7){_inherits(FailedCrypto,_Error7);function FailedCrypto(err){_classCallCheck(this,FailedCrypto);return _possibleConstructorReturn(this,(FailedCrypto.__proto__||Object.getPrototypeOf(FailedCrypto)).call(this,"Failed to decrypt file"+(err&&err.message?" "+err.message:"")+"."))}return FailedCrypto}(Error)};module.exports=Errors},function(module,exports,__webpack_require__){"use strict";var MediaTag=__webpack_require__(21);var ImagePlugin=__webpack_require__(43);var AudioPlugin=__webpack_require__(44);var VideoPlugin=__webpack_require__(45);var PdfPlugin=__webpack_require__(46);var DashPlugin=__webpack_require__(47);var DownloadPlugin=__webpack_require__(48);var CryptoFilter=__webpack_require__(7);var ClearKeyFilter=__webpack_require__(49);var MediaObjectSanitizer=__webpack_require__(50);MediaTag.pluginStore.store(new ImagePlugin);MediaTag.pluginStore.store(new AudioPlugin);MediaTag.pluginStore.store(new VideoPlugin);MediaTag.pluginStore.store(new PdfPlugin);MediaTag.pluginStore.store(new DashPlugin);MediaTag.pluginStore.store(new DownloadPlugin);MediaTag.pluginStore.store(new CryptoFilter);MediaTag.pluginStore.store(new ClearKeyFilter);MediaTag.pluginStore.store(new MediaObjectSanitizer);var Salsa20Poly1305Algorithm=__webpack_require__(51);var CryptpadAlgorithm=__webpack_require__(52);CryptoFilter.functionStore.store("salsa20poly1305",Salsa20Poly1305Algorithm);CryptoFilter.functionStore.store("cryptpad",CryptpadAlgorithm);var defaultPlugin=new DownloadPlugin("

MediaTag cannot find a plugin able to renderer your content

","Download");MediaTag.processingEngine.setDefaultPlugin(defaultPlugin);MediaTag.CryptoFilter=CryptoFilter;var allowedMediaTypes=["image/png","image/jpeg","image/jpg","image/gif","audio/mp3","audio/ogg","audio/wav","audio/webm","video/mp4","video/ogg","video/webm","application/pdf","application/dash+xml","download"];MediaTag.CryptoFilter.setAllowedMediaTypes(allowedMediaTypes);var Configuration=__webpack_require__(53);var Permission=__webpack_require__(14);var Identifier=__webpack_require__(0);var configuration=new Configuration;MediaTag.PdfPlugin=PdfPlugin;MediaTag.PdfPlugin.viewer="/pdfjs/web/viewer.html";MediaTag.processingEngine.configure(configuration);module.exports=MediaTag},function(module,exports,__webpack_require__){"use strict";function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function")}}function _possibleConstructorReturn(self,call){if(!self){throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}return call&&(typeof call==="object"||typeof call==="function")?call:self}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function, not "+typeof superClass)}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__=superClass}var Type=__webpack_require__(1);var Occurrence=__webpack_require__(5);var Plugin=__webpack_require__(6);var Sanitizer=function(_Plugin){_inherits(Sanitizer,_Plugin);function Sanitizer(identifier){_classCallCheck(this,Sanitizer);return _possibleConstructorReturn(this,(Sanitizer.__proto__||Object.getPrototypeOf(Sanitizer)).call(this,identifier,Type.SANITIZER,Occurrence.EVERY))}return Sanitizer}(Plugin);module.exports=Sanitizer},function(module,exports,__webpack_require__){"use strict";var ImageMatcher=__webpack_require__(22);var AudioMatcher=__webpack_require__(23);var VideoMatcher=__webpack_require__(24);var PdfMatcher=__webpack_require__(25);var DashMatcher=__webpack_require__(26);var DownloadMatcher=__webpack_require__(27);var CryptoMatcher=__webpack_require__(28);var ClearKeyMatcher=__webpack_require__(29);var MediaObjectMatcher=__webpack_require__(30);var MediaTag=__webpack_require__(2);MediaTag.pluginStore.store(new ImageMatcher);MediaTag.pluginStore.store(new AudioMatcher);MediaTag.pluginStore.store(new VideoMatcher);MediaTag.pluginStore.store(new PdfMatcher);MediaTag.pluginStore.store(new DashMatcher);MediaTag.pluginStore.store(new DownloadMatcher);MediaTag.pluginStore.store(new CryptoMatcher);MediaTag.pluginStore.store(new ClearKeyMatcher);MediaTag.pluginStore.store(new MediaObjectMatcher);module.exports=MediaTag},function(module,exports,__webpack_require__){"use strict";var _createClass=function(){function defineProperties(target,props){for(var i=0;i=ProcessingEngine.STACK_LIMIT){console.error(this.snapshots[stackId]);throw new Error("Plugin stack size exceed")}if(this.snapshots[stackId].length>=ProcessingEngine.SNAPSHOT_LIMIT){console.error(this.snapshots[stackId]);throw new Error("Plugin snapshots size exceed")}var rendererCount=0;this.stacks[stackId].forEach(function(plugin){if(plugin.type===Type.RENDERER){rendererCount++}});if(rendererCount>1){console.error(this.snapshots[stackId]);throw new Error("More of one renderer in the stack")}if(this.stacks[stackId].length===0&&!this.stats[stackId][Type.RENDERER]){if(!this.defaultPlugin){throw new Error("No default plugin assignated")}this.stacks[stackId].unshift(this.defaultPlugin)}}},{key:"return",value:function _return(mediaObject){var stackId=mediaObject.getId();var plugin=this.unstack(mediaObject);if(!plugin){return}try{if(!this.stats[stackId]){this.stats[stackId]={}}if(this.stats[stackId][plugin.type]){this.stats[stackId][plugin.type]+=1}else{this.stats[stackId][plugin.type]=1}}catch(err){console.error(err,this.snapshots[stackId])}if(this.stacks[stackId].length===0&&plugin.type===Type.RENDERER){this.run(mediaObject)}else if(plugin.type!==Type.SANITIZER){this.fill(mediaObject)}this.snapshot(mediaObject);this.check(mediaObject);this.run(mediaObject)}},{key:"process",value:function process(mediaObject){var stackId=mediaObject.getId();var size=this.stacks[stackId].length;var plugin=this.stacks[stackId][size-1];if(plugin){plugin.process(mediaObject)}else{console.log(this.stacks);throw new Error("Impossible to run a undefined plugin")}}},{key:"isStacked",value:function isStacked(mediaObject,plugin){var stackId=mediaObject.getId();if(this.stacks[stackId]){if(this.stacks[stackId].includes(plugin)){return true}}return false}},{key:"setDefaultPlugin",value:function setDefaultPlugin(plugin){this.defaultPlugin=plugin}}]);return ProcessingEngine}();ProcessingEngine.STACK_LIMIT=100;ProcessingEngine.SNAPSHOT_LIMIT=100;module.exports=ProcessingEngine},function(module,exports,__webpack_require__){"use strict";var _createClass=function(){function defineProperties(target,props){for(var i=0;i0){activate(mediaTag.mediaObjects[index-1],mediaTag)}}},function(module,exports,__webpack_require__){"use strict";var _createClass=function(){function defineProperties(target,props){for(var i=0;i1){return array[0]}return window.location.protocol}},{key:"hostname",value:function hostname(AttributeObject){var array=AttributeObject.getAttribute("src").split("://");if(array.length>1){return array[1].split("/")[0]}return window.location.hostname}},{key:"source",value:function source(AttributeObject){var source=AttributeObject.getAttribute("src");return source}},{key:"schemes",value:function schemes(AttributeObject){return/\w+:/.exec(AttributeObject.getAttribute("src"))}},{key:"sources",value:function sources(AttributeObject){var sources=AttributeObject.getAttribute("sources")||AttributeObject.getAttribute("srcs");if(sources){return JSON.parse(sources)}return null}},{key:"actions",value:function actions(AttributeObject){var actions=AttributeObject.getAttribute("actions");if(actions){return JSON.parse(actions)}return null}},{key:"parse",value:function parse(AttributeObject){return{protocol:Parser.protocol(AttributeObject),hostname:Parser.hostname(AttributeObject),src:Parser.source(AttributeObject),type:Parser.type(AttributeObject),extension:Parser.extension(AttributeObject),mime:Parser.mime(AttributeObject),sources:Parser.sources(AttributeObject),actions:Parser.actions(AttributeObject)}}}]);return Parser}();module.exports=Parser},function(module,exports,__webpack_require__){"use strict";var _createClass=function(){function defineProperties(target,props){for(var i=0;i1){if(PARANOIA){if(typeof N[l]!=="number"){throw new Error("E_UNSAFE_TYPE")}if(N[l]>255){throw new Error("E_OUT_OF_BOUNDS")}}if(N[l]!==255){return void N[l]++}N[l]=0;if(l===0){throw new Error("E_NONCE_TOO_LARGE")}}}},{key:"encodePrefix",value:function encodePrefix(p){return[65280,255].map(function(n,i){return(p&n)>>(1-i)*8})}},{key:"decodePrefix",value:function decodePrefix(A){return A[0]<<8|A[1]}},{key:"joinChunks",value:function joinChunks(chunks){return new Blob(chunks)}},{key:"slice",value:function slice(u8){return Array.prototype.slice.call(u8)}},{key:"getRandomKeyStr",value:function getRandomKeyStr(){var Nacl=window.nacl;var rdm=Nacl.randomBytes(18);return Nacl.util.encodeBase64(rdm)}},{key:"getKeyFromStr",value:function getKeyFromStr(str){return window.nacl.util.decodeBase64(str)}},{key:"encrypt",value:function encrypt(){}},{key:"decrypt",value:function decrypt(u8,key,done){var Nacl=window.nacl;var progress=function progress(offset){var ev=new Event("decryptionProgress");ev.percent=offset/u8.length*100;window.document.dispatchEvent(ev)};var nonce=Cryptopad.createNonce();var i=0;var prefix=u8.subarray(0,2);var metadataLength=Cryptopad.decodePrefix(prefix);var res={metadata:undefined};var metaBox=new Uint8Array(u8.subarray(2,2+metadataLength));var metaChunk=Nacl.secretbox.open(metaBox,nonce,key);Cryptopad.increment(nonce);try{res.metadata=JSON.parse(Nacl.util.encodeUTF8(metaChunk))}catch(e){return done("E_METADATA_DECRYPTION")}if(!res.metadata){return done("NO_METADATA")}var takeChunk=function takeChunk(cb){setTimeout(function(){var start=i*cypherChunkLength+2+metadataLength;var end=start+cypherChunkLength;i++;var box=new Uint8Array(u8.subarray(start,end));var plaintext=Nacl.secretbox.open(box,nonce,key);Cryptopad.increment(nonce);if(!plaintext){return void cb("DECRYPTION_FAILURE")}progress(Math.min(end,u8.length));cb(void 0,plaintext)})};var chunks=[];var again=function again(){takeChunk(function(e,plaintext){if(e){return setTimeout(function(){done(e)})}if(plaintext){if(i*cypherChunkLength=0&&f.mediaTypes.splice(t,1)},f.removeAllAllowedMediaTypes=function(e){e.forEach(function(e){f.removeAllowedMediaType(e)})},f.isAllowedMediaType=function(e){return f.mediaTypes.some(function(t){return t===e})},e.exports=f},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var o=function(){function e(e,t){for(var n=0;n0}}]),e}();e.exports=i},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var u={PluginExists:function(e){function t(e){return r(this,t),o(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,'Plugin with same "'+e.identifier+'" identifier found.'))}return i(t,e),t}(Error),TypeNotFound:function(e){function t(){return r(this,t),o(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,"Media Tag could not find the content type of an instance.}."))}return i(t,e),t}(Error),FilterExists:function(e){function t(e){return r(this,t),o(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,'Filter with same "'+e.identifier+' identifier found."'))}return i(t,e),t}(Error),FetchFail:function(e){function t(e){return r(this,t),o(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,'Could not fetch "'+e.url+'", received "'+e.status+": "+e.statusText+'".'))}return i(t,e),t}(Error),InvalidCryptoKey:function(e){function t(){return r(this,t),o(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,"Invalid cryptographic key."))}return i(t,e),t}(Error),InvalidCryptoLib:function(e){function t(){return r(this,t),o(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,"Invalid cryptographic algorithm name."))}return i(t,e),t}(Error),FailedCrypto:function(e){function t(e){return r(this,t),o(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,"Failed to decrypt file"+(e&&e.message?" "+e.message:"")+"."))}return i(t,e),t}(Error)};e.exports=u},function(e,t,n){"use strict";var r=n(21),o=n(43),i=n(44),u=n(45),a=n(46),c=n(47),s=n(48),f=n(7),l=n(49),p=n(50);r.pluginStore.store(new o),r.pluginStore.store(new i),r.pluginStore.store(new u),r.pluginStore.store(new a),r.pluginStore.store(new c),r.pluginStore.store(new s),r.pluginStore.store(new f),r.pluginStore.store(new l),r.pluginStore.store(new p);var y=n(51),h=n(52);f.functionStore.store("salsa20poly1305",y),f.functionStore.store("cryptpad",h);var b=new s("

MediaTag cannot find a plugin able to renderer your content

","Download");r.processingEngine.setDefaultPlugin(b),r.CryptoFilter=f;var d=["image/png","image/jpeg","image/jpg","image/gif","audio/mp3","audio/ogg","audio/wav","audio/webm","video/mp4","video/ogg","video/webm","application/pdf","application/dash+xml","download"];r.CryptoFilter.setAllowedMediaTypes(d);var v=n(53),g=(n(14),n(0),new v);r.PdfPlugin=a,r.PdfPlugin.viewer="/pdfjs/web/viewer.html",r.processingEngine.configure(g),e.exports=r},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var u=n(1),a=n(5),c=n(6),s=function(e){function t(e){return r(this,t),o(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e,u.SANITIZER,a.EVERY))}return i(t,e),t}(c);e.exports=s},function(e,t,n){"use strict";var r=n(22),o=n(23),i=n(24),u=n(25),a=n(26),c=n(27),s=n(28),f=n(29),l=n(30),p=n(2);p.pluginStore.store(new r),p.pluginStore.store(new o),p.pluginStore.store(new i),p.pluginStore.store(new u),p.pluginStore.store(new a),p.pluginStore.store(new c),p.pluginStore.store(new s),p.pluginStore.store(new f),p.pluginStore.store(new l),e.exports=p},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var u=function(){function e(e,t){for(var n=0;n=e.STACK_LIMIT)throw console.error(this.snapshots[n]),new Error("Plugin stack size exceed");if(this.snapshots[n].length>=e.SNAPSHOT_LIMIT)throw console.error(this.snapshots[n]),new Error("Plugin snapshots size exceed");var r=0;if(this.stacks[n].forEach(function(e){e.type===a.RENDERER&&r++}),r>1)throw console.error(this.snapshots[n]),new Error("More of one renderer in the stack");if(0===this.stacks[n].length&&!this.stats[n][a.RENDERER]){if(!this.defaultPlugin)throw new Error("No default plugin assignated");this.stacks[n].unshift(this.defaultPlugin)}}},{key:"return",value:function(e){var t=e.getId(),n=this.unstack(e);if(n){try{this.stats[t]||(this.stats[t]={}),this.stats[t][n.type]?this.stats[t][n.type]+=1:this.stats[t][n.type]=1}catch(e){console.error(e,this.snapshots[t])}0===this.stacks[t].length&&n.type===a.RENDERER?this.run(e):n.type!==a.SANITIZER&&this.fill(e),this.snapshot(e),this.check(e),this.run(e)}}},{key:"process",value:function(e){var t=e.getId(),n=this.stacks[t].length,r=this.stacks[t][n-1];if(!r)throw console.log(this.stacks),new Error("Impossible to run a undefined plugin");r.process(e)}},{key:"isStacked",value:function(e,t){var n=e.getId();return!(!this.stacks[n]||!this.stacks[n].includes(t))}},{key:"setDefaultPlugin",value:function(e){this.defaultPlugin=e}}]),e}();f.STACK_LIMIT=100,f.SNAPSHOT_LIMIT=100,e.exports=f},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var o=function(){function e(e,t){for(var n=0;n0&&r(e.mediaObjects[t-1],e)}},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var o=function(){function e(e,t){for(var n=0;n1?t[0]:window.location.protocol}},{key:"hostname",value:function(e){var t=e.getAttribute("src").split("://");return t.length>1?t[1].split("/")[0]:window.location.hostname}},{key:"source",value:function(e){return e.getAttribute("src")}},{key:"schemes",value:function(e){return/\w+:/.exec(e.getAttribute("src"))}},{key:"sources",value:function(e){var t=e.getAttribute("sources")||e.getAttribute("srcs");return t?JSON.parse(t):null}},{key:"actions",value:function(e){var t=e.getAttribute("actions");return t?JSON.parse(t):null}},{key:"parse",value:function(t){return{protocol:e.protocol(t),hostname:e.hostname(t),src:e.source(t),type:e.type(t),extension:e.extension(t),mime:e.mime(t),sources:e.sources(t),actions:e.actions(t)}}}]),e}();e.exports=i},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var u=function(){function e(e,t){for(var n=0;n1;){if("number"!=typeof e[t])throw new Error("E_UNSAFE_TYPE");if(e[t]>255)throw new Error("E_OUT_OF_BOUNDS");if(255!==e[t])return void e[t]++;if(e[t]=0,0===t)throw new Error("E_NONCE_TOO_LARGE")}}},{key:"encodePrefix",value:function(e){return[65280,255].map(function(t,n){return(e&t)>>8*(1-n)})}},{key:"decodePrefix",value:function(e){return e[0]<<8|e[1]}},{key:"joinChunks",value:function(e){return new Blob(e)}},{key:"slice",value:function(e){return Array.prototype.slice.call(e)}},{key:"getRandomKeyStr",value:function(){var e=window.nacl,t=e.randomBytes(18);return e.util.encodeBase64(t)}},{key:"getKeyFromStr",value:function(e){return window.nacl.util.decodeBase64(e)}},{key:"encrypt",value:function(){}},{key:"decrypt",value:function(t,n,r){var o=window.nacl,i=function(e){var n=new Event("decryptionProgress");n.percent=e/t.length*100,console.log(n.percent),window.document.dispatchEvent(n)},u=e.createNonce(),a=0,c=t.subarray(0,2),s=e.decodePrefix(c),f={metadata:void 0},l=new Uint8Array(t.subarray(2,2+s)),p=o.secretbox.open(l,u,n);e.increment(u);try{f.metadata=JSON.parse(o.util.encodeUTF8(p))}catch(e){return r("E_METADATA_DECRYPTION")}if(!f.metadata)return r("NO_METADATA");var y=function(r){setTimeout(function(){var c=131088*a+2+s,f=c+131088;a++;var l=new Uint8Array(t.subarray(c,f)),p=o.secretbox.open(l,u,n);if(e.increment(u),!p)return void r("DECRYPTION_FAILURE");i(Math.min(f,t.length)),r(void 0,p)})},h=[];!function n(){y(function(o,i){return o?setTimeout(function(){r(o)}):i?2+s+131088*a<=t.length?(h.push(i),n()):(h.push(i),f.content=e.joinChunks(h),r(void 0,f)):void r("UNEXPECTED_ENDING")})}()}}]),e}(),l=function(){function e(){r(this,e)}return u(e,null,[{key:"getArrayBuffer",value:function(e){return fetch(e).then(function(e){if(e.ok)return e.arrayBuffer();throw new a.FetchFails}).then(function(e){return e})}},{key:"createUrl",value:function(e){return window.URL.createObjectURL(e)}},{key:"getBlobUrl",value:function(e,t){return window.URL.createObjectURL(new Blob([e],{type:t}))}},{key:"getDataUrl",value:function(e,t){return"data:"+t+";base64,"+window.nacl.util.encodeBase64(e)}}]),e}();e.exports=i},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var o=function(){function e(e,t){for(var n=0;n