remove all blobutil stuff
This commit is contained in:
parent
0ccfeb6b9c
commit
32d45ea332
6 changed files with 2 additions and 65 deletions
|
@ -41,7 +41,6 @@ export const SET_SELECTED_FILE = 'SET_SELECTED_FILE';
|
|||
export const SHOW_MODAL = 'SHOW_MODAL';
|
||||
export const HIDE_MODAL = 'HIDE_MODAL';
|
||||
export const CREATE_FILE = 'CREATE_FILE';
|
||||
export const SET_BLOB_URL = 'SET_BLOB_URL';
|
||||
|
||||
export const EXPAND_SIDEBAR = 'EXPAND_SIDEBAR';
|
||||
export const COLLAPSE_SIDEBAR = 'COLLAPSE_SIDEBAR';
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
import * as ActionTypes from '../../../constants';
|
||||
import axios from 'axios';
|
||||
import blobUtil from 'blob-util';
|
||||
import xhr from 'xhr';
|
||||
import fileType from 'file-type';
|
||||
import objectID from 'bson-objectid';
|
||||
|
||||
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) {
|
||||
return (dispatch, getState) => {
|
||||
const state = getState();
|
||||
|
@ -89,9 +54,6 @@ export function createFile(formProps) {
|
|||
};
|
||||
axios.post(`${ROOT_URL}/projects/${state.project.id}/files`, postParams, { withCredentials: true })
|
||||
.then(response => {
|
||||
if (response.data.url) {
|
||||
getBlobUrl(response.data)(dispatch);
|
||||
}
|
||||
dispatch({
|
||||
type: ActionTypes.CREATE_FILE,
|
||||
...response.data,
|
||||
|
@ -106,9 +68,6 @@ export function createFile(formProps) {
|
|||
error: response.data
|
||||
}));
|
||||
} else {
|
||||
if (formProps.url) {
|
||||
getBlobUrl(formProps)(dispatch);
|
||||
}
|
||||
const id = objectID().toHexString();
|
||||
dispatch({
|
||||
type: ActionTypes.CREATE_FILE,
|
||||
|
|
|
@ -4,25 +4,13 @@ import axios from 'axios';
|
|||
import JSZip from 'jszip';
|
||||
import JSZipUtils from 'jszip-utils';
|
||||
import { saveAs } from 'file-saver';
|
||||
import { getBlobUrl } from './files';
|
||||
import { showToast, setToastText } from './toast';
|
||||
import { setUnsavedChanges } from './ide';
|
||||
|
||||
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) {
|
||||
return (dispatch, getState) => {
|
||||
return (dispatch) => {
|
||||
axios.get(`${ROOT_URL}/projects/${id}`, { withCredentials: true })
|
||||
.then(response => {
|
||||
// browserHistory.push(`/projects/${id}`);
|
||||
|
@ -32,7 +20,6 @@ export function getProject(id) {
|
|||
files: response.data.files,
|
||||
owner: response.data.user
|
||||
});
|
||||
getProjectBlobUrls()(dispatch, getState);
|
||||
dispatch(setUnsavedChanges(false));
|
||||
})
|
||||
.catch(response => dispatch({
|
||||
|
|
|
@ -181,7 +181,7 @@ class PreviewFrame extends React.Component {
|
|||
const fileName = filePathArray[filePathArray.length - 1];
|
||||
mediaFiles.forEach(file => {
|
||||
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
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -119,13 +119,6 @@ const files = (state, action) => {
|
|||
|
||||
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:
|
||||
return [...action.files];
|
||||
case ActionTypes.SET_PROJECT:
|
||||
|
|
|
@ -62,7 +62,6 @@
|
|||
"axios": "^0.12.0",
|
||||
"babel-core": "^6.8.0",
|
||||
"bcrypt-nodejs": "0.0.3",
|
||||
"blob-util": "^1.2.1",
|
||||
"body-parser": "^1.15.1",
|
||||
"bson-objectid": "^1.1.4",
|
||||
"classnames": "^2.2.5",
|
||||
|
|
Loading…
Reference in a new issue