From 750487e8adacb5b45ea0fd174ef4d5396a344ce2 Mon Sep 17 00:00:00 2001 From: Andrew Bastin Date: Tue, 15 Mar 2022 21:16:22 +0530 Subject: [PATCH] refactor: correct type error in useDownloadResponse --- .../lenses/composables/useDownloadResponse.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/hoppscotch-app/helpers/lenses/composables/useDownloadResponse.ts b/packages/hoppscotch-app/helpers/lenses/composables/useDownloadResponse.ts index acc357929..95a070169 100644 --- a/packages/hoppscotch-app/helpers/lenses/composables/useDownloadResponse.ts +++ b/packages/hoppscotch-app/helpers/lenses/composables/useDownloadResponse.ts @@ -1,3 +1,6 @@ +import * as S from "fp-ts/string" +import * as RNEA from "fp-ts/ReadonlyNonEmptyArray" +import { pipe } from "fp-ts/function" import { Ref, ref } from "@nuxtjs/composition-api" import { useI18n, useToast } from "~/helpers/utils/composables" @@ -20,8 +23,18 @@ export default function useDownloadResponse( const a = document.createElement("a") const url = URL.createObjectURL(file) a.href = url - // TODO get uri from meta - a.download = `${url.split("/").pop().split("#")[0].split("?")[0]}` + + // TODO: get uri from meta + a.download = pipe( + url, + S.split("/"), + RNEA.last, + S.split("#"), + RNEA.head, + S.split("?"), + RNEA.head + ) + document.body.appendChild(a) a.click() downloadIcon.value = "check"