refactor: eliminate redundancy

This commit is contained in:
jamesgeorge007
2023-12-18 23:29:35 +05:30
parent 2affb21d22
commit e23bc2d864
6 changed files with 20 additions and 60 deletions

View File

@@ -48,7 +48,7 @@ import { getTeamCollectionJSON } from "~/helpers/backend/helpers"
import { platform } from "~/platform"
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 { teamCollectionsExporter } from "~/helpers/import-export/export/teamCollections"
@@ -470,11 +470,11 @@ const HoppGistCollectionsExporter: ImporterOrExporter = {
icon: IconGithub,
disabled: !currentUser.value
? true
: currentUser.value.provider !== "github.com",
: currentUser.value?.provider !== "github.com",
title:
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
currentUser?.value.provider === "github.com"
currentUser?.value?.provider === "github.com"
? "export.create_secret_gist_tooltip_text"
: "export.require_github",
applicableTo: ["personal-workspace", "team-workspace"],
@@ -497,10 +497,7 @@ const HoppGistCollectionsExporter: ImporterOrExporter = {
}
if (E.isRight(collectionJSON)) {
const res = await collectionsGistExporter(
collectionJSON.right,
accessToken
)
const res = await gistExporter(collectionJSON.right, accessToken)
console.log(JSON.stringify(res, null, 2))
@@ -608,3 +605,4 @@ const getCollectionJSON = async () => {
return E.left("INVALID_SELECTED_TEAM_OR_INVALID_COLLECTION_TYPE")
}
</script>
~/helpers/import-export/export/gist

View File

@@ -31,7 +31,7 @@ import {
} from "~/newstore/collections"
import { hoppGqlCollectionsImporter } from "~/helpers/import-export/import/hoppGql"
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 { hoppGQLImporter } from "~/helpers/import-export/import/hopp"
@@ -165,13 +165,13 @@ const GqlCollectionsGistExporter: ImporterOrExporter = {
title:
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
currentUser?.value.provider === "github.com"
currentUser?.value?.provider === "github.com"
? "export.create_secret_gist_tooltip_text"
: "export.require_github",
icon: IconUser,
disabled: !currentUser.value
? true
: currentUser.value.provider !== "github.com",
: currentUser.value?.provider !== "github.com",
applicableTo: ["personal-workspace"],
isLoading: isGqlCollectionGistExportInProgress,
},
@@ -190,7 +190,7 @@ const GqlCollectionsGistExporter: ImporterOrExporter = {
const accessToken = currentUser.value?.accessToken
if (accessToken) {
const res = await gqlCollectionsGistExporter(
const res = await gistExporter(
JSON.stringify(gqlCollections.value),
accessToken
)

View File

@@ -40,7 +40,7 @@ import { initializeDownloadCollection } from "~/helpers/import-export/export"
import { computed } from "vue"
import { useReadonlyStream } from "~/composables/stream"
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"
const t = useI18n()
@@ -265,13 +265,13 @@ const HoppEnvironmentsGistExporter: ImporterOrExporter = {
title:
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
currentUser?.value.provider === "github.com"
currentUser?.value?.provider === "github.com"
? "export.create_secret_gist_tooltip_text"
: "export.require_github",
icon: IconUser,
disabled: !currentUser.value
? true
: currentUser.value.provider !== "github.com",
: currentUser.value?.provider !== "github.com",
applicableTo: ["personal-workspace", "team-workspace"],
isLoading: isEnvironmentGistExportInProgress,
},
@@ -290,9 +290,10 @@ const HoppEnvironmentsGistExporter: ImporterOrExporter = {
const accessToken = currentUser.value?.accessToken
if (accessToken) {
const res = await environmentsGistExporter(
const res = await gistExporter(
JSON.stringify(environmentJson.value),
accessToken
accessToken,
"hoppscotch-environment.json"
)
if (E.isLeft(res)) {

View File

@@ -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)
}

View File

@@ -1,19 +1,16 @@
import { createGist } from "~/helpers/gist"
import * as E from "fp-ts/Either"
export const collectionsGistExporter = async (
collectionJSON: string,
accessToken: string
export const gistExporter = async (
JSONFileContents: string,
accessToken: string,
fileName = "hoppscotch-collections.json"
) => {
if (!accessToken) {
return E.left("Invalid User")
}
const res = await createGist(
collectionJSON,
"hoppscotch-collections.json",
accessToken
)()
const res = await createGist(JSONFileContents, fileName, accessToken)()
if (E.isLeft(res)) {
return E.left(res.left)

View File

@@ -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)
}