chore: cleanup - remove writing request object to url

This commit is contained in:
liyasthomas
2021-11-22 15:02:29 +05:30
parent d0386ef86f
commit 508809eba1

View File

@@ -101,7 +101,6 @@
<script lang="ts">
import {
computed,
defineComponent,
onBeforeMount,
onBeforeUnmount,
@@ -109,7 +108,6 @@ import {
Ref,
ref,
useContext,
watch,
} from "@nuxtjs/composition-api"
import { Splitpanes, Pane } from "splitpanes"
import "splitpanes/dist/splitpanes.css"
@@ -118,7 +116,6 @@ import { Subscription } from "rxjs"
import isEqual from "lodash/isEqual"
import { useSetting } from "~/newstore/settings"
import {
restRequest$,
restActiveParamsCount$,
restActiveHeadersCount$,
getRESTRequest,
@@ -134,72 +131,16 @@ import {
} from "~/helpers/utils/composables"
import { loadRequestFromSync, startRequestSync } from "~/helpers/fb/request"
import { onLoggedIn } from "~/helpers/fb/auth"
import {
FormDataKeyValue,
HoppRESTRequest,
} from "~/helpers/types/HoppRESTRequest"
import { HoppRESTRequest } from "~/helpers/types/HoppRESTRequest"
import { oauthRedirect } from "~/helpers/oauth"
import { HoppRESTAuthOAuth2 } from "~/helpers/types/HoppRESTAuth"
import useWindowSize from "~/helpers/utils/useWindowSize"
function bindRequestToURLParams() {
const {
route,
app: { router },
} = useContext()
const request = useStream(restRequest$, getRESTRequest(), setRESTRequest)
// Process headers and params to proper values
const headers = computed(() => {
const filtered = request.value.headers.filter((x) => x.key !== "")
return filtered.length > 0 ? JSON.stringify(filtered) : null
})
const params = computed(() => {
const filtered = request.value.params.filter((x) => x.key !== "")
return filtered.length > 0 ? JSON.stringify(filtered) : null
})
const body = computed(() => {
const contentType = request.value.body.contentType
if (contentType === "multipart/form-data") {
const body = request.value.body.body as FormDataKeyValue[]
const filtered = body.filter((x) => x.key !== "")
return JSON.stringify({ body: filtered, contentType })
}
return JSON.stringify({ body: request.value.body.body, contentType })
})
// Combine them together to a cleaner value
const urlParams = computed(() => ({
v: request.value.v,
method: request.value.method,
endpoint: request.value.endpoint,
headers: headers.value,
params: params.value,
body: body.value,
}))
// Watch and update accordingly
watch(urlParams, () => {
history.replaceState(
window.location.href,
"",
`${router!.options.base}?${encodeURI(
Object.entries(urlParams.value)
.filter((x) => x[1] !== null)
.map((x) => `${x[0]}=${x[1]!}`)
.join("&")
)}`
)
})
// Now, we have to see the initial URL param and set that as the request
const { route } = useContext()
// Get URL parameters and set that as the request
onMounted(() => {
const query = route.value.query
// If query params are empty, or contains code or error param (these are from Oauth Redirect)
// We skip URL params parsing
if (Object.keys(query).length === 0 || query.code || query.error) return