Skip to content
This repository has been archived by the owner on Jul 30, 2021. It is now read-only.

Fixed bugs. #400

Merged
merged 9 commits into from Oct 29, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
fix: Fixed vulnerability 4.
  • Loading branch information
Tuisku-L committed Oct 22, 2020
commit 69de77b163f6debaeb3f8d1a85367310a40d196f
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -179,6 +179,7 @@
"nodemailer-mailgun-transport": "1.4.0",
"omit-deep-lodash": "1.1.4",
"onefx": "1.8.5",
"piexifjs": "^1.0.6",
Tuisku-L marked this conversation as resolved.
Show resolved Hide resolved
"process": "0.11.10",
"react-apollo": "2.5.8",
"react-calendar-heatmap": "1.8.1",
Expand Down
54 changes: 40 additions & 14 deletions src/shared/contact/profile-editor/profile-editor.tsx
Expand Up @@ -38,6 +38,8 @@ import { formatToE164 } from "../phone-input/util";
import DynamicFormItems from "./dynamic-form-items";
import { ExperienceForm } from "./experience-form";
import { ObservationForm } from "./observation-form";
// @ts-ignore
import piexifjs from "piexifjs";

const { TabPane } = Tabs;

Expand Down Expand Up @@ -218,7 +220,7 @@ class PersonalForm extends Component<
formRef: any;
},
PersonalFormState
> {
> {
state: PersonalFormState = { avatarUrl: "" };

renderPhoneNumbers(): JSX.Element | null {
Expand Down Expand Up @@ -254,19 +256,43 @@ class PersonalForm extends Component<
);
}

actionTryRemoveExif = async (file: File, cb: Function) => {
if (file && (file.type.includes("jpg") || file.type.includes("jpeg"))) {
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = async (e) => {
const base64 = e.target?.result;
const newFile = piexifjs.remove(base64);
let fileArr = newFile.split(',');
let mime = fileArr[0].match(/:(.*?);/)[1]
let bstr = atob(fileArr[1])
let length = bstr.length;
let fileBits = new Uint8Array(length);
while (length--) {
fileBits[length] = bstr.charCodeAt(length);
}
await cb(new File([fileBits], file.name, { type: mime }))
}
} else {
await cb(file);
}
}

render(): JSX.Element | null {
const { human, formRef } = this.props;

const beforeUpload = async ({ file, onSuccess }: any) => {
const fieldName = "avatarUrl";
const data = await upload(file, fieldName);
if (formRef && formRef.current) {
formRef.current.setFieldsValue({
[fieldName]: data.secure_url
});
this.setState({ [fieldName]: data.secure_url });
onSuccess(data, file);
}
await this.actionTryRemoveExif(file, async (newFile: File) => {
const data = await upload(newFile, fieldName);
if (formRef && formRef.current) {
formRef.current.setFieldsValue({
[fieldName]: data.secure_url
});
this.setState({ [fieldName]: data.secure_url });
onSuccess(data, newFile);
}
})
};

return (
Expand Down Expand Up @@ -303,10 +329,10 @@ class PersonalForm extends Component<
src={this.state.avatarUrl || human.avatarUrl}
/>
) : (
<Button>
<UploadOutlined /> Click to Upload
</Button>
)}
<Button>
<UploadOutlined /> Click to Upload
</Button>
)}
</Upload>
</Form.Item>

Expand Down Expand Up @@ -360,7 +386,7 @@ const DeleteContactPopover = withRouter(
class DeleteContactPopoverInner extends Component<
{ name: string; contactId: string } & RouterProps,
{ visible: boolean }
> {
> {
state: { visible: boolean } = { visible: false };

render(): JSX.Element {
Expand Down