chore: split url and file importer steps

This commit is contained in:
liyasthomas
2022-01-11 16:04:42 +05:30
parent f6fc3782b5
commit 04d73a855d
11 changed files with 139 additions and 99 deletions

View File

@@ -0,0 +1,41 @@
import { pipe } from "fp-ts/function"
import * as TE from "fp-ts/TaskEither"
import * as E from "fp-ts/Either"
import { step } from "../steps"
import { defineImporter, IMPORTER_INVALID_FILE_FORMAT } from "."
import { translateToNewRESTCollection } from "~/newstore/collections"
export default defineImporter({
name: "import.gist",
icon: "github",
steps: [
step({
stepName: "URL_IMPORT",
metadata: {
placeholder: "import.gist_url",
},
}),
] as const,
importer: ([content]) =>
pipe(
E.tryCatch(
async () => {
await fetch(
`https://api.github.com/gists/${content.split("/").pop()}`,
{
headers: {
Accept: "application/vnd.github.v3+json",
},
}
).then((files) => {
debugger
return JSON.parse(Object.values(files)[0].content).map(
(coll: any) => translateToNewRESTCollection(coll)
)
})
},
() => IMPORTER_INVALID_FILE_FORMAT
),
TE.fromEither
),
})

View File

@@ -10,7 +10,7 @@ export default defineImporter({
icon: "folder-plus",
steps: [
step({
stepName: "FILE_OR_URL_IMPORT",
stepName: "FILE_IMPORT",
metadata: {
acceptedFileTypes: "application/json",
},

View File

@@ -2,10 +2,12 @@ import HoppRESTCollImporter from "./hopp"
import OpenAPIImporter from "./openapi"
import PostmanImporter from "./postman"
import InsomniaImporter from "./insomnia"
import GistImporter from "./gist"
export const RESTCollectionImporters = [
HoppRESTCollImporter,
OpenAPIImporter,
PostmanImporter,
InsomniaImporter,
GistImporter,
] as const

View File

@@ -14,7 +14,7 @@ export default defineImporter({
icon: "insomnia",
steps: [
step({
stepName: "FILE_OR_URL_IMPORT",
stepName: "FILE_IMPORT",
metadata: {
acceptedFileTypes: ".json",
},

View File

@@ -589,7 +589,7 @@ export default defineImporter({
icon: "file",
steps: [
step({
stepName: "FILE_OR_URL_IMPORT",
stepName: "FILE_IMPORT",
metadata: {
acceptedFileTypes: ".json, .yaml, .yml",
},

View File

@@ -183,7 +183,7 @@ export default defineImporter({
icon: "postman",
steps: [
step({
stepName: "FILE_OR_URL_IMPORT",
stepName: "FILE_IMPORT",
metadata: {
acceptedFileTypes: ".json",
},

View File

@@ -3,16 +3,22 @@
* Add an entry here when you define a step
*/
export type StepDefinition = {
FILE_OR_URL_IMPORT: {
FILE_IMPORT: {
returnType: string
metadata: {
acceptedFileTypes: string
}
} // String content of the file/url
} // String content of the file
TARGET_MY_COLLECTION: {
returnType: number
metadata: never
} // folderPath
URL_IMPORT: {
returnType: string
metadata: {
placeholder: string
}
} // String content of the url
}
/**