Merge branch 'main' of https://github.com/hoppscotch/hoppscotch
This commit is contained in:
@@ -182,6 +182,7 @@ import { translateToNewRequest } from "@hoppscotch/data"
|
||||
import { currentUser$ } from "~/helpers/fb/auth"
|
||||
import * as teamUtils from "~/helpers/teams/utils"
|
||||
import { useReadonlyStream } from "~/helpers/utils/composables"
|
||||
import { parseInsomniaCollection } from "~/helpers/utils/parseInsomniaCollection"
|
||||
import {
|
||||
restCollections$,
|
||||
setRESTCollections,
|
||||
@@ -317,8 +318,12 @@ export default defineComponent({
|
||||
importFromJSON() {
|
||||
const reader = new FileReader()
|
||||
reader.onload = ({ target }) => {
|
||||
const content = target.result
|
||||
let content = target.result
|
||||
let collections = JSON.parse(content)
|
||||
if (this.isInsomniaCollection(collections)) {
|
||||
collections = parseInsomniaCollection(content)
|
||||
content = JSON.stringify(collections)
|
||||
}
|
||||
if (collections[0]) {
|
||||
const [name, folders, requests] = Object.keys(collections[0])
|
||||
if (
|
||||
@@ -334,7 +339,7 @@ export default defineComponent({
|
||||
) {
|
||||
// replace the variables, postman uses {{var}}, Hoppscotch uses <<var>>
|
||||
collections = JSON.parse(
|
||||
content.replaceAll(/{{([a-z]+)}}/gi, "<<$1>>")
|
||||
content.replaceAll(/{{([a-zA-Z_$][a-zA-Z_$0-9]*)}}/gi, "<<$1>>")
|
||||
)
|
||||
collections = [this.parsePostmanCollection(collections)]
|
||||
} else {
|
||||
@@ -550,6 +555,15 @@ export default defineComponent({
|
||||
hasFolder(item) {
|
||||
return Object.prototype.hasOwnProperty.call(item, "item")
|
||||
},
|
||||
isInsomniaCollection(collection) {
|
||||
if (typeof collection === "object") {
|
||||
return (
|
||||
Object.prototype.hasOwnProperty.call(collection, "__export_source") &&
|
||||
collection.__export_source.includes("insomnia")
|
||||
)
|
||||
}
|
||||
return false
|
||||
},
|
||||
},
|
||||
})
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user