remove all blobutil stuff

This commit is contained in:
Cassie Tarakajian 2016-10-19 15:33:14 -04:00
parent 0ccfeb6b9c
commit 32d45ea332
6 changed files with 2 additions and 65 deletions

View file

@ -41,7 +41,6 @@ export const SET_SELECTED_FILE = 'SET_SELECTED_FILE';
export const SHOW_MODAL = 'SHOW_MODAL'; export const SHOW_MODAL = 'SHOW_MODAL';
export const HIDE_MODAL = 'HIDE_MODAL'; export const HIDE_MODAL = 'HIDE_MODAL';
export const CREATE_FILE = 'CREATE_FILE'; export const CREATE_FILE = 'CREATE_FILE';
export const SET_BLOB_URL = 'SET_BLOB_URL';
export const EXPAND_SIDEBAR = 'EXPAND_SIDEBAR'; export const EXPAND_SIDEBAR = 'EXPAND_SIDEBAR';
export const COLLAPSE_SIDEBAR = 'COLLAPSE_SIDEBAR'; export const COLLAPSE_SIDEBAR = 'COLLAPSE_SIDEBAR';

View file

@ -1,8 +1,5 @@
import * as ActionTypes from '../../../constants'; import * as ActionTypes from '../../../constants';
import axios from 'axios'; import axios from 'axios';
import blobUtil from 'blob-util';
import xhr from 'xhr';
import fileType from 'file-type';
import objectID from 'bson-objectid'; import objectID from 'bson-objectid';
const ROOT_URL = location.href.indexOf('localhost') > 0 ? 'http://localhost:8000/api' : '/api'; const ROOT_URL = location.href.indexOf('localhost') > 0 ? 'http://localhost:8000/api' : '/api';
@ -36,38 +33,6 @@ export function updateFileContent(name, content) {
}; };
} }
export function getBlobUrl(file) {
return (dispatch) => {
xhr({
uri: file.url,
responseType: 'arraybuffer',
useXDR: true
}, (err, body, res) => {
if (err) throw err;
const typeOfFile = fileType(new Uint8Array(res));
blobUtil.arrayBufferToBlob(res, typeOfFile.mime)
.then(blobUtil.createObjectURL)
.then(objectURL => {
dispatch({
type: ActionTypes.SET_BLOB_URL,
name: file.name,
blobURL: objectURL
});
});
});
// blobUtil.imgSrcToBlob(file.url, undefined, { crossOrigin: 'Anonymous' })
// .then(blobUtil.createObjectURL)
// .then(objectURL => {
// dispatch({
// type: ActionTypes.SET_BLOB_URL,
// name: file.name,
// blobURL: objectURL
// });
// });
};
}
export function createFile(formProps) { export function createFile(formProps) {
return (dispatch, getState) => { return (dispatch, getState) => {
const state = getState(); const state = getState();
@ -89,9 +54,6 @@ export function createFile(formProps) {
}; };
axios.post(`${ROOT_URL}/projects/${state.project.id}/files`, postParams, { withCredentials: true }) axios.post(`${ROOT_URL}/projects/${state.project.id}/files`, postParams, { withCredentials: true })
.then(response => { .then(response => {
if (response.data.url) {
getBlobUrl(response.data)(dispatch);
}
dispatch({ dispatch({
type: ActionTypes.CREATE_FILE, type: ActionTypes.CREATE_FILE,
...response.data, ...response.data,
@ -106,9 +68,6 @@ export function createFile(formProps) {
error: response.data error: response.data
})); }));
} else { } else {
if (formProps.url) {
getBlobUrl(formProps)(dispatch);
}
const id = objectID().toHexString(); const id = objectID().toHexString();
dispatch({ dispatch({
type: ActionTypes.CREATE_FILE, type: ActionTypes.CREATE_FILE,

View file

@ -4,25 +4,13 @@ import axios from 'axios';
import JSZip from 'jszip'; import JSZip from 'jszip';
import JSZipUtils from 'jszip-utils'; import JSZipUtils from 'jszip-utils';
import { saveAs } from 'file-saver'; import { saveAs } from 'file-saver';
import { getBlobUrl } from './files';
import { showToast, setToastText } from './toast'; import { showToast, setToastText } from './toast';
import { setUnsavedChanges } from './ide'; import { setUnsavedChanges } from './ide';
const ROOT_URL = location.href.indexOf('localhost') > 0 ? 'http://localhost:8000/api' : '/api'; const ROOT_URL = location.href.indexOf('localhost') > 0 ? 'http://localhost:8000/api' : '/api';
export function getProjectBlobUrls() {
return (dispatch, getState) => {
const state = getState();
state.files.forEach(file => {
if (file.url) {
getBlobUrl(file)(dispatch);
}
});
};
}
export function getProject(id) { export function getProject(id) {
return (dispatch, getState) => { return (dispatch) => {
axios.get(`${ROOT_URL}/projects/${id}`, { withCredentials: true }) axios.get(`${ROOT_URL}/projects/${id}`, { withCredentials: true })
.then(response => { .then(response => {
// browserHistory.push(`/projects/${id}`); // browserHistory.push(`/projects/${id}`);
@ -32,7 +20,6 @@ export function getProject(id) {
files: response.data.files, files: response.data.files,
owner: response.data.user owner: response.data.user
}); });
getProjectBlobUrls()(dispatch, getState);
dispatch(setUnsavedChanges(false)); dispatch(setUnsavedChanges(false));
}) })
.catch(response => dispatch({ .catch(response => dispatch({

View file

@ -181,7 +181,7 @@ class PreviewFrame extends React.Component {
const fileName = filePathArray[filePathArray.length - 1]; const fileName = filePathArray[filePathArray.length - 1];
mediaFiles.forEach(file => { mediaFiles.forEach(file => {
if (file.name === fileName) { if (file.name === fileName) {
newJSFile.content = newJSFile.content.replace(filePath, file.blobURL); // eslint-disable-line newJSFile.content = newJSFile.content.replace(filePath, file.url); // eslint-disable-line
} }
}); });
} }

View file

@ -119,13 +119,6 @@ const files = (state, action) => {
return Object.assign({}, file, { content: action.content }); return Object.assign({}, file, { content: action.content });
}); });
case ActionTypes.SET_BLOB_URL:
return state.map(file => {
if (file.name !== action.name) {
return file;
}
return Object.assign({}, file, { blobURL: action.blobURL });
});
case ActionTypes.NEW_PROJECT: case ActionTypes.NEW_PROJECT:
return [...action.files]; return [...action.files];
case ActionTypes.SET_PROJECT: case ActionTypes.SET_PROJECT:

View file

@ -62,7 +62,6 @@
"axios": "^0.12.0", "axios": "^0.12.0",
"babel-core": "^6.8.0", "babel-core": "^6.8.0",
"bcrypt-nodejs": "0.0.3", "bcrypt-nodejs": "0.0.3",
"blob-util": "^1.2.1",
"body-parser": "^1.15.1", "body-parser": "^1.15.1",
"bson-objectid": "^1.1.4", "bson-objectid": "^1.1.4",
"classnames": "^2.2.5", "classnames": "^2.2.5",