fix: collection parser for hopp importer
This commit is contained in:
committed by
Andrew Bastin
parent
681a957611
commit
a9292eed9e
@@ -156,6 +156,7 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "@nuxtjs/composition-api"
|
||||
import { HoppRESTRequest, translateToNewRequest } from "@hoppscotch/data"
|
||||
import * as E from "fp-ts/Either"
|
||||
import { apolloClient } from "~/helpers/apollo"
|
||||
import {
|
||||
useAxios,
|
||||
@@ -173,6 +174,7 @@ import {
|
||||
Collection,
|
||||
makeCollection,
|
||||
} from "~/newstore/collections"
|
||||
import { RESTCollectionImporters } from "~/helpers/import-export/import"
|
||||
|
||||
const props = defineProps<{
|
||||
show: boolean
|
||||
@@ -557,7 +559,7 @@ const importFromJSON = () => {
|
||||
|
||||
const reader = new FileReader()
|
||||
|
||||
reader.onload = ({ target }) => {
|
||||
reader.onload = async ({ target }) => {
|
||||
let content = target!.result as string | null
|
||||
|
||||
if (!content) {
|
||||
@@ -566,6 +568,8 @@ const importFromJSON = () => {
|
||||
}
|
||||
|
||||
let collections = JSON.parse(content)
|
||||
await hoppImporterOutput(content)
|
||||
|
||||
if (isInsomniaCollection(collections)) {
|
||||
collections = parseInsomniaCollection(content)
|
||||
content = JSON.stringify(collections)
|
||||
@@ -653,4 +657,16 @@ const exportJSON = () => {
|
||||
URL.revokeObjectURL(url)
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
const hoppImporter = RESTCollectionImporters[0]
|
||||
|
||||
const hoppImporterOutput = async (content: string) => {
|
||||
const importedFunc = await hoppImporter.importer()
|
||||
const result = await importedFunc(content)()
|
||||
if (E.isLeft(result)) {
|
||||
console.log("error", result.left)
|
||||
} else if (E.isRight(result)) {
|
||||
console.log("success", result)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -8,10 +8,13 @@ import {
|
||||
translateToNewRESTCollection,
|
||||
} from "~/newstore/collections"
|
||||
|
||||
const importer: HoppImporter<Collection<HoppRESTRequest>> = (content) =>
|
||||
const importer: HoppImporter<Collection<HoppRESTRequest>[]> = (content) =>
|
||||
pipe(
|
||||
E.tryCatch(
|
||||
() => translateToNewRESTCollection(content),
|
||||
() =>
|
||||
JSON.parse(content).map((coll: any) =>
|
||||
translateToNewRESTCollection(coll)
|
||||
),
|
||||
() => IMPORTER_INVALID_FILE_FORMAT
|
||||
),
|
||||
TE.fromEither
|
||||
|
||||
@@ -30,7 +30,7 @@ export type HoppImporterDefintion<T> = {
|
||||
}
|
||||
|
||||
export const RESTCollectionImporters: HoppImporterDefintion<
|
||||
Collection<HoppRESTRequest>
|
||||
Collection<HoppRESTRequest>[]
|
||||
>[] = [
|
||||
{
|
||||
name: "Hoppscotch REST Collection",
|
||||
|
||||
@@ -236,7 +236,7 @@
|
||||
"from_postman": "Import from Postman",
|
||||
"from_url": "Import from URL",
|
||||
"gist_url": "Enter Gist URL",
|
||||
"json": "Import from JSON",
|
||||
"json": "Import from file",
|
||||
"title": "Import"
|
||||
},
|
||||
"layout": {
|
||||
|
||||
Reference in New Issue
Block a user