aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/components/ViewPaste.js
diff options
context:
space:
mode:
authorjackyzha0 <[email protected]>2020-05-12 22:28:19 -0700
committerjackyzha0 <[email protected]>2020-05-12 22:28:19 -0700
commitb8118ba07534cdcd01788c6c508be267da1fa87e (patch)
treec8f1feaf1b16d89ec7d592a08f54215baf1d1a38 /frontend/src/components/ViewPaste.js
parentworking password render (diff)
downloadctrl-v-b8118ba07534cdcd01788c6c508be267da1fa87e.tar.xz
ctrl-v-b8118ba07534cdcd01788c6c508be267da1fa87e.zip
abstract http funcs into helper
Diffstat (limited to 'frontend/src/components/ViewPaste.js')
-rw-r--r--frontend/src/components/ViewPaste.js57
1 files changed, 24 insertions, 33 deletions
diff --git a/frontend/src/components/ViewPaste.js b/frontend/src/components/ViewPaste.js
index d591d19..6a2be4c 100644
--- a/frontend/src/components/ViewPaste.js
+++ b/frontend/src/components/ViewPaste.js
@@ -1,9 +1,9 @@
import React from 'react';
-import axios from 'axios';
import Error from './Err';
import { TitleInput, PasteInput } from './Inputs';
import PasteInfo from './PasteInfo';
import PasswordModal from './PasswordModal'
+import { FetchPaste, FetchPasswordPaste } from './httpHelper'
const RENDER_MODES = Object.freeze({
RAW: 'raw text',
@@ -74,35 +74,28 @@ class ViewPaste extends React.Component {
}
validatePass(pass) {
- var bodyFormData = new FormData();
- bodyFormData.set('password', pass);
-
- axios({
- method: 'post',
- url: `http://localhost:8080/api/${this.props.hash}`,
- data: bodyFormData,
- headers: { 'Content-Type': 'multipart/form-data' },
- }).then((response) => {
- this.setState({ validPass: true })
- this.setStateFromData(response.data)
- }).catch((error) => {
- const resp = error.response
-
- // 401 unauth (bad pass)
- if (resp.status === 401) {
- this.newPassErr()
- return
- }
-
- // otherwise, just log it lmao
- if (resp !== undefined) {
- const errTxt = `${resp.statusText}: ${resp.data}`
- this.newErr(errTxt)
- } else {
- // some weird err (e.g. network)
- this.newErr(error)
- }
- });
+ FetchPasswordPaste(this.props.hash, pass)
+ .then((response) => {
+ this.setState({ validPass: true })
+ this.setStateFromData(response.data)
+ }).catch((error) => {
+ const resp = error.response
+
+ // 401 unauth (bad pass)
+ if (resp.status === 401) {
+ this.newPassErr()
+ return
+ }
+
+ // otherwise, just log it lmao
+ if (resp !== undefined) {
+ const errTxt = `${resp.statusText}: ${resp.data}`
+ this.newErr(errTxt)
+ } else {
+ // some weird err (e.g. network)
+ this.newErr(error)
+ }
+ });
}
render() {
@@ -146,9 +139,7 @@ class ViewPaste extends React.Component {
}
componentDidMount() {
- const serverURL = `http://localhost:8080/api/${this.props.hash}`
-
- axios.get(serverURL)
+ FetchPaste(this.props.hash)
.then((response) => {
const data = response.data
this.setStateFromData(data)