From e8d1e38b66d2496dbdcd3a0578abd7f1927ecd26 Mon Sep 17 00:00:00 2001 From: "tristan-mihai.radulescu" Date: Wed, 13 Nov 2024 10:21:07 +0100 Subject: [PATCH] feat(GIST-90): fixed curl command and refactor raw url generation --- src/app/(gistLayout)/mygist/[gistId]/page.tsx | 3 ++- src/app/(gistLayout)/org/[orgId]/gist/[gistId]/page.tsx | 3 ++- src/components/ui/gist-details.tsx | 9 ++------- src/lib/utils.ts | 8 ++++++++ 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/app/(gistLayout)/mygist/[gistId]/page.tsx b/src/app/(gistLayout)/mygist/[gistId]/page.tsx index 4ed521a..e165ed0 100644 --- a/src/app/(gistLayout)/mygist/[gistId]/page.tsx +++ b/src/app/(gistLayout)/mygist/[gistId]/page.tsx @@ -3,6 +3,7 @@ import React from "react" import MyGistIdPage from "./page-ui" import { useGist, usePatchGistContent, usePatchGistName } from "@/lib/queries/gists.queries" import { useToast } from "@/components/shadcn/use-toast" +import { getRawGistURL } from "@/lib/utils" interface MyGistIdFeaturePageProps { params: { @@ -67,7 +68,7 @@ export default function MyGistIdFeaturePage({ params }: MyGistIdFeaturePageProps } const onCopyCurl = () => { - const curlCommand = `curl https://raw.gists.app/${gistId} | /bin/bash` + const curlCommand = `curl ${getRawGistURL(gistId)} -o- | /bin/bash` toast({ title: "Gist Copied", description: "Your curl command has been copied successfully", diff --git a/src/app/(gistLayout)/org/[orgId]/gist/[gistId]/page.tsx b/src/app/(gistLayout)/org/[orgId]/gist/[gistId]/page.tsx index ac3ceb6..4ac7d00 100644 --- a/src/app/(gistLayout)/org/[orgId]/gist/[gistId]/page.tsx +++ b/src/app/(gistLayout)/org/[orgId]/gist/[gistId]/page.tsx @@ -3,6 +3,7 @@ import { useToast } from "@/components/shadcn/use-toast" import GistDetails from "@/components/ui/gist-details" import { useGist, usePatchGistContent, usePatchGistName } from "@/lib/queries/gists.queries" import { useOrg } from "@/lib/queries/orgs.queries" +import { getRawGistURL } from "@/lib/utils" import React from "react" interface MyOrgGistIdFeaturePageProps { @@ -78,7 +79,7 @@ export default function MyOrgGistIdFeaturePage({ params }: MyOrgGistIdFeaturePag } const onCopyCurl = () => { - const curlCommand = `curl https://raw.gists.app/${gistId} | /bin/bash` + const curlCommand = `curl ${getRawGistURL(gistId)} -o- | /bin/bash` toast({ title: "Gist Copied", description: "Your curl command has been copied successfully", diff --git a/src/components/ui/gist-details.tsx b/src/components/ui/gist-details.tsx index 93e6ba3..f4d873b 100644 --- a/src/components/ui/gist-details.tsx +++ b/src/components/ui/gist-details.tsx @@ -16,7 +16,7 @@ import { useState } from "react" import { Codearea } from "../shadcn/codearea" import { getLanguage } from "@/lib/language" import TooltipShortcut, { TooltipShortcutTrigger } from "./tooltip-shortcut" -import { getBackendURL } from "@/lib/utils" +import { getBackendURL, getRawGistURL } from "@/lib/utils" import { SidebarTrigger } from "../shadcn/sidebar" import { Button } from "../shadcn/button" @@ -56,12 +56,7 @@ export default function GistDetails({ const onOpenPlainText = (gistID: string) => { // if production go to https://raw.gists.app/{gistID} console.log(process.env.NODE_ENV) - if (process.env.NODE_ENV === "production") { - const raw_url = getBackendURL().replace("api", "raw") + "/" + gistID - window.open(raw_url, "_blank") - return - } - window.open(getBackendURL() + "/gists/raw/" + gistID, "_blank") + window.open(getRawGistURL(gistID), "_blank") } return ( diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 9e95e94..2da1e49 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -8,3 +8,11 @@ export function cn(...inputs: ClassValue[]) { export function getBackendURL() { return process.env.NEXT_PUBLIC_BACKEND_URL || "https://api.gists.app" } + +export function getRawGistURL(id: string) { + if (process.env.NODE_ENV === "production") { + const raw_url = getBackendURL().replace("api", "raw") + "/" + id + return raw_url + } + return getBackendURL() + "/gists/raw/" + id +}