Skip to content
This repository has been archived by the owner on Sep 27, 2019. It is now read-only.

Commit

Permalink
Fix reading binary file error
Browse files Browse the repository at this point in the history
  • Loading branch information
yqf3139 committed Mar 22, 2017
1 parent f589242 commit e686d41
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
15 changes: 9 additions & 6 deletions app/containers/FunctionCreatePage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { makeSelectLoading, makeSelectError, makeSelectFunctionTest } from 'cont
import { makeSelectEnvironments } from 'containers/EnvironmentsPage/selectors';
import { loadEnvironmentAction } from 'containers/EnvironmentsListPage/actions';
import { createFunctionAction, testFunctionAction, cleanTestFunctionAction } from 'containers/FunctionCreatePage/actions';
import { slug } from 'utils/util';
import { slug, encodeBase64 } from 'utils/util';
import commonMessages from 'messages';

export class FunctionCreatePage extends React.Component { // eslint-disable-line react/prefer-stateless-function
Expand Down Expand Up @@ -83,16 +83,19 @@ export class FunctionCreatePage extends React.Component { // eslint-disable-line
onSave() {
const { item } = this.state;
if (this.isFunctionRequiredInputValid(item)) {
this.props.createFunction(item);
const fn = Object.assign({}, item);
fn.code = encodeBase64(fn.code);
this.props.createFunction(fn);
}
}

onFunctionTest(test) {
const obj = Object.assign({}, this.state.item);
const fn = Object.assign({}, this.state.item);

if (this.isFunctionRequiredInputValid(obj)) {
obj.test = test;
this.props.testFunction(obj);
if (this.isFunctionRequiredInputValid(fn)) {
fn.test = test;
fn.code = encodeBase64(fn.code);
this.props.testFunction(fn);
return true;
}
return false;
Expand Down
12 changes: 8 additions & 4 deletions app/containers/FunctionEditPage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { loadEnvironmentAction } from 'containers/EnvironmentsListPage/actions';
import { testFunctionAction, cleanTestFunctionAction } from 'containers/FunctionCreatePage/actions';
import { getFunctionAction, loadTriggersHttpAction, deleteTriggerHttpAction, updateFunctionAction, createTriggerHttpAction, loadKubeWatchersAction, createKubeWatcherAction, deleteKubeWatcherAction } from 'containers/FunctionEditPage/actions';
import commonMessages from 'messages';
import { encodeBase64 } from 'utils/util';

export class FunctionEditPage extends React.Component { // eslint-disable-line react/prefer-stateless-function
constructor(props) {
Expand Down Expand Up @@ -109,9 +110,10 @@ export class FunctionEditPage extends React.Component { // eslint-disable-line r
}

onFunctionTest(test) {
const obj = Object.assign({}, this.state.item);
obj.test = test;
this.props.testFunction(obj);
const fn = Object.assign({}, this.state.item);
fn.code = encodeBase64(fn.code);
fn.test = test;
this.props.testFunction(fn);
return true;
}

Expand Down Expand Up @@ -150,7 +152,9 @@ export class FunctionEditPage extends React.Component { // eslint-disable-line r
onSave(event) {
event.preventDefault();
const { item } = this.state;
this.props.updateFunction(item);
const fn = Object.assign({}, item);
fn.code = encodeBase64(fn.code);
this.props.updateFunction(fn);
}

render() {
Expand Down
4 changes: 3 additions & 1 deletion app/containers/FunctionUploadPage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,14 @@ export class FunctionUploadPage extends React.Component { // eslint-disable-line
const reader = new FileReader();
reader.onload = (e) => {
f.code = e.target.result;
// remove the header: data:application/x-go;base64,
f.code = f.code.slice(f.code.indexOf(',') + 1);
counter[0] += 1;
if (counter[0] === length) {
that.props.setUploadFunctions(fns);
}
};
reader.readAsText(f.file);
reader.readAsDataURL(f.file);
delete f.file;
});
}
Expand Down
4 changes: 1 addition & 3 deletions app/utils/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
*/
import axios from 'axios';

import { encodeBase64 } from './util';

const basePath = '/proxy/controller/v1/';
const routerPath = '/proxy/router';

Expand Down Expand Up @@ -37,7 +35,7 @@ function checkStatus(response) {
}

function buildFunction(item) {
return { metadata: { name: item.name }, environment: { name: item.environment }, code: encodeBase64(item.code) };
return { metadata: { name: item.name }, environment: { name: item.environment }, code: item.code };
}

export function getEnvironments() {
Expand Down

1 comment on commit e686d41

@yqf3139
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit fixes #15 partially

Please sign in to comment.