fix a few regexes for preview frame
This commit is contained in:
parent
ec728eb392
commit
1de8c02cf2
4 changed files with 14 additions and 9 deletions
|
@ -1,5 +1,6 @@
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { createFile } from './files';
|
import { createFile } from './files';
|
||||||
|
const textFileRegex = /text\//;
|
||||||
|
|
||||||
const s3Bucket = `http://${process.env.S3_BUCKET}.s3.amazonaws.com/`;
|
const s3Bucket = `http://${process.env.S3_BUCKET}.s3.amazonaws.com/`;
|
||||||
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';
|
||||||
|
@ -34,7 +35,7 @@ export function dropzoneAcceptCallback(file, done) {
|
||||||
// check mime type
|
// check mime type
|
||||||
// if text, local interceptor
|
// if text, local interceptor
|
||||||
console.log(file.type);
|
console.log(file.type);
|
||||||
if (file.type.match(/text\//)) {
|
if (file.type.match(textFileRegex)) {
|
||||||
localIntercept(file).then(result => {
|
localIntercept(file).then(result => {
|
||||||
file.content = result; // eslint-disable-line
|
file.content = result; // eslint-disable-line
|
||||||
done();
|
done();
|
||||||
|
@ -74,7 +75,7 @@ export function dropzoneAcceptCallback(file, done) {
|
||||||
|
|
||||||
export function dropzoneSendingCallback(file, xhr, formData) {
|
export function dropzoneSendingCallback(file, xhr, formData) {
|
||||||
return () => {
|
return () => {
|
||||||
if (!file.type.match(/text\//)) {
|
if (!file.type.match(textFileRegex)) {
|
||||||
Object.keys(file.postData).forEach(key => {
|
Object.keys(file.postData).forEach(key => {
|
||||||
formData.append(key, file.postData[key]);
|
formData.append(key, file.postData[key]);
|
||||||
});
|
});
|
||||||
|
@ -87,7 +88,7 @@ export function dropzoneSendingCallback(file, xhr, formData) {
|
||||||
|
|
||||||
export function dropzoneCompleteCallback(file) {
|
export function dropzoneCompleteCallback(file) {
|
||||||
return (dispatch, getState) => { // eslint-disable-line
|
return (dispatch, getState) => { // eslint-disable-line
|
||||||
if (!file.type.match(/text\//)) {
|
if (!file.type.match(textFileRegex)) {
|
||||||
let inputHidden = '<input type="hidden" name="attachments[]" value="';
|
let inputHidden = '<input type="hidden" name="attachments[]" value="';
|
||||||
const json = {
|
const json = {
|
||||||
url: `${s3Bucket}${file.postData.key}`,
|
url: `${s3Bucket}${file.postData.key}`,
|
||||||
|
|
|
@ -24,11 +24,15 @@ class FileUploader extends React.Component {
|
||||||
thumbnailWidth: 200,
|
thumbnailWidth: 200,
|
||||||
thumbnailHeight: 200,
|
thumbnailHeight: 200,
|
||||||
// TODO what is a good list of MIME types????
|
// TODO what is a good list of MIME types????
|
||||||
acceptedFiles: 'image/*,audio/*,text/javascript,text/html,text/css',
|
acceptedFiles: 'image/*,audio/*,text/javascript,text/html,text/css,application/json,application/x-font-ttf,application/x-font-truetype',
|
||||||
dictDefaultMessage: 'Drop files here to upload or click to use the file browser',
|
dictDefaultMessage: 'Drop files here to upload or click to use the file browser',
|
||||||
accept: this.props.dropzoneAcceptCallback,
|
accept: this.props.dropzoneAcceptCallback,
|
||||||
sending: this.props.dropzoneSendingCallback,
|
sending: this.props.dropzoneSendingCallback,
|
||||||
complete: this.props.dropzoneCompleteCallback
|
complete: this.props.dropzoneCompleteCallback,
|
||||||
|
error: (file, errorMessage) => {
|
||||||
|
console.log(file);
|
||||||
|
console.log(errorMessage);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -104,7 +104,7 @@ class PreviewFrame extends React.Component {
|
||||||
let jsFileStrings = newJSFile.content.match(/(['"])((\\\1|.)*?)\1/gm);
|
let jsFileStrings = newJSFile.content.match(/(['"])((\\\1|.)*?)\1/gm);
|
||||||
jsFileStrings = jsFileStrings || [];
|
jsFileStrings = jsFileStrings || [];
|
||||||
jsFileStrings.forEach(jsFileString => {
|
jsFileStrings.forEach(jsFileString => {
|
||||||
if (jsFileString.match(/^('|")(?!(http:\/\/|https:\/\/)).*\.(png|jpg|jpeg|gif|bmp|mp3|wav|aiff|ogg)('|")$/)) {
|
if (jsFileString.match(/^('|")(?!(http:\/\/|https:\/\/)).*\.(png|jpg|jpeg|gif|bmp|mp3|wav|aiff|ogg|json)('|")$/i)) {
|
||||||
const filePath = jsFileString.substr(1, jsFileString.length - 2);
|
const filePath = jsFileString.substr(1, jsFileString.length - 2);
|
||||||
let fileName = filePath;
|
let fileName = filePath;
|
||||||
if (fileName.match(/^\.\//)) {
|
if (fileName.match(/^\.\//)) {
|
||||||
|
|
|
@ -131,9 +131,9 @@ export const setSelectedFile = (state, id) =>
|
||||||
});
|
});
|
||||||
|
|
||||||
export const getFile = (state, id) => state.filter(file => file.id === id)[0];
|
export const getFile = (state, id) => state.filter(file => file.id === id)[0];
|
||||||
export const getHTMLFile = (state) => state.filter(file => file.name.match(/.*\.html$/))[0];
|
export const getHTMLFile = (state) => state.filter(file => file.name.match(/.*\.html$/i))[0];
|
||||||
export const getJSFiles = (state) => state.filter(file => file.name.match(/.*\.js$/));
|
export const getJSFiles = (state) => state.filter(file => file.name.match(/.*\.js$/i));
|
||||||
export const getCSSFiles = (state) => state.filter(file => file.name.match(/.*\.css$/));
|
export const getCSSFiles = (state) => state.filter(file => file.name.match(/.*\.css$/i));
|
||||||
export const getLinkedFiles = (state) => state.filter(file => file.url);
|
export const getLinkedFiles = (state) => state.filter(file => file.url);
|
||||||
|
|
||||||
export default files;
|
export default files;
|
||||||
|
|
Loading…
Reference in a new issue