chore: cleanup - remove writing request object to url
This commit is contained in:
@@ -101,7 +101,6 @@
|
|||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import {
|
import {
|
||||||
computed,
|
|
||||||
defineComponent,
|
defineComponent,
|
||||||
onBeforeMount,
|
onBeforeMount,
|
||||||
onBeforeUnmount,
|
onBeforeUnmount,
|
||||||
@@ -109,7 +108,6 @@ import {
|
|||||||
Ref,
|
Ref,
|
||||||
ref,
|
ref,
|
||||||
useContext,
|
useContext,
|
||||||
watch,
|
|
||||||
} from "@nuxtjs/composition-api"
|
} from "@nuxtjs/composition-api"
|
||||||
import { Splitpanes, Pane } from "splitpanes"
|
import { Splitpanes, Pane } from "splitpanes"
|
||||||
import "splitpanes/dist/splitpanes.css"
|
import "splitpanes/dist/splitpanes.css"
|
||||||
@@ -118,7 +116,6 @@ import { Subscription } from "rxjs"
|
|||||||
import isEqual from "lodash/isEqual"
|
import isEqual from "lodash/isEqual"
|
||||||
import { useSetting } from "~/newstore/settings"
|
import { useSetting } from "~/newstore/settings"
|
||||||
import {
|
import {
|
||||||
restRequest$,
|
|
||||||
restActiveParamsCount$,
|
restActiveParamsCount$,
|
||||||
restActiveHeadersCount$,
|
restActiveHeadersCount$,
|
||||||
getRESTRequest,
|
getRESTRequest,
|
||||||
@@ -134,72 +131,16 @@ import {
|
|||||||
} from "~/helpers/utils/composables"
|
} from "~/helpers/utils/composables"
|
||||||
import { loadRequestFromSync, startRequestSync } from "~/helpers/fb/request"
|
import { loadRequestFromSync, startRequestSync } from "~/helpers/fb/request"
|
||||||
import { onLoggedIn } from "~/helpers/fb/auth"
|
import { onLoggedIn } from "~/helpers/fb/auth"
|
||||||
import {
|
import { HoppRESTRequest } from "~/helpers/types/HoppRESTRequest"
|
||||||
FormDataKeyValue,
|
|
||||||
HoppRESTRequest,
|
|
||||||
} from "~/helpers/types/HoppRESTRequest"
|
|
||||||
import { oauthRedirect } from "~/helpers/oauth"
|
import { oauthRedirect } from "~/helpers/oauth"
|
||||||
import { HoppRESTAuthOAuth2 } from "~/helpers/types/HoppRESTAuth"
|
import { HoppRESTAuthOAuth2 } from "~/helpers/types/HoppRESTAuth"
|
||||||
import useWindowSize from "~/helpers/utils/useWindowSize"
|
import useWindowSize from "~/helpers/utils/useWindowSize"
|
||||||
|
|
||||||
function bindRequestToURLParams() {
|
function bindRequestToURLParams() {
|
||||||
const {
|
const { route } = useContext()
|
||||||
route,
|
// Get URL parameters and set that as the request
|
||||||
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
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
const query = route.value.query
|
const query = route.value.query
|
||||||
|
|
||||||
// If query params are empty, or contains code or error param (these are from Oauth Redirect)
|
// If query params are empty, or contains code or error param (these are from Oauth Redirect)
|
||||||
// We skip URL params parsing
|
// We skip URL params parsing
|
||||||
if (Object.keys(query).length === 0 || query.code || query.error) return
|
if (Object.keys(query).length === 0 || query.code || query.error) return
|
||||||
|
|||||||
Reference in New Issue
Block a user