From cba34c1ff3fc4fa3e4444884133a9140443bb233 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Wed, 30 May 2018 14:37:03 +0200 Subject: parse urls using the old parser --- app/client/api/index.js | 3 + app/client/api/parser.js | 329 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 332 insertions(+) create mode 100644 app/client/api/parser.js (limited to 'app/client/api') diff --git a/app/client/api/index.js b/app/client/api/index.js index a0cae50..2fcd434 100644 --- a/app/client/api/index.js +++ b/app/client/api/index.js @@ -1,5 +1,6 @@ import { crud_actions } from './crud.actions' import * as util from './util' +import * as parser from './parser' /* for our crud events, create corresponding actions @@ -14,6 +15,8 @@ so you can do ... folderActions.upload(12, form_data) */ +export { util, parser } + export const actions = [ 'folder', 'file', diff --git a/app/client/api/parser.js b/app/client/api/parser.js new file mode 100644 index 0000000..2530410 --- /dev/null +++ b/app/client/api/parser.js @@ -0,0 +1,329 @@ +import fetch from 'node-fetch' +import fetchJsonp from 'fetch-jsonp' + +export const integrations = [ + { + type: 'image', + regex: /\.(jpeg|jpg|gif|png|svg)(\?.*)?$/i, + fetch: function(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 (media) { + return ''; + } + }, { + type: 'video', + regex: /\.(mp4|webm)(\?.*)?$/i, + fetch: function(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 (media) { + return '