Merge branch 'code2' of github.com:xwiki-labs/cryptpad into code2
This commit is contained in:
commit
db86a2dbee
6 files changed
+133
-25
No files matched your search
+31
-14
@@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
@@ -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<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor)}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor}}();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 Matcher=function(_Plugin){_inherits(Matcher,_Plugin);function Matcher(identifier,targetType){_classCallCheck(this,Matcher);var _this=_possibleConstructorReturn(this,(Matcher.__proto__||Object.getPrototypeOf(Matcher)).call(this,identifier,Type.MATCHER,Occurrence.ANY));_this.targetType=targetType;return _this}_createClass(Matcher,[{key:"getTargetType",value:function getTargetType(){return this.targetType}}]);return Matcher}(Plugin);module.exports=Matcher},function(module,exports,__webpack_require__){"use stricLine truncated
|
||||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.MediaTag=t():e.MediaTag=t()}(this,function(){return function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var n={};return t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=63)}([function(e,t,n){"use strict";var r={IMAGE:"image",AUDIO:"audio",VIDEO:"video",PDF:"pdf",DASH:"dash",DOWNLOAD:"download",CRYPTO:"crypto",CLEAR_KEY:"clear-key",MEDIA_OBJECT:"media-object"};e.exports=r},function(e,t,n){"use strict";var r={MATCHER:"matcher",RENDERER:"renderer",FILTER:"filter",SANITIZER:"sanitizer"};e.exports=r},function(e,t,n){"use strict";function r(e){if(e instanceof Array){var t=[];return e.forEach(function(e){if(e.mediaObject)t.push(e.mediaObject);else{new c(e,r.processingEngine).mediaObjects.forEach(function(e){t.push(r.processingEngine.start(e))})}}),t}new c(e,r.processingEngine).mediaObjects.forEach(function(e){r.processingEngine.start(e)})}var o=n(31),i=n(33),u=n(34),a=n(35),c=n(36);r.pluginStore=r.pluginStore||new u,r.uriStore=r.uriStore||new a("../plugins"),r.processingEngine=r.processingEngine||new o(r.pluginStore),r.matchingEngine=r.matchingEngine||new i(r.pluginStore,r.uriStore),r.loadingEngine=null,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=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),a=n(1),c=n(5),s=n(6),f=function(e){function t(e,n){r(this,t);var i=o(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e,a.MATCHER,c.ANY));return i.targetType=n,i}return i(t,e),u(t,[{key:"getTargetType",value:function(){return this.targetType}}]),t}(s);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")}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.RENDERER,a.ONCE))}return i(t,e),t}(c);e.exports=s},function(e,t,n){"use strict";var r={EVERY:"every",ANY:"any",ONCE:"once"};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")}var o=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),i=function(){function e(t,n,o){r(this,e),this.identifier=t,this.type=n,this.occurrence=o}return o(e,[{key:"getIdentifier",value:function(){if(this.identifier)return this.identifier;throw new Error("Plugin has not identifier")}},{key:"getType",value:function(){if(this.type)return this.type;throw new Error("Plugin has no type")}},{key:"start",value:function(e){return this.process(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")}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.__pLine truncated
|
||||
Reference in new issue
Block a user