From 93a5b395effd88a783ef4bcd4162de281f6281ee Mon Sep 17 00:00:00 2001 From: jackyzha0 Date: Tue, 12 May 2020 22:30:23 -0700 Subject: fix dir --- frontend/src/components/NewPaste.js | 2 +- frontend/src/components/ViewPaste.js | 2 +- frontend/src/components/httpHelper.js | 67 ----------------------------------- frontend/src/helpers/httpHelper.js | 67 +++++++++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 69 deletions(-) delete mode 100644 frontend/src/components/httpHelper.js create mode 100644 frontend/src/helpers/httpHelper.js (limited to 'frontend/src') diff --git a/frontend/src/components/NewPaste.js b/frontend/src/components/NewPaste.js index dbcc5a7..1409c22 100644 --- a/frontend/src/components/NewPaste.js +++ b/frontend/src/components/NewPaste.js @@ -3,7 +3,7 @@ import { TitleInput, PasteInput } from './Inputs' import OptionsContainer from './Options' import { Redirect } from 'react-router-dom' import Error from './Err' -import { PostNewPaste } from './httpHelper' +import { PostNewPaste } from '../helpers/httpHelper' class NewPaste extends React.Component { constructor(props) { diff --git a/frontend/src/components/ViewPaste.js b/frontend/src/components/ViewPaste.js index 6a2be4c..d7bd355 100644 --- a/frontend/src/components/ViewPaste.js +++ b/frontend/src/components/ViewPaste.js @@ -3,7 +3,7 @@ import Error from './Err'; import { TitleInput, PasteInput } from './Inputs'; import PasteInfo from './PasteInfo'; import PasswordModal from './PasswordModal' -import { FetchPaste, FetchPasswordPaste } from './httpHelper' +import { FetchPaste, FetchPasswordPaste } from '../helpers/httpHelper' const RENDER_MODES = Object.freeze({ RAW: 'raw text', diff --git a/frontend/src/components/httpHelper.js b/frontend/src/components/httpHelper.js deleted file mode 100644 index 696980c..0000000 --- a/frontend/src/components/httpHelper.js +++ /dev/null @@ -1,67 +0,0 @@ -import axios from 'axios'; - -const base = `http://localhost:8080/api` - - -export function FetchPaste(hash) { - const serverURL = `${base}/${hash}` - console.log(serverURL) - return axios.get(serverURL) -} - -export function FetchPasswordPaste(hash, pass) { - var bodyFormData = new FormData(); - bodyFormData.set('password', pass); - - return axios({ - method: 'post', - url: `${base}/${hash}`, - data: bodyFormData, - headers: { 'Content-Type': 'multipart/form-data' }, - }) -} - -export function PostNewPaste(state) { - var bodyFormData = new FormData(); - bodyFormData.set('title', state.title); - bodyFormData.set('content', state.content); - bodyFormData.set('password', state.pass); - bodyFormData.set('expiry', parseExpiry(state.expiry)); - - return axios({ - method: 'post', - url: 'http://localhost:8080/api', - data: bodyFormData, - headers: { 'Content-Type': 'multipart/form-data' }, - }) -} - -function parseExpiry(e) { - var cur = new Date(); - var inSeconds = 0 - switch (e) { - case '5 years': - inSeconds = 600 * 6 * 24 * 7 * 4 * 12 * 5 - break; - case '1 year': - inSeconds = 600 * 6 * 24 * 7 * 4 * 12 - break; - case '1 month': - inSeconds = 600 * 6 * 24 * 7 * 4 - break; - case '1 day': - inSeconds = 600 * 6 * 24 - break; - case '1 hour': - inSeconds = 600 * 6 - break; - case '10 min': - inSeconds = 600 - break; - case '1 week': - default: - inSeconds = 600 * 6 * 24 * 7 - break; - } - return new Date(cur.getTime() + inSeconds * 1000).toISOString(); -} \ No newline at end of file diff --git a/frontend/src/helpers/httpHelper.js b/frontend/src/helpers/httpHelper.js new file mode 100644 index 0000000..696980c --- /dev/null +++ b/frontend/src/helpers/httpHelper.js @@ -0,0 +1,67 @@ +import axios from 'axios'; + +const base = `http://localhost:8080/api` + + +export function FetchPaste(hash) { + const serverURL = `${base}/${hash}` + console.log(serverURL) + return axios.get(serverURL) +} + +export function FetchPasswordPaste(hash, pass) { + var bodyFormData = new FormData(); + bodyFormData.set('password', pass); + + return axios({ + method: 'post', + url: `${base}/${hash}`, + data: bodyFormData, + headers: { 'Content-Type': 'multipart/form-data' }, + }) +} + +export function PostNewPaste(state) { + var bodyFormData = new FormData(); + bodyFormData.set('title', state.title); + bodyFormData.set('content', state.content); + bodyFormData.set('password', state.pass); + bodyFormData.set('expiry', parseExpiry(state.expiry)); + + return axios({ + method: 'post', + url: 'http://localhost:8080/api', + data: bodyFormData, + headers: { 'Content-Type': 'multipart/form-data' }, + }) +} + +function parseExpiry(e) { + var cur = new Date(); + var inSeconds = 0 + switch (e) { + case '5 years': + inSeconds = 600 * 6 * 24 * 7 * 4 * 12 * 5 + break; + case '1 year': + inSeconds = 600 * 6 * 24 * 7 * 4 * 12 + break; + case '1 month': + inSeconds = 600 * 6 * 24 * 7 * 4 + break; + case '1 day': + inSeconds = 600 * 6 * 24 + break; + case '1 hour': + inSeconds = 600 * 6 + break; + case '10 min': + inSeconds = 600 + break; + case '1 week': + default: + inSeconds = 600 * 6 * 24 * 7 + break; + } + return new Date(cur.getTime() + inSeconds * 1000).toISOString(); +} \ No newline at end of file -- cgit v1.2.3