diff options
Diffstat (limited to 'public/bundle.js')
| -rw-r--r-- | public/bundle.js | 593 |
1 files changed, 559 insertions, 34 deletions
diff --git a/public/bundle.js b/public/bundle.js index b788ccc..a5fe85b 100644 --- a/public/bundle.js +++ b/public/bundle.js @@ -387,7 +387,7 @@ var upload_action = exports.upload_action = function upload_action(type, id, fd) Object.defineProperty(exports, "__esModule", { value: true }); -exports.actions = undefined; +exports.actions = exports.parser = exports.util = undefined; var _crud = __webpack_require__(/*! ./crud.actions */ "./app/client/api/crud.actions.js"); @@ -395,6 +395,10 @@ var _util = __webpack_require__(/*! ./util */ "./app/client/api/util.js"); var util = _interopRequireWildcard(_util); +var _parser = __webpack_require__(/*! ./parser */ "./app/client/api/parser.js"); + +var parser = _interopRequireWildcard(_parser); + function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } /* @@ -410,12 +414,367 @@ so you can do ... folderActions.upload(12, form_data) */ +exports.util = util; +exports.parser = parser; var actions = exports.actions = ['folder', 'file', 'dataset', 'task', 'user'].reduce(function (a, b) { return (a[b] = (0, _crud.crud_actions)(b)) && a; }, {}); /***/ }), +/***/ "./app/client/api/parser.js": +/*!**********************************!*\ + !*** ./app/client/api/parser.js ***! + \**********************************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.tumblr = exports.thumbnail = exports.loadImage = exports.tag = exports.parse = exports.lookup = exports.integrations = undefined; + +var _nodeFetch = __webpack_require__(/*! node-fetch */ "./node_modules/node-fetch/browser.js"); + +var _nodeFetch2 = _interopRequireDefault(_nodeFetch); + +var _fetchJsonp = __webpack_require__(/*! fetch-jsonp */ "./node_modules/fetch-jsonp/build/fetch-jsonp.js"); + +var _fetchJsonp2 = _interopRequireDefault(_fetchJsonp); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +var integrations = exports.integrations = [{ + type: 'image', + regex: /\.(jpeg|jpg|gif|png|svg)(\?.*)?$/i, + fetch: function fetch(url, done) { + var img = new Image(); + img.onload = function () { + if (!img) return; + var width = img.naturalWidth, + height = img.naturalHeight; + img = null; + done({ + url: url, + type: "image", + token: "", + thumbnail: "", + title: "", + width: width, + height: height + }); + }; + img.src = url; + if (img.complete) { + img.onload(); + } + }, + tag: function tag(media) { + return '<img src="' + media.url + '">'; + } +}, { + type: 'video', + regex: /\.(mp4|webm)(\?.*)?$/i, + fetch: function fetch(url, done) { + var video = document.createElement("video"); + var url_parts = url.replace(/\?.*$/, "").split("/"); + var filename = url_parts[url_parts.length - 1]; + video.addEventListener("loadedmetadata", function () { + var width = video.videoWidth, + height = video.videoHeight; + video = null; + done({ + url: url, + type: "video", + token: url, + thumbnail: "/public/assets/img/video-thumbnail.png", + title: filename, + width: width, + height: height + }); + }); + video.src = url; + video.load(); + }, + tag: function tag(media) { + return '<video src="' + media.url + '">'; + } +}, { + type: 'audio', + regex: /\.(wav|mp3)(\?.*)?$/i, + fetch: function fetch(url, done) { + var audio = document.createElement("audio"); + var url_parts = url.replace(/\?.*$/, "").split("/"); + var filename = url_parts[url_parts.length - 1]; + audio.addEventListener("loadedmetadata", function () { + var duration = audio.duration; + audio = null; + done({ + url: url, + type: "audio", + token: url, + thumbnail: "/public/assets/img/audio-thumbnail.png", + title: filename, + duration: duration + }); + }); + audio.src = url; + audio.load(); + }, + tag: function tag(media) { + return '<audio src="' + media.url + '">'; + } +}, { + type: 'youtube', + regex: /(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/ ]{11})/i, + fetch: function fetch(url, done) { + var id = (url.match(/v=([-_a-zA-Z0-9]{11})/i) || url.match(/youtu.be\/([-_a-zA-Z0-9]{11})/i) || url.match(/embed\/([-_a-zA-Z0-9]{11})/i))[1].split('&')[0]; + var thumb = "https://i.ytimg.com/vi/" + id + "/hqdefault.jpg"; + + var jsonp_url = new URL('https://www.googleapis.com/youtube/v3/videos'); + if (data) { + Object.keys({ + id: id, + key: "AIzaSyCaLRGY-hxs92045X-Jew7w1FgQPkStHgc", + part: "id,contentDetails,snippet,status" + }).forEach(function (key) { + return jsonp_url.searchParams.append(key, data[key]); + }); + } + + (0, _fetchJsonp2.default)(jsonp_url).then(function (result) { + return result.json(); + }).then(function (result) { + if (!result || !result.items.length) { + return alert("Sorry, this video URL is invalid."); + } + var res = result.items[0]; + // console.log(res) + + var dd = res.contentDetails.duration.match(/\d+/g).map(function (i) { + return parseInt(i); + }); + var duration = 0; + if (dd.length == 3) { + duration = dd[0] * 60 + dd[1] * 60 + dd[2]; + } else if (dd.length == 2) { + duration = dd[0] * 60 + dd[1]; + } else { + duration = dd[0]; + } + + ["maxres", "high", "medium", "standard", "default"].some(function (t) { + if (res.snippet.thumbnails[t]) { + thumb = res.snippet.thumbnails[t].url; + return true; + } + return false; + }); + + done({ + url: url, + type: "youtube", + token: id, + thumbnail: thumb, + title: res.snippet.title, + duration: duration, + width: 640, + height: 360 + }); + }); + }, + tag: function tag(media) { + // return '<img class="video" type="youtube" vid="'+media.token+'" src="'+media.thumbnail+'"><span class="playvid">▶</span>'; + return '<div class="video" style="width: ' + media.width + 'px; height: ' + media.height + 'px; overflow: hidden; position: relative;"><iframe frameborder="0" scrolling="no" seamless="seamless" webkitallowfullscreen="webkitAllowFullScreen" mozallowfullscreen="mozallowfullscreen" allowfullscreen="allowfullscreen" id="okplayer" width="' + media.width + '" height="' + media.height + '" src="https://youtube.com/embed/' + media.token + '?showinfo=0" style="position: absolute; top: 0px; left: 0px; width: ' + media.width + 'px; height: ' + media.height + 'px;"></iframe></div>'; + } +}, { + type: 'vimeo', + regex: /vimeo.com\/\d+$/i, + fetch: function fetch(url, done) { + var id = url.match(/\d+$/i)[0]; + (0, _nodeFetch2.default)('https://vimeo.com/api/v2/video/' + id + '.json').then(function (result) { + return result.json(); + }).then(function (result) { + if (result.length == 0) { + return done(id, "", 640, 360); + } + var res = result[0]; + if (res.embed_privacy != "anywhere") { + alert("Sorry, the author of this video has marked it private, preventing it from being embedded.", function () {}); + return; + } + done({ + url: url, + type: "vimeo", + token: id, + thumbnail: res.thumbnail_large, + duration: res.duration, + title: res.title, + width: res.width, + height: res.height + }); + }); + }, + tag: function tag(media) { + // return '<img class="video" type="vimeo" vid="'+media.token+'" src="'+media.thumbnail+'"><span class="playvid">▶</span>'; + return '<div class="video" style="width: ' + media.width + 'px; height: ' + media.height + 'px; overflow: hidden; position: relative;"><iframe frameborder="0" scrolling="no" seamless="seamless" webkitallowfullscreen="webkitAllowFullScreen" mozallowfullscreen="mozallowfullscreen" allowfullscreen="allowfullscreen" id="okplayer" src="https://player.vimeo.com/video/' + media.token + '?api=1&title=0&byline=0&portrait=0&playbar=0&player_id=okplayer&loop=0&autoplay=0" width="' + media.width + '" height="' + media.height + '" style="position: absolute; top: 0px; left: 0px; width: ' + media.width + 'px; height: ' + media.height + 'px;"></iframe></div>'; + } +}, { + type: 'soundcloud', + regex: /soundcloud.com\/[-a-zA-Z0-9]+\/[-a-zA-Z0-9]+\/?$/i, + fetch: function fetch(url, done) { + (0, _nodeFetch2.default)('https://api.soundcloud.com/resolve.json?url=' + url + '&client_id=' + '0673fbe6fc794a7750f680747e863b10').then(function (result) { + return result.json(); + }).then(function (result) { + console.log(result); + done({ + url: url, + type: "soundcloud", + token: result.id, + thumbnail: result.artwork_url || result.user.avatar_url, + title: result.user.username + " - " + result.title, + duration: result.duration, + width: 166, + height: 166 + }); + }); + }, + tag: function tag(media) { + return '<iframe width="166" height="166" scrolling="no" frameborder="no"' + 'src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/' + media.token + '&color=ff6600&auto_play=false&show_artwork=true"></iframe>'; + } +}, { + type: 'link', + regex: /^http.+/i, + fetch: function fetch(url, done) { + done({ + url: url, + type: "link", + token: "", + thumbnail: "", + title: "", + width: 100, + height: 100 + }); + }, + tag: function tag(media) { + return '<a href="' + media.url + '" target="_blank">' + media.url + '</a>'; + } +}]; + +var lookup = exports.lookup = integrations.reduce(function (a, b) { + return (a[b.type] = b) && a; +}, {}); + +var parse = exports.parse = function parse(url, cb) { + var matched = integrations.some(function (integration) { + if (integration.regex.test(url)) { + integration.fetch(url, function (res) { + cb(res); + }); + return true; + } + return false; + }); + if (!matched) { + cb(null); + } +}; + +var tag = exports.tag = function tag(media) { + if (media.type in lookup) { + return lookup[media.type].tag(media); + } + return ""; +}; + +var loadImage = exports.loadImage = function loadImage(url, cb, error) { + if (lookup.image.regex.test(url)) { + lookup.image.fetch(url, function (media) { + cb(media); + }); + } else error && error(); +}; + +var thumbnail = exports.thumbnail = function thumbnail(media) { + return '<img src="' + (media.thumbnail || media.url) + '" class="thumb">'; +}; + +var tumblr = exports.tumblr = function tumblr(url, cb) { + var domain = url.replace(/^https?:\/\//, "").split("/")[0]; + if (domain.indexOf(".") == -1) { + domain += ".tumblr.com"; + } + (0, _fetchJsonp2.default)("http://" + domain + "/api/read").then(function (data) { + // const blog = data.tumblelog + var media_list = data.posts.reduce(parseTumblrPost, []); + cb(media_list); + }); +}; + +function parseTumblrPost(media_list, post) { + var media = void 0, + caption = void 0, + url = void 0; + switch (post.type) { + case 'photo': + caption = stripHTML(post['photo-caption']); + if (post.photos.length) { + post.photos.forEach(function (photo) { + media = { + url: photo['photo-url-1280'], + type: "image", + token: "", + thumbnail: photo['photo-url-500'], + description: caption, + width: parseInt(photo.width), + height: parseInt(photo.height) + }; + media_list.push(media); + }); + } else { + media = { + url: post['photo-url-1280'], + type: "image", + token: "", + thumbnail: post['photo-url-500'], + description: caption, + width: parseInt(post.width), + height: parseInt(post.height) + }; + media_list.push(media); + } + break; + case 'video': + url = post['video-source']; + if (url.indexOf("http") !== 0) { + break; + } + if (lookup.youtube.regex.test(url)) { + var id = (url.match(/v=([-_a-zA-Z0-9]{11})/i) || url.match(/youtu.be\/([-_a-zA-Z0-9]{11})/i) || url.match(/embed\/([-_a-zA-Z0-9]{11})/i))[1].split('&')[0]; + var thumb = "https://i.ytimg.com/vi/" + id + "/hqdefault.jpg"; + media = { + url: post['video-source'], + type: "youtube", + token: id, + thumbnail: thumb, + title: stripHTML(post['video-caption']), + width: 640, + height: 360 + }; + media_list.push(media); + } + break; + default: + break; + } + return media_list; +} + +/***/ }), + /***/ "./app/client/api/util.js": /*!********************************!*\ !*** ./app/client/api/util.js ***! @@ -3604,20 +3963,27 @@ var SampleRNNDatasets = function (_Component) { }, { key: 'handleURL', value: function handleURL(url) { + var _this2 = this; + // name url // mime datatype // duration analysis // size activity // opt created_at updated_at - var folder = this.props.samplernn.folder; - this.props.actions.file.create({ - folder_id: folder.id, - module: 'samplernn', - activity: 'url', - epoch: 0, - processed: false, - generated: false, - url: url + _api.parser.parse(url, function (media) { + if (!media) return; + console.log('media', media); + return; + var folder = _this2.props.samplernn.folder; + _this2.props.actions.file.create({ + folder_id: folder.id, + module: 'samplernn', + activity: 'url', + epoch: 0, + processed: false, + generated: false, + url: url + }); }); } }, { @@ -3640,7 +4006,7 @@ var SampleRNNDatasets = function (_Component) { }, { key: 'fileOptions', value: function fileOptions(file) { - var _this2 = this; + var _this3 = this; console.log(file); if (file.activity === 'url' && !file.dataset) { @@ -3654,7 +4020,7 @@ var SampleRNNDatasets = function (_Component) { return (0, _preact.h)( 'div', { className: 'link', onClick: function onClick() { - return _this2.fetchURL(file.url); + return _this3.fetchURL(file.url); } }, 'fetch' ); @@ -3666,7 +4032,7 @@ var SampleRNNDatasets = function (_Component) { (0, _preact.h)( 'div', { className: 'link', onClick: function onClick() { - return _this2.train(file); + return _this3.train(file); } }, 'train' ), @@ -3683,6 +4049,8 @@ var SampleRNNDatasets = function (_Component) { value: function render() { var samplernn = this.props.samplernn; + console.log(samplernn.upload); + // sort files?? return (0, _preact.h)( 'div', { className: 'app' }, @@ -3725,19 +4093,29 @@ var SampleRNNDatasets = function (_Component) { (0, _preact.h)( 'div', { className: 'params col' }, - samplernn.files.length ? (0, _preact.h)( - 'h3', - null, - 'Files' - ) : (0, _preact.h)( - 'h4', - null, - 'No files' + (0, _preact.h)( + 'div', + { 'class': 'row heading' }, + samplernn.files.length ? (0, _preact.h)( + 'h3', + null, + 'Files' + ) : (0, _preact.h)( + 'h4', + null, + 'No files' + ), + (0, _preact.h)( + 'div', + null, + samplernn.upload.loading && samplernn.upload.status + ) ), (0, _preact.h)(_fileList2.default, { files: samplernn.files, options: this.fileOptions, onClick: this.pickFile, + showDelete: true, linkFiles: true }) ) @@ -3865,8 +4243,8 @@ var samplernnInitialState = { files: [], results: [], upload: { - loading: true, - status: 'Loading...' + loading: false, + status: '' } }; @@ -3882,26 +4260,19 @@ var samplernnReducer = function samplernnReducer() { return _extends({}, state); case _types2.default.task.task_finish: return _extends({}, state); + case _types2.default.folder.index: - console.log(action); return _extends({}, state, { folders: action.data, folder: action.data[0] }); case _types2.default.folder.update: - console.log(action); return state; case _types2.default.file.index: - console.log(action); return _extends({}, state, { files: action.data }); - case _types2.default.file.create: - console.log(action); - return _extends({}, state, { - files: [action.data].concat(undefined.files) - }); - return; + case _types2.default.folder.upload_loading: return _extends({}, state, { upload: { @@ -3932,13 +4303,39 @@ var samplernnReducer = function samplernnReducer() { status: 'Waiting for server to finish processing...' } }); + case _types2.default.file.create_loading: + return _extends({}, state, { + upload: { + loading: true, + status: 'Creating file...' + } + }); + case _types2.default.file.create: + console.log('booo'); + if (state.folder.id === action.data.folder_id) { + return _extends({}, state, { + files: [action.data].concat(state.files), + upload: { + loading: false, + status: 'File created' + } + }); + } else { + return _extends({}, state, { + upload: { + loading: false, + status: 'created' + } + }); + } case _types2.default.folder.upload_complete: console.log(action); if (state.folder.id === action.folder) { return _extends({}, state, { - files: state.files.concat(state.file), // sort here also + files: [action.files].concat(state.files), upload: { - loading: false + loading: false, + status: 'Upload complete' } }); } else { @@ -5518,6 +5915,134 @@ module.exports = warning; /***/ }), +/***/ "./node_modules/fetch-jsonp/build/fetch-jsonp.js": +/*!*******************************************************!*\ + !*** ./node_modules/fetch-jsonp/build/fetch-jsonp.js ***! + \*******************************************************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;(function (global, factory) { + if (true) { + !(__WEBPACK_AMD_DEFINE_ARRAY__ = [exports, module], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory), + __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? + (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), + __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); + } else { var mod; } +})(this, function (exports, module) { + 'use strict'; + + var defaultOptions = { + timeout: 5000, + jsonpCallback: 'callback', + jsonpCallbackFunction: null + }; + + function generateCallbackFunction() { + return 'jsonp_' + Date.now() + '_' + Math.ceil(Math.random() * 100000); + } + + function clearFunction(functionName) { + // IE8 throws an exception when you try to delete a property on window + // http://stackoverflow.com/a/1824228/751089 + try { + delete window[functionName]; + } catch (e) { + window[functionName] = undefined; + } + } + + function removeScript(scriptId) { + var script = document.getElementById(scriptId); + if (script) { + document.getElementsByTagName('head')[0].removeChild(script); + } + } + + function fetchJsonp(_url) { + var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; + + // to avoid param reassign + var url = _url; + var timeout = options.timeout || defaultOptions.timeout; + var jsonpCallback = options.jsonpCallback || defaultOptions.jsonpCallback; + + var timeoutId = undefined; + + return new Promise(function (resolve, reject) { + var callbackFunction = options.jsonpCallbackFunction || generateCallbackFunction(); + var scriptId = jsonpCallback + '_' + callbackFunction; + + window[callbackFunction] = function (response) { + resolve({ + ok: true, + // keep consistent with fetch API + json: function json() { + return Promise.resolve(response); + } + }); + + if (timeoutId) clearTimeout(timeoutId); + + removeScript(scriptId); + + clearFunction(callbackFunction); + }; + + // Check if the user set their own params, and if not add a ? to start a list of params + url += url.indexOf('?') === -1 ? '?' : '&'; + + var jsonpScript = document.createElement('script'); + jsonpScript.setAttribute('src', '' + url + jsonpCallback + '=' + callbackFunction); + if (options.charset) { + jsonpScript.setAttribute('charset', options.charset); + } + jsonpScript.id = scriptId; + document.getElementsByTagName('head')[0].appendChild(jsonpScript); + + timeoutId = setTimeout(function () { + reject(new Error('JSONP request to ' + _url + ' timed out')); + + clearFunction(callbackFunction); + removeScript(scriptId); + window[callbackFunction] = function () { + clearFunction(callbackFunction); + }; + }, timeout); + + // Caught if got 404/500 + jsonpScript.onerror = function () { + reject(new Error('JSONP request to ' + _url + ' failed')); + + clearFunction(callbackFunction); + removeScript(scriptId); + if (timeoutId) clearTimeout(timeoutId); + }; + }); + } + + // export as global function + /* + let local; + if (typeof global !== 'undefined') { + local = global; + } else if (typeof self !== 'undefined') { + local = self; + } else { + try { + local = Function('return this')(); + } catch (e) { + throw new Error('polyfill failed because global object is unavailable in this environment'); + } + } + local.fetchJsonp = fetchJsonp; + */ + + module.exports = fetchJsonp; +}); + +/***/ }), + /***/ "./node_modules/file-saver/FileSaver.js": /*!**********************************************!*\ !*** ./node_modules/file-saver/FileSaver.js ***! |
