refactor: eliminate redundancy
This commit is contained in:
@@ -48,7 +48,7 @@ import { getTeamCollectionJSON } from "~/helpers/backend/helpers"
|
|||||||
import { platform } from "~/platform"
|
import { platform } from "~/platform"
|
||||||
|
|
||||||
import { initializeDownloadCollection } from "~/helpers/import-export/export"
|
import { initializeDownloadCollection } from "~/helpers/import-export/export"
|
||||||
import { collectionsGistExporter } from "~/helpers/import-export/export/gistExport"
|
import { gistExporter } from "~/helpers/import-export/export/gist"
|
||||||
import { myCollectionsExporter } from "~/helpers/import-export/export/myCollections"
|
import { myCollectionsExporter } from "~/helpers/import-export/export/myCollections"
|
||||||
import { teamCollectionsExporter } from "~/helpers/import-export/export/teamCollections"
|
import { teamCollectionsExporter } from "~/helpers/import-export/export/teamCollections"
|
||||||
|
|
||||||
@@ -470,11 +470,11 @@ const HoppGistCollectionsExporter: ImporterOrExporter = {
|
|||||||
icon: IconGithub,
|
icon: IconGithub,
|
||||||
disabled: !currentUser.value
|
disabled: !currentUser.value
|
||||||
? true
|
? true
|
||||||
: currentUser.value.provider !== "github.com",
|
: currentUser.value?.provider !== "github.com",
|
||||||
title:
|
title:
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
currentUser?.value.provider === "github.com"
|
currentUser?.value?.provider === "github.com"
|
||||||
? "export.create_secret_gist_tooltip_text"
|
? "export.create_secret_gist_tooltip_text"
|
||||||
: "export.require_github",
|
: "export.require_github",
|
||||||
applicableTo: ["personal-workspace", "team-workspace"],
|
applicableTo: ["personal-workspace", "team-workspace"],
|
||||||
@@ -497,10 +497,7 @@ const HoppGistCollectionsExporter: ImporterOrExporter = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (E.isRight(collectionJSON)) {
|
if (E.isRight(collectionJSON)) {
|
||||||
const res = await collectionsGistExporter(
|
const res = await gistExporter(collectionJSON.right, accessToken)
|
||||||
collectionJSON.right,
|
|
||||||
accessToken
|
|
||||||
)
|
|
||||||
|
|
||||||
console.log(JSON.stringify(res, null, 2))
|
console.log(JSON.stringify(res, null, 2))
|
||||||
|
|
||||||
@@ -608,3 +605,4 @@ const getCollectionJSON = async () => {
|
|||||||
return E.left("INVALID_SELECTED_TEAM_OR_INVALID_COLLECTION_TYPE")
|
return E.left("INVALID_SELECTED_TEAM_OR_INVALID_COLLECTION_TYPE")
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
~/helpers/import-export/export/gist
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ import {
|
|||||||
} from "~/newstore/collections"
|
} from "~/newstore/collections"
|
||||||
import { hoppGqlCollectionsImporter } from "~/helpers/import-export/import/hoppGql"
|
import { hoppGqlCollectionsImporter } from "~/helpers/import-export/import/hoppGql"
|
||||||
import { gqlCollectionsExporter } from "~/helpers/import-export/export/gqlCollections"
|
import { gqlCollectionsExporter } from "~/helpers/import-export/export/gqlCollections"
|
||||||
import { gqlCollectionsGistExporter } from "~/helpers/import-export/export/gqlCollectionsGistExporter"
|
import { gistExporter } from "~/helpers/import-export/export/gist"
|
||||||
import { computed } from "vue"
|
import { computed } from "vue"
|
||||||
import { hoppGQLImporter } from "~/helpers/import-export/import/hopp"
|
import { hoppGQLImporter } from "~/helpers/import-export/import/hopp"
|
||||||
|
|
||||||
@@ -165,13 +165,13 @@ const GqlCollectionsGistExporter: ImporterOrExporter = {
|
|||||||
title:
|
title:
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
currentUser?.value.provider === "github.com"
|
currentUser?.value?.provider === "github.com"
|
||||||
? "export.create_secret_gist_tooltip_text"
|
? "export.create_secret_gist_tooltip_text"
|
||||||
: "export.require_github",
|
: "export.require_github",
|
||||||
icon: IconUser,
|
icon: IconUser,
|
||||||
disabled: !currentUser.value
|
disabled: !currentUser.value
|
||||||
? true
|
? true
|
||||||
: currentUser.value.provider !== "github.com",
|
: currentUser.value?.provider !== "github.com",
|
||||||
applicableTo: ["personal-workspace"],
|
applicableTo: ["personal-workspace"],
|
||||||
isLoading: isGqlCollectionGistExportInProgress,
|
isLoading: isGqlCollectionGistExportInProgress,
|
||||||
},
|
},
|
||||||
@@ -190,7 +190,7 @@ const GqlCollectionsGistExporter: ImporterOrExporter = {
|
|||||||
const accessToken = currentUser.value?.accessToken
|
const accessToken = currentUser.value?.accessToken
|
||||||
|
|
||||||
if (accessToken) {
|
if (accessToken) {
|
||||||
const res = await gqlCollectionsGistExporter(
|
const res = await gistExporter(
|
||||||
JSON.stringify(gqlCollections.value),
|
JSON.stringify(gqlCollections.value),
|
||||||
accessToken
|
accessToken
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ import { initializeDownloadCollection } from "~/helpers/import-export/export"
|
|||||||
import { computed } from "vue"
|
import { computed } from "vue"
|
||||||
import { useReadonlyStream } from "~/composables/stream"
|
import { useReadonlyStream } from "~/composables/stream"
|
||||||
import { environmentsExporter } from "~/helpers/import-export/export/environments"
|
import { environmentsExporter } from "~/helpers/import-export/export/environments"
|
||||||
import { environmentsGistExporter } from "~/helpers/import-export/export/environmentsGistExport"
|
import { gistExporter } from "~/helpers/import-export/export/gist"
|
||||||
import { platform } from "~/platform"
|
import { platform } from "~/platform"
|
||||||
|
|
||||||
const t = useI18n()
|
const t = useI18n()
|
||||||
@@ -265,13 +265,13 @@ const HoppEnvironmentsGistExporter: ImporterOrExporter = {
|
|||||||
title:
|
title:
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
currentUser?.value.provider === "github.com"
|
currentUser?.value?.provider === "github.com"
|
||||||
? "export.create_secret_gist_tooltip_text"
|
? "export.create_secret_gist_tooltip_text"
|
||||||
: "export.require_github",
|
: "export.require_github",
|
||||||
icon: IconUser,
|
icon: IconUser,
|
||||||
disabled: !currentUser.value
|
disabled: !currentUser.value
|
||||||
? true
|
? true
|
||||||
: currentUser.value.provider !== "github.com",
|
: currentUser.value?.provider !== "github.com",
|
||||||
applicableTo: ["personal-workspace", "team-workspace"],
|
applicableTo: ["personal-workspace", "team-workspace"],
|
||||||
isLoading: isEnvironmentGistExportInProgress,
|
isLoading: isEnvironmentGistExportInProgress,
|
||||||
},
|
},
|
||||||
@@ -290,9 +290,10 @@ const HoppEnvironmentsGistExporter: ImporterOrExporter = {
|
|||||||
const accessToken = currentUser.value?.accessToken
|
const accessToken = currentUser.value?.accessToken
|
||||||
|
|
||||||
if (accessToken) {
|
if (accessToken) {
|
||||||
const res = await environmentsGistExporter(
|
const res = await gistExporter(
|
||||||
JSON.stringify(environmentJson.value),
|
JSON.stringify(environmentJson.value),
|
||||||
accessToken
|
accessToken,
|
||||||
|
"hoppscotch-environment.json"
|
||||||
)
|
)
|
||||||
|
|
||||||
if (E.isLeft(res)) {
|
if (E.isLeft(res)) {
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
import * as E from "fp-ts/Either"
|
|
||||||
import { createGist } from "~/helpers/gist"
|
|
||||||
|
|
||||||
export const environmentsGistExporter = async (
|
|
||||||
environmentsJSON: string,
|
|
||||||
accessToken: string
|
|
||||||
) => {
|
|
||||||
const res = await createGist(
|
|
||||||
environmentsJSON,
|
|
||||||
"hoppscotch-collections.json",
|
|
||||||
accessToken
|
|
||||||
)()
|
|
||||||
|
|
||||||
if (E.isLeft(res)) {
|
|
||||||
return E.left(res.left)
|
|
||||||
}
|
|
||||||
return E.right(res.right.data.html_url as string)
|
|
||||||
}
|
|
||||||
@@ -1,19 +1,16 @@
|
|||||||
import { createGist } from "~/helpers/gist"
|
import { createGist } from "~/helpers/gist"
|
||||||
import * as E from "fp-ts/Either"
|
import * as E from "fp-ts/Either"
|
||||||
|
|
||||||
export const collectionsGistExporter = async (
|
export const gistExporter = async (
|
||||||
collectionJSON: string,
|
JSONFileContents: string,
|
||||||
accessToken: string
|
accessToken: string,
|
||||||
|
fileName = "hoppscotch-collections.json"
|
||||||
) => {
|
) => {
|
||||||
if (!accessToken) {
|
if (!accessToken) {
|
||||||
return E.left("Invalid User")
|
return E.left("Invalid User")
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await createGist(
|
const res = await createGist(JSONFileContents, fileName, accessToken)()
|
||||||
collectionJSON,
|
|
||||||
"hoppscotch-collections.json",
|
|
||||||
accessToken
|
|
||||||
)()
|
|
||||||
|
|
||||||
if (E.isLeft(res)) {
|
if (E.isLeft(res)) {
|
||||||
return E.left(res.left)
|
return E.left(res.left)
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
import * as E from "fp-ts/Either"
|
|
||||||
import { createGist } from "~/helpers/gist"
|
|
||||||
|
|
||||||
export const gqlCollectionsGistExporter = async (
|
|
||||||
gqlCollectionsJSON: string,
|
|
||||||
accessToken: string
|
|
||||||
) => {
|
|
||||||
const res = await createGist(
|
|
||||||
gqlCollectionsJSON,
|
|
||||||
"hoppscotch-collections.json",
|
|
||||||
accessToken
|
|
||||||
)()
|
|
||||||
|
|
||||||
if (E.isLeft(res)) {
|
|
||||||
return E.left(res.left)
|
|
||||||
}
|
|
||||||
return E.right(res.right.data.html_url as string)
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user