diff options
| author | Jacky Zhao <[email protected]> | 2021-04-11 15:06:48 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-04-11 15:06:48 -0700 |
| commit | 82bda5ee85efbd2eae25427a839529d5e230eeaa (patch) | |
| tree | 1f7a88938fd6664a9a048503a5a78d010e3db1e2 /frontend/src/components/hooks/shared.js | |
| parent | Merge pull request #72 from jackyzha0/no-ip (diff) | |
| parent | readd preset height (diff) | |
| download | ctrl-v-82bda5ee85efbd2eae25427a839529d5e230eeaa.tar.xz ctrl-v-82bda5ee85efbd2eae25427a839529d5e230eeaa.zip | |
Merge pull request #74 from jackyzha0/next-refactor
Diffstat (limited to 'frontend/src/components/hooks/shared.js')
| -rw-r--r-- | frontend/src/components/hooks/shared.js | 74 |
1 files changed, 0 insertions, 74 deletions
diff --git a/frontend/src/components/hooks/shared.js b/frontend/src/components/hooks/shared.js deleted file mode 100644 index 00d41e9..0000000 --- a/frontend/src/components/hooks/shared.js +++ /dev/null @@ -1,74 +0,0 @@ -import axios from 'axios'; - -// uncomment for local dev -// const base = `http://localhost:8080/api` -const base = `https://api.ctrl-v.app/api` -export function fetchPaste(hash, pass = "") { - const serverURL = `${base}/${hash}` - - if (pass === "") { - return axios.get(serverURL) - } else { - const bodyFormData = new FormData(); - bodyFormData.set('password', pass); - return axios({ - method: 'post', - url: `${base}/${hash}`, - data: bodyFormData, - headers: { 'Content-Type': 'multipart/form-data' }, - }) - } -} - -export function newPaste(paste) { - const {title, content, language, pass, expiry} = paste - const bodyFormData = new FormData(); - bodyFormData.set('title', title); - bodyFormData.set('content', content); - bodyFormData.set('language', language); - bodyFormData.set('password', pass); - bodyFormData.set('expiry', parseExpiry(expiry)); - - return axios({ - method: 'post', - url: base, - data: bodyFormData, - headers: { 'Content-Type': 'multipart/form-data' }, - }) -} - -export 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(); -} - -export function fmtDateStr(dateString) { - const d = new Date(dateString) - const options = { hour: '2-digit', minute: '2-digit', year: 'numeric', month: 'long', day: 'numeric' } - return d.toLocaleDateString("en-US", options).toLocaleLowerCase() -}
\ No newline at end of file |